Error: Requires permission android.permission.WRITE_SECURE_SETTINGS
CoderBuck opened this issue · 34 comments
XiaoMi4 Android 6.0 MIUI8
$ ./gnirehtet rt
Starting gnirehtet...
'adb' reverse tcp:31416 tcp:31416
'adb' shell am startservice -a com.genymobile.gnirehtet.START
Starting service: Intent { act=com.genymobile.gnirehtet.START }
Error: Requires permission android.permission.WRITE_SECURE_SETTINGS
'java' -jar relay.jar
2017-04-06 17:31:05.886 I Main: Starting server...
Stopping gnirehtet...
'adb' shell am startservice -a com.genymobile.gnirehtet.STOP
Starting service: Intent { act=com.genymobile.gnirehtet.STOP }
Error: Requires permission android.permission.WRITE_SECURE_SETTINGS
[Edit by @rom1v] Solution: #302 (comment)
Arf, it seems that your shell
user does not have this permission… It should have it.
This requirement (a bit hacky) had been introduced by commit e7b8407 (the commit message provides some details).
Does anyone have an idea to get the same "restriction" without the WRITE_SECURE_SETTINGS
permission?
Have same issue with Xiaomi Redmi 3S Prime MIUI8 Android 6.0.1
Permissions granted to the app according to the phone are 'full network access' and 'view network connections'.
When I try
adb shell pm grant com.genymobile.gnirehtet android.permission.WRITE_SECURE_SETTINGS
I get
Operation not allowed: java.lang.SecurityException: grantRuntimePermission: Neither user 2000 nor current process has android.permission.GRANT_RUNTIME_PERMISSIONS.
@CoderBuck @yashrajtalan Could you give the permissions of your Android shell, please?
First, locate Shell.apk
:
$ adb shell pm list package -f com.android.shell
package:/system/priv-app/Shell/Shell.apk=com.android.shell
Then pull it:
adb pull /system/priv-app/Shell/Shell.apk
Finally, print its permissions:
aapt d permissions Shell.apk
(aapt
is available in $ANDROID_SDK/build-tools/25.0.2/aapt
, or there is an aapt
package in Debian)
Maybe we could find a better permission which works also for your devices ;-)
$ adb shell pm list package -f com.android.shell
package:/system/priv-app/Shell/Shell.apk=com.android.shell
$ adb pull /system/priv-app/Shell/Shell.apk
adb: error: remote object 'D:/Develop/Git/Git/system/priv-app/Shell/Shell.apk' does not exist
I am not familiar with this ;-0
@CoderBuck It seems you are using git bash on Windows: http://stackoverflow.com/questions/16344985/how-do-i-pass-an-absolute-path-to-the-adb-command-via-git-bash-for-windows
Try with cmd.exe
instead, since git bash mangles pathes at some point.
EDIT: or:
adb pull //system/priv-app/Shell/Shell.apk
thanks ;-)
package: com.android.shell
uses-permission: name='android.permission.SEND_SMS'
uses-permission: name='android.permission.CALL_PHONE'
uses-permission: name='android.permission.READ_PHONE_STATE'
uses-permission: name='android.permission.READ_CONTACTS'
uses-permission: name='android.permission.WRITE_CONTACTS'
uses-permission: name='android.permission.READ_CALENDAR'
uses-permission: name='android.permission.WRITE_CALENDAR'
uses-permission: name='android.permission.READ_USER_DICTIONARY'
uses-permission: name='android.permission.WRITE_USER_DICTIONARY'
uses-permission: name='android.permission.ACCESS_FINE_LOCATION'
uses-permission: name='android.permission.ACCESS_COARSE_LOCATION'
uses-permission: name='android.permission.ACCESS_LOCATION_EXTRA_COMMANDS'
uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
uses-permission: name='android.permission.ACCESS_WIFI_STATE'
uses-permission: name='android.permission.BLUETOOTH'
uses-permission: name='android.permission.EXPAND_STATUS_BAR'
uses-permission: name='android.permission.DISABLE_KEYGUARD'
uses-permission: name='android.permission.REAL_GET_TASKS'
uses-permission: name='android.permission.CHANGE_CONFIGURATION'
uses-permission: name='android.permission.REORDER_TASKS'
uses-permission: name='android.permission.SET_ANIMATION_SCALE'
uses-permission: name='android.permission.SET_PREFERRED_APPLICATIONS'
uses-permission: name='android.permission.WRITE_SETTINGS'
uses-permission: name='android.permission.WRITE_SECURE_SETTINGS'
uses-permission: name='android.permission.BROADCAST_STICKY'
uses-permission: name='android.permission.SET_DEBUG_APP'
uses-permission: name='android.permission.SET_PROCESS_LIMIT'
uses-permission: name='android.permission.SET_ALWAYS_FINISH'
uses-permission: name='android.permission.DUMP'
uses-permission: name='android.permission.SIGNAL_PERSISTENT_PROCESSES'
uses-permission: name='android.permission.KILL_BACKGROUND_PROCESSES'
uses-permission: name='android.permission.FORCE_BACK'
uses-permission: name='android.permission.BATTERY_STATS'
uses-permission: name='android.permission.INTERNAL_SYSTEM_WINDOW'
uses-permission: name='android.permission.INJECT_EVENTS'
uses-permission: name='android.permission.RETRIEVE_WINDOW_CONTENT'
uses-permission: name='android.permission.SET_ACTIVITY_WATCHER'
uses-permission: name='android.permission.READ_INPUT_STATE'
uses-permission: name='android.permission.SET_ORIENTATION'
uses-permission: name='android.permission.INSTALL_PACKAGES'
uses-permission: name='android.permission.MOVE_PACKAGE'
uses-permission: name='android.permission.CLEAR_APP_USER_DATA'
uses-permission: name='android.permission.DELETE_CACHE_FILES'
uses-permission: name='android.permission.DELETE_PACKAGES'
uses-permission: name='android.permission.ACCESS_SURFACE_FLINGER'
uses-permission: name='android.permission.READ_FRAME_BUFFER'
uses-permission: name='android.permission.DEVICE_POWER'
uses-permission: name='android.permission.INSTALL_LOCATION_PROVIDER'
uses-permission: name='android.permission.BACKUP'
uses-permission: name='android.permission.FORCE_STOP_PACKAGES'
uses-permission: name='android.permission.STOP_APP_SWITCHES'
uses-permission: name='android.permission.ACCESS_CONTENT_PROVIDERS_EXTERNALLY'
uses-permission: name='android.permission.GRANT_RUNTIME_PERMISSIONS'
uses-permission: name='android.permission.REVOKE_RUNTIME_PERMISSIONS'
uses-permission: name='android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS'
uses-permission: name='android.permission.SET_KEYBOARD_LAYOUT'
uses-permission: name='android.permission.GET_DETAILED_TASKS'
uses-permission: name='android.permission.SET_SCREEN_COMPATIBILITY'
uses-permission: name='android.permission.READ_EXTERNAL_STORAGE'
uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE'
uses-permission: name='android.permission.WRITE_MEDIA_STORAGE'
uses-permission: name='android.permission.INTERACT_ACROSS_USERS'
uses-permission: name='android.permission.INTERACT_ACROSS_USERS_FULL'
uses-permission: name='android.permission.CREATE_USERS'
uses-permission: name='android.permission.MANAGE_DEVICE_ADMINS'
uses-permission: name='android.permission.BLUETOOTH_STACK'
uses-permission: name='android.permission.GET_ACCOUNTS'
uses-permission: name='android.permission.RETRIEVE_WINDOW_TOKEN'
uses-permission: name='android.permission.FRAME_STATS'
uses-permission: name='android.permission.BIND_APPWIDGET'
uses-permission: name='android.permission.UPDATE_APP_OPS_STATS'
uses-permission: name='android.permission.MODIFY_APPWIDGET_BIND_PERMISSIONS'
uses-permission: name='android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS'
uses-permission: name='android.permission.CHANGE_APP_IDLE_STATE'
uses-permission: name='android.permission.MOUNT_UNMOUNT_FILESYSTEMS'
uses-permission: name='android.permission.MOUNT_FORMAT_FILESYSTEMS'
uses-permission: name='android.permission.MODIFY_PHONE_STATE'
uses-permission: name='android.permission.REGISTER_CALL_PROVIDER'
uses-permission: name='android.permission.REGISTER_CONNECTION_MANAGER'
uses-permission: name='android.permission.REGISTER_SIM_SUBSCRIPTION'
uses-permission: name='android.permission.GET_APP_OPS_STATS'
OK so it declares using android.permission.WRITE_SECURE_SETTINGS
.
Could you give the result of the following commands, please:
adb shell id
adb shell cat /proc/'$$'/status
EDIT: in fact, these commands will not help.
Ok.
adb shell id
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
uid=2000(shell) gid=2000(shell) groups=2000(shell),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats) context=u:r:shell:s0
adb shell cat /proc/'$$'/status
/system/bin/sh: cat: /proc/$$/status: No such file or directory
To summarize:
android.permission.WRITE_SECURE_SETTINGS
has protection level "signature"- sending the intent from shell leads to error
Requires permission android.permission.WRITE_SECURE_SETTINGS
- shell declares using the permission
android.permission.WRITE_SECURE_SETTINGS
One possibility is that Shell.apk
is not signed with the same signature as the ROM. Which is very strange…
Could you replace android.permission.WRITE_SECURE_SETTINGS
by android.permission.WRITE_SETTINGS
(a permission with normal protection level) here, build, and try again, please?
If it works, it suggests that the problem is related to Shell.apk
signature…
error
Error: Requires permission android.permission.WRITE_SETTINGS
So you have a shell with no permissions… Can you find a permission listed from Shell.apk
that does work?
What about:
adb shell am startservice -a com.genymobile.gnirehtet.START --user 0
adb shell am startservice -a com.genymobile.gnirehtet.START --user -2
adb shell am startservice -a com.genymobile.gnirehtet.START --user -3
?
The result of this command may also be interesting:
adb shell dumpsys package com.android.shell
@CoderBuck @yashrajtalan Could you please give the result of:
adb shell dumpsys package com.android.shell
And also try these commands.
Thank you :)
The issue seems to be resolved by heading over to Developer Options on MIUI, and enabling the following:
USB debugging -Debug mode when USB is connected
Install via USB -Allow installing apps via USB
USB debugging (Security Settings)- Allow granting permissions and simulating input via USB debugging
The first was already enabled, and I installed the apk file manually so I didn't need the second option.
I'm guessing the issue can be pinned down to the last option, which allows granting the necessary permissions. @CoderBuck please confirm.
Thank you @rom1v for this amazing app. This is a worthy free replacement for ReverseTethering NoRoot.
@rom1v @yashrajtalan Sorry to replay late! @yashrajtalan you are right!
thanks a lot!
Great, thank you 👍 So I close the issue.
@yashrajtalan Your procedure requires MI account in Xiaomi Redmi phones. You just remove android.permission.WRITE_SECURE_SETTINGS
in manifest file (mentioned in #40).
@yashrajtalan,
Thanks a lot, your solution worked for me.
edit gnirehtet-run.cmd as below:
@echo off
adb shell "su -c 'setenforce 0'"
adb shell "su -c 'am start -a com.genymobile.gnirehtet.START -n com.genymobile.gnirehtet/.GnirehtetActivity'"
adb shell "su -c 'setenforce 1'"
gnirehtet.exe run
pause
Note: if your device's SELInux mode is Permissive then you can remove setenforce commands
@echo off
adb shell "su -c 'am start -a com.genymobile.gnirehtet.START -n com.genymobile.gnirehtet/.GnirehtetActivity'"
gnirehtet.exe run
pause
edit gnirehtet-run.cmd as below:
@echo off adb shell "su -c 'setenforce 0'" adb shell "su -c 'am start -a com.genymobile.gnirehtet.START -n com.genymobile.gnirehtet/.GnirehtetActivity'" adb shell "su -c 'setenforce 1'" gnirehtet.exe run pause
Note: if your device's SELInux mode is Permissive then you can remove setenforce commands
@echo off adb shell "su -c 'am start -a com.genymobile.gnirehtet.START -n com.genymobile.gnirehtet/.GnirehtetActivity'" gnirehtet.exe run pause
thank you this worked for me on realme 2 pro ColorOs android pie and realmeUi android Q
i made a script file to work on Arch linux from your commands ,, here is its contents
#!/bin/sh
adb shell "su -c 'setenforce 0'"
adb shell "su -c 'am start -a com.genymobile.gnirehtet.START -n com.genymobile.gnirehtet/.GnirehtetActivity'"
adb shell "su -c 'setenforce 1'"
gnirehtet run
What about:
adb shell am startservice -a com.genymobile.gnirehtet.START --user 0 adb shell am startservice -a com.genymobile.gnirehtet.START --user -2 adb shell am startservice -a com.genymobile.gnirehtet.START --user -3
?
how to run them ?
@CoderBuck @yashrajtalan Could you give the permissions of your Android shell, please?
First, locate
Shell.apk
:$ adb shell pm list package -f com.android.shell package:/system/priv-app/Shell/Shell.apk=com.android.shell
Then pull it:
adb pull /system/priv-app/Shell/Shell.apk
Finally, print its permissions:
aapt d permissions Shell.apk
(
aapt
is available in$ANDROID_SDK/build-tools/25.0.2/aapt
, or there is anaapt
package in Debian)Maybe we could find a better permission which works also for your devices ;-)
root@www:/mnt/c/scrcpy-win64-v1.16# aapt d permissions Shell.apk
package: com.android.shell
uses-permission: name='android.permission.SEND_SMS'
uses-permission: name='android.permission.CALL_PHONE'
uses-permission: name='android.permission.READ_PHONE_STATE'
uses-permission: name='android.permission.READ_CONTACTS'
uses-permission: name='android.permission.WRITE_CONTACTS'
uses-permission: name='android.permission.READ_CALENDAR'
uses-permission: name='android.permission.WRITE_CALENDAR'
uses-permission: name='android.permission.READ_USER_DICTIONARY'
uses-permission: name='android.permission.WRITE_USER_DICTIONARY'
uses-permission: name='android.permission.ACCESS_FINE_LOCATION'
uses-permission: name='android.permission.ACCESS_COARSE_LOCATION'
uses-permission: name='android.permission.ACCESS_LOCATION_EXTRA_COMMANDS'
uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
uses-permission: name='android.permission.ACCESS_WIFI_STATE'
uses-permission: name='android.permission.BLUETOOTH'
uses-permission: name='android.permission.LOCAL_MAC_ADDRESS'
uses-permission: name='android.permission.EXPAND_STATUS_BAR'
uses-permission: name='android.permission.DISABLE_KEYGUARD'
uses-permission: name='android.permission.MANAGE_NETWORK_POLICY'
uses-permission: name='android.permission.MANAGE_USB'
uses-permission: name='android.permission.USE_RESERVED_DISK'
uses-permission: name='android.permission.FOREGROUND_SERVICE'
uses-permission: name='android.permission.REAL_GET_TASKS'
uses-permission: name='android.permission.CHANGE_CONFIGURATION'
uses-permission: name='android.permission.REORDER_TASKS'
uses-permission: name='android.permission.SET_ANIMATION_SCALE'
uses-permission: name='android.permission.SET_PREFERRED_APPLICATIONS'
uses-permission: name='android.permission.WRITE_SETTINGS'
uses-permission: name='android.permission.WRITE_SECURE_SETTINGS'
uses-permission: name='android.permission.BROADCAST_STICKY'
uses-permission: name='android.permission.SET_DEBUG_APP'
uses-permission: name='android.permission.SET_PROCESS_LIMIT'
uses-permission: name='android.permission.SET_ALWAYS_FINISH'
uses-permission: name='android.permission.DUMP'
uses-permission: name='android.permission.SIGNAL_PERSISTENT_PROCESSES'
uses-permission: name='android.permission.KILL_BACKGROUND_PROCESSES'
uses-permission: name='android.permission.FORCE_BACK'
uses-permission: name='android.permission.BATTERY_STATS'
uses-permission: name='android.permission.PACKAGE_USAGE_STATS'
uses-permission: name='android.permission.INTERNAL_SYSTEM_WINDOW'
uses-permission: name='android.permission.INJECT_EVENTS'
uses-permission: name='android.permission.RETRIEVE_WINDOW_CONTENT'
uses-permission: name='android.permission.SET_ACTIVITY_WATCHER'
uses-permission: name='android.permission.READ_INPUT_STATE'
uses-permission: name='android.permission.SET_ORIENTATION'
uses-permission: name='android.permission.INSTALL_PACKAGES'
uses-permission: name='android.permission.MOVE_PACKAGE'
uses-permission: name='android.permission.CLEAR_APP_USER_DATA'
uses-permission: name='android.permission.CLEAR_APP_CACHE'
uses-permission: name='android.permission.DELETE_CACHE_FILES'
uses-permission: name='android.permission.DELETE_PACKAGES'
uses-permission: name='android.permission.ACCESS_SURFACE_FLINGER'
uses-permission: name='android.permission.READ_FRAME_BUFFER'
uses-permission: name='android.permission.DEVICE_POWER'
uses-permission: name='android.permission.INSTALL_LOCATION_PROVIDER'
uses-permission: name='android.permission.BACKUP'
uses-permission: name='android.permission.FORCE_STOP_PACKAGES'
uses-permission: name='android.permission.STOP_APP_SWITCHES'
uses-permission: name='android.permission.ACCESS_CONTENT_PROVIDERS_EXTERNALLY'
uses-permission: name='android.permission.GRANT_RUNTIME_PERMISSIONS'
uses-permission: name='android.permission.REVOKE_RUNTIME_PERMISSIONS'
uses-permission: name='android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS'
uses-permission: name='android.permission.SET_KEYBOARD_LAYOUT'
uses-permission: name='android.permission.GET_DETAILED_TASKS'
uses-permission: name='android.permission.SET_SCREEN_COMPATIBILITY'
uses-permission: name='android.permission.READ_EXTERNAL_STORAGE'
uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE'
uses-permission: name='android.permission.WRITE_MEDIA_STORAGE'
uses-permission: name='android.permission.INTERACT_ACROSS_USERS'
uses-permission: name='android.permission.INTERACT_ACROSS_USERS_FULL'
uses-permission: name='android.permission.CREATE_USERS'
uses-permission: name='android.permission.MANAGE_DEVICE_ADMINS'
uses-permission: name='android.permission.MANAGE_COMPANION_DEVICES'
uses-permission: name='android.permission.ACCESS_LOWPAN_STATE'
uses-permission: name='android.permission.CHANGE_LOWPAN_STATE'
uses-permission: name='android.permission.READ_LOWPAN_CREDENTIAL'
uses-permission: name='android.permission.BLUETOOTH_STACK'
uses-permission: name='android.permission.GET_ACCOUNTS'
uses-permission: name='android.permission.RETRIEVE_WINDOW_TOKEN'
uses-permission: name='android.permission.FRAME_STATS'
uses-permission: name='android.permission.BIND_APPWIDGET'
uses-permission: name='android.permission.UPDATE_APP_OPS_STATS'
uses-permission: name='android.permission.MODIFY_APPWIDGET_BIND_PERMISSIONS'
uses-permission: name='android.permission.CHANGE_APP_IDLE_STATE'
uses-permission: name='android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST'
uses-permission: name='android.permission.MOUNT_UNMOUNT_FILESYSTEMS'
uses-permission: name='android.permission.MOUNT_FORMAT_FILESYSTEMS'
uses-permission: name='android.permission.MODIFY_PHONE_STATE'
uses-permission: name='android.permission.REGISTER_CALL_PROVIDER'
uses-permission: name='android.permission.REGISTER_CONNECTION_MANAGER'
uses-permission: name='android.permission.REGISTER_SIM_SUBSCRIPTION'
uses-permission: name='android.permission.GET_APP_OPS_STATS'
uses-permission: name='android.permission.MANAGE_APP_OPS_MODES'
uses-permission: name='android.permission.VIBRATE'
uses-permission: name='android.permission.MANAGE_ACTIVITY_STACKS'
uses-permission: name='android.permission.START_TASKS_FROM_RECENTS'
uses-permission: name='android.permission.ACTIVITY_EMBEDDING'
uses-permission: name='android.permission.CONNECTIVITY_INTERNAL'
uses-permission: name='android.permission.CHANGE_COMPONENT_ENABLED_STATE'
uses-permission: name='android.permission.MANAGE_AUTO_FILL'
uses-permission: name='android.permission.NETWORK_SETTINGS'
uses-permission: name='android.permission.CHANGE_WIFI_STATE'
uses-permission: name='android.permission.SET_TIME'
uses-permission: name='android.permission.SET_TIME_ZONE'
uses-permission: name='android.permission.DISABLE_HIDDEN_API_CHECKS'
uses-permission: name='android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME'
uses-permission: name='android.permission.WAKE_LOCK'
uses-permission: name='android.permission.CHANGE_OVERLAY_PACKAGES'
uses-permission: name='android.permission.RESTRICTED_VR_ACCESS'
uses-permission: name='android.permission.MANAGE_BIND_INSTANT_SERVICE'
uses-permission: name='android.permission.SET_HARMFUL_APP_WARNINGS'
uses-permission: name='android.permission.MANAGE_SENSORS'
uses-permission: name='android.permission.MANAGE_AUDIO_POLICY'
uses-permission: name='android.permission.MANAGE_CAMERA'
uses-permission: name='android.permission.ACCESS_INSTANT_APPS'
uses-permission: name='android.permission.MANAGE_BLUETOOTH_WHEN_PERMISSION_REVIEW_REQUIRED'
uses-permission: name='android.permission.MANAGE_WIFI_WHEN_PERMISSION_REVIEW_REQUIRED'
uses-permission: name='android.permission.WATCH_APPOPS'
uses-permission: name='android.permission.CONTROL_KEYGUARD'
root@www:/mnt/c/scrcpy-win64-v1.16# apt install adb
It's stuck on "Starting: Intent { act=com.genymobile.gnirehtet.STOP cmp=com.genymobile.gnirehtet/.GnirehtetActivity }" for me
I don't see these two options on Samsung One UI 2.5:
Install via USB -Allow installing apps via USB
USB debugging (Security Settings)- Allow granting permissions and simulating input via USB debuggingInstall via USB -Allow
Please test enabling "security settings" in developer options: appium/appium#13802 (comment)
Could you replace
android.permission.WRITE_SECURE_SETTINGS
byandroid.permission.WRITE_SETTINGS
(a permission with normal protection level) here, build, and try again, please?If it works, it suggests that the problem is related to
Shell.apk
signature…
I am having similar issues
is there any way I can overwrite the permission?
See #302 (comment)
On my OnePlus Nord 2T 5G (Android 12, OxygenOS 12.1), I also had to tick Developer options > Disable permission monitoring
along with USB Debugging to get past a similar exception.
P.S.: apologies for reviving this old issue.
I had the same problem on OnePlus 8t, and the solution was to go to the Developer Settings on the phone and enable:
Developer Options > Apps > Disable permission monitoring
The issue seems to be resolved by heading over to Developer Options on MIUI, and enabling the following: USB debugging -Debug mode when USB is connected Install via USB -Allow installing apps via USB USB debugging (Security Settings)- Allow granting permissions and simulating input via USB debugging
The first was already enabled, and I installed the apk file manually so I didn't need the second option.
I'm guessing the issue can be pinned down to the last option, which allows granting the necessary permissions. @CoderBuck please confirm.
Thank you @rom1v for this amazing app. This is a worthy free replacement for ReverseTethering NoRoot.
turning on the install via usb option requires an internet connection and currently am unable to do that. Is there a way to do this without having to connect to the internet. Note: the option is turned on in the screenshot but it automatically switches off after a couple of seconds..
I had the same problem on OnePlus 8t, and the solution was to go to the Developer Settings on the phone and enable:
Developer Options > Apps > Disable permission monitoring
The same solution worked for Oppo.
I had the same problem on OnePlus 8t, and the solution was to go to the Developer Settings on the phone and enable:
Developer Options > Apps > Disable permission monitoring
Also works on OnePlus Nord