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

Commit e93321c1 authored by Nathan Harold's avatar Nathan Harold
Browse files

Add set/getUsageSetting APIs

Add the APIs in SubscriptionInfo/SubscriptionManager to
set and to get the Usage Setting.

Bug: 210023167
Test: atest SubscriptionControllerTest#testUsageSettingProperty
Change-Id: I515700ac0a7731c80002eee13d466c28c977f419
parent 10de8e54
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -230,7 +230,7 @@ public class SubscriptionInfo implements Parcelable {
    /**
     * Subscription's preferred usage setting.
     */
    private int mUsageSetting = SubscriptionManager.USAGE_SETTING_UNKNOWN;
    private @UsageSetting int mUsageSetting = SubscriptionManager.USAGE_SETTING_UNKNOWN;

    /**
     * Public copy constructor.
@@ -822,7 +822,20 @@ public class SubscriptionInfo implements Parcelable {
        return mAreUiccApplicationsEnabled;
    }

    public static final @android.annotation.NonNull Parcelable.Creator<SubscriptionInfo> CREATOR = new Parcelable.Creator<SubscriptionInfo>() {
    /**
     * Get the usage setting for this subscription.
     *
     * @return the usage setting used for this subscription.
     *
     * @hide
     */
    public @UsageSetting int getUsageSetting() {
        return mUsageSetting;
    }

    public static final @android.annotation.NonNull
            Parcelable.Creator<SubscriptionInfo> CREATOR =
                    new Parcelable.Creator<SubscriptionInfo>() {
        @Override
        public SubscriptionInfo createFromParcel(Parcel source) {
            int id = source.readInt();
+29 −0
Original line number Diff line number Diff line
@@ -4013,4 +4013,33 @@ public class SubscriptionManager {
            throw ex.rethrowAsRuntimeException();
        }
    }

    /**
     * Set the preferred usage setting.
     *
     * The cellular usage setting is a switch which controls the mode of operation for the cellular
     * radio to either require or not require voice service. It is not managed via Android’s
     * Settings.
     *
     * @param subscriptionId the subId of the subscription.
     * @param usageSetting the requested usage setting.
     *
     * @throws IllegalStateException if a specific mode or setting the mode is not supported on a
     * particular device.
     *
     * <p>Requires {@link android.Manifest.permission#MODIFY_PHONE_STATE}
     * or that the calling app has CarrierPrivileges for the given subscription.
     *
     * Note: This method will not allow the setting of USAGE_SETTING_UNKNOWN.
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    void setUsageSetting(int subscriptionId, @UsageSetting int usageSetting) {
        if (VDBG) logd("[setUsageSetting]+ setting:" + usageSetting + " subId:" + subscriptionId);
        setSubscriptionPropertyHelper(subscriptionId, "setUsageSetting",
                (iSub)-> iSub.setUsageSetting(
                        usageSetting, subscriptionId, mContext.getOpPackageName()));
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -313,4 +313,15 @@ interface ISub {

    void setPhoneNumber(int subId, int source, String number,
            String callingPackage, String callingFeatureId);

    /**
     * Set the Usage Setting for this subscription.
     *
     * @param usageSetting the usage setting for this subscription
     * @param subId the unique SubscriptionInfo index in database
     * @param callingPackage The package making the IPC.
     *
     * @throws SecurityException if doesn't have MODIFY_PHONE_STATE or Carrier Privileges
     */
    int setUsageSetting(int usageSetting, int subId, String callingPackage);
}