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

Commit 15c81089 authored by Thomas Stuart's avatar Thomas Stuart
Browse files

fix test failure by wrapping createContextAsUser with catch block

android growler reported some new test failures in
android.telephony2.cts.TelephonyManagerNoPermissionTest due to a
recent change in TelecomManager#enforceCallingPackage.  The test
failed at the createContextAsUser API call in
callingUidMatchesPackageManagerRecords.  I've added a try/catch
around the createContextAsUser and the method will throw a SE
if the catch block is executed.

I've also fixed some log spew in isPrivilegedUid

Test: manual
Bug: 258729003
Change-Id: I0877a8410349cfe613d05cd71a615704ca5b2720
parent a9a45f33
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -1046,7 +1046,6 @@ public class TelecomServiceImpl {
        private boolean isPrivilegedUid(String callingPackage) {
            int callingUid = Binder.getCallingUid();
            boolean isPrivileged = false;

            switch (callingUid) {
                case Process.ROOT_UID:
                case Process.SYSTEM_UID:
@@ -1054,10 +1053,6 @@ public class TelecomServiceImpl {
                    isPrivileged = true;
                    break;
            }

            Log.i(this, "isPrivilegedUid: callingPackage=[%s], callingUid=[%d], isPrivileged=[%b]",
                    callingPackage, callingUid, isPrivileged);

            return isPrivileged;
        }

@@ -2443,9 +2438,16 @@ public class TelecomServiceImpl {
    private boolean callingUidMatchesPackageManagerRecords(String packageName) {
        int packageUid = -1;
        int callingUid = Binder.getCallingUid();
        PackageManager pm = mContext.createContextAsUser(
        PackageManager pm;
        try{
            pm = mContext.createContextAsUser(
                    UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();

        }
        catch (Exception e){
            Log.i(this, "callingUidMatchesPackageManagerRecords:"
                            + " createContextAsUser hit exception=[%s]", e.toString());
            return false;
        }
        if (pm != null) {
            try {
                packageUid = pm.getPackageUid(packageName, 0);