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

Commit c78e8c3c authored by Hai Zhang's avatar Hai Zhang
Browse files

Fix NPEs in DevicePermissionPolicy.

Similar to ag/25910620

Fixes: 322101844
Test: presubmit
Change-Id: I33e6999d818d899dc29cee8f4644918a68cc27b4
parent d91d78d8
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -94,7 +94,9 @@ class DevicePermissionPolicy : SchemePolicy() {
        isSystemUpdated: Boolean
    ) {
        packageNames.forEachIndexed { _, packageName ->
            val packageState = newState.externalState.packageStates[packageName]!!
            // The package may still be removed even if it was once notified as installed.
            val packageState = newState.externalState.packageStates[packageName]
                ?: return@forEachIndexed
            trimPermissionStates(packageState.appId)
        }
    }
@@ -245,6 +247,13 @@ class DevicePermissionPolicy : SchemePolicy() {
        flagMask: Int,
        flagValues: Int
    ): Boolean {
        if (userId !in newState.userStates) {
            // Despite that we check UserManagerInternal.exists() in PermissionService, we may still
            // sometimes get race conditions between that check and the actual mutateState() call.
            // This should rarely happen but at least we should not crash.
            Slog.e(LOG_TAG, "Unable to update permission flags for missing user $userId")
            return false
        }
        val oldFlags =
            newState.userStates[userId]!!
                .appIdDevicePermissionFlags[appId]