[Q] Android + jy-mcu = not receiving full string - Android Q&A, Help & Troubleshooting

so i am developing an app to go with my home made alarm system...i am using the jy-mcu bluetooth module for arduino...it is running at 56700 baud...but when i try to transmit a string, either it gets chopped up or it is missing parts...can someone give my code a once over and tell me if it is anything on the Android side of things??? i basically moded the Bluetooth Chat sample in the api 8 folder...so i know it worked once before.
Here is some of the data from the logcat:
11-20 01:35:53.754: I/GET MESSAGE(16751): why di
11-20 01:35:53.764: I/GET MESSAGE(16751): d i never know streetlight manifesto covered a postal service son
11-20 01:46:10.436: I/GET MESSAGE(16751): w
11-20 01:46:10.446: I/GET MESSAGE(16751): hy did i never know streetlight manifesto covered a postal service son
11-20 01:46:15.551: I/GET MESSAGE(16751): w
11-20 01:46:15.581: I/GET MESSAGE(16751): ce sonii never know streetlight manifesto covered a posta
11-20 01:46:15.591: I/GET MESSAGE(16751): ce soni
11-20 01:46:15.591: I/GET MESSAGE(16751): ce son
11-20 01:46:22.558: I/GET MESSAGE(16751): w
11-20 01:46:22.568: I/GET MESSAGE(16751): hy did i never know streetlight manifesto covered a postal service son
the sentence was supposed to be "why did i never know streetlight manifesto covered a postal service son"
any idea
ps code is include via zip/rar

I figured out where it is erroring out
I have figured out where i am having the issues...it is on the ConnectedThread...here is the code:
Code:
public void run()
{
Log.i(TAG, "BEGIN mConnectedThread");
byte[] buffer = new byte[1024];
int bytes;
String mm = "";
while (true)
{
try
{
bytes = mmInStream.read(buffer);
mm += new String(buffer,0,bytes);
if (mm.contains("%"))
{
String[] temp = mm.split("%");
mHandler.obtainMessage(Main.MESSAGE_READ, bytes, -1, temp[0])
.sendToTarget();
if (temp.length > 1)
{
mm = "";
for(int i = 1; i < temp.length - 1; i++)
{
mm += temp[i];
if(i + 1 < mm.length() - 1)
{
mm += "+";
}
else
{
}
}
}
}
}
catch (IOException e)
{
Log.e(TAG, "disconnected", e);
connectionLost();
break;
}
catch (Exception e)
{
Log.e(TAG, "ERROR-RUN", e);
}
}
}
So here is what it is SUPPOSED to do...it is supposed to read in the data from the BlueTooth being sent from my Arduino...the commands are delimited by a +...let say it sends the string "update-1-2-2-1-2-1-1-1-2-2-1-2+"...it will split the string at the +...send the most recent command to the handler...lets say it is being slow and receives 2 commands "update-1-2-2-1-2-1-1-1-2-2-1-2+update-1-2-2-1-2-1-1-1-2-2-1-2+"...still not a problem...but lets say it hits the end of the buffer half way thur like "update-1-2-2-1-2-1-1-1-2-2-1-2+update-1-2-"...it is supposed to save the 2nd part and wait for the remainder...but it isn't saving it...when i use debug mode...it for some reason starts to get to the for loop and then just ends up back at the beginning of the while...truth be told i am NOT good at Java...i am a VB programmer at heart (be my guest to point fingers...lol)...does anyone see any issues with the code???

Related

[Q] Exception when receiving an Intent

Hello,
we are developing something to watch the battery drain - logging battery % steps - and get sometimes an exception into our Uncaught Exception Handler looks like this:
Code:
07-15 12:29:41.815 D/AndroidRuntime(27028): Shutting down VM
07-15 12:29:41.815 W/dalvikvm(27028): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
07-15 12:29:41.815 E/DrainGuardService(27028): Default uncaught exception handler
07-15 12:29:41.815 E/DrainGuardService(27028): Caught throwable java.lang.RuntimeException: [B]Error receiving broadcast Intent [/B]{ act=[B]android.intent.action.BATTERY_CHANGED[/B] flg=0x60000000 (has extras) } in [email protected] for thread Thread[main,5,main]
Thats our Codesnipplet
Code:
private IntentFilter batteryLevelFilterpercentchange = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
private BroadcastReceiver batteryLevelReceiver3;
Code:
batteryLevelReceiver3 = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
int level = -1;
try
{
int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
if (rawlevel >= 0 && scale > 0) {
level = (rawlevel * 100) / scale;
}
...
We tried to catch the exception with a try-finally but it looks like we are crashing before.
Funny thing: It happens only 1-2 times a week but we want to fix it. How/where can we catch this exception correctly without ending the app?
I also think that its not our mistake, because the system sends the message with the intent. but sometimes it seems not to be filled in correctly.
Thanks in advance!
Here's a pretty cookie cutter BroadcastReceiver that I use frequently(Modified with your code). Let me know if it helps.
Code:
private class BatteryLevelReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null)
return;
if (context == null)
return;
String action = intent.getAction();
if (action == null)
return;
if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
int level = -1;
int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
if (rawlevel >= 0 && scale > 0) {
level = (rawlevel * 100) / scale;
}
else {
// DO SOMETHING ELSE
}
}
}
Thanks, will try tomorrow and report back in a few days after testing.
After optimizing my code - had ~5 batterylevel receiver xD - and implementing your code, everything works like a charm.
Many thanks!
Thanks so much for the code! I was ahving the same issue, now it's solved!!!! Thanks again
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums & Read the Forum Rules
Moving to Q&A

[Q] Android bluetooth pairing Security

Since I upgraded to android 4.2 I'm having trouble when i try to pair a device The device should be paired but now it says that acros_user_permission is required.
Here is the error log :
error:code 3: java.lang.SecurityException:: Permission Denial: broadcast from android asks to run as user -1 but is calling from user0; this requires android.permission.INTERACT_ACROSS_USERS_FULL or android.permission.INTERACT_ACROSS_USERS.
and here my method :
public boolean ensurePaired(BluetoothDevice bd) {
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(bd.getAddress());
boolean paired = false;
Log.d(TAG,"Pairing with Bluetooth device with name " + device.getName()+" and address "+device.getAddress());
try {
Method m = device.getClass().getMethod("createBond");
paired = (Boolean) m.invoke(device);
} catch (Exception e)
{
return paired;
}
Log.d("BluetoothPlugin -", "Returning "+ "Result: "+paired);
return paired;
}

[Q] My research on rooting Blade Apex 2

Hello XDA, i have been looking for a way to root the ZTE Blade Apex2 from Orange Spain (also known as Orange Hi 4G), and i found some interesting things about how the system manages the partitions and how the OTA update is done.
Packed inside Recovery.img in /etc/recovery.fstab we can read this:
Code:
# mount point fstype device [device2] [length=]
/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,barrier=1 wait
/dev/block/platform/msm_sdcc.1/by-name/cache /cache ext4 noatime,nosuid,nodev,barrier=1,data=ordered wait,check
As you can see, the property BARRIER is enabled on all the mountpoints "interesting" to be accesed, so we CANT remount this mountpoints.
So i changed my mind to look for another way to try to make the trick, and unexpectedly, i found a nice glitch on the way how the official updater does the ota update process.
I decrypted the app itself from the decompyleandroid web, and got surprised.
The first thing called my attention is that the reboot on recovery to install the ota update, DONT check the signature of the file, its done by the otaupdater itself, so, we can try a replace file trick to change the target file.
Another interesting thing i found, is in the otaupdater, found this interesting piece of code:
Code:
[HIDE]package com.orange.authentication.utunneling.ttg;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
public class TtgX509TrustManager
implements X509TrustManager
{
private static final String KEYSTORE = "AAAAAQAAABSR52UCnjiSFiwLKyzthZxY4sJ0ZQAABdEBAAh2ZXJpc2lnbgAAASw2S2EsAAAAAAAFWC41MDkAAAMGMIIDAjCCAmsCEH3Z/gfPqB63EHln+6eJNMYwDQYJKoZIhvcNAQEFBQAwgcExCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE8MDoGA1UECxMzQ2xhc3MgMyBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMTowOAYDVQQLEzEoYykgMTk5OCBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMB4XDTk4MDUxODAwMDAwMFoXDTI4MDgwMTIzNTk1OVowgcExCzAJBgNVB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VyaXNpZ24uY29tL2NwczAqBggrBgEFBQcCAjAeGhxodHRwczovL3d3dy52ZXJpc2lnbi5jb20vcnBhMDQGA1UdHwQtMCswKaAnoCWGI2h0dHA6Ly9jcmwudmVyaXNpZ24uY29tL3BjYTMtZzIuY3JsMA4GA1UdDwEB/wQEAwIBBjBtBggrBgEFBQcBDARhMF+hXaBbMFkwVzBVFglpbWFnZS9naWYwITAfMAcGBSsOAwIaBBSP5dMahqyNjmvDz4Bq1EgYLHsZLjAlFiNodHRwOi8vbG9nby52ZXJpc2lnbi5jb20vdnNsb2dvLmdpZjApBgNVHREEIjAgpB4wHDEaMBgGA1UEAxMRQ2xhc3MzQ0EyMDQ4LTEtNTIwHQYDVR0OBBYEFKXvCxHOwEEDo0plkEiyHOBXLX1HMIHnBgNVHSMEgd8wgdyhgcekgcQwgcExCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE8MDoGA1UECxMzQ2xhc3MgMyBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMTowOAYDVQQLEzEoYykgMTk5OCBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrghB92f4Hz6getxB5Z/uniTTGMA0GCSqGSIb3DQEBBQUAA4GBAGN0Lz1Tqi+X7CYRZhr+8d5BJxnSf9jBHPniOFY6H5CuOcUgdav4bC1nHynCIdcUiGNLsJsnY5H48KMBJLb7j+M9AgtvVP7UzNvWhb98lR5eYhHB2QmcQrmy1KotmDojYMyimvFu6M+O0Ro8XhnF15s1sAIjJOUFuNWI4+D6ufRfAF0Slrj4O266ePon5MC54zEX3hju";
[B][I][SIZE="3"][COLOR="Red"]private static final char PASSPHRASE[] = "orange".toCharArray();[/COLOR][/SIZE][/I][/B]
private X509TrustManager mTrustManager;
public TtgX509TrustManager(boolean flag)
throws GeneralSecurityException, IOException
{
if (flag)
{
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(newInputStream(decodeBase64("AAAAAQAAABSR52UCnjiSFiwLKyzthZxY4sJ0ZQAABdEBAAh2ZXJpc2lnbgAAASw2S2EsAAAAAAAFWC41MDkAAAMGMIIDAjCCAmsCEH3Z/gfPqB63EHln+6eJNMYwDQYJKoZIhvcNAQEFBQAwgcExCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE8MDoGA1UECxMzQ2xhc3MgMyBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMTowOAYDVQQLEzEoYykgMTk5OCBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMB4XDTk4MDUxODAwMDAwMFoXDTI4MDgwMTIzNTk1OVowgcExCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE8MDoGA1UECxMzQ2xhc3MgMyBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMTowOAYDVQQLEzEoYykgMTk5OCBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMXtERXVxp0KvTuWpMmR9ZmDCOFoUgRm1HP9SFIIThbbP4pO0M8RcPO/mn+SXXwc+EY/J8Y8+iR/LGWzOOZEAEaMGAuWQcRXfH2G71lSk8UOg013gfqLptQ5GVj0VXXn7F+8qkBOvqlzdUMG+7AUcyM83cV5tkaWH4mx0ciU9cZwIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAFFNzb5cy5gZnBWyATl4Lk0PZ3B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MyBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMTowOAYDVQQLEzEoYykgMTk5OCBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrghB92f4Hz6getxB5Z/uniTTGMA0GCSqGSIb3DQEBBQUAA4GBAGN0Lz1Tqi+X7CYRZhr+8d5BJxnSf9jBHPniOFY6H5CuOcUgdav4bC1nHynCIdcUiGNLsJsnY5H48KMBJLb7j+M9AgtvVP7UzNvWhb98lR5eYhHB2QmcQrmy1KotmDojYMyimvFu6M+O0Ro8XhnF15s1sAIjJOUFuNWI4+D6ufRfAF0Slrj4O266ePon5MC54zEX3hju")), PASSPHRASE);
TrustManagerFactory trustmanagerfactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustmanagerfactory.init(keystore);
javax.net.ssl.TrustManager atrustmanager[] = trustmanagerfactory.getTrustManagers();
if (atrustmanager == null || atrustmanager.length != 1 || !(atrustmanager[0] instanceof X509TrustManager))
{
throw new IllegalArgumentException("Invalid keystore");
}
mTrustManager = (X509TrustManager)atrustmanager[0];
}
}
private static ByteBuffer decodeBase64(String s)
{
ByteBuffer bytebuffer = ByteBuffer.allocate((6 * s.length()) / 8);
int i = 0;
int j = 0;
for (int k = 0; k < s.length(); k++)
{
int l = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(s.charAt(k));
if (l == -1)
{
continue;
}
i = l | i << 6;
for (j += 6; j >= 8;)
{
j -= 8;
bytebuffer.put((byte)(i >> j));
}
}
bytebuffer.flip();
return bytebuffer;
}
private static InputStream newInputStream(ByteBuffer bytebuffer)
{
return new InputStream(bytebuffer) {
final ByteBuffer val$buffer;
public int read()
throws IOException
{
this;
JVM INSTR monitorenter ;
boolean flag = buffer.hasRemaining();
if (flag) goto _L2; else goto _L1
_L1:
byte byte1 = -1;
_L4:
this;
JVM INSTR monitorexit ;
return byte1;
_L2:
byte byte0 = buffer.get();
byte1 = byte0;
if (true) goto _L4; else goto _L3
_L3:
Exception exception;
exception;
throw exception;
}
public int read(byte abyte0[], int i, int j)
throws IOException
{
this;
JVM INSTR monitorenter ;
int k;
k = Math.min(j, buffer.remaining());
buffer.get(abyte0, i, k);
this;
JVM INSTR monitorexit ;
return k;
Exception exception;
exception;
throw exception;
}
{
buffer = bytebuffer;
super();
}
};
}
public void checkClientTrusted(X509Certificate ax509certificate[], String s)
throws CertificateException
{
if (mTrustManager != null)
{
mTrustManager.checkClientTrusted(ax509certificate, s);
}
}
public void checkServerTrusted(X509Certificate ax509certificate[], String s)
throws CertificateException
{
if (mTrustManager != null)
{
mTrustManager.checkServerTrusted(ax509certificate, s);
}
}
public X509Certificate[] getAcceptedIssuers()
{
if (mTrustManager != null)
{
return mTrustManager.getAcceptedIssuers();
} else
{
return new X509Certificate[0];
}
}
}[/HIDE]
Orange is so kind to provide us not only the certificate, but the key itself
Im uploading the sources of the otaupdater application that Orange is using on our Blade Apex2 aka Orange Hi 4G.
P.S. This phone allows us to upgrade and downgrade all the times needed, so dont hesitate to ask, just booting on recovery menu lets me flash previous firmware versions.
Hopes any developer find some time to take a look on it, im ready to test anything.

[Q] Unable to hook HttpURLConnection.setReadTimeout

Hi,
I found an app often gets timed out in http request, the code is identified here:
Code:
invoke-virtual {v3, v0}, Ljava/net/HttpURLConnection;->setReadTimeout(I)V
I try to hook it:
Code:
final Class<?> httpUrlConnection = XposedHelpers.findClass("java.net.HttpURLConnection", lpparam.classLoader);
try {
XposedHelpers.findAndHookMethod(httpUrlConnection, "setReadTimeout", int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
int oldValue = (Integer)param.args[0];
param.args[0] = 90000;
XLog("setReadTimeout: old value: " + oldValue);
}
});
} catch (Exception E) {
XLog(E.toString());
}
But this exception is thrown:
Code:
java.lang.NoSuchMethodError: java.net.HttpURLConnection#setReadTimeout(int)#exact
at de.robv.android.xposed.XposedHelpers.findMethodExact(XposedHelpers.java:179)
at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:129)
From Android source code:
https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/java/net/URLConnection.java
https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/java/net/HttpURLConnection.java
setReadTimeout is defined in the parent class, URLConnection, not in sub class HttpURLConnection.
So I change the first line to
Code:
final Class<?> httpUrlConnection = XposedHelpers.findClass("java.net.URLConnection", lpparam.classLoader);
This time, nothing happens, no exception, no my customized log, the app still gets timed out.
I'm wondering what's the right way to hook such a method?
Thanks
The best thing you can do is build small app which calls this method (so you are sure it's called). Now you can see in Xposed log whether is your hook right.

Class name for android.net.wifi.p2p.WifiP2pService in Moto E

I'm developing a module in Xposed Framework which tries to access to Wifi p2p service to modify it. This is perfectly working on an Samsung Galaxy S3 by the code found in other posts:
Code:
@Override
public void handleLoadPackage(LoadPackageParam lpparam) {
try {
Class<?> wifiP2pService = Class.forName("android.net.wifi.p2p.WifiP2pService", false, lpparam.classLoader);
for (Class<?> c : wifiP2pService.getDeclaredClasses()) {
//XposedBridge.log("inner class " + c.getSimpleName());
if ("P2pStateMachine".equals(c.getSimpleName())) {
XposedBridge.log("Class " + c.getName() + " found");
Method notifyInvitationReceived = c.getDeclaredMethod("notifyInvitationReceived");
final Method sendMessage = c.getMethod("sendMessage", int.class);
XposedBridge.hookMethod(notifyInvitationReceived, new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
final int PEER_CONNECTION_USER_ACCEPT = 0x00023000 + 2;
sendMessage.invoke(param.thisObject, PEER_CONNECTION_USER_ACCEPT);
return null;
}
});
break;
}
}
} catch (Throwable t) {
XposedBridge.log(t);
}
}
It uses the class name "android.net.wifi.p2p.WifiP2pService" to access the method. My problem comes when trying to run it on a Moto E device, the logs say:
Code:
E/Xposed: java.lang.ClassNotFoundException: android.net.wifi.p2p.WifiP2pService
So I guess there must have been a change in the name of the class. ¿Does anyone have a reference on what could be going on with wifi p2p service on MOTO E (2nd generetion)? The version is lollipop 5.0.2

Categories

Resources