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

Commit 2d77a335 authored by Danny Baumann's avatar Danny Baumann
Browse files

Allow system apps to query the voicemail number.

Change-Id: Iad5756462da2092ebe441e6047eee21981e96bff
parent fcaa59c0
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;