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

Commit ad91e86c authored by Danny Baumann's avatar Danny Baumann Committed by Gerrit Code Review
Browse files

Merge "Allow system apps to query the voicemail number." into cm-12.1

parents 353f49f3 2d77a335
Loading
Loading
Loading
Loading
+27 −6
Original line number Diff line number Diff line
@@ -443,13 +443,24 @@ public class TelecomService extends Service {
        public boolean hasVoiceMailNumber(PhoneAccountHandle accountHandle) {
            enforceReadPermissionOrDefaultDialer();
            try {
                if (!isVisibleToCaller(accountHandle)) {
                    Log.w(this, "%s is not visible for the calling user", accountHandle);
                    return false;
                return !TextUtils.isEmpty(getVoiceMailNumberInternal(accountHandle));
            } catch (Exception e) {
                Log.e(this, e, "getSubscriptionIdForPhoneAccount");
                throw e;
            }
        }

                int subId = mPhoneAccountRegistrar.getSubscriptionIdForPhoneAccount(accountHandle);
                return !TextUtils.isEmpty(getTelephonyManager().getVoiceMailNumber(subId));
        /**
         * @see android.telecom.TelecomManager#getVoiceMailNumber
         */
        @Override
        public String getVoiceMailNumber(PhoneAccountHandle accountHandle) {
            if (!isCallerSystemApp()) {
                throw new SecurityException(
                        "Only system apps are allowed to call getVoiceMailNumber()");
            }
            try {
                return getVoiceMailNumberInternal(accountHandle);
            } catch (Exception e) {
                Log.e(this, e, "getSubscriptionIdForPhoneAccount");
                throw e;
@@ -744,6 +755,16 @@ public class TelecomService extends Service {
    // Supporting methods for the ITelecomService interface implementation.
    //

    private String getVoiceMailNumberInternal(PhoneAccountHandle accountHandle) {
        if (!isVisibleToCaller(accountHandle)) {
            Log.w(this, "%s is not visible for the calling user", accountHandle);
            return null;
        }

        int subId = mPhoneAccountRegistrar.getSubscriptionIdForPhoneAccount(accountHandle);
        return getTelephonyManager().getVoiceMailNumber(subId);
    }

    private boolean isVisibleToCaller(PhoneAccountHandle accountHandle) {
        if (accountHandle == null) {
            return false;