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

Commit 02ac3ea6 authored by Winson Chiu's avatar Winson Chiu Committed by Android (Google) Code Review
Browse files

Merge changes from topic "actorenforceuser"

* changes:
  Fix user handling for actor enforcement
  Fix OverlayableInfo native construction
parents 22bd0ac2 578b32a4
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -32,6 +32,11 @@ using ::android::base::unique_fd;

namespace android {

static struct overlayableinfo_offsets_t {
  jclass classObject;
  jmethodID constructor;
} gOverlayableInfoOffsets;

static jlong NativeLoad(JNIEnv* env, jclass /*clazz*/, jstring java_path, jboolean system,
                        jboolean force_shared_lib, jboolean overlay, jboolean for_loader) {
  ScopedUtfChars path(env, java_path);
@@ -222,12 +227,9 @@ static jobject NativeGetOverlayableInfo(JNIEnv* env, jclass /*clazz*/, jlong ptr
    return 0;
  }

  jclass overlayable_class = env->FindClass("android/content/om/OverlayableInfo");
  jmethodID overlayable_constructor = env->GetMethodID(overlayable_class, "<init>",
                                                       "(Ljava/lang/String;Ljava/lang/String;I)V");
  return env->NewObject(
      overlayable_class,
      overlayable_constructor,
      gOverlayableInfoOffsets.classObject,
      gOverlayableInfoOffsets.constructor,
      overlayable_name,
      actor_string
  );
@@ -267,6 +269,11 @@ static const JNINativeMethod gApkAssetsMethods[] = {
};

int register_android_content_res_ApkAssets(JNIEnv* env) {
  jclass overlayableInfoClass = FindClassOrDie(env, "android/content/om/OverlayableInfo");
  gOverlayableInfoOffsets.classObject = MakeGlobalRefOrDie(env, overlayableInfoClass);
  gOverlayableInfoOffsets.constructor = GetMethodIDOrDie(env, gOverlayableInfoOffsets.classObject,
      "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");

  return RegisterMethodsOrDie(env, "android/content/res/ApkAssets", gApkAssetsMethods,
                              arraysize(gApkAssetsMethods));
}
+81 −70
Original line number Diff line number Diff line
@@ -533,13 +533,13 @@ public final class OverlayManagerService extends SystemService {

    private final IBinder mService = new IOverlayManager.Stub() {
        @Override
        public Map<String, List<OverlayInfo>> getAllOverlays(int userId) throws RemoteException {
        public Map<String, List<OverlayInfo>> getAllOverlays(final int userIdArg) {
            try {
                traceBegin(TRACE_TAG_RRO, "OMS#getAllOverlays " + userId);
                userId = handleIncomingUser(userId, "getAllOverlays");
                traceBegin(TRACE_TAG_RRO, "OMS#getAllOverlays " + userIdArg);
                final int realUserId = handleIncomingUser(userIdArg, "getAllOverlays");

                synchronized (mLock) {
                    return mImpl.getOverlaysForUser(userId);
                    return mImpl.getOverlaysForUser(realUserId);
                }
            } finally {
                traceEnd(TRACE_TAG_RRO);
@@ -548,16 +548,17 @@ public final class OverlayManagerService extends SystemService {

        @Override
        public List<OverlayInfo> getOverlayInfosForTarget(@Nullable final String targetPackageName,
                int userId) throws RemoteException {
            try {
                traceBegin(TRACE_TAG_RRO, "OMS#getOverlayInfosForTarget " + targetPackageName);
                userId = handleIncomingUser(userId, "getOverlayInfosForTarget");
                final int userIdArg) {
            if (targetPackageName == null) {
                return Collections.emptyList();
            }

            try {
                traceBegin(TRACE_TAG_RRO, "OMS#getOverlayInfosForTarget " + targetPackageName);
                final int realUserId = handleIncomingUser(userIdArg, "getOverlayInfosForTarget");

                synchronized (mLock) {
                    return mImpl.getOverlayInfosForTarget(targetPackageName, userId);
                    return mImpl.getOverlayInfosForTarget(targetPackageName, realUserId);
                }
            } finally {
                traceEnd(TRACE_TAG_RRO);
@@ -566,16 +567,17 @@ public final class OverlayManagerService extends SystemService {

        @Override
        public OverlayInfo getOverlayInfo(@Nullable final String packageName,
                int userId) throws RemoteException {
            try {
                traceBegin(TRACE_TAG_RRO, "OMS#getOverlayInfo " + packageName);
                userId = handleIncomingUser(userId, "getOverlayInfo");
                final int userIdArg) {
            if (packageName == null) {
                return null;
            }

            try {
                traceBegin(TRACE_TAG_RRO, "OMS#getOverlayInfo " + packageName);
                final int realUserId = handleIncomingUser(userIdArg, "getOverlayInfo");

                synchronized (mLock) {
                    return mImpl.getOverlayInfo(packageName, userId);
                    return mImpl.getOverlayInfo(packageName, realUserId);
                }
            } finally {
                traceEnd(TRACE_TAG_RRO);
@@ -584,19 +586,20 @@ public final class OverlayManagerService extends SystemService {

        @Override
        public boolean setEnabled(@Nullable final String packageName, final boolean enable,
                int userId) throws RemoteException {
            try {
                traceBegin(TRACE_TAG_RRO, "OMS#setEnabled " + packageName + " " + enable);
                enforceActor(packageName, "setEnabled", userId);
                userId = handleIncomingUser(userId, "setEnabled");
                int userIdArg) {
            if (packageName == null) {
                return false;
            }

            try {
                traceBegin(TRACE_TAG_RRO, "OMS#setEnabled " + packageName + " " + enable);
                final int realUserId = handleIncomingUser(userIdArg, "setEnabled");
                enforceActor(packageName, "setEnabled", realUserId);

                final long ident = Binder.clearCallingIdentity();
                try {
                    synchronized (mLock) {
                        return mImpl.setEnabled(packageName, enable, userId);
                        return mImpl.setEnabled(packageName, enable, realUserId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -608,20 +611,21 @@ public final class OverlayManagerService extends SystemService {

        @Override
        public boolean setEnabledExclusive(@Nullable final String packageName, final boolean enable,
                int userId) throws RemoteException {
            try {
                traceBegin(TRACE_TAG_RRO, "OMS#setEnabledExclusive " + packageName + " " + enable);
                enforceActor(packageName, "setEnabledExclusive", userId);
                userId = handleIncomingUser(userId, "setEnabledExclusive");
                int userIdArg) {
            if (packageName == null || !enable) {
                return false;
            }

            try {
                traceBegin(TRACE_TAG_RRO, "OMS#setEnabledExclusive " + packageName + " " + enable);
                final int realUserId = handleIncomingUser(userIdArg, "setEnabledExclusive");
                enforceActor(packageName, "setEnabledExclusive", realUserId);

                final long ident = Binder.clearCallingIdentity();
                try {
                    synchronized (mLock) {
                        return mImpl.setEnabledExclusive(packageName, false /* withinCategory */,
                                userId);
                                realUserId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -632,21 +636,23 @@ public final class OverlayManagerService extends SystemService {
        }

        @Override
        public boolean setEnabledExclusiveInCategory(@Nullable String packageName, int userId)
                throws RemoteException {
            try {
                traceBegin(TRACE_TAG_RRO, "OMS#setEnabledExclusiveInCategory " + packageName);
                enforceActor(packageName, "setEnabledExclusiveInCategory", userId);
                userId = handleIncomingUser(userId, "setEnabledExclusiveInCategory");
        public boolean setEnabledExclusiveInCategory(@Nullable String packageName,
                final int userIdArg) {
            if (packageName == null) {
                return false;
            }

            try {
                traceBegin(TRACE_TAG_RRO, "OMS#setEnabledExclusiveInCategory " + packageName);
                final int realUserId = handleIncomingUser(userIdArg,
                        "setEnabledExclusiveInCategory");
                enforceActor(packageName, "setEnabledExclusiveInCategory", realUserId);

                final long ident = Binder.clearCallingIdentity();
                try {
                    synchronized (mLock) {
                        return mImpl.setEnabledExclusive(packageName, true /* withinCategory */,
                                userId);
                                realUserId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -658,20 +664,21 @@ public final class OverlayManagerService extends SystemService {

        @Override
        public boolean setPriority(@Nullable final String packageName,
                @Nullable final String parentPackageName, int userId) throws RemoteException {
            try {
                traceBegin(TRACE_TAG_RRO, "OMS#setPriority " + packageName + " "
                        + parentPackageName);
                enforceActor(packageName, "setPriority", userId);
                userId = handleIncomingUser(userId, "setPriority");
                @Nullable final String parentPackageName, final int userIdArg) {
            if (packageName == null || parentPackageName == null) {
                return false;
            }

            try {
                traceBegin(TRACE_TAG_RRO, "OMS#setPriority " + packageName + " "
                        + parentPackageName);
                final int realUserId = handleIncomingUser(userIdArg, "setPriority");
                enforceActor(packageName, "setPriority", realUserId);

                final long ident = Binder.clearCallingIdentity();
                try {
                    synchronized (mLock) {
                        return mImpl.setPriority(packageName, parentPackageName, userId);
                        return mImpl.setPriority(packageName, parentPackageName, realUserId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -682,20 +689,20 @@ public final class OverlayManagerService extends SystemService {
        }

        @Override
        public boolean setHighestPriority(@Nullable final String packageName, int userId)
                throws RemoteException {
            try {
                traceBegin(TRACE_TAG_RRO, "OMS#setHighestPriority " + packageName);
                enforceActor(packageName, "setHighestPriority", userId);
                userId = handleIncomingUser(userId, "setHighestPriority");
        public boolean setHighestPriority(@Nullable final String packageName, final int userIdArg) {
            if (packageName == null) {
                return false;
            }

            try {
                traceBegin(TRACE_TAG_RRO, "OMS#setHighestPriority " + packageName);
                final int realUserId = handleIncomingUser(userIdArg, "setHighestPriority");
                enforceActor(packageName, "setHighestPriority", realUserId);

                final long ident = Binder.clearCallingIdentity();
                try {
                    synchronized (mLock) {
                        return mImpl.setHighestPriority(packageName, userId);
                        return mImpl.setHighestPriority(packageName, realUserId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -706,20 +713,20 @@ public final class OverlayManagerService extends SystemService {
        }

        @Override
        public boolean setLowestPriority(@Nullable final String packageName, int userId)
                throws RemoteException {
            try {
                traceBegin(TRACE_TAG_RRO, "OMS#setLowestPriority " + packageName);
                enforceActor(packageName, "setLowestPriority", userId);
                userId = handleIncomingUser(userId, "setLowestPriority");
        public boolean setLowestPriority(@Nullable final String packageName, final int userIdArg) {
            if (packageName == null) {
                return false;
            }

            try {
                traceBegin(TRACE_TAG_RRO, "OMS#setLowestPriority " + packageName);
                final int realUserId = handleIncomingUser(userIdArg, "setLowestPriority");
                enforceActor(packageName, "setLowestPriority", realUserId);

                final long ident = Binder.clearCallingIdentity();
                try {
                    synchronized (mLock) {
                        return mImpl.setLowestPriority(packageName, userId);
                        return mImpl.setLowestPriority(packageName, realUserId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -730,7 +737,7 @@ public final class OverlayManagerService extends SystemService {
        }

        @Override
        public String[] getDefaultOverlayPackages() throws RemoteException {
        public String[] getDefaultOverlayPackages() {
            try {
                traceBegin(TRACE_TAG_RRO, "OMS#getDefaultOverlayPackages");
                getContext().enforceCallingOrSelfPermission(
@@ -750,18 +757,17 @@ public final class OverlayManagerService extends SystemService {
        }

        @Override
        public void invalidateCachesForOverlay(@Nullable String packageName, int userId)
                throws RemoteException {
        public void invalidateCachesForOverlay(@Nullable String packageName, final int userIdArg) {
            if (packageName == null) {
                return;
            }

            enforceActor(packageName, "invalidateCachesForOverlay", userId);
            userId = handleIncomingUser(userId, "invalidateCachesForOverlay");
            final int realUserId = handleIncomingUser(userIdArg, "invalidateCachesForOverlay");
            enforceActor(packageName, "invalidateCachesForOverlay", realUserId);
            final long ident = Binder.clearCallingIdentity();
            try {
                synchronized (mLock) {
                    mImpl.removeIdmapForOverlay(packageName, userId);
                    mImpl.removeIdmapForOverlay(packageName, realUserId);
                }
            } finally {
                Binder.restoreCallingIdentity(ident);
@@ -876,11 +882,16 @@ public final class OverlayManagerService extends SystemService {
            getContext().enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, message);
        }

        private void enforceActor(String packageName, String methodName, int userId)
        private void enforceActor(String packageName, String methodName, int realUserId)
                throws SecurityException {
            OverlayInfo overlayInfo = mImpl.getOverlayInfo(packageName, userId);
            OverlayInfo overlayInfo = mImpl.getOverlayInfo(packageName, realUserId);
            if (overlayInfo == null) {
                throw new IllegalArgumentException("Unable to retrieve overlay information for "
                        + packageName);
            }

            int callingUid = Binder.getCallingUid();
            mActorEnforcer.enforceActor(overlayInfo, methodName, callingUid, userId);
            mActorEnforcer.enforceActor(overlayInfo, methodName, callingUid, realUserId);
        }
    };