I am trying to permanently disable Bluetooth and WiFi on some Galaxy Tab S2's. They will have material loaded onto them which can not be disseminated on the internet. Ideally I would like to physically rip the cards out but I have to many to do that - I was thinking about using ADB to somehow disable the services.
Is there a way to do this using ADB? svc wifi disable works but then a user could just re-enable it in the user interface. Any thoughts? I'm not even sure what to search for or where to start.
Related
I'd like to cut off emulator's internet while keeping wifi and mobile data enabled so I can run some automated tests covering this case without having to turn off the internet manually.
While running an emulator on the PC it gets its internet access through the host PC, I'm interested in whether there's an adb command that would let me disable (and re-enable mid-test, potentially multiple times) the internet access the emulator is getting from the host PC while keeping wifi and mobile data enabled?
I've been using svc wifi/data enable/disable to enable and disable wifi and mobile data repectively.
This could be a duplicate of Can I truly enable and disable network access mid-test? but taking into account that it's almost 10 years old something might have changed in the meantime.
As loss of internet connectivity is a completely external event, the most accurate way you can simulate it is using a proxy.
First, configure a proxy in your network. You can even write one in a few lines of python if you want to have more control over it.
Then start the emulator providing the command line option -http-proxy or the environment variable http_proxy defining your proxy. This option forces the emulator to use the specified HTTP/HTTPS proxy for all outgoing TCP connections. Redirection for UDP is not currently supported.
For example
emulator -http-proxy http://192.168.200.1:9999
then, you can control the emulator access to the internet (HTTP/HTTPS) via the proxy.
Diego's answer pushed me in the right direction.
Using: add shell settings put global http_proxy <ip>:<port> and add shell settings put global http_proxy :0 to set and reset emulator's global proxy along with using the same proxy in the code (if it's set, to check so I'm using System.getProperty("http.proxyHost") and System.getProperty("http.proxyPort")), because it's not used automatically, I was able to achieve what I wanted.
Thanks Diego.
Edit:
In fact the APIs such as HttpURLConnection do use the proxy automatically (if set, so no checking and manually setting needed on my side). Well HttpURLConnection comes with its own problems such as not always honouring timeouts, so back to using other APIs and manually checking for proxy and if set using it.
I have an Android TV for which I want to turn the display on and off based on a motion sensor. I have connected the tv to a raspberry pi via Wifi and I'm trying now via adb commands to turn off the display of the Android TV.
As far as I've seen, I need to execute the following command:
./adb shell input keyevent 26
Unfortunately, this also turns down the device and most importantly Wifi. After this the TV is offline and not reachable anymore via the IP address. So I have to use the remote to turn it on again.
So I need a way to keep the Wifi active. I've already tried the following commands without luck:
adb shell svc power stayon true
adb shell settings put global stay_on_while_plugged_in 3
I've also sideloaded a Wakelock app, but that also didn't work. After keyevent 26, the device is always offline.
The TV is a TCL 43P615.
Any ideas how I could achieve this?
Thanks
There would not be a standard way of turning off the screen (https://support.google.com/androidtv/thread/58069060/is-it-possible-to-turn-screen-off?hl=en-GB) but perhaps your TV provides one in settings or eco-mode.
Perhaps you best bet is to disable the screensaver and create a completely black fullscreen Activity that you can start and stop from adb.
I have app in KioskMode. Cannot allow user to use usb connection to remove app. Want to make sure user cannot tamper with the app at all via USB. I want to detect if user has connected via USB to the device, and if they do not have the right permissions, terminate that connection. Or not allow connection in the first place for normal users. Detecting the connection seems possible, but dont see how to prevent or terminate the connection programatically. I have not found the API to do this.
UPDATE: changing debug mode programmatically does not appear to be an option for a non-system app, SO question is can the connection be detected and then terminated?
The adb commands are only accessible in debug mode. Disable USB-Debugging and you can't execute these commands anymore.
Essentially, my problem is that I tried connecting my device to adb over Wifi, got to adb connect xxx.xx.xx.xxx but then adb claims that it was unable to connect to xxx.xx.xx.xxx:5555.
Ok, but now I'm having trouble getting it back to listening over USB. adb usb tells me that there isn't a device attached and adb devices gives me an empty list.
I've tried killing the adb server and then restarting it, toggling the device's debugging mode and toggling the device's USB storage transfer but nothing seems to be working. This question seems very similar to my problem but I have no idea what the guy is doing in the solution.
I'm guessing the problem is that adb is still trying to listen through Wifi but since I can't connect to it over Wifi it can never go back to listening to it over USB. Idk...
For wifi, you may be able to get it to work if you first use the browser on the device to visit a webpage or something and so effectively wake up the wifi radio and its connection to the access point. You may need to keep doing this every once in a while.
(Maybe you should listen to internet radio while you work?)
Of course your access point will have to permit peer-to-peer traffic on the local subnet. In many cases that may be the norm, but I believe an access point can be configured not to support that, and some may default to such settings. There can also be issues between wired and wireless subnets sourced from the same box.
Finally, restarting the device might get it back into USB mode.
I have desktop application communicating with Android devices via adb. Sometimes device goes to offline state and my program does not work. Now I am trying to make workaround for it by disabling and enabling usb port programatically, but unfortunatelly I can not test it, because devices still remains in online state...
Is there any possibility to enforce offline state of device?