I'm trying to write an app that can turn my mobile data connection on and off.
Already got the source and built my own sdk, where I removed the #hide statements so I can use the relevant function
cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
cm.setMobileDataEnabled(true);
Also found out which permissions I need, in particular WRITE_SECURE_SETTINGS, which is only available to system apps. I read adamk's comment and now need to know how to do what he suggested (add the app to system or sign it with the platform key).
At first I would like to do that on the emulator only, and then on my phone (which is rooted and using a custom ROM).
I tried pushing it to the system directory on the emulator:
adb remount
adb push app.apk /system/app/
adb sync
which did not work, the app was not found and installed.
What did I forget? How is the proper way to do this?
So, I finally found the problem and solved it.
I was actually quite close:
adb remount
adb push app.apk /system/app/
This is the correct way to do it on the emulator (no adb sync needed). I watched the logcat, and found out that you need to sign your .apk file so the system does not reject it, even if that does not add any validity in this case.
If you push a signed .apk this way, it will get the needed permissions and work as expected — in my case, turning the mobile data connection on and off.
For the phone part (using ClockworkMod):
Boot into recovery mode, mount the /system folder and enable USB storage. Then proceed in the same way as with the emulator, reboot the phone, and you are good to go.
Hope this helps someone who encounters the same problem.
Related
well, my problem is: I have an application which is set as the device owner of a device (my tablet in this case). I did it from the terminal in Ubuntu, connecting the tablet to my PC and executting this line in the adb shell:
dpm set-device-owner my.app.package/my.app.route.MyAdmin
So, I want to disable the device owner app without restoring the device, just executing a line similar to the last one. Me and my coworker have been researching for a long time and we've never found anything about this, so I would like to know if it is possible or not, and if it is, how to do that.
Thanks!
you can use the following ADB shell command to remove device owner
adb shell dpm remove-active-admin com.example.app/.AdminReceiver
Disables an active admin, the admin must have declared android:testOnly in the application in its manifest. This will also remove device owner and profile owners
You can use DevicePolicyManager.clearDeviceOwnerApp() from your device owner app.
However note that this method has been deprecated in Android Oreo, you can still use it on Oreo devices but it might be removed in future Android versions.
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.
Following scenario:
I have a unrooted (stock) android phone (Samsung) and I need to enable adb, but I don't have access to the device (forgot the lock code).
Is it possible to enable adb debugging via adb sideload from recovery?
For example creating a update.zip, that enables adb or installs an app, that enables adb on boot?
Thanks
Is it possible to enable adb debugging via adb sideload from recovery?
No. Your app would need special permissions to do such a thing. Obviously if an arbitrary app was able to turn on adb debugging without asking the user that'd be a bad thing.
As a side note, this sounds like what someone would ask if they had acquired a phone that didn't belong to them. Not that this would change the validity of my answer.
I just bought a second hand phone and when I connected it to the computer it wasn't recognized (code 43). Since I really like the phone would it be possible for me to install apps I make on android studio another way than with an USB cable ? Like via wifi or something ?
Build your .apk
Download the .apk to the phone
Run the .apk
You can use an app like ES File Explorer, which allow you to access shared files on your network.
http://developer.android.com/tools/help/adb.html#wireless
You can connect to ADB over the network.
sure!, are 2 ways to this, using wifi like you say, 1 is with root and the other is without root.
1.- Root: need a app like "adb over wifi" LINK i use the adb over wifi widget, anyway, the app give you a ip, so, in your pc/lap go to the location of your adb something like "C:\Users\USER\AppData\Local\Android\sdk\platform-tools" using cmd and enter adb connect ipcellphone:port thats all
2.- Without root need a specific app called "ADB Wireless (no-root)" LINK and follow the instructions, BUT need to plug in your cellphone 1 time (first use) but just one time is better than using the cellphone everytime.
see ya!
I have made a mistake somewhere in my code that my Android app crashes when I switch off the network in the emulator while the app's HTTPClient is making some request.
But I cannot debug it, because when I switched off the network, I also lost the ADB connection. Thus I cannot see what exception is causing the crash.
I have tried switching off the network by:
F8
Set 'Data' to 'Unregistered' or 'Denied' in DDMS Emulator Control
I can put my Mac offline and ADB will stay up, but unfortunately I cannot reproduce the crash that way.
Is there a way to turn off network in the emulator, while keeping ADB alive? I basically need access to the LogCat entries.
Thanks!
You can run logcat from the device instead of from ADB and redirect it to a file for offline reading.
adb shell logcat [-v threadtime] > /sdcard/mylogs/logcat.log
Instead of
adb logcat [-v threadtime]
Then you can get the file when you reconnect to the device.
On linux this is pretty simple with iptables firewall. I suppose you trying to debug api calls so just block api host:
iptables -I OUTPUT -d api.example.com -j DROP
Sure you can do the same thing with Mac or Windows firewall.
You could always put the device into airplane mode, that will still allow you to connect over adb but not give the emulator a connection to the internet. You can also turn off data through eclipse via the emulator control section in ddms by putting in unregistered/denied to the data drop down.
I know this is old question but someone might use find for this.
My setup
Eclipse Kepler with emulated android 4.4
If you want to keep your adb alive and network turned off, you can try this.
Start emulated device
Activate flight/airplane mode
Restart Eclipse
It should work! Check DDMS perspective for attached devices or use adb devices command