Debugging with broken charging port - android

I'm designing an android app, however the charging port on my phone was damaged and when I connect the computer to my phone, it says USB device not recognised. I have looked up debugging through bluetooth and wifi, however they either require a root, which needs me to connect my phone to the PC or they need that connection to set up the bluetooth/wifi debugging at first. I've been trying alternatively to use the emulator, however after fixing errors with the intel hardware acceleration, I now get a black screen whenever I launch the emulator. I would like to be able to debug on my phone, is there any workaround you can suggest that would work in this situation?

This may not be the best solution but it will let you grab logs from the device.
1. Enable the developer option on your phone if you have not done it already.
2. Enable "Bug report shortcut" or "Include bug reports in power menu" under developer options in settings. This will let you send an email with device logs attached to it.
3. Add whatever logs to your application and install it on the phone.
4. Run the app.
5. Send the logs in email using the option in power button menu.
6. Go through the logs. Go to step 3 until you fix the problem.

The .apk file may be easily transfered using Dropbox or any other filesharing service. Pick it up in the build outputs folder.
However this is not the best way to debug your app, one way of doing this would be to implement your own Log wrapper and to write your output to the file on an external storage.
A quick example would be:
public class Log {
public static int v(String tag, String msg) {
writeToLogFile(msg);
return android.util.Log.v(tag, msg);
}
public static int d(String tag, String msg) {
writeToLogFile(msg);
return android.util.Log.d(tag, msg);
}
private static void writeToLogFile(String msg){
// write to log file
}
// TODO: implement I / W / E levels logging
}
Also, how about using Fabric kit for troubleshooting.

Related

connection resets when using set_configuration in PyUSB

I've recently updated my android phone to Marshmallow. Unfortunately for me, that broke my python code.
using PyUSB, I can get the device to enter accessory mode. Unfortunately, I can no longer read/write to the device, as now using set_configuration() resets the connection, causing the device to exit accessory mode and re-enter MTP mode.
dev = list(usb.core.find(find_all=True))[0]
dev.ctrl_transfer(0xc0,51,data_or_wLength=2)
dev.ctrl_transfer(0x40,52,wIndex=0,data_or_wLength='SAMSUNG')
dev.ctrl_transfer(0x40,52,wIndex=1,data_or_wLength='SAMSUNG_Android')
dev.ctrl_transfer(0x40,52,wIndex=2,data_or_wLength='16DIGITSERIALNUM')
dev.ctrl_transfer(0x40,52,wIndex=3,data_or_wLength='AOA')
dev.ctrl_transfer(0x40,52,wIndex=4,data_or_wLength='Whatever')
dev.ctrl_transfer(0x40,52,wIndex=5,data_or_wLength='4')
dev.ctrl_transfer(0x40,53)
time.sleep(5)
dev = list(usb.core.find(find_all=True))[0]
dev.set_configuration() ## Aaaaaand we're back to MTP...
I can't find any way around this; no references to this problem. Only solution I can some up with is to learn C and use libusb directly, assuming the PyUSB module is to blame...
Well, this isn't a good solution, but just in case anyone else just happens to come across this problem and find this:
The problem is with the specific backend (libusb0), which sends a message to reset configuration or something like that if an interface is already claimed. In some devices (mine, for example), this causes a programmatic reset of the connection.
My workaround involves using thelibusb1 backend when re-acquiring the device in accessory mode, since it doesn't cause a reset. But since libusb1 won't let me do control transfers, I need to switch between backends.
from usb.backend import libusb0, libusb1, and then be0,be1 = libusb0.get_backend(),libusb1.get_backend().
Then just specify the backend as a parameter to usb.core.find

Enable DEBUG logging on Blu R1 HD (Amazon phone)

I bought the Blu R1 HD, Amazon's Android phone, for use in dev testing. When I view its logs via logcat, only messages logged at the INFO level or higher are showing up for both my app and other system-related messages.
Yes, developer mode is enabled and ADB Integration is enabled via Android Studio. The same app installed on other devices or the emulator shows the DEBUG and VERBOSE log messages as expected.
I see that some specific phone manufactures have default settings to suppress log messages at runtime, e.g.
Huawei, logcat not showing the log for my app?
Perhaps the Blu phone is doing something similar. Does anyone know of a way to get DEBUG and VERBOSE logs to show up on this particular phone? (It is the low-end version, 8GB storage, and shows Amazon ads on the lock screen.)
Daniel, its probably the same exact instructions..
dial
##2846579##
you should see a hidden menu:
Go ProjectMenu / Background Setting / Log setting
change the log setting than reboot phone
I have a more recent BLU Vivo 5 phone and I noticed that only some of my logcat messages were showing up. After some more experimentation I discovered that the tag names I was using were somehow being filtered. For example, if I do some logging like this:
public class MyClass {
....
...
public void test() {
Log.d("MyClass", "Test log");
Log.d("MyClass1", "Test log");
Log.d("TestTag", "Test log");
}
Only the second and third log statements will show up:
05-31 18:35:48.812 7294 7294 D TestTag: here
05-31 18:35:48.812 7294 7294 D MyClass1: here
On the BLU phone, it seems like there is a tag filter that blocks log messages with tags matching certain criteria.
I'm sure there is a proper explanation but for now, in my app, to get the logcats on the BLU phone, I just simply add an extra space to my tags like so:
public class MyLogger {
public static void d(String tag, String msg) {
Log.d(tag + " ", msg);
}
}
Btw, just to clarify, I did not have to enter any special # codes in the phone dialer to get log messages to show up. The logcats just show up by default.

Can I Use e.PrintStackTrace() or Breakpoints When Using Android USB Device?

In the Android app I'm currently working on I have all my try/catches to print out a stack trace but when using a physical android device via USB these errors do not seem to get printed. Further more, when I attempt to create a debug log on the device, it never shows up. My assumption is that I have to start relying on Log.d and print everything to the logcat. Is this correct?
Edit: I should also mention that these stack traces appear when using an emulator as well.
Also, I have noticed when debugging on a physical device when I hit break points it locks the application but it does not allow me to continue with debugging, a.k.a pass over the break point. Is this an error or simply how it preforms? Break points work fine on the genymotion emulator.
You are doing something in wrong way, be sure not to debug and look for logs at the same time and be sure you are using right filter at loging.
And at last be sure that you turn on debug mode on at your release version of app(or what version you are using at device).
For the logs, you should have to check is the log is enable, by using the following steps in eclipse:
* Go in Windows -> Preferences.
* After that, select Android -> LogCat.
* And set the option "Show logcat view if message priority is atleast:" to "VERBOSE".

Connect cp2102 or FTDI to Android 4.x

I want to connect a custom device with cp2102 to Android powered tablet. I connect it in VCP mode (using PID EA60) and use JavaComm to find it,
#SuppressWarnings("unchecked")
Enumeration <CommPortIdentifier> ports = CommPortIdentifier.getPortIdentifiers();
while (ports.hasMoreElements())
{
final CommPortIdentifier port = ports.nextElement();
Log.d(null, port.toString());
}
but I never enter the loop.
I have an option to use FTDI instead of silabs. They have a variant of using their D2xx dll through JNI. I followed their guide but I have a memory crash (signal something and heap corrupted message in LogCat), when I connect ft232r and try to determine the number of connected devices. When I unplug the device from the tablet, the same code (their sample code) works just fine, returning zero, which is true.
When I use JavaComm with FTDI the result is the same as with cp2102: the loop is not entered.
I guess I miss something or do something wrong.
If I'm to use, say, usb-mode instead of VCP, I'm ready to start searching, I just need a hint.
Any help would be greatly appreciated.
The issue here is that the CP210x driver is not enabled in the Android kernel by default. So you will either need to build this driver in to your kernel to get the tty access and ability to use JavaComm.
The other option is to use the USB Host functionality and access your CP210x directly with it's API.

USB Connection notification

can we receive notification if user connected there phone through USB cable.
Actually there is one broadcast event; if you turned on Debug in your application settings, your will see a bug on your notification bar when you plugged usb. Following is the sample how it works;
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// UsbManager.ACTION_USB_STATE -> "android.hardware.usb.action.USB_STATE" actually
if (action.equals(UsbManager.ACTION_USB_STATE)) {
Bundle extras = intent.getExtras();
// UsbManager.USB_CONNECTED -> "connected" actually
usbConnected = extras.getBoolean(UsbManager.USB_CONNECTED);
...
You can find this at framework/base/service/java/com/android/server/NotificationManagerService.java.
Hope this helps.
Ajay,
I wasn't able to find anything specific to just "USB Connected," but there are a few Broadcast Actions that may be of interest in this case depending on what you are trying to accomplish:
ACTION_MEDIA_SHARED: External media is unmounted because it is being shared via USB mass storage.
ACTION_UMS_CONNECTED: The device has entered USB Mass Storage mode. This is used mainly for the USB Settings panel.
ACTION_UMS_DISCONNECTED: The device has exited USB Mass Storage mode. This is used mainly for the USB Settings panel.
There doesn't seem to be a Broadcast Action specific to USB simply being plugged in, you could also try doing something with:
ACTION_POWER_CONNECTED: External power has been connected to the device.
But this would go off for both USB connected to a computer and USB connect ONLY to a power source...
Interestingly, I also found this LINK simply stating that there was no Broadcast Action for "USB Connected".
You may be out of luck in this case :-\
Since: API Level 5
An activity to run when device is inserted into a car dock. Used with ACTION_MAIN to launch an activity. For more information, see UiModeManager.
Constant Value: "android.intent.category.CAR_DOCK"
public static final String CATEGORY_CAR_MODE
Since: API Level 8
Used to indicate that the activity can be used in a car environment.
Constant Value: "android.intent.category.CAR_MODE"
A number of years later... this might help someone that came looking like I did. Since Honeycomb, there are two actions one can listen for USB_DEVICE_ATTACHED and USB_DEVICE_DETACHED.

Categories

Resources