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

Commit fd11df29 authored by Malcolm Chen's avatar Malcolm Chen
Browse files

Adding callback for setPreferredDataSubscriptionId.

The purpose is to provide a way to return success or failure upon
switching data to CBRS subscription.
The same callback is used for ONS to call internal API. Later it
will also be used by Carrier apps to call TelephonyManager#
setPreferredOpportunisticDataSubscription.

Bug: 122255288
Test: manual

Change-Id: Id3f43e024c902d6785017e7866f9e804a486b04f
Merged-In: Id3f43e024c902d6785017e7866f9e804a486b04f
parent eee18bd5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -551,6 +551,7 @@ java_defaults {
        "telephony/java/com/android/internal/telephony/IOnSubscriptionsChangedListener.aidl",
        "telephony/java/com/android/internal/telephony/IPhoneStateListener.aidl",
        "telephony/java/com/android/internal/telephony/IPhoneSubInfo.aidl",
        "telephony/java/com/android/internal/telephony/ISetOpportunisticDataCallback.aidl",
        "telephony/java/com/android/internal/telephony/ISms.aidl",
        "telephony/java/com/android/internal/telephony/ISub.aidl",
        "telephony/java/com/android/internal/telephony/IOns.aidl",
+3 −0
Original line number Diff line number Diff line
@@ -43193,6 +43193,9 @@ package android.telephony {
    field public static final int PHONE_TYPE_GSM = 1; // 0x1
    field public static final int PHONE_TYPE_NONE = 0; // 0x0
    field public static final int PHONE_TYPE_SIP = 3; // 0x3
    field public static final int SET_OPPORTUNISTIC_SUB_INVALID_PARAMETER = 2; // 0x2
    field public static final int SET_OPPORTUNISTIC_SUB_SUCCESS = 0; // 0x0
    field public static final int SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED = 1; // 0x1
    field public static final int SIM_STATE_ABSENT = 1; // 0x1
    field public static final int SIM_STATE_CARD_IO_ERROR = 8; // 0x8
    field public static final int SIM_STATE_CARD_RESTRICTED = 9; // 0x9
+1 −0
Original line number Diff line number Diff line
@@ -6295,6 +6295,7 @@ package android.telephony {
    method public void requestEmbeddedSubscriptionInfoListRefresh(int);
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDefaultDataSubId(int);
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDefaultSmsSubId(int);
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setPreferredDataSubscriptionId(int, boolean, @NonNull java.util.concurrent.Executor, java.util.function.Consumer<java.lang.Integer>);
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setSubscriptionEnabled(int, boolean);
    field public static final android.net.Uri ADVANCED_CALLING_ENABLED_CONTENT_URI;
    field public static final int PROFILE_CLASS_DEFAULT = -1; // 0xffffffff
+24 −4
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.util.DisplayMetrics;
import android.util.Log;

import com.android.internal.telephony.IOnSubscriptionsChangedListener;
import com.android.internal.telephony.ISetOpportunisticDataCallback;
import com.android.internal.telephony.ISub;
import com.android.internal.telephony.ITelephonyRegistry;
import com.android.internal.telephony.PhoneConstants;
@@ -72,6 +73,7 @@ import java.util.List;
import java.util.Locale;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
@@ -2577,17 +2579,35 @@ public class SubscriptionManager {
     *              {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID}, it means
     *              it's unset and {@link SubscriptionManager#getDefaultDataSubscriptionId()}
     *              is used to determine which modem is preferred.
     * @param needValidation whether validation is needed before switch happens.
     * @param executor The executor of where the callback will execute.
     * @param callback Callback will be triggered once it succeeds or failed.
     *                 See {@link TelephonyManager.SetOpportunisticSubscriptionResult}
     *                 for more details. Pass null if don't care about the result.
     *
     * @hide
     *
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    public void setPreferredDataSubscriptionId(int subId) {
    public void setPreferredDataSubscriptionId(int subId, boolean needValidation,
            @NonNull @CallbackExecutor Executor executor, Consumer<Integer> callback) {
        if (VDBG) logd("[setPreferredDataSubscriptionId]+ subId:" + subId);
        try {
            ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
            if (iSub != null) {
                iSub.setPreferredDataSubscriptionId(subId);
            if (iSub == null) return;

            ISetOpportunisticDataCallback callbackStub = new ISetOpportunisticDataCallback.Stub() {
                @Override
                public void onComplete(int result) {
                    Binder.withCleanCallingIdentity(() -> executor.execute(() -> {
                        if (callback != null) {
                            callback.accept(result);
                        }
                    }));
                }
            };
            iSub.setPreferredDataSubscriptionId(subId, needValidation, callbackStub);
        } catch (RemoteException ex) {
            // ignore it
        }
+23 −0
Original line number Diff line number Diff line
@@ -10099,6 +10099,29 @@ public class TelephonyManager {
        return false;
    }

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = {"SET_OPPORTUNISTIC_SUB"}, value = {
            SET_OPPORTUNISTIC_SUB_SUCCESS,
            SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED,
            SET_OPPORTUNISTIC_SUB_INVALID_PARAMETER})
    public @interface SetOpportunisticSubscriptionResult {}

    /**
     * No error. Operation succeeded.
     */
    public static final int SET_OPPORTUNISTIC_SUB_SUCCESS = 0;

    /**
     * Validation failed when trying to switch to preferred subscription.
     */
    public static final int SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED = 1;

    /**
     * The parameter passed in is invalid.
     */
    public static final int SET_OPPORTUNISTIC_SUB_INVALID_PARAMETER = 2;

    /**
     * Set preferred opportunistic data subscription id.
     *
Loading