Batch script for granting adb permissions

General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
User avatar
Bluscre
Posts: 144
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Batch script for granting adb permissions

Post by Bluscre » 12 Jan 2020 19:17

On unrooted devices there are some permissions that can be granted via a ADB connection. so it would be nice if there was a batch script that would use ADB to grant all grantable permissions through a PC without root
Unofficial AutoMagic Telegram Group: http://t.me/automagic4android
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.
Sent from my Lenovo TAB 2 A10-70L running Android 6.0.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Batch script for granting adb permissions

Post by Desmanto » 14 Jan 2020 17:35

Maybe we can just extract all available permission and then create the multiple lines command. Automagic 1.37 has all these permission.

Code: Select all

android.permission.ACCESS_COARSE_LOCATION
android.permission.ACCESS_FINE_LOCATION
android.permission.RECEIVE_BOOT_COMPLETED
android.permission.VIBRATE
android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN
android.permission.CALL_PHONE
android.permission.CAMERA
android.permission.DISABLE_KEYGUARD
android.permission.FLASHLIGHT
android.permission.GET_TASKS
android.permission.KILL_BACKGROUND_PROCESSES
android.permission.MODIFY_AUDIO_SETTINGS
android.permission.PROCESS_OUTGOING_CALLS
android.permission.READ_CALENDAR
android.permission.READ_CONTACTS
android.permission.READ_PHONE_STATE
android.permission.READ_SYNC_SETTINGS
android.permission.READ_SYNC_STATS
android.permission.RECEIVE_SMS
android.permission.RECORD_AUDIO
android.permission.SEND_SMS
android.permission.SET_WALLPAPER
android.permission.USE_CREDENTIALS
android.permission.WAKE_LOCK
android.permission.WRITE_CALENDAR
android.permission.WRITE_CONTACTS
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.WRITE_SYNC_SETTINGS
android.permission.ACCESS_NETWORK_STATE
android.permission.CHANGE_NETWORK_STATE
android.permission.INTERNET
android.permission.NFC
android.permission.GET_ACCOUNTS
android.permission.READ_CALL_LOG
android.permission.WRITE_CALL_LOG
android.permission.BROADCAST_STICKY
android.permission.ACCESS_NOTIFICATION_POLICY
android.permission.ANSWER_PHONE_CALLS
android.permission.USE_FINGERPRINT
android.permission.USE_BIOMETRIC
android.permission.FOREGROUND_SERVICE
android.permission.WRITE_SECURE_SETTINGS
android.permission.ACTIVITY_RECOGNITION
android.permission.READ_EXTERNAL_STORAGE
android.permission.ACCESS_BACKGROUND_LOCATION
android.permission.ACCESS_MEDIA_LOCATION
To grant all above via adb shell, maybe these lines

Code: Select all

adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.ACCESS_COARSE_LOCATION
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.ACCESS_FINE_LOCATION
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.RECEIVE_BOOT_COMPLETED
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.VIBRATE
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.ACCESS_WIFI_STATE
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.CHANGE_WIFI_STATE
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.BLUETOOTH
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.BLUETOOTH_ADMIN
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.CALL_PHONE
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.CAMERA
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.DISABLE_KEYGUARD
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.FLASHLIGHT
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.GET_TASKS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.KILL_BACKGROUND_PROCESSES
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.MODIFY_AUDIO_SETTINGS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.PROCESS_OUTGOING_CALLS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.READ_CALENDAR
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.READ_CONTACTS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.READ_PHONE_STATE
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.READ_SYNC_SETTINGS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.READ_SYNC_STATS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.RECEIVE_SMS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.RECORD_AUDIO
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.SEND_SMS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.SET_WALLPAPER
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.USE_CREDENTIALS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.WAKE_LOCK
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.WRITE_CALENDAR
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.WRITE_CONTACTS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.WRITE_EXTERNAL_STORAGE
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.WRITE_SYNC_SETTINGS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.ACCESS_NETWORK_STATE
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.CHANGE_NETWORK_STATE
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.INTERNET
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.NFC
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.GET_ACCOUNTS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.READ_CALL_LOG
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.WRITE_CALL_LOG
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.BROADCAST_STICKY
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.ACCESS_NOTIFICATION_POLICY
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.ANSWER_PHONE_CALLS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.USE_FINGERPRINT
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.USE_BIOMETRIC
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.FOREGROUND_SERVICE
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.WRITE_SECURE_SETTINGS
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.ACTIVITY_RECOGNITION
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.READ_EXTERNAL_STORAGE
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.ACCESS_BACKGROUND_LOCATION
adb shell pm grant ch.gridvision.ppam.androidautomagic android.permission.ACCESS_MEDIA_LOCATION
However, there are some features/permissions those still require manual toggling. I just changed ROM and restore all my apps via migrate. It restored most app permissions correctly, including Automagic. But I still have to manually grant several features/permissions such as :
- Display over other app
- Modify setting
- Usage access
- Notification access
- Device Admin
- Do Not Disturb Access
- Accessibility

So I think although we have the script, there are still some manual stuff need to be done. Can't help with that. That's why I am so lazy to change ROM once I have settled with certain ROM.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

richaardvark
Posts: 2
Joined: 11 Jun 2020 12:44

Re: Batch script for granting adb permissions

Post by richaardvark » 14 Aug 2020 10:39

Desmanto wrote:
14 Jan 2020 17:35
However, there are some features/permissions those still require manual toggling. I just changed ROM and restore all my apps via migrate. It restored most app permissions correctly, including Automagic. But I still have to manually grant several features/permissions such as :
- Display over other app
- Modify setting
- Usage access
- Notification access
- Device Admin
- Do Not Disturb Access
- Accessibility
For those of us who are rooted, I would like to be able to set/fix some of these additional permissions via "Execute Root Command." There is a frustrating Automagic bug where Accessibility Service and Notification Access are both enabled but Automagic gets confused and doesn't realize they are. I am running Automagic on a rooted Amazon Fire TV Stick and as such Amazon has of course greatly modified stock Android to create what they call "FireOS," but which is just Android with many of the GUI and settings menu areas removed or hidden. Therefore, when I am in the main Automagic settings "Check Permissions" or whatever submenu, and it says that Notification Access or Accessibility are not granted permission (they are, I have confirmed this via ADB), when I click the check box to change the setting through the GUI settings menu nothing happens (because Amazon has removed those GUI sections of the Android settings apk. The permissions have to be set via ADB.

I use the following adb commands to fix my permissions:

Code: Select all

adb shell cmd notification allow_listener ch.gridvision.ppam.androidautomagic/ch.gridvision.ppam.androidautomagic.NotificationDetectorService
adb shell settings put secure enabled_accessibility_services ch.gridvision.ppam.androidautomagic/ch.gridvision.ppam.androidautomagic.AccessibilityService
adb shell settings put secure accessibility_enabled 1
And then can confirm that they are set with "adb shell settings get..." and they are correctly set, but the annoying Automagic GUI/menu doesn't recognize this. The only way to fix this is to export all flows/variables/widgets (wait, I don't think you can export variables data, can you? Annoying if not...) and then delete the entire Automagic app or delete all the app data and then re-import all of my flows/widgets/variable data. This is super annoying. Is there any other way to make Automagic recognize permissions correctly? Can this bug be fixed please??

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Batch script for granting adb permissions

Post by Desmanto » 14 Aug 2020 11:14

@richaardvark : Those permission/features require manual toggling. Usually the features are moved to other location, you can find it using action Launch App, choose the default setting app, then try to to find accessibility/notification access in the class name. Automagic can't recognize it from the adb shell secure setting because these toggling require the special app permission from the setting itself. The same reason why some secure setting modification won't be reflected by the OS (such as toggle mobile data, airplane, wireless adb). This is android limitation, can't be fixed from Automagic part.

You can't export glovar, that's why I create my own glovar manager, but never really finish it. I create it to maintain multi version of glovar, since I use it for logging too. Sometimes I forgot to stop logging and end up in too big glovar, causing every flow to slow down significantly.

The only way to import glovar is to clear automagic data as you have done; put the flows.xml, widget.xml and variables.bin in Automagic folder. It should be recognized properly at first run after clear data.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

richaardvark
Posts: 2
Joined: 11 Jun 2020 12:44

Re: Batch script for granting adb permissions

Post by richaardvark » 14 Aug 2020 20:03

@Desmanto : Thank you very much for the information you have shared here!
Desmanto wrote:
14 Aug 2020 11:14
@richaardvark : Those permission/features require manual toggling. Usually the features are moved to other location, you can find it using action Launch App, choose the default setting app, then try to to find accessibility/notification access in the class name. Automagic can't recognize it from the adb shell secure setting because these toggling require the special app permission from the setting itself. The same reason why some secure setting modification won't be reflected by the OS (such as toggle mobile data, airplane, wireless adb). This is android limitation, can't be fixed from Automagic part.
Thanks. I have used the Launch App action before to find the activity to launch the GUI to modify those accessibility features/permission, but it simply does not exist :-/ I have spent a lot of time probing the "FireOS" structure, mainly using the application "Activity Launcher," which lets you see all activities for each user-installed and system apk and lets you launch them directly. There simply are not activities for the typical Android settings menu-area for these features - it can only be done via ADB. That's why nothing happens when I try to use the Automagic "Features & Permissions" area of the Automagic Settings menu to try to enable these features - there does not exist a GUI menu or settings activity to enable these features, only ADB. And this is how I have always been successful in the past, when initially installing and configuring Automagic, to have Automagic working correctly and having permission to view notifications, have accessibility service access, etc. I run into this problem every few months: Automagic will crash for one reason or another (not often, but perhaps a Flow ran into an error too many times or something just happened and there is a "contact the developer" type error message/java error but than at that same time Accessibility Service is no longer recognized by Automagic as being enabled. I've had to fix this only maybe four times in the last year or so of successfully running Automagic on this device, but I cannot remember for the life of me how I have been able to resolve this each time. When I delete the Automagic apk and reinstall, all of my data is still there. I have tried deleting the main "Automagic" when deleting and reinstalling Automagic but it is still not recognizing ADB as enabled. I have been able to successfully make Automagic recognize that Accessibility/notification access/IME keyboard etc. permissions are granted and enabled via ADB before, but I just can't remember how I have done this.

I think for now I am going to see if I can fix this by restoring a previous instance of Automagic using Titanium Backup, from when the permissions were properly recognized by Automagic, and then importing my latest Flow/Widget data. Maybe this will work. It's such a pain to have to go through this every time there is a big crash of the app though... :(

.......
Edit: Ok, I am back up an running again! ✔ I remember now how I was able to get all permissions/features properly working... I used a separate/third-party app called "Settings Database Editor" which lets you directly modify the system databases/tables and I was able to manually type in the Automagic notification listener, keyboard, and accessibility services and I guess this more-or-less was able to act as my GUI-way of doing it, without using ADB, and as such Automagic recognized that the features/services had been enabled and everything is working fine again.

I'll have to remember this for the future... use "Settings Database Editor" app to fix Automagic permissions.

Thanks again for your help! Also, copying the .bin file worked perfectly for the glovars. :)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Batch script for granting adb permissions

Post by Desmanto » 15 Aug 2020 04:16

@richaardvark : If editing the database directly work, maybe you can try action set system setting, at the same Name - Value.

Notification listener
[secure] enabled_notification_listeners : ch.gridvision.ppam.androidautomagic/ch.gridvision.ppam.androidautomagic.NotificationDetectorService

Enable accessibility
[secure] accessibility_enabled : 1

Accessibility for Automagic
[secure] enabled_accessibility_services : ch.gridvision.ppam.androidautomagic/ch.gridvision.ppam.androidautomagic.AccessibilityService

For notification access and accessibility, if you use other apps too, the list would be longer.

There are some brand really remove some of the feature from Android. Such as several oppo/vivo ROM, they can't enable adb input, as it is completely non existent at those ROM.

To edit database, I use MiXplorer built-in SQL editor. But at my phone, not all values are reflected by the system.


I prepare a flow to execute when I switch ROM. One of them is to grant write secure and other permission

Code: Select all

cmd = "pm grant ch.gridvision.ppam.androidautomagic android.permission.WRITE_SECURE_SETTINGS\n" +
"pm grant ch.gridvision.ppam.androidautomagic android.permission.READ_LOGS\n" +
"pm grant ch.gridvision.ppam.androidautomagic android.permission.DUMP"
Later execute root command {cmd}, this will grant Automagic permission which require adb. Although I usually have access to adb shell, but it is just so I don't forget. As I also have other need to setup thru similar way.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply