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

Commit 6497645a authored by Atneya Nair's avatar Atneya Nair
Browse files

[appops] Fix opChanged null String

The AIDL interface is not nullable, so we should not pass null strings
here. We do pass a null package when the op change involves a
restriction which is not associated with a package.

Substitute empty string instead which emulates the old manual parceling
handling on the native side. Assert on persistentDeviceId since that
should not be null.

Also do some callsite cleanup: this callback fired with a combo of a
negative UID and null when appops change due to restrictions. Most users
don't handle this case, since there is limited usage of restrictions.
Ideally, the behavior on restrictions would be a flag, but for now, for
the callers which don't care about the appop changing due to a
restriction state, simply drop events with a negative UID (the null
package check was doing this for some callsites previously).

Test: manual audioserver callback handling in response to sensor toggle
Flag: EXEMPT bugfix
Fixes: 397859987
Bug: 322692565
Change-Id: I14d337b695374d257fbdc638b8daa7799f72d53a
parent 48012db1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2004,7 +2004,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                new IAppOpsCallback.Stub() {
                    @Override public void opChanged(int op, int uid, String packageName,
                            String persistentDeviceId) {
                        if (op == AppOpsManager.OP_RUN_IN_BACKGROUND && packageName != null) {
                        if (op == AppOpsManager.OP_RUN_IN_BACKGROUND && uid >= 0) {
                            if (getAppOpsManager().checkOpNoThrow(op, uid, packageName)
                                    != AppOpsManager.MODE_ALLOWED) {
                                runInBackgroundDisabled(uid);
+1 −0
Original line number Diff line number Diff line
@@ -394,6 +394,7 @@ final class AppPermissionTracker extends BaseAppStateTracker<AppPermissionPolicy
    private class MyAppOpsCallback extends IAppOpsCallback.Stub {
        @Override
        public void opChanged(int op, int uid, String packageName, String persistentDeviceId) {
            if (uid < 0) return;
            mHandler.obtainMessage(MyHandler.MSG_APPOPS_CHANGED, op, uid, packageName)
                    .sendToTarget();
        }
+2 −1
Original line number Diff line number Diff line
@@ -822,7 +822,8 @@ public class AppOpsService extends IAppOpsService.Stub {
        @Override
        public void onOpModeChanged(int op, int uid, String packageName, String persistentDeviceId)
                throws RemoteException {
            mCallback.opChanged(op, uid, packageName, persistentDeviceId);
            mCallback.opChanged(op, uid, packageName != null ? packageName : "",
                    Objects.requireNonNull(persistentDeviceId));
        }
    }

+3 −6
Original line number Diff line number Diff line
@@ -235,15 +235,12 @@ public final class PermissionPolicyService extends SystemService {
                this::synchronizeUidPermissionsAndAppOpsAsync);

        mAppOpsCallback = new IAppOpsCallback.Stub() {
            public void opChanged(int op, int uid, @Nullable String packageName,
                    String persistentDeviceId) {
            public void opChanged(int op, int uid, String packageName, String persistentDeviceId) {
                if (!Objects.equals(persistentDeviceId,
                        VirtualDeviceManager.PERSISTENT_DEVICE_ID_DEFAULT)) {
                        VirtualDeviceManager.PERSISTENT_DEVICE_ID_DEFAULT) || uid < 0) {
                    return;
                }
                if (packageName != null) {
                synchronizeUidPermissionsAndAppOpsAsync(uid);
                }
                resetAppOpPermissionsIfNotRequestedForUidAsync(uid);
            }
        };