GmsCore: Can not grand SMS and BACKGROUND_LOCATION Permission on Android 11

Describe the bug Trying to grand the permissions for

  • android.permission.ACCESS_BACKGROUND_LOCATION
  • android.permission.RECEIVE_SMS Is not possible.

To Reproduce Steps to reproduce the behavior:

  1. Go to Permission settings for GMS Core
  2. Click on SMS permission
  3. Click on “grand”
  4. Go back
  5. See permissin is still not granded

Expected behavior Permission is granded

Screenshots/Logs

https://user-images.githubusercontent.com/1891273/114101423-02a13d00-98c6-11eb-9b20-72b85464c5f9.mp4

Sysdump for package

...
      runtime permissions:
        android.permission.ACCESS_FINE_LOCATION: granted=true, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED]
        android.permission.RECEIVE_SMS: granted=false, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED|APPLY_RESTRICTION]
        android.permission.READ_EXTERNAL_STORAGE: granted=true, flags=[ USER_SET|USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED|APPLY_RESTRICTION]
        android.permission.ACCESS_COARSE_LOCATION: granted=true, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED]
        android.permission.READ_PHONE_STATE: granted=true, flags=[ USER_SET|USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED]
        android.permission.GET_ACCOUNTS: granted=true, flags=[ USER_SET|USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED]
        android.permission.WRITE_EXTERNAL_STORAGE: granted=true, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED|APPLY_RESTRICTION]
        android.permission.ACCESS_BACKGROUND_LOCATION: granted=false, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED|APPLY_RESTRICTION]
...

/data/system/user/0/runtime-permissions.xml:

...
<pkg name="com.google.android.gms">
  <item name="android.permission.ACCESS_FINE_LOCATION" granted="true" flags="330"/>
  <item name="android.permission.RECEIVE_SMS" granted="true" flags="3b20"/>
  <item name="android.permission.READ_EXTERNAL_STORAGE" granted="true" flags="3b20"/>
  <item name="android.permission.ACCESS_COARSE_LOCATION" granted="true" flags="330"/>
  <item name="android.permission.READ_PHONE_STATE" granted="true" flags="320"/>
  <item name="android.permission.GET_ACCOUNTS" granted="true" flags="320"/>
  <item name="android.permission.WRITE_EXTERNAL_STORAGE" granted="true" flags="3b20"/>
  <item name="android.permission.ACCESS_BACKGROUND_LOCATION" granted="true" flags="3b30"/>
</pkg>
...

System Android Version:11 Custom ROM: LineageOS 18.1

Additional context Maybe my system is just F*** up. I tried to upgrade from LineageOS 17.1 with a Riru based MicroG installation to a lineag.microg.org based setup. This might cause trouble apparently.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (3 by maintainers)

Most upvoted comments

You can also take a look at #1280

As my comment there suggests, you can work around this issue by installing GmsCore twice - first as a priv-app and then from the .apk as an user app update.

Hello everyone! I’ve been investigating this issue in detail lately, and I believe I have found the cause. I want to share with you what I have discovered.

RECEIVE_SMS and ACCESS_BACKGROUND_LOCATION - the two permissions giving troubles - are considered “hard restricted” permissions from Android 10 onwards, which means that they cannot be granted by the user unless explicitly marked as whitelisted for that specific app by the system. The system package installer marks all restricted permissions as whitelisted by default when you install an APK manually, which is why installing or updating microG manually solves the issue. Therefore, if you happen to install microG by simply copying the APK into /system/priv-app (or using a Magisk module), this whitelisting doesn’t happen and therefore causes the inability to grant the permission (in the sysdump above, you can see that those permissions have the APPLY_RESTRICTION flag which means that they are not whitelisted).

So the key takeaways are:

  • this is not really a microG bug but a quirk in how Android handles certain permissions
  • can be easily worked around by installing/updating microG manually, as others have already discovered
  • is present on Android 10 and higher (PackageManager APIs to interact with permission whitelists have been added in API 29, and I also encountered this issue on Android 10)

Also, the whitelisting alone was not enough to be able to grant ACCESS_BACKGROUND_LOCATION permission for me: I had to enable location inside device settings, then go back to microG Self-Check and check background location permission. I don’t know why.

I got it fixed following xda microG GmsCore - lightweight free software clone of Google Play Services post. Basically I changed granted and flags attribute in /data/system/users/0/runtime-permissions.xml from twrp recovery.

--- /data/system/users/0/runtime-permissions.xml	2021-11-05 12:21:18.972951060 +0100
+++ /data/system/users/0/runtime-permissions.xml	2021-11-05 12:07:34.578981494 +0100
@@ -409,13 +409,13 @@
   <pkg name="com.google.android.gms">
     <item name="android.permission.ACCESS_FINE_LOCATION" granted="true" flags="300" />
     <item name="android.permission.FAKE_PACKAGE_SIGNATURE" granted="true" flags="0" />
-    <item name="android.permission.RECEIVE_SMS" granted="false" flags="300" />
+    <item name="android.permission.RECEIVE_SMS" granted="true" flags="3320" />
     <item name="android.permission.READ_EXTERNAL_STORAGE" granted="true" flags="4300" />
     <item name="android.permission.ACCESS_COARSE_LOCATION" granted="true" flags="300" />
     <item name="android.permission.READ_PHONE_STATE" granted="true" flags="300" />
     <item name="android.permission.GET_ACCOUNTS" granted="true" flags="300" />
     <item name="android.permission.WRITE_EXTERNAL_STORAGE" granted="true" flags="4300" />
-    <item name="android.permission.ACCESS_BACKGROUND_LOCATION" granted="false" flags="300" />
+    <item name="android.permission.ACCESS_BACKGROUND_LOCATION" granted="true" flags="3020" />
   </pkg>
   <pkg name="com.sec.spp.push">
     <item name="android.permission.READ_EXTERNAL_STORAGE" granted="false" flags="2180" />

Same on Android10

There isn’t any need to complicate things like this.

For installers, they just need to add whitelisted="true" (where needed) in default-permissions xml files (most installers already do this).

For users that have the problem they can simply reinstall the app: adb shell "pm install -r -g /system/priv-app/GmsCore/GmsCore.apk"

This is more like an install issue rather than microG issue so I will close it. Those that still have issues can open another ticket.

@stainlesspot Yes this did the job for my installation to 😃. Thank you.

Installed it as priv-app, still can`t grant these permissions

I said the opposite, if you don’t install as a priv-app.