Disable USB charging - android

For some reasons not related to the battery life, I need to disable the battery charging when a USB host is connected to my phone (a rooted Nexus 4).
Taking a look around on the internet (link1, link2), it looks like I should modify a system file.
I have found a series of interesting files located in /sys/class/power_supply/battery and /sys/class/power_supply/usb, that could be the right ones to be modified in order to achieve the usb charging disabling (e.g. /sys/class/power_supply/usb/present 0/1).
Has anyone tried something like that?
Which is the best way to modify those system files? Should I use the adb shell or another tool?
I tried the "root explore" app in order to modify those files, however when I modified a file (after changing its permissions), it was automatically kept back to its original value.

Related

Cloning data partition to other Android devices

We have several devices running Android in an industrial environment.
We think about completely setting up one device and then copy the whole /data directory to the other devices. The expected benefit is to configure things like wireless settings and install the required apps and updates only once on one device and somehow bring this onto the other devices.
Is this a good idea?
I am not sure if there is device specific information stored in data such as a device ID or something else that we would mess up with our idea.
Besides this what about 'uid's that are responsible to represent app permissions? Do you expect problems if our apps are not installed onto a device but simply come by a copied /data partition?
Is something specific established on a device after the first boot when /data is created and filled, that should not be replaced with something else?
Would it be better to copy only selected directories or even files? This is much more effort but ok if there is no other way...
I would appreciate any input about what can go wrong and what we should consider.

Locating file responsible for display battery animation when charger is plugged in

I am trying to enable my generic android device to turn on when plugging in the charge cable. I have read that this is possible by changing the contents of playlpm to be a shell script with the reboot command inside. However, this device doesn't have this playlpm file.
A similar question was asked a while ago...
Altering Android offline battery charging display (playlpm), How to make Android device boot when power is plugged in?
I assume this is specific to a certain vendor, Samsung it seems? Not sure. When I plug in a usb cable, there is a battery animation but I have no idea what gets called to show the animation. I have only found the images related to the animation. Anyways, I was wondering if someone knew what file is actually used to start this animation.

Changing Android adb debug settings programmatically from recovery

I'm trying to set up 60 Galaxy Tab 2 devices, by flashing CyanogenMod and then gapps onto each one. Unfortunately, at the moment I need some manual intervention on each one, which is annoying.
I can programmatically turn each one on and boot it into recovery mode, and then flash the CM ROM. It then automatically reboots the tablet, though, and I can't touch it after that because the default bootup doesn't have adb debugging turned on. I thus have to turn it back off, or boot it into recovery mode manually, before the next step.
What I would really like to do is to use adb while it's in recovery mode to turn on USB debugging, so that when it reboots, I'll be able to get to it. Ideally I'd just change a setting (use SQLite3 to change something somewhere?), but I could if necessary rebuild the CM11 zip to incorporate the setting somehow. I think I will need to turn on debugging, and also add the computer's RSA fingerprint so that it's allowed to talk to the device.
Any idea on how I can do this?
I could if necessary rebuild the CM11
A possible way for this option is to set ro.debuggable=1 in build/core/main.mk even for user builds. However, please note that that could lead to security breach as USB debugging is not meant to be used by normal end users.

Android: Determining connected USB device storage size

I have a widget that will tell the user the capacity of a connected USB device, as well as the amount of space used. I have gone through the android.hardware.usb API and I see nothing that can accomplish determining the size of a connected USB device and its usage.
Right now I am capturing Intent.ACTION_MEDIA_MOUNTED and searching in the Dir of the mount point for specific files etc... All of that is working fine, but for the life of me I cannot see how to leverage the API to determine the overall size, and usage, of a connected USB device.
Do any of you fine folks know, or have an article for me to read? Thanks all.
It sounds like your device is actually mounting the connected USB device's file system, which seems like it may be a vendor add-on rather than a stock android capability.
If that is indeed the case, whatever other options you might have you can use the df shell command, or more properly duplicate its functionality in java or a native subroutine.
You can view the source of android's df here:
https://github.com/android/platform_system_core/blob/master/toolbox/df.c
It looks to be a fairly standard implementation - read /proc/mounts to find the filesystems, call statfs() on each one. You'd probably want to filter by those of interest.

How to set the Usb connection mode?

I'm writing an application which is supposed to dump data on the SD card and then another application on a pc which should read the data when the device is connected to the pc (in disc drive mode).
On my HTC Legend there is a dialog to choose between: Charge only, HTC Sync, Disk drive..
Is there a possibility to set the mode with which the device is connecting to the pc
or at least an intent to ask the user to switch the mode?
I haven't found a way of setting the mode programmatically, but I believe you can bring up the settings menu programmatically by invoking the same activity that the system invokes from the notification area. Unfortunately this appears to be manufacturer-specific: on my phone it is com.htc.android.psclient.SwitchUsbSettings.
On HTC devices, open the ConnectToPC service (whilst USB is not plugged in) in Manage Apps (ICS - probably applies to Gingerbread too; don't remember), and hit Clear Data. Then, plug the USB back again, and you should have the option to "Don't ask again" available. Select your desired mode, check the box, and accept.
CompanionLink does this when you request a USB sync in their android app: it flushes data to SD, then exports the SD as storage (a "disk drive") on the USB, then waits for the user to manually signal the android app when the PC is finished using the SD, and then undoes the SD export to USB again. Though the CompanionLink app can be very frustrating to use, at least this part of it is (largely) reliable.
Unfortunately I don't know the technical details, may well need to figure them out myself one of these months. If you can't get any traction with android docs, perhaps you could study what CompanionLink does on android to implement this. The sequence I describe above is when it is configured to sync over USB against a (PC-based) Palm Desktop.
As an aside, it appears that the reason for this highly-convoluted process is that the SD card's FS is accessed directly and at least the presently-used card FAT FS can only support a single client: the phone itself or USB. imo it would be extremely helpful if concurrent shared access to the SD were possible, but this would likely require deep android changes.
For anyone having this issue with an HTC One M8, this is a bit off the wall, but makes the point to think outside the box. A USB connection resulted in the device charging, that was it.
The solution was the combination of a different USB cable, uninstalling an application called Battery Doctor (which apparently likes to manage everything around your battery), AND USB Network Setting - turn ON Smart Network Sharing...Seemingly unrelated...but this combination got my connected with MobileGo for Android to manage and back up files,contacts and settings.
Hope this helps someone.
Yes .In Android there is a way to change the behaviour of the devices`s USB mode when the device is connected with the PC.
I used a Motorola Milestone[running 2.1] and i was able to switch between the following modes :
PC Suite[developed by Motorola],MemoryCardAccess and Charge alone.
If you need to access phone memory I think you should turn ON "USB Debugging Mode " in your device.Am not sure about it though,I feel it may be handy !!

Categories

Resources