Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 05b75fb4 authored by Hai Zhang's avatar Hai Zhang
Browse files

Create a better implementation for permission GIDs.

The old subsystem creates "fake" permissions owned by the "android"
package that will contain the GIDs and be overridden by system apps,
however that approach is fragile because it depends a lot on the package
scan order since these "fake" permissions will be trimmed after we scan
the "android" package.

In contrast, it's a lot easier and straightforward to just look up the
GIDs upon scanning permission definitions, which will also fix the
package scanning order issue. It also helps with removing one type of
permission definition and the special cases we had to add for it.

This is a better version of the easier but behavior changing fix
ag/26216413.

This change is behind a bug-fix flag since it's still a new way of doing
things, despite that it's straightforward and there's no expected
behavior change except for fixing GID assignment for permissions
declared in APKs-in-APEX etc on first boot.

Fixes: 325137277
Bug: 322197421
Test: manually check the GIDs in dumpsys permissionmgr after clean flash
Change-Id: Ied24c45734e7c57ce8ed0d015121675bfcbae54f
parent 5a92428a
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -119,3 +119,14 @@ flag {
     description: "Enables the getEmergencyRoleHolder API."
     bug: "323157319"
}

flag {
    name: "new_permission_gid_enabled"
    is_fixed_read_only: true
    namespace: "permissions"
    description: "Enable new permission GID implementation"
    bug: "325137277"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+53 −32
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.server.pm.KnownPackages
import com.android.server.pm.parsing.PackageInfoUtils
import com.android.server.pm.pkg.AndroidPackage
import com.android.server.pm.pkg.PackageState
import libcore.util.EmptyArray

class AppIdPermissionPolicy : SchemePolicy() {
    private val persistence = AppIdPermissionPersistence()
@@ -73,6 +74,7 @@ class AppIdPermissionPolicy : SchemePolicy() {
    }

    override fun MutateStateScope.onInitialized() {
        if (!Flags.newPermissionGidEnabled()) {
            newState.externalState.configPermissions.forEach { (permissionName, permissionEntry) ->
                val oldPermission = newState.systemState.permissions[permissionName]
                val newPermission =
@@ -109,6 +111,7 @@ class AppIdPermissionPolicy : SchemePolicy() {
                newState.mutateSystemState().mutatePermissions()[permissionName] = newPermission
            }
        }
    }

    override fun MutateStateScope.onUserAdded(userId: Int) {
        newState.externalState.packageStates.forEach { (_, packageState) ->
@@ -459,7 +462,7 @@ class AppIdPermissionPolicy : SchemePolicy() {
                )
                return@forEachIndexed
            }
            val newPermission =
            var newPermission =
                if (oldPermission != null && newPackageName != oldPermission.packageName) {
                    val oldPackageName = oldPermission.packageName
                    // Only allow system apps to redefine non-system permissions.
@@ -582,6 +585,24 @@ class AppIdPermissionPolicy : SchemePolicy() {
                        )
                    }
                }
            if (Flags.newPermissionGidEnabled()) {
                var gids = EmptyArray.INT
                var areGidsPerUser = false
                if (!parsedPermission.isTree && packageState.isSystem) {
                    newState.externalState.configPermissions[permissionName]?.let {
                        gids = it.gids
                        areGidsPerUser = it.perUser
                    }
                }
                newPermission = Permission(
                    newPermissionInfo,
                    true,
                    Permission.TYPE_MANIFEST,
                    packageState.appId,
                    gids,
                    areGidsPerUser
                )
            }

            if (parsedPermission.isTree) {
                newState.mutateSystemState().mutatePermissionTrees()[permissionName] = newPermission