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

Skip to content
Commit 1993c884 authored by Hai Zhang's avatar Hai Zhang
Browse files

Make PermissionPolicyService use OnPermissionsChangeListener.

And remove the internal OnRuntimePermissionStateChangedListener.

The system API PackageMangaer.addOnPermissionsChangeListener()
actually works very similar to
PermissionManagerServiceInternal.addOnRuntimePermissionStateChangedListener(),
as long as some fixes are applied to the former. Specifically:

1.  OnPermissionsChangeListener is currently notified for runtime
    permission state and flag changes, as well as install permission
    flag changes. However, since permission flags are only used for
    runtime permissions, it makes no sense to notify for install
    permission flag changes while not notifying for install permission
    state changes which is far more important for install
    permissions. So we can remove the useless notification for install
    permission flag changes, and make it align with the internal
    listener to be replaced & removed in this CL.

    This means we can replace
    onInstallPermissionUpdatedNotifyListener() with
    onInstallPermissionUpdated(), since we shouldn't notify the
    listener for install permission changes.

2.  Start to notify OnPermissionsChangeListener for changes inside
    restorePermissionState(). This may happen when packages are
    updated and it's natural for callers to expect a callback if the
    permission state changed, but so far that's not true for
    OnPermissionsChangeListener, and it only works for the internal
    listener. So we should fix that and make PermissionManagerService
    actually behave consistently.

    This means we can merge onPermissionUpdatedNotifyListener() into
    onPermissionUpdated(), since the listener should always be
    notified.

Another thing to note is that AndroidPackage.getUid() returns the app
ID instead of the per-user UID despite its name.

PermissionPolicyService is also updated to work by UIDs instead of
packages, since it would just query that package for its UID to get
all the package names in that UID. Calls into package manager are also
reduced a bit, which may result in a slight performance improvement
since we skipped one PackageInfo generation.

OnPermissionsChangeListener is async (because binder calls are
possible) while the internal listener is sync. This would mean
PermissionPolicyService are now getting callbacks async, but we always
treated those callbacks as async anyway (we post work onto a worker
thread in the callback) so that's unlikely a problem.

Bug: 263504888
Test: presubmit
Change-Id: Ieb0742832ed9c30e90a79422aa4048133a2f8258
parent c46674d0
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment