Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MI 9 Android Q 上的关闭 Shizuku 授权闪退问题。 #45

Closed
zhaobozhen opened this issue Aug 30, 2019 · 9 comments
Closed

MI 9 Android Q 上的关闭 Shizuku 授权闪退问题。 #45

zhaobozhen opened this issue Aug 30, 2019 · 9 comments
Labels

Comments

@zhaobozhen
Copy link

你好,最近着手开发一个应用引入了 Shizuku。引入后试着关闭 Shizuku Manager (3.4.5) 中的授权,程序会直接闪退。尝试关闭App Ops,冰箱也有同样问题。系统版本MIUI 10 9.8.22 Android Q。崩溃日志如下。

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lbe.security.miui/com.android.packageinstaller.permission.ui.GrantPermissionsActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x7f100026
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3304)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3443)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7520)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f100026
at android.content.res.Resources.getText(Resources.java:379)
at android.content.res.MiuiResources.getText(MiuiResources.java:97)
at android.widget.TextView.setText(TextView.java:6376)
at com.android.packageinstaller.permission.ui.GrantPermissionsDefaultViewHandler.updateDescription(Unknown Source:61)
at com.android.packageinstaller.permission.ui.GrantPermissionsDefaultViewHandler.updateAll(Unknown Source:0)
at com.android.packageinstaller.permission.ui.GrantPermissionsDefaultViewHandler.updateUi(Unknown Source:29)
at com.android.packageinstaller.permission.ui.GrantPermissionsActivity.showNextPermissionGroupGrantRequest(Unknown Source:436)
at com.android.packageinstaller.permission.ui.GrantPermissionsActivity.onCreate(Unknown Source:535)
at android.app.Activity.performCreate(Activity.java:7880)
at android.app.Activity.performCreate(Activity.java:7869)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1300)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3279)
... 11 more

@haruue haruue added the miui label Aug 30, 2019
@zhaobozhen
Copy link
Author

补充一下,刚才在 MI 6 Android P 上测试也有同样的问题。

@RikkaW
Copy link
Member

RikkaW commented Aug 31, 2019

锅看起来是在凄惨 MIUI 的 com.lbe.security.miui(

@haruue
Copy link
Member

haruue commented Aug 31, 2019

我在我的设备上重现了这个问题, MI MIX 2 / MIUI 10 9.8.22 开发版 (国内版)。
我这边在申请权限的时候就崩了。不过调用栈不太一样。

08-31 15:07:03.465 21945 21945 E AndroidRuntime: FATAL EXCEPTION: main
08-31 15:07:03.465 21945 21945 E AndroidRuntime: Process: com.lbe.security.miui:ui, PID: 21945
08-31 15:07:03.465 21945 21945 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lbe.security.miui/com.android.packageinstaller.permission.ui.GrantPermissionsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2985)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3120)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1840)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:106)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:207)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6878)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at com.android.packageinstaller.permission.ui.GrantPermissionsDefaultViewHandler.updateDescription(Unknown Source:23)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at com.android.packageinstaller.permission.ui.GrantPermissionsDefaultViewHandler.updateUi(Unknown Source:25)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at com.android.packageinstaller.permission.ui.GrantPermissionsActivity.showNextPermissionGroupGrantRequest(Unknown Source:257)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at com.android.packageinstaller.permission.ui.GrantPermissionsActivity.onCreate(Unknown Source:540)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at android.app.Activity.performCreate(Activity.java:7232)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at android.app.Activity.performCreate(Activity.java:7221)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2965)
08-31 15:07:03.465 21945 21945 E AndroidRuntime: 	... 11 more

总之是 MIUI 的申请权限时的 UI (也就是 com.lbe.security.miui ) 有问题, 随便砸开来看一下就知道问题所在:

首先是在 com.android.packageinstaller.permission.ui.GrantPermissionsDefaultViewHandler.updateDescription() , 他们在用户申请权限时, 会显示一个与权限组相关的图标 (如下图红框所示), 他们会从一个硬编码的 map 中取得该图标。

private void updateDescription() {
    // ...
    if (this.mPermissions != null) {
        this.mPermissionIcon.setImageResource(((Integer) Utils.mGroupIconMap.get(this.mGroupName)).intValue());
    }
    // ...
}

Screenshot_2019-08-31-15-28-56-099_com lbe security miui2

这个 map 硬编码在 com.android.packageinstaller.permission.utils.Utils 的静态代码块中, 很显然, 里面不可能包含 shizuku 的权限组 moe.shizuku.manager.permission-group.API , get() 方法返回了 null, 于是就 NullPointerException 了。
image

可能 MIUI 开发团队不知道第三方应用程序也可以声明 dangerous 级别的权限, 并且其他应用也可以按照运行时权限来申请授权。

我进行了一些额外的测试:

  • 即使关掉 MIUI 优化, 同样的问题仍然会发生。
  • 在开启 MIUI 优化之后, 系统的权限管理 (com.miui.securitycenter) 中并不能看到申请的 Shizuku 权限(如图所示)。
    Screenshot_2019-08-31-15-46-35-203_com miui securitycenter
  • 用户如果希望手动开启权限, 需要关掉 MIUI 优化, 然后在 AOSP 原生的应用程序详情 (android.settings.APPLICATION_DETAILS_SETTINGS) 中的「权限」中才能看到 Shizuku 定义的几个权限。 并且, 在用户开启了 MIUI 优化时, 这个原生的「权限」界面是进不去的 (即使能进入 AOSP 的「应用程序详情」界面)。

解决方案

  • 等待 MIUI 团队修复这个问题。
  • 我们自己可以做什么:检测到 MIUI 并且没有授权时, 将本来的运行时权限申请过程替换成弹出提示界面 (可能是一个 Dialog 然后带有一个开启帮助网页的按钮),引导用户关掉 MIUI 优化, 并手动给应用授予 Shizuku 权限。

@zhaobozhen
Copy link
Author

感谢回复。
了解了,看来问题确实出在了 MIUI 最近更新的 Package Manager。我也会争取和 MIUI 开发组联系看看会不会有更好的解决方案。

rimistri1 added a commit to rimistri1/websites that referenced this issue Jan 7, 2020
# How to start Shizuku?  ## Device is rooted  For rooted devices, start Shizuku directly in Shizuku app.  ## Device is not rooted  For non rooted devices, you need to start Shizuku with `adb`. Using `adb` is not difficult, please read the tutorial below.  ### 1. What is `adb`?  Android Debug Bridge (`adb`) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you Can use to run a variety of commands on a device.  See [Android Developer](https://developer.android.com/studio/command-line/adb) for more information.  ### 2. Install `adb`  #### 2.1. Windows  1. Download the [SDK Platform Tools](https://dl.google.com/android/repository/platform-tools-latest-windows.zip) provided by Google and extract it to any folder 2. Open the folder with Explorer,hold down Shift and right click, select "Open PowerShell Window here" (for Windows 7, select open CMD) 3. Enter `adb`, if success, you can see a long list of content instead of the prompt not finding adb.  ::: tip Please do not close this window. The "terminal" mentioned later refers to this window (if you closed the window, please go back to step 2) :::  ::: tip If you use PowerShell, all `adb` should be replaced with `./adb` :::  #### 2.2. Linux / macOS  You definitely can do this yourself :D  ### 3. Setting `adb`  To use `adb` you first need to turn on USB debugging on your device, usually by following these steps:  1. Open system Settings and go to About. 2. Click "Build number" quickly for several times, you can see a message similar to "You are a developer". 3. At this point, you should able to find "Developer Options" in Settings,  enable "USB Debugging". 4. Connect the device to the computer and type `adb devices` in the terminal. 5. At this time, the dialog "Allow debugging" will appear on the device, check "Always allow" and confirm. 6. Enter `adb devices` again in the terminal. If there is no problem, you will see something like the following.     ```    List of devices attached    XXX      device    ```  ::: tip The steps for enabling Developer Options on different devices may vary, please search for yourself. :::  #### 3.1. MIUI device  _"It's 2019, garbage MIUI still breaks Android features."_  If you use MIUI, you also need to enable "USB Debug (Security options)".  If you use MIUI 11, MIUI 11 breaks custom permission (user apps cannot request for custom permission, please refer [this issue](RikkaApps/Shizuku#45) and [this issue](android-in-china/Compatibility#16)), so you must grant permission for user apps in Shizuku app.  ### 4. Start Shizuku  ::: danger This step needs to be re-executed each time the device is rebooted. :::  Enter `adb shell sh /sdcard/Android/data/moe.shizuku.privileged.api/files/start.sh` in the terminal. If there is no problem, you will see that Shizuku has started successfully in Shizuku app.  ### 5. How to avoid Shizuku stop (even if there is no restart)  ::: danger Please follow the rules below, otherwise it will be stopped. :::  1. Do not turn off "USB Debugging" 2. Do not modify the USB usage mode after connecting the device to the computer (or change to "charge only" if not)     After a security patch, if the USB usage mode is not "charge only", changing the USB usage mode will kill all processes of adb. **Therefore, be sure not to modify the USB usage mode after change to "charge only".** (This step may not be needed if your device has not received security patchs for a long time)     In addition, some manufacturers (such as Sony) added a dialog that will modify the USB usage mode when the computer is connected. Please don't click any dialog before disconnecting.  #### 5.1. Huawei devices  Turn on "Allow ADB Debugging "
@siemsen522

This comment has been minimized.

@ChhonChhai

This comment has been minimized.

@ChhonChhai

This comment has been minimized.

@larry18001

This comment was marked as spam.

@larry18001

This comment was marked as spam.

@RikkaApps RikkaApps locked as spam and limited conversation to collaborators Jun 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants
@RikkaW @haruue @zhaobozhen @siemsen522 @larry18001 @ChhonChhai and others