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

Commit 61b76a89 authored by Kiran Ramachandra's avatar Kiran Ramachandra
Browse files

Reused existing method in getAllPermissionStates

1) Reused isPermissionGranted
2) Added utility methods to PermissionState dataclass

Bug: 322876542
Test: atest CtsPermissionTestCases:DevicePermissionsTest
Change-Id: I8efd295adc7f676a51d5cd654c1f0789a5588b52
parent e4a0015e
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -1788,6 +1788,9 @@ public final class PermissionManager {

    /**
     * Gets the permission states for requested package and persistent device.
     * <p>
     * <strong>Note: </strong>Default device permissions are not inherited in this API. Returns the
     * exact permission states for the requested device.
     *
     * @param packageName name of the package you are checking against
     * @param persistentDeviceId id of the persistent device you are checking against
@@ -2073,5 +2076,29 @@ public final class PermissionManager {
                return new PermissionState[size];
            }
        };

        /** @hide */
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            PermissionState that = (PermissionState) o;
            return mGranted == that.mGranted && mFlags == that.mFlags;
        }

        /** @hide */
        @Override
        public int hashCode() {
            return Objects.hash(mGranted, mFlags);
        }

        /** @hide */
        @Override
        public String toString() {
            return "PermissionState{"
                    + "mGranted=" + mGranted
                    + ", mFlags=" + mFlags
                    + '}';
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -408,6 +408,9 @@ public interface PermissionManagerServiceInterface extends PermissionManagerInte

    /**
     * Gets the permission states for requested package, persistent device and user.
     * <p>
     * <strong>Note: </strong>Default device permissions are not inherited in this API. Returns the
     * exact permission states for the requested device.
     *
     * @param packageName name of the package you are checking against
     * @param deviceId id of the persistent device you are checking against
+9 −11
Original line number Diff line number Diff line
@@ -1135,26 +1135,24 @@ class PermissionService(private val service: AccessCheckingService) :
            return emptyMap()
        }

        val permissionFlagsMap =
        service.getState {
            val permissionFlags =
                if (deviceId == VirtualDeviceManager.PERSISTENT_DEVICE_ID_DEFAULT) {
                    with(policy) { getAllPermissionFlags(packageState.appId, userId) }
                } else {
                    with(devicePolicy) {
                        getAllPermissionFlags(packageState.appId, deviceId, userId)
                    }
                }
            }
                ?: return emptyMap()

                } ?: return emptyMap()
            val permissionStates = ArrayMap<String, PermissionState>()
        permissionFlagsMap.forEachIndexed { _, permissionName, flags ->
            val granted = PermissionFlags.isPermissionGranted(flags)
            permissionFlags.forEachIndexed { _, permissionName, flags ->
                val granted = isPermissionGranted(packageState, userId, permissionName, deviceId)
                val apiFlags = PermissionFlags.toApiFlags(flags)
                permissionStates[permissionName] = PermissionState(granted, apiFlags)
            }
            return permissionStates
        }
    }

    override fun isPermissionRevokedByPolicy(
        packageName: String,