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

Commit f19541e2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Clear calling identify before using package manager in TelecomServiceImpl." into main

parents 7e197733 9db9305e
Loading
Loading
Loading
Loading
+23 −14
Original line number Diff line number Diff line
@@ -1537,15 +1537,21 @@ public class TelecomServiceImpl {
            int callingUid = Binder.getCallingUid();
            int systemUiUid;
            if (mPackageManager != null && mSystemUiPackageName != null) {
                long whosCalling = Binder.clearCallingIdentity();
                try {
                    try {
                        systemUiUid = mPackageManager.getPackageUid(mSystemUiPackageName, 0);
                        Log.i(TAG, "isSysUiUid: callingUid = " + callingUid + "; systemUiUid = "
                                + systemUiUid);
                        return isSameApp(callingUid, systemUiUid);
                    } catch (PackageManager.NameNotFoundException e) {
                    Log.w(TAG, "isSysUiUid: caught PackageManager NameNotFoundException = " + e);
                        Log.w(TAG,
                                "isSysUiUid: caught PackageManager NameNotFoundException = " + e);
                        return false;
                    }
                } finally {
                    Binder.restoreCallingIdentity(whosCalling);
                }
            } else {
                Log.w(TAG, "isSysUiUid: caught null check and returned false; "
                        + "mPackageManager = " + mPackageManager + "; mSystemUiPackageName = "
@@ -3317,13 +3323,9 @@ public class TelecomServiceImpl {
        try {
            pm = mContext.createContextAsUser(
                    UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
        } catch (Exception e) {
            Log.i(this, "callingUidMatchesPackageManagerRecords:"
                    + " createContextAsUser hit exception=[%s]", e.toString());
            return false;
        } finally {
            Binder.restoreCallingIdentity(token);
        }

            // This has to happen inside the scope of the `clearCallingIdentity` block
            // otherwise the caller may fail to call `TelecomManager#endCall`.
            if (pm != null) {
                try {
                    packageUid = pm.getPackageUid(packageName, 0);
@@ -3331,6 +3333,13 @@ public class TelecomServiceImpl {
                    // packageUid is -1.
                }
            }
        } catch (Exception e) {
            Log.i(this, "callingUidMatchesPackageManagerRecords:"
                    + " createContextAsUser hit exception=[%s]", e.toString());
            return false;
        } finally {
            Binder.restoreCallingIdentity(token);
        }

        if (packageUid != callingUid) {
            Log.i(this, "callingUidMatchesPackageManagerRecords: uid mismatch found for"