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

Commit ac316924 authored by Kiran Ramachandra's avatar Kiran Ramachandra Committed by Android (Google) Code Review
Browse files

Merge "Reused existing method in getAllPermissionStates" into main

parents 10ad2ad6 61b76a89
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,