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

Commit 8156503c authored by Thomas Stuart's avatar Thomas Stuart
Browse files

decouple TelecomManager#getSelfManagedPhoneAccounts (1/3)

Recently TelecomManager#getSelfManagedPhoneAccounts was updated
to allow callingPackages to get their PA's.  However, API council
noted there was ambiguity with what was returned from the method.
Thus the method has been decoupled into 2 methods.

bug: 216640181
Test: CTS
Change-Id: I3931fc999937aaafa34d08ca9eb21af72ab960b1
parent e6f35e8e
Loading
Loading
Loading
Loading
+48 −49
Original line number Diff line number Diff line
@@ -226,11 +226,11 @@ public class TelecomServiceImpl {
        public List<PhoneAccountHandle> getSelfManagedPhoneAccounts(String callingPackage,
                String callingFeatureId) {
            try {
                Log.startSession("TSI.gSMPA",
                        Log.getPackageAbbreviation(callingPackage));
                try {
                    if (canReadPhoneState(callingPackage, callingFeatureId,
                Log.startSession("TSI.gSMPA", Log.getPackageAbbreviation(callingPackage));
                if (!canReadPhoneState(callingPackage, callingFeatureId,
                        "Requires READ_PHONE_STATE permission.")) {
                    throw new SecurityException("Requires READ_PHONE_STATE permission.");
                }
                synchronized (mLock) {
                    final UserHandle callingUserHandle = Binder.getCallingUserHandle();
                    long token = Binder.clearCallingIdentity();
@@ -244,13 +244,19 @@ public class TelecomServiceImpl {
                        Binder.restoreCallingIdentity(token);
                    }
                }
            } finally {
                Log.endSession();
            }
                } catch (SecurityException e) {
                    //  SecurityException thrown from canReadPhoneState(...) due to READ_PHONE_STATE
                    //   permission.  check MANAGE_OWN_CALLS permission next.
        }

                if (canReadMangeOwnCalls("Requires MANAGE_OWN_CALLS permission")) {
        @Override
        public List<PhoneAccountHandle> getOwnSelfManagedPhoneAccounts(String callingPackage,
                String callingFeatureId) {
            try {
                Log.startSession("TSI.gOSMPA", Log.getPackageAbbreviation(callingPackage));
                if (!canReadMangeOwnCalls("Requires MANAGE_OWN_CALLS permission.")) {
                    throw new SecurityException("Requires MANAGE_OWN_CALLS permission.");
                }
                synchronized (mLock) {
                    final UserHandle callingUserHandle = Binder.getCallingUserHandle();
                    long token = Binder.clearCallingIdentity();
@@ -266,27 +272,11 @@ public class TelecomServiceImpl {
                        Binder.restoreCallingIdentity(token);
                    }
                }
                } else {
                    throw new SecurityException(
                            "Requires caller to be the default dialer app or at least one of the "
                                    + "following permissions READ_PRIVILEGED_PHONE_STATE, "
                                    + "READ_PHONE_STATE, or MANAGE_OWN_CALLS for the calling "
                                    + "package: " + callingPackage);
                }
            } finally {
                Log.endSession();
            }
        }

        private boolean canReadMangeOwnCalls(String message) {
            try {
                mContext.enforceCallingOrSelfPermission(MANAGE_OWN_CALLS, message);
                return true;
            } catch (SecurityException e) {
                return false;
            }
        }

        @Override
        public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme,
                String callingPackage) {
@@ -2464,6 +2454,15 @@ public class TelecomServiceImpl {
        }
    }

    private boolean canReadMangeOwnCalls(String message) {
        try {
            mContext.enforceCallingOrSelfPermission(MANAGE_OWN_CALLS, message);
            return true;
        } catch (SecurityException e) {
            return false;
        }
    }

    private boolean canReadPhoneNumbers(String callingPackage, String callingFeatureId,
            String message) {
        boolean targetSdkPreR = false;