Turning on a mobile phone (SGS2) automatically / remotely - android

I want to use my phones as a remote camera system that charges via a solar panel however I was wondering whether there is any way to turn the phone on automatically or remotely.
Thats to say, if the phone runs out of battery and turns off, is there anyway to turn it back on automatically or remotely?

If the phone is rooted, here is what you can do.
(Optional) Rename /system/bin/playlpm:
adb shell remount
adb shell mv /system/bin/playlpm /system/bin/playlpm-original
Then create a playlpm file locally and put the following:
#!/system/bin/sh
/system/bin/reboot
And push it to the target:
adb push playlpm /system/bin
Then give it a proper permission:
adb shell chmod 0755 /system/bin/playlpm
adb shell chown root.shell /system/bin/playlpm
Now, whenever phone is connected to a power supply, it is going to (re)boot automatically. That's, if its battery has drained it will boot up when a power will be available from solar panel.
Also see:
Auto Power on Android when the charger is Connected
Programmatically auto-power on the phone
Is there a way to auto-power on the phone
[root] NoMoarPowah!

Related

Remotely turning on display and opening Apps

I have a tablet connected to my home automation system. I would like my tablet to open an app when specific conditions are met.
My idea was to install some sort of SSH server on the tablet. When my server wants the tablet to open the App, it logins into the tablet and executes a command turn on the display and open the App.
In theory this works but I haven't been able to find any documentation on the web on how to do this.
I've got as far as installing SSHDroid however when the tablet locks, the SSH disconnects. I'm also unable to find any commands which turn on the display and open apps.
From a computer, if you have USB access already (no root required), check this answer more details.
Connect your tablet with computer(has adb installed) and run
adb tcpip 5555
Then you can control your tablet over wifi by run
adb connect 192.168.0.101:5555 // you can use port forward in you gateway to enable you connect over internet.
Now after connected with tablet you are able to use adb shell commands.
Turn Screen On
adb shell input keyevent KEYCODE_POWER
Start an Application
adb shell am start -n com.package.name/com.package.name.ActivityName

Command to clear the previous dumpsys info

Question is straight forward and simple. Is it possible to get the dumpsys information after certain point or certain user action. Not from the scratch.
There is no such thing.
Logs belong to the logcat facility. dumpsys is mostly for reporting the current state and some more advanced things. It is true that few of the Android service developers included some limited logging excerpts into their dumpsys output but virtually none of them implemented a way to clear those logs.
I realise this is a bit late but...
As per the documentation:
Connect your mobile device to your computer.
Open a terminal and type the following commands to reset the adb server:
adb kill-server
adb devices
This will list any connected devices (If you don't see any devices listed, make sure your phone is connected, and USB Debugging is turned on, and then kill and restart adb again).
Next you will need to reset battery data gathering. The device is always collecting batterystats and other debugging information in the background. Resetting erases old battery collection data. If you do not reset, the output will be huge.
In terminal use command:
adb shell dumpsys batterystats --reset
Disconnect your device from your computer so that you are only drawing current from the device's battery.
Play with your app and perform actions for which you would like data; for example, disconnect from WiFi and send data to the cloud.
Reconnect your phone and make sure it is recognized:
adb devices
Dump all battery data (This can take a while):
adb shell dumpsys batterystats > [path/]batterystats.txt
The batterystats.txt file is created in the directory you specify using the optional path argument. If you leave out [path/], the file is created in your home directory.
You can find the home directory in Android Studio by going to:
Tools > SDK Manager > Android SDK Location.
Navigate to that filepath then open the subdirectory 'platform-tools' and look for batterystats.txt.

How "adb reboot bootloader" works internally?

I am seeing an issue with my android images where the command adb reboot bootloader simply reboots back the android, instead of going to bootloader mode.
In order to fix the issue, I did some study and find that there are acually two things, adb and adbd and the host and target devices communicate using the TCP protocol over sockets.
So, the interesting thing is commands like adb shell and adb devices are working but not the reboot bootloader. I want to understand what the adbd on receiving the reboot bootloader. Does it change the boor order, sets some flag, changes EFI vars....?
Can you please point to some good links or understanding you can share?
PS : I am working on embedded device environ, similar to raspberry pi...
This is how adb reboot bootloader works on a standard Android device connected via USB (the only transport supported by the standard Android bootloader in the fastboot mode):
adb client sends the reboot bootloader command to the adb server (over TCP)
adb server forwards the reboot bootloader command to the adbd on the device (over USB)
adbd sets the sys.powerctl property to reboot,bootloader
sys.powerctl change triggers the init.rc rule which runs powerctl init's built-in
which does _NR_reboot syscall
which sets the reboot to bootloader flag and reboots the device
On the next power up the bootloader would see the flag and go to the fastboot mode. But only if USB is connected.

How to toggle turn on/off mobile data with adb command

I looking for toggle my android phone mobile data with adb command. that is usually i do it with touch my mobile data icon in settings.
i found many reference to do it, for example this question , but nothing work for me, i try use:
$ adb shell svc data enable
$ adb shell svc data disable
when i look to my android phone nothing happen.
my android is KitKat 4 and i sure have rooted
Thanks.

How to disable battery charging during ADB connection?

Problem description:
Each time wen I connect USB cable between PC and my mobile phone the battery automatically is charged. I want to use ADB protocol but I don't want to charge my battery during ADB connection. Is it possible to to turn off this charging? And ofcourse how can I do this?
Environment:
Mobile phone with Android os 4 and higher
I need only mention that my referential device working on android 5 so there is no /sys/class/power_supply/battery/force_usb_charging file
BEWARE: adb shell dumpsys battery unplug only MOCKS the battery status. I checked with a current indicator on my usb cable and this does not change the amount of flowing current at all so the battery is still charging.
It only changes what applications think about the state, so for example google play would not start updating if you have configured that it can only update when charging...
Changing the value of a file like /sys/devices/battery.XX/power_supply/battery/hv_charger_set to 0 does really work but its a different file for every device. For example, for my yotaphone 2 with a snapdragon 805 there is a file: /sys/devices/qpnp-charger-14/power_supply/battery/charging_enabled
So you could make a script that you can use in tasker(if you have root):
echo $1 > /sys/devices/qpnp-charger-14/power_supply/battery/charging_enabled
if you write that to an executable file /data/setcharging.sh then you could call the script like /data/setcharging.sh 0 to disable or
/data/setcharging.sh 1 to enable.
This works, I checked with my current metering usb cable, but it does not show that it works in the battery status icon. So you could use a combination of this and adb shell dumpsys battery unplug / reset to make it look better, but the problem is that then apps like tasker don't know whether you have ac power or not, so you can not put triggers for that when you've set it to unplugged...
One more thing, I also tested what it does in recovery (twrp) and during boot. And it turns out that during boot and in recovery, the charging just works. So its not like your device will end up dead if you forget to turn on charging again. You can always charge it in recovery mode and then boot up and change the value again (or change it while in recovery if your recovery gives access to adb).
Lastly, there are apps on the play store that are made exactly for this, but I would recommend getting such a current indicating usb-cable and checking if they really do what they say and are not just mocking.
You can make the system think it is not loading th battery using
adb shell dumpsys battery unplug
Refer to this good article :
https://stanfy.com/blog/android-shell-part-1-mocking-battery-status/
Try this for rooted device:
To enable battery Charging:
adb shell dumpsys battery set ac 1
adb shell dumpsys battery set usb 1
adb shell dumpsys battery set wireless 1
To disable battery Charging:
adb shell dumpsys battery set ac 0
adb shell dumpsys battery set usb 0
adb shell dumpsys battery set wireless 0
Probably it can be done via (root privileges):
/sys/devices/battery.XX/power_supply/battery/hv_charger_set
0 - Disable USB Charging
1 - Enable USB Charging
if android os version is more than 6 use unplug and reset to revert back.
adb shell dumpsys battery unplug
adb shell dumpsys battery reset
Copied from perfetto.dev
On rooted phones the power management IC driver allows to disconnect the USB charging while keeping the USB data link active. This feature is SoC-specific, is undocumented and not exposed through any HAL. For instance on a Pixel 2 this can be achieved running, as root: echo 1 > /sys/devices/soc/800f000.qcom,spmi/spmi-0/spmi0-02/800f000.qcom,spmi:qcom,pmi8998#2:qcom,qpnp-smb2/power_supply/battery/input_suspend. Note that in most devices the kernel USB driver holds a wakelock to keep the USB data link active, so the device will never fully suspend even when turning the screen off.

Categories

Resources