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

Commit 71eeae18 authored by Hai Zhang's avatar Hai Zhang
Browse files

Cork PackageInfo cache for onStorageVolumeMounted() and onUserCreated().

Because we used to do so in
PermissionManagerServiceImpl.updateAllPermissions().

Bug: 284205103
Test: presubmit
Change-Id: I9985f4057d987a1aec0ee618cd851422b36986dc
parent d84e31b5
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -2009,8 +2009,10 @@ class PermissionService(
    }

    override fun onUserCreated(userId: Int) {
        withCorkedPackageInfoCache {
            service.onUserAdded(userId)
        }
    }

    override fun onUserRemoved(userId: Int) {
        service.onUserRemoved(userId)
@@ -2024,8 +2026,10 @@ class PermissionService(
            packageNames = storageVolumePackageNames.remove(volumeUuid) ?: emptyList()
            mountedStorageVolumes += volumeUuid
        }
        withCorkedPackageInfoCache {
            service.onStorageVolumeMounted(volumeUuid, packageNames, fingerprintChanged)
        }
    }

    override fun onPackageAdded(
        packageState: PackageState,
@@ -2120,6 +2124,15 @@ class PermissionService(
        }
    }

    private inline fun <T> withCorkedPackageInfoCache(block: () -> T): T {
        PackageManager.corkPackageInfoCache()
        try {
            return block()
        } finally {
            PackageManager.uncorkPackageInfoCache()
        }
    }

    /**
     * Check whether a UID is root or system UID.
     */