1

Got this shiny manifest ready to be granted all ze permissions

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="exm.rand.lol">

  <uses-permission android:name="com.google.android.things.permission.MODIFY_SCREEN_SETTINGS" />
  <uses-permission android:name="com.google.android.things.permission.REBOOT"/>


  <application>
    <uses-library android:name="com.google.android.things" />

    <activity android:name=".MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.IOT_LAUNCHER" />
        <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
    </activity>
  </application>

</manifest>

and yet when I boot up the raspberry pi it fails with this in the logcat

12-01 15:23:19.349  2960  2960 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{exm.rand.lol/exm.rand.lol.MainActivity}: java.lang.SecurityException: Calling process requires permission com.google.android.things.permission.MODIFY_SCREEN_SETTINGS

I searched high and low, stumbled upon multiple threads on StackOverflow

Android Things permission com.google.android.things.permission.MANAGE_INPUT_DRIVERS not found

How to request permission on Android Things?

but to no avail. Rebooting doesn't do anything, reinstalling doesn't do anything, the only way I found atm to give permissions is to manually grant them through adb like dis

 adb shell pm grant exm.rand.lol com.google.android.things.permission.REBOOT

Running latest Preiew 6 of Android Things.

Nikki Kononov
  • 549
  • 1
  • 8
  • 20
  • You don't actually need the `REBOOT` permission to [reboot Android Things device](https://stackoverflow.com/a/44209713/3290339) – Onik Dec 01 '17 at 16:33
  • Are you sure that's the manifest that is giving you that error? The error implies that, on the `` element, you have `android:permission="com.google.android.things.permission.MODIFY_SCREEN_SETTINGS"`. – CommonsWare Dec 01 '17 at 16:42
  • @Onik still doesn't solve the original problem of permissions not being granted. – Nikki Kononov Dec 04 '17 at 07:37
  • @CommonsWare not the manifest file but app just doesn't start if permission is not granted. VM crashes with the error above requiring permissions. – Nikki Kononov Dec 04 '17 at 07:37

2 Answers2

0

With Developer Preview 6, you should use the DeviceManager API. Reboot permission can only be granted to system apps if I'm not wrong, and the Android Things console will never package your APK as a system app.

new DeviceManager().reboot()
Keith Leow
  • 56
  • 5
  • That is what I am using but again per android things docs if the calling context does not have com.google.android.things.permission.REBOOT permission it will throw SecurityException and my problem is that it doesn't give said permissions even though I added them in the manifest file. They only work if I manually add them via adb. – Nikki Kononov Dec 07 '17 at 08:06
0

To summerize things... Altough it's stated in Android Things readme that:

All normal and dangerous permissions declared in your app's manifest are granted at install time.

It's not enough to declare permissions in manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.yyy">

    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="com.google.android.things.permission.MODIFY_SCREEN_SETTINGS"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <application>
    </application>
</manifest>

You need to restart the device with the installed application.

APPLICATION RIGHTS ARE GRANTED UPON DEVICE RESTART not application restart.

  • Quoting what I wrote in the OP 'Rebooting doesn't do anything,' I am very well aware of that but it still doesn't grant permissions. – Nikki Kononov Feb 08 '18 at 10:30
  • I my case I needed to install android app with the listed permissions in Manifest and the restart the **device**. It worked. After the restart I had all the permissions granted at runtime. – kosiara - Bartosz Kosarzycki Feb 09 '18 at 14:48