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

Commit 28f7ce80 authored by Thomas Stuart's avatar Thomas Stuart Committed by Android (Google) Code Review
Browse files

Merge "decouple TelecomManager#getSelfManagedPhoneAccounts (1/3)" into tm-dev

parents 842f6060 8156503c
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;