【问题标题】:rebooting Android phone - permission denial重新启动 Android 手机 - 权限被拒绝
【发布时间】:2023-09-21 06:15:01
【问题描述】:

我正在尝试在某个时候(通过代码)重启手机。为了做到这一点,我这样做:


    Intent i = new Intent(android.content.Intent.ACTION_REBOOT);
    i.putExtra("nowait", 1);
    i.putExtra("interval", 1);
    i.putExtra("window", 0);
    this.sendBroadcast(i);

问题是,即使我在清单中有这一行:

uses-permission android:name="android.permission.REBOOT"(带分隔符)。

当试图执行它时,它给了我下一个错误:


Permission Denial: not allowed to send broadcast android.intent.action.REBOOT from pid= uid= gids= 

我读到您应该创建一个 .apk 并使用 SignApk 对其进行签名,但我使用 openssl 创建了密钥/证书并使用它们进行了签名,但这也没有运行,我继续遇到完全相同的错误。

您对如何解决此问题并能够重新启动手机有任何线索吗?我确实需要这样做。

【问题讨论】:

    标签: android


    【解决方案1】:
    public static final String ACTION_REBOOT
    
    Since: API Level 1
    Broadcast Action: Have the device reboot. **This is only for use by system code.**
    **This is a protected intent that can only be sent by the system.**
    
    Constant Value: "android.intent.action.REBOOT"
    

    http://developer.android.com/reference/android/content/Intent.html#ACTION_REBOOT

    因此,除非您离开乐队并依赖超级用户,否则您将无法强制重启。

    【讨论】:

      【解决方案2】:

      Why does my app throw an `android.permission.REBOOT SecurityException`?

      据我了解,REBOOT权限仅适用于由硬件签名密钥签名的应用程序,即系统应用程序

      【讨论】:

        【解决方案3】:

        要通过代码重新启动 Android 设备,您需要“android.intent.action.REBOOT”权限,该权限仅授予系统应用程序或使用与系统应用程序相同的密钥签名的应用程序。除此之外,还必须在 Android Manifest android:sharedUserId="android.uid.system" 中添加一个标签。以确保应用程序与系统应用程序共享相同的uid。

        用于签署系统应用程序的密钥。设备制造商独有,不可复制。

        【讨论】:

          【解决方案4】:

          Android应用不允许发送android.content.Intent.ACTION_REBOOT

          在此处查看注释http://www.google.com/codesearch/p?hl=en#5oTG8Wvrixk/trunk/android-x86/frameworks/base/core/java/android/content/Intent.java&l=1510

          /**
           * Broadcast Action: Have the device reboot.  This is only for use by
           * system code.
           */
          @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
          public static final String ACTION_REBOOT =
                  "android.intent.action.REBOOT";
          

          【讨论】:

            【解决方案5】:

            http://www.krvarma.com/posts/android/security-permissions-in-android/

            安装时软件包安装程序会授予应用程序权限。但并非所有权限都将授予系统。有一些系统权限不会授予用户应用程序,而只授予系统应用程序。以下是一些可能不会授予用户应用程序的权限。

            要获得这些权限,必须使用用于签署平台的密钥对应用程序进行签名。对于制造商来说,这可能会有所不同。因此,实际上不可能将这些权限授予用户应用程序。

            【讨论】:

              最近更新 更多