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

Commit b3236d49 authored by Riddle Hsu's avatar Riddle Hsu Committed by Automerger Merge Worker
Browse files

Merge "Restrict the getter of where the app launched from" into sc-qpr1-dev am: 0e40c2c9

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15583403

Change-Id: I60998be55634c05037931432c0ed6d11539da94a
parents b1d7c78e 0e40c2c9
Loading
Loading
Loading
Loading
+31 −1
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.os.Process.INVALID_UID;
import static android.os.Process.SYSTEM_UID;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_APPLICATION;
import static android.view.Display.DEFAULT_DISPLAY;
@@ -53,6 +55,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ParceledListSlice;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
@@ -64,6 +67,7 @@ import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.Trace;
import android.os.UserHandle;
import android.service.voice.VoiceInteractionManagerInternal;
import android.util.Slog;
import android.view.RemoteAnimationDefinition;
@@ -74,6 +78,7 @@ import com.android.internal.policy.IKeyguardDismissCallback;
import com.android.internal.protolog.common.ProtoLog;
import com.android.server.LocalServices;
import com.android.server.Watchdog;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.uri.NeededUriGrants;
import com.android.server.vr.VrManagerInternal;

@@ -557,20 +562,45 @@ class ActivityClientController extends IActivityClientController.Stub {

    @Override
    public int getLaunchedFromUid(IBinder token) {
        if (!canGetLaunchedFrom()) {
            return INVALID_UID;
        }
        synchronized (mGlobalLock) {
            final ActivityRecord r = ActivityRecord.forTokenLocked(token);
            return r != null ? r.launchedFromUid : android.os.Process.INVALID_UID;
            return r != null ? r.launchedFromUid : INVALID_UID;
        }
    }

    @Override
    public String getLaunchedFromPackage(IBinder token) {
        if (!canGetLaunchedFrom()) {
            return null;
        }
        synchronized (mGlobalLock) {
            final ActivityRecord r = ActivityRecord.forTokenLocked(token);
            return r != null ? r.launchedFromPackage : null;
        }
    }

    /** Whether the caller can get the package or uid that launched its activity. */
    private boolean canGetLaunchedFrom() {
        final int uid = Binder.getCallingUid();
        if (UserHandle.getAppId(uid) == SYSTEM_UID) {
            return true;
        }
        final PackageManagerInternal pm = mService.mWindowManager.mPmInternal;
        final AndroidPackage callingPkg = pm.getPackage(uid);
        if (callingPkg == null) {
            return false;
        }
        if (callingPkg.isSignedWithPlatformKey()) {
            return true;
        }
        final String[] installerNames = pm.getKnownPackageNames(
                PackageManagerInternal.PACKAGE_INSTALLER, UserHandle.getUserId(uid));
        return installerNames.length > 0 && callingPkg.getPackageName().equals(installerNames[0]);
    }

    @Override
    public void setRequestedOrientation(IBinder token, int requestedOrientation) {
        final long origId = Binder.clearCallingIdentity();