android dumpsys permission denial - android

I have an application where I create a process and call the dumpsys telephony.registry command to get information about the mobile network status.
String[] cmds={"dumpsys telephony.registry"};
Process p = Runtime.getRuntime().exec(cmds [0]+"\n");
and then after that I parse the result of the command. For "ls" or other commands it works fine. For dupmsys I get Permission Denial: can't dump telephony.registry from pid-953, uid=10090. I get the same error results for dumpsys power or other dumpsys commands.
I have set DUMP permissions android.permission.DUMP in the android Manifest like suggested here
I think that I am doing this right since Android offers this feature here
I have also done the step described here to force eclipse to allow me to give my application DUMP permission in the manifest.
When I execute the dumpsys command I always get the same result
Permission Denial: can't dump telephony.registry from pid-953, uid=10090
Am I doing something wrong? Why does android OS still deny me access to the dump service ?
PS I have set min API 8 and I am testing the application on device running (ICS)
API 15

Why does android OS still deny me access to the dump service ?
Because that permission is flagged as android:protectionLevel="signature|system|development" (or signatureOrSystem using the old syntax) on Android 2.3+, and therefore cannot be held by ordinary Android SDK applications.

There's another (hacky) way to access dumpsys without rooting your device - through adb shell.
This will require allowing USB debugging, and finding the port of the adb service.
Enable USB debugging on your device. This option is found under Settings -> Developer Options.
Connect your device to a PC, and run the following command from the PC's shell/command line:
adb tcpip 12345. Then, from your devices shell, issue the command adb connect localhost:12345 from your application. You can now disconnect the device from USB.
Alternatively, you can scan the ports on your device one by one without USB connection, using adb connect localhost:<portnum> and find the port adb service is listening to.
Authorize USB debugging from the pop up confirmation dialog, if prompted. Check the "always" checkbox to do not require this step again.
Now, when you have access to the adb service, use adb shell dumpsys ... from your application code to get whatever service dump you need.
NOTE: You don't need the DUMP permission for that to work.

The android dev team decided to stop granting these permissions to third-party apps. Only system apps can now get them.
more details:https://code.google.com/p/acra/issues/detail?id=100

It reports private values of core Android services that you would never be able to typically obtain. Official document says "Not for use by third-party applications".

Add permission on your manifest "android.permission.DUMP". I have not tried it yet but it shows on adb shell that it is missing that permission

Related

Track Logs of installed apk in android

Im new to android development. I want to track logs in the testing devices, i googled it and i'm confused pls guide which is the correct way.
1. Can Log4j be used and save the logs in device sd card?
2. Firebase Analytics can be used? Is that free to use or paid?
3. Or any other tracking solution?
Guide me which is the correct way to track the logs. Since my app is based on notifications it behaves abnormal randomly in different versions and im not able to track the log
For that, you can use Logcat Extreame app. You can view per-app logs in it.
setup:
if your device is rooted you don't need to do anything special to get logs.
For unrooted devices, grant read_logs permission by following these
steps:
1) install ADB (Android Debug Bridge) on your computer
2) connect your Android device to the computer
3) open shell (Linux,Mac) or command prompt (Windows) and run the following command "adb
shell pm grant scd.lcex android.permission.READ_LOGS"
Logcat Extreme is free and even free of ads
You can use this command:
adb shell logcat YOURLOGTAG:I *:S
you can use Log from android.util, example Log.i (YOURTAG, "Hello")

Android adb:opendir failed permission denied

I try to use adb to connect my android device:
C:\Users\vince>adb shell
shell#M3s:/ $ su root
enter main
start command :am start -a android.intent.action.MAIN -n com.android.settings/com.meizu.settings.root.FlymeRootRequestActivity --ei uid 2000 --ei pid 3472 > /dev/null
shell#M3s:/ # cd data
shell#M3s:/data # ls
opendir failed, Permission denied
255|shell#M3s:/data #
I got the #,but the permission is denied
In past it was easy for anyone to ROOT the mobile device for any purpose. But now for user's security, Android has made it really tough to ROOT the android device. There are still some ways and 3rd party software available that can help you in ROOTing the device. But doing so may harm your device or data.
A Workaround for Developers
If you are an android developer and want to test your app using ADB like accessing your app's SQLite DB, then I'll suggest you to use android's emulators. They are purpose built emulators and I think they are ROOTED by default. Currently connecting to those emulators through ADB is really easy and requires no SU access.
NOTE
If you are not an Android developer and want to get ROOT access for cracking / unlocking your device then you may need to play with your device's kernel and any mistake can lead to a non-recoverable damage to your device or to your data.

How to debug/reset Android 6.0 permissions?

While migrating one of my apps to use the Android 6.0 permissions system, I found it very hard to debug permissions using the emulator.
Findings:
Disabling a permission in the app info screen doesn't re-show the grant permission dialog when using the requestPermissions() method.
Reinstalling the app seems to be the only way to make the app show the grant permission dialog again.
What is the proper method to debug permission using the Android emulator?
It’s actually very easy to debug Android 6.0 permissions. You can reset the permissions to the "install state" for the current foreground app all apps using the following ADB shell command:
adb shell pm reset-permissions
Note: Currently you can't reset the runtime permissions for a specific package, the package manger (pm) tool help section states:
revert all runtime permissions to their default state.
You can easily execute the reset-permissions command using the terminal interface in Android Studio. Note that ADB commands only works if the ADB directory is added to the PATH system environment variable (see: add ADB to path variable).
You can also reset/revoke a specific permissions using:
adb shell pm revoke com.your.package android.permission.WRITE_EXTERNAL_STORAGE
A downside of this command is that it will restart your app, but this doesn't reset the runtime permissions for all apps. To grant a permission replace revoke with grant.

Use the "logcat -b radio" in unroot phone

I have tried to execute logcat -b radio programmatically, but failed. The command can be executed successfully from a PC terminal while the device is connected.
So I want to connect adbd service directly on the phone. Is there any method to connect adbd? Perhaps with a socket or usb driver? Who can give some advice on this?
The READ_LOGS permission control is changed since Android 4.1. Normal application cannot read the logs generated by other process (with different UID).
However, you can still get this permission manually by execute
"pm grant com.yourpackage.name android.permission.READ_LOGS"
on Adb shell. You might need to reboot your device after this.
Back to you question, you cannot connect to ADB daemon on your device with your application running on the same one. Another workaround for your application to read the logs is to write a daemon application to start and be daemonized on ADB shell, which will communicate with your application via IPC to get the log for you.

Enable USB debugging (under settings/applications/development) programmatically from within an app

Is it possible to enable USB debugging (under settings/applications/development) programmatically from within my app?
I was looking at Permission.WRITE_SETTINGS and
http://developer.android.com/reference/android/provider/Settings.System.html,
but I couldn't find anything appropriate.
You will need root permissions to do so from an app.
That said, it is possible to enable ADB by executing the following terminal commands:
setprop persist.service.adb.enable 1
start adbd
This blog post gives an excellent example of how to execute these commands with escalated permissions through su.
First: Your app must be a system app
This line of code may help:
Settings.Global.putInt(getContentResolver(), Global.ADB_ENABLED, 1);
and you need this permission:
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
but after adding this permission in manifest you will get this error:
Permission is only granted to system apps
which means your app must be a system app.
It's not possible without using your own custom firmware that grants access to the security settings.
See thread here: http://groups.google.com/group/android-developers/browse_frm/thread/953c6f0eb0fa9bed#
You can enable adb programmatically by requesting WRITE_SECURE_SETTINGS in manifest and granting it over adb shell:
adb shell pm grant your.package.name android.permission.WRITE_SECURE_SETTINGS
Then you can enable adb on API 17 and above by calling:
Settings.Global.putString(mContext.getContentResolver, Settings.Global.ADB_ENABLED,"1");
For API 16 to API 3 call:
Settings.Secure.putString(mContext.getContentResolver, Settings.Secure.ADB_ENABLED,"1");
To disable adb replace "1" with "0" in commands
You need to follow these 3 steps
in the manifest put <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
Use this command in the code to enable USB debug Settings.Secure.putInt(requireActivity().contentResolver, Settings.Global.ADB_ENABLED, 1) or Settings.Secure.putInt(requireActivity().contentResolver, Settings.Global.ADB_ENABLED, 0) to disable it
IMPORTANT Before being able to use these system API you must grant WRITE_SECURE_SETTINGS from adb running adb shell pm grant your.package.name android.permission.WRITE_SECURE_SETTINGS. The device has to be attached to the computer with USB debug active.
I developed a simple app that uses this approach to enable/disable some developer options such as Debug USB and Keep Device Screen Active https://play.google.com/store/apps/details?id=it.stzan.devtools
Disclaimer: I am the actual developer of DevTools
If your device has root, and API level > 17 for enable adb:
Runtime.getRuntime().exec(new String[] {"su", "-c", "settings put global adb_enabled 1"});
or (depends of su implementation)
Runtime.getRuntime().exec(new String[] {"su", "settings put global adb_enabled 1"});
For disable - change last argument from 1 to 0

Categories

Resources