diff --git a/services/core/java/com/android/server/pm/permission/Permission.java b/services/core/java/com/android/server/pm/permission/Permission.java
index c81d6d7d0918ac6cb5fdda568bba403ad82bb2e4..1440a1e2fafe07c728881f58de264807d68dbff9 100644
--- a/services/core/java/com/android/server/pm/permission/Permission.java
+++ b/services/core/java/com/android/server/pm/permission/Permission.java
@@ -146,6 +146,10 @@ public final class Permission {
         return mPermissionInfo.packageName;
     }
 
+    public boolean isReconciled() {
+        return mReconciled;
+    }
+
     public int getType() {
         return mType;
     }
diff --git a/services/core/java/com/android/server/pm/permission/PermissionManagerServiceImpl.java b/services/core/java/com/android/server/pm/permission/PermissionManagerServiceImpl.java
index 574f121b033a5171f8c1a96edc07cf6f5e65ba41..b92ae23fdd857094032eb5d8dbec3a64a4f13ce3 100644
--- a/services/core/java/com/android/server/pm/permission/PermissionManagerServiceImpl.java
+++ b/services/core/java/com/android/server/pm/permission/PermissionManagerServiceImpl.java
@@ -4137,6 +4137,10 @@ public class PermissionManagerServiceImpl implements PermissionManagerServiceInt
                     // being uninstalled,
                     continue;
                 }
+                // Don't remove config permissions and lose their GIDs.
+                if (bp.getType() == Permission.TYPE_CONFIG && !bp.isReconciled()) {
+                    continue;
+                }
                 // The target package is the source of the current permission
                 // Set to changed for either install or uninstall
                 changed = true;