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

Commit b1c64b52 authored by Sandeep Bandaru's avatar Sandeep Bandaru Committed by Android (Google) Code Review
Browse files

Merge "Add OnDeviceIntelligence service to known list of system-services under...

Merge "Add OnDeviceIntelligence service to known list of system-services under isolated_compute_app, such that package manager returns owner package name when requested using the isolated child uid" into main
parents f3c874db 9c77e14b
Loading
Loading
Loading
Loading
+41 −7
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ import com.android.internal.util.CollectionUtils;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.Preconditions;
import com.android.modules.utils.TypedXmlSerializer;
import com.android.server.ondeviceintelligence.OnDeviceIntelligenceManagerInternal;
import com.android.server.pm.dex.DexManager;
import com.android.server.pm.dex.PackageDexUsage;
import com.android.server.pm.parsing.PackageInfoUtils;
@@ -4353,9 +4354,8 @@ public class ComputerEngine implements Computer {
        if (Process.isSdkSandboxUid(uid)) {
            uid = getBaseSdkSandboxUid();
        }
        if (Process.isIsolatedUid(uid)
                && mPermissionManager.getHotwordDetectionServiceProvider() != null
                && uid == mPermissionManager.getHotwordDetectionServiceProvider().getUid()) {
        final int callingUserId = UserHandle.getUserId(callingUid);
        if (isKnownIsolatedComputeApp(uid, callingUserId)) {
            try {
                uid = getIsolatedOwner(uid);
            } catch (IllegalStateException e) {
@@ -4363,7 +4363,6 @@ public class ComputerEngine implements Computer {
                Slog.wtf(TAG, "Expected isolated uid " + uid + " to have an owner", e);
            }
        }
        final int callingUserId = UserHandle.getUserId(callingUid);
        final int appId = UserHandle.getAppId(uid);
        final Object obj = mSettings.getSettingBase(appId);
        if (obj instanceof SharedUserSetting) {
@@ -4399,9 +4398,7 @@ public class ComputerEngine implements Computer {
            if (Process.isSdkSandboxUid(uid)) {
                uid = getBaseSdkSandboxUid();
            }
            if (Process.isIsolatedUid(uid)
                    && mPermissionManager.getHotwordDetectionServiceProvider() != null
                    && uid == mPermissionManager.getHotwordDetectionServiceProvider().getUid()) {
            if (isKnownIsolatedComputeApp(uid, callingUserId)) {
                try {
                    uid = getIsolatedOwner(uid);
                } catch (IllegalStateException e) {
@@ -5802,6 +5799,43 @@ public class ComputerEngine implements Computer {
        return getPackage(mService.getSdkSandboxPackageName()).getUid();
    }


    private boolean isKnownIsolatedComputeApp(int uid, int callingUserId) {
        if (!Process.isIsolatedUid(uid)) {
            return false;
        }
        final boolean isHotword =
                mPermissionManager.getHotwordDetectionServiceProvider() != null
                        && uid
                        == mPermissionManager.getHotwordDetectionServiceProvider().getUid();
        if (isHotword) {
            return true;
        }
        OnDeviceIntelligenceManagerInternal onDeviceIntelligenceManagerInternal =
                mInjector.getLocalService(OnDeviceIntelligenceManagerInternal.class);
        if (onDeviceIntelligenceManagerInternal == null) {
            return false;
        }

        String onDeviceIntelligencePackage =
                onDeviceIntelligenceManagerInternal.getRemoteServicePackageName();
        if (onDeviceIntelligencePackage == null) {
            return false;
        }

        try {
            if (getIsolatedOwner(uid) == getPackageUid(onDeviceIntelligencePackage, 0,
                    callingUserId)) {
                return true;
            }
        } catch (IllegalStateException e) {
            // If the owner uid doesn't exist, just use the current uid
            Slog.wtf(TAG, "Expected isolated uid " + uid + " to have an owner", e);
        }

        return false;
    }

    @Nullable
    @Override
    public SharedUserApi getSharedUser(int sharedUserAppId) {