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

Commit b75ec04c authored by Jack Yu's avatar Jack Yu
Browse files

Added getSubscriptionsInGroup support

Bug: 239607619
Test: atest SubscriptionManagerServiceTest
Merged-In: Iac3731c63bfece061c3b8f99fa795b98e27d0e4d
Change-Id: Iac3731c63bfece061c3b8f99fa795b98e27d0e4d
parent 2aca31a1
Loading
Loading
Loading
Loading
+16 −15
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
import com.android.internal.telephony.imsphone.ImsPhoneMmiCode;
import com.android.internal.telephony.metrics.TelephonyMetrics;
import com.android.internal.telephony.metrics.VoiceCallSessionStats;
import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
import com.android.internal.telephony.subscription.SubscriptionManagerService.SubscriptionManagerServiceCallback;
import com.android.internal.telephony.test.SimulatedRadioControl;
import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
@@ -4655,14 +4656,20 @@ public class GsmCdmaPhone extends Phone {
        boolean mDefaultVonr =
                config.getBoolean(CarrierConfigManager.KEY_VONR_ON_BY_DEFAULT_BOOL);

        String result = SubscriptionController.getInstance().getSubscriptionProperty(
                getSubId(),
                SubscriptionManager.NR_ADVANCED_CALLING_ENABLED);

        int setting = -1;
        if (isSubscriptionManagerServiceEnabled()) {
            SubscriptionInfoInternal subInfo = mSubscriptionManagerService
                    .getSubscriptionInfoInternal(getSubId());
            if (subInfo != null) {
                setting = subInfo.getNrAdvancedCallingEnabled();
            }
        } else {
            String result = SubscriptionController.getInstance().getSubscriptionProperty(
                    getSubId(), SubscriptionManager.NR_ADVANCED_CALLING_ENABLED);
            if (result != null) {
                setting = Integer.parseInt(result);
            }
        }

        logd("VoNR setting from telephony.db:"
                + setting
@@ -4671,15 +4678,9 @@ public class GsmCdmaPhone extends Phone {
                + " ,vonr_on_by_default_bool:"
                + mDefaultVonr);

        if (!mIsVonrEnabledByCarrier) {
            mCi.setVoNrEnabled(false, obtainMessage(EVENT_SET_VONR_ENABLED_DONE), null);
        } else if (setting == -1) {
            mCi.setVoNrEnabled(mDefaultVonr, obtainMessage(EVENT_SET_VONR_ENABLED_DONE), null);
        } else if (setting == 1) {
            mCi.setVoNrEnabled(true, obtainMessage(EVENT_SET_VONR_ENABLED_DONE), null);
        } else if (setting == 0) {
            mCi.setVoNrEnabled(false, obtainMessage(EVENT_SET_VONR_ENABLED_DONE), null);
        }
        boolean enbleVonr = mIsVonrEnabledByCarrier
                && (setting == 1 || (setting == -1 && mDefaultVonr));
        mCi.setVoNrEnabled(enbleVonr, obtainMessage(EVENT_SET_VONR_ENABLED_DONE), null);
    }

    private void updateCdmaRoamingSettingsAfterCarrierConfigChanged(PersistableBundle config) {
+11 −5
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.data.DataSettingsManager.DataSettingsManagerCallback;
import com.android.internal.telephony.subscription.SubscriptionManagerService;
import com.android.internal.telephony.util.ArrayUtils;

import java.lang.annotation.Retention;
@@ -903,11 +904,16 @@ public class MultiSimSettingController extends Handler {
     * are synced.
     */
    private void setRoamingDataEnabledForGroup(int subId, boolean enable) {
        SubscriptionController subController = SubscriptionController.getInstance();
        List<SubscriptionInfo> infoList = subController.getSubscriptionsInGroup(
        List<SubscriptionInfo> infoList;
        if (PhoneFactory.getDefaultPhone().isSubscriptionManagerServiceEnabled()) {
            infoList = SubscriptionManagerService.getInstance().getSubscriptionsInGroup(
                    mSubController.getGroupUuid(subId), mContext.getOpPackageName(),
                    mContext.getAttributionTag());

        } else {
            infoList = SubscriptionController.getInstance().getSubscriptionsInGroup(
                    mSubController.getGroupUuid(subId), mContext.getOpPackageName(),
                    mContext.getAttributionTag());
        }
        if (infoList == null) return;

        for (SubscriptionInfo info : infoList) {
+11 −9
Original line number Diff line number Diff line
@@ -628,11 +628,12 @@ public class SubscriptionInfoInternal {
     * @return {@code true} if enhanced 4G mode is enabled by the user or not.
     */
    public boolean isEnhanced4GModeEnabled() {
        return mIsEnhanced4GModeEnabled != 0;
        return mIsEnhanced4GModeEnabled == 1;
    }

    /**
     * @return {@code 1} if enhanced 4G mode is enabled by the user or not.
     * @return {@code 1} if enhanced 4G mode is enabled by the user or not. {@code 0} if disabled.
     * {@code -1} if the user did not change any setting.
     */
    public int getEnhanced4GModeEnabled() {
        return mIsEnhanced4GModeEnabled;
@@ -657,12 +658,12 @@ public class SubscriptionInfoInternal {
     * roaming.
     */
    public boolean isWifiCallingEnabled() {
        return mIsWifiCallingEnabled != 0;
        return mIsWifiCallingEnabled == 1;
    }

    /**
     * @return {@code 1} if Wi-Fi calling is enabled by the user or not when the device is not
     * roaming.
     * roaming. {@code 0} if disabled. {@code -1} if the user did not change any setting.
     */
    public int getWifiCallingEnabled() {
        return mIsWifiCallingEnabled;
@@ -686,10 +687,10 @@ public class SubscriptionInfoInternal {

    /**
     * @return {@code true} if Wi-Fi calling is enabled by the user or not when the device is
     * roaming.
     * roaming. {@code 0} if disabled. {@code -1} if the user did not change any setting.
     */
    public boolean isWifiCallingEnabledForRoaming() {
        return mIsWifiCallingEnabledForRoaming != 0;
        return mIsWifiCallingEnabledForRoaming == 1;
    }

    /**
@@ -894,11 +895,12 @@ public class SubscriptionInfoInternal {
     * @return {@code true} if the user has enabled NR advanced calling.
     */
    public boolean isNrAdvancedCallingEnabled() {
        return mIsNrAdvancedCallingEnabled != 0;
        return mIsNrAdvancedCallingEnabled == 1;
    }

    /**
     * @return {@code 1} if the user has enabled NR advanced calling.
     * @return {@code 1} if the user has enabled NR advanced calling. {code 0} if disabled.
     * {code -1} if the user did not change any setting.
     */
    public int getNrAdvancedCallingEnabled() {
        return mIsNrAdvancedCallingEnabled;
@@ -1407,7 +1409,7 @@ public class SubscriptionInfoInternal {
        /**
         * Whether the user has enabled NR advanced calling.
         */
        private int mIsNrAdvancedCallingEnabled = 0;
        private int mIsNrAdvancedCallingEnabled = -1;

        /**
         * The phone number retrieved from carrier.
+76 −4
Original line number Diff line number Diff line
@@ -20,8 +20,12 @@ import android.Manifest;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.content.Context;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
@@ -38,6 +42,7 @@ import android.telephony.TelephonyManager;
import android.telephony.TelephonyRegistryManager;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.EventLog;
import android.util.IndentingPrintWriter;
import android.util.LocalLog;

@@ -71,6 +76,15 @@ public class SubscriptionManagerService extends ISub.Stub {
    /** Whether enabling verbose debugging message or not. */
    private static final boolean VDBG = false;

    /**
     * Apps targeting on Android T and beyond will get exception if there is no access to device
     * identifiers nor has carrier privileges when calling
     * {@link SubscriptionManager#getSubscriptionsInGroup}.
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
    public static final long REQUIRE_DEVICE_IDENTIFIERS_FOR_GROUP_UUID = 213902861L;

    /** Instance of subscription manager service. */
    @NonNull
    private static SubscriptionManagerService sInstance;
@@ -82,6 +96,9 @@ public class SubscriptionManagerService extends ISub.Stub {
    /** Telephony manager instance. */
    private final TelephonyManager mTelephonyManager;

    /** Subscription manager instance. */
    private final SubscriptionManager mSubscriptionManager;

    /** The main handler of subscription manager service. */
    @NonNull
    private final Handler mHandler;
@@ -234,6 +251,7 @@ public class SubscriptionManagerService extends ISub.Stub {
        sInstance = this;
        mContext = context;
        mTelephonyManager = context.getSystemService(TelephonyManager.class);
        mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
        mHandler = new Handler(looper);
        TelephonyServiceManager.ServiceRegisterer subscriptionServiceRegisterer =
                TelephonyFrameworkInitializer
@@ -344,8 +362,8 @@ public class SubscriptionManagerService extends ISub.Stub {
     *
     * @return {@code true} if the caller has identifier access.
     */
    private boolean hasSubscriberIdentifierAccess(int subId, String callingPackage,
            String callingFeatureId, String message, boolean reportFailure) {
    private boolean hasSubscriberIdentifierAccess(int subId, @NonNull String callingPackage,
            @Nullable String callingFeatureId, @Nullable String message, boolean reportFailure) {
        try {
            return TelephonyPermissions.checkCallingOrSelfReadSubscriberIdentifiers(mContext, subId,
                    callingPackage, callingFeatureId, message, reportFailure);
@@ -360,7 +378,7 @@ public class SubscriptionManagerService extends ISub.Stub {
    /**
     * Conditionally removes identifiers from the provided {@link SubscriptionInfo} if the {@code
     * callingPackage} does not meet the access requirements for identifiers and returns the
     * potentially modified object..
     * potentially modified object.
     *
     * <p>
     * If the caller does not have {@link Manifest.permission#READ_PHONE_NUMBERS} permission,
@@ -809,10 +827,64 @@ public class SubscriptionManagerService extends ISub.Stub {
            @NonNull String callingPackage) {
    }

    /**
     * Get subscriptionInfo list of subscriptions that are in the same group of given subId.
     * See {@link #createSubscriptionGroup(int[], String)} for more details.
     *
     * Caller must have {@link android.Manifest.permission#READ_PHONE_STATE}
     * or carrier privilege permission on the subscription.
     *
     * <p>Starting with API level 33, the caller also needs permission to access device identifiers
     * to get the list of subscriptions associated with a group UUID.
     * This method can be invoked if one of the following requirements is met:
     * <ul>
     *     <li>If the app has carrier privilege permission.
     *     {@link TelephonyManager#hasCarrierPrivileges()}
     *     <li>If the app has {@link android.Manifest.permission#READ_PHONE_STATE} permission and
     *     access to device identifiers.
     * </ul>
     *
     * @param groupUuid of which list of subInfo will be returned.
     * @param callingPackage The package making the call.
     * @param callingFeatureId The feature in the package.
     *
     * @return List of {@link SubscriptionInfo} that belong to the same group, including the given
     * subscription itself. It will return an empty list if no subscription belongs to the group.
     *
     * @throws SecurityException if the caller doesn't meet the requirements outlined above.
     *
     */
    @Override
    @NonNull
    public List<SubscriptionInfo> getSubscriptionsInGroup(@NonNull ParcelUuid groupUuid,
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
        return null;
        // If the calling app neither has carrier privileges nor READ_PHONE_STATE and access to
        // device identifiers, it will throw a SecurityException.
        if (CompatChanges.isChangeEnabled(REQUIRE_DEVICE_IDENTIFIERS_FOR_GROUP_UUID,
                Binder.getCallingUid())) {
            try {
                if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mContext,
                        callingPackage, callingFeatureId, "getSubscriptionsInGroup")) {
                    EventLog.writeEvent(0x534e4554, "213902861", Binder.getCallingUid());
                    throw new SecurityException("Need to have carrier privileges or access to "
                            + "device identifiers to call getSubscriptionsInGroup");
                }
            } catch (SecurityException e) {
                EventLog.writeEvent(0x534e4554, "213902861", Binder.getCallingUid());
                throw e;
            }
        }

        return mSubscriptionDatabaseManager.getAllSubscriptions().stream()
                .map(SubscriptionInfoInternal::toSubscriptionInfo)
                .filter(info -> groupUuid.equals(info.getGroupUuid())
                        && (mSubscriptionManager.canManageSubscription(info, callingPackage)
                        || TelephonyPermissions.checkCallingOrSelfReadPhoneState(
                                mContext, info.getSubscriptionId(), callingPackage,
                        callingFeatureId, "getSubscriptionsInGroup")))
                .map(subscriptionInfo -> conditionallyRemoveIdentifiers(subscriptionInfo,
                        callingPackage, callingFeatureId, "getSubscriptionsInGroup"))
                .collect(Collectors.toList());
    }

    @Override
+151 −48

File changed.

Preview size limit exceeded, changes collapsed.