Can someone tell me is there any adb command to verify wifi wake lock in android phone. I am trying to check that wake lock is active or not after acquire from my application but not found this information in following file:
adb shell "cat /sys/kernel/debug/wakeup_sources"
Is it written somewhere else ?
To list the wifilocks active in android device, use the following command.
adb shell dumpsys wifi | grep "your wake_lock tag name"
Example:
adb shell dumpsys wifi | grep wake_lock_next
output:
WifiLock{wake_lock_next type=2 binder=android.os.BinderProxy#420bcfd0}
Related
I'm writing a shell script that turns off a notification category from specific applications. some built-in apps doesn't allow to turn off some of their notification without root access. for example com.google.android.dialer doesn't allow to turn off Google Play service availability. I hope this can do via adb shell.
first, I tried this command:
$ adb shell dumpsys notification | egrep Phone
mDefaultPhoneApp=ComponentInfo{com.google.android.dialer/com.android.incallui.InCallServiceImpl}
and if I filter phone:
$ adb shell dumpsys notification | egrep phone
NotificationChannel{mId='phone_ongoing_call', ...}
NotificationChannel{mId='phone_incoming_call', ...}
NotificationChannel{mId='phone_low_priority', ...}
NotificationChannel{mId='phone_voicemail_account', ...}
NotificationChannel{mId='phone_missed_call', ...}
NotificationChannel{mId='phone_default', ...}
So is there any command for disable/enable specific notification for a application via adb shell?
I have checked over the internet and on the stackoverflow also but can't find a solution for this..Is this Possible Using ADB?
You can check whether your custom service is running or not by below adb command.
adb shell dumpsys activity services <your-package-name>
It will give all your running service info.
You can use shell command to check if your application is running.
ps | grep com.yourpackage
To check if your service is running.
ps | grep service
And to get the running service list for your package,
service list | grep com.yourpackage
ADB command:
adb shell service list | grep com.yourpackage
This question already has answers here:
Enable/Disable NFC with ADB command
(6 answers)
Closed 5 years ago.
Is it possible to turn off/on (disable/enable) NFC with ADB for non-rooted Android device with v 6.0.1 version or higher?
i tried many stuff but it wont work for me.
Stuff i tried are:
Via ADB:
adb shell settings put global airplane_mode_toggleable_radios bluetooth,cell,wimax,nfc
adb shell am broadcast -a android.intent.action.airplane_mode_toggleable_radios
adb shell settings put global airplane_mode_on 1
adb shell am broadcast -a android.intent.action.AIRPLANE_MODE
adb shell settings put global radio_nfc 0
adb shell am broadcast -a android.intent.action.radio_nfc
adb shell settings put global AIRPLANE_MODE_RADIOS 0
adb shell am broadcast -a android.intent.action.AIRPLANE_MODE_RADIOS
adb shell settings put global NfcAdapter 0
adb shell am broadcast -a android.intent.action.NFC_adapter
adb shell settings put global airplane_mode_radios cell,bluetooth,nfc,wimax
adb shell content update --uri content://settings/global --bind value:s:'bluetooth,nfc,wimax' --where "name='airplane_mode_radios'"
also:
adb shell settings get global airplane_mode_radios
adb shell content query --uri content://settings/global --projection name:value --where "name='airplane_mode_radios'"
adb shell settings put global airplane_mode_radios "cell,nfc,wimax"
adb shell content update --uri content://settings/global --bind value:s:'cell,nfc,wimax' --where "name='airplane_mode_radios'"
adb shell settings put global airplane_mode_radios "cell,bluetooth,wifi,nfc,wimax"
adb shell content update --uri content://settings/global --bind value:s:'cell,bluetooth,wifi,nfc,wimax' --where "name='airplane_mode_radios'"
After restarting the device i can turn ON the airplane-mode with ADB but the nfc does NOT go off.
As i turn ON the airplane-mode on the native device (quick settings OR settings) it does go off!
Another one i tried is:
List the running services with:
adb shell service list
there you can read that nfc is running at number 9 " nfc: [android.nfc.INfcAdapter] "
try to disable with
adb shell pm hide com.android.nfc
does not work and throws:
Error: java.lang.SecurityException: Neither user 2000 nor current process has android.permission.MANAGE_USERS.
or:
adb shell pm grant EXAMPLE.android.services android.permission.WRITE_SECURE_SETTINGS
adb shell pm grant EXAMPLE.android.services android.permission.CHANGE_CONFIGURATION
-
following is working on devices up to Android 5x:
Enable/Disable NFC with ADB command
After playing around with Enable/Disable NFC with ADB command
On android Marshmallow (6.0.0 or 6.0.1)
Disable
service call nfc 5
Enable
~~service call nfc 6~~
Edit:
This doesn't seem to disable permanently, rebooting re-enables the service
Found the real answer!
svc nfc <enable|disable>
I have to test how my app behaves in doze mode. According to the documentation, I first must make the device think it's unplugged by entering the following command in the terminal:
$ adb shell dumpsys battery unplug
However, nothing happens and it logs:
Can't find service: battery
What should I do?
There is no battery service as the log points out (this may be device specific).
Enter the following command to find existing battery related services:
$ adb shell service list | grep battery
it will result in something like this
$ adb shell service list | grep battery
88 batterymanager: [android.app.IBatteryService]
107 batterystats: [com.android.internal.app.IBatteryStats]
114 batteryproperties: [android.os.IBatteryPropertiesRegistrar]
It makes sense that to manage the battery, you should use the batterymanager.
$ adb shell dumpsys batterymanager
outputs (in case the usb charged is plugged)
Current Battery Service state:
(UPDATES STOPPED -- use 'reset' to restart)
AC powered: false
USB powered: true
then, when you type
$ adb shell dumpsys batterymanager unplug
and run the previous command again, it outputs
Current Battery Service state:
(UPDATES STOPPED -- use 'reset' to restart)
AC powered: false
USB powered: false
Which validates that you should use the batterymanager service instead of battery.
Im automating wifi off/on via adb.
I would either like to disable/enable wifi based on the test case
so far I have found good information here
However I want to test the connection before executing following command
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings adb shell input keyevent 19 & adb shell input keyevent 19 & adb shell input keyevent 23
Above command disables wifi if enabled, enables wifi if disabled. I want to first test the connection and take action if required. I am wondering if there is a way to do using adb command. This can be achieved programatically but I want it to be done through adb for making it more reliable.
Also following command works only if device is rooted
adb shell "svc wifi enable"
Also following command launches test on screen but provides no info via adb
adb shell am start -n com.android.settings/.wifi.WifiStatusTest
To know everything about Wifi status of the device:
adb shell dumpsys wifi
To just know whether it's enabled or not:
adb shell dumpsys wifi | grep "Wi-Fi is"
To know more detailed status:
adb shell dumpsys wifi | grep "mNetworkInfo"
If connected to a valid network, it shows
"CONNECTED/CONNECTED". It also shows the name of the connected network.
If wifi has been enabled but it is yet to connect to a network, it shows "DISCONNECTED/SCANNING".
If wifi is disabled, it shows "DISCONNECTED/DISCONNECTED".
Below command will give you the internet status and connectivity mode(cellular or Wi-Fi)
adb shell dumpsys connectivity
If you're trying to determine whether or not WiFi is turned on you can run adb shell settings get global wifi_on which returns 1 if it's on and 0 if it's off.
If you have multiple devices connected you can run adb -s [UDID_HERE] shell settings get global wifi_on to get the WiFi status of an individual phone. To find the UDID you can run adb devices.
This would only tell you if there is internet access but you can do:
adb shell ping www.google.com
adb shell dumpsys wifi | sed -n '1p'
is faster and safer than
adb shell dumpsys wifi | grep "Wi-Fi is"
because the output of dumpsys wifi contains the system logs that may have been contaminated by other applications
Atish's answer was working fine until Android 11/R. For this OS onwards, I recommend using Abhishek's suggestion:
adb shell dumpsys wifi | grep "curState=ConnectedState"
Not perfect, but you could dump UI layout and then search for ON/OFF text like this (bash):
adb pull $(adb shell uiautomator dump | grep -o '[^ ]*.xml') ui.xml
grep 'text="OFF"' ui.xml
if [ $? == 0 ]; then
# Turn WIFI on
fi