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

Commit d727a959 authored by Rubin Xu's avatar Rubin Xu Committed by Evelyn Torres
Browse files

Use correct API to get calling package name in CredentialStorage

Activity.getCallingPackage() does not always return the package
name of the actual calling app. getLaunchedFromPackage() should
be used instead.

Bug: 389681530
Test: manual
Flag: EXEMPT bugfix
(cherry picked from commit 70bd3efe)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:131e19e3fdf184332015e2592cff3467a360ff99)
Merged-In: Ibdbc45e53f4aa46fae79fa234705b3735bfda4cd
Change-Id: Ibdbc45e53f4aa46fae79fa234705b3735bfda4cd
parent e6fd90f4
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.security;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.DialogInterface;
@@ -331,15 +332,25 @@ public final class CredentialStorage extends FragmentActivity {
        }
    }

    private String getCallingPackageName() {
        try {
            return ActivityManager.getService().getLaunchedFromPackage(getActivityToken());
        } catch (RemoteException re) {
            // Error talking to ActivityManager, just give up
            return null;
        }
    }

    /**
     * Check that the caller is either certinstaller or Settings running in a profile of this user.
     */
    private boolean checkCallerIsCertInstallerOrSelfInProfile() {
        if (TextUtils.equals("com.android.certinstaller", getCallingPackage())) {
        String callingPackage = getCallingPackageName();
        if (TextUtils.equals("com.android.certinstaller", callingPackage)) {
            // CertInstaller is allowed to install credentials if it has the same signature as
            // Settings package.
            return getPackageManager().checkSignatures(
                    getCallingPackage(), getPackageName()) == PackageManager.SIGNATURE_MATCH;
                    callingPackage, getPackageName()) == PackageManager.SIGNATURE_MATCH;
        }

        final int launchedFromUserId;