From b2b88b3735969d85318fc635408459154bf93732 Mon Sep 17 00:00:00 2001 From: Malcolm Chen Date: Tue, 5 Feb 2019 17:19:48 -0800 Subject: [PATCH] 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 --- Android.bp | 1 + api/current.txt | 3 ++ api/system-current.txt | 1 + .../telephony/SubscriptionManager.java | 28 ++++++++++++++++--- .../android/telephony/TelephonyManager.java | 23 +++++++++++++++ .../ISetOpportunisticDataCallback.aidl | 25 +++++++++++++++++ .../com/android/internal/telephony/ISub.aidl | 7 ++++- 7 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 telephony/java/com/android/internal/telephony/ISetOpportunisticDataCallback.aidl diff --git a/Android.bp b/Android.bp index 7bdedc79943db..5c995def76d07 100644 --- a/Android.bp +++ b/Android.bp @@ -602,6 +602,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", diff --git a/api/current.txt b/api/current.txt index abab90182b018..3075a83eac922 100644 --- a/api/current.txt +++ b/api/current.txt @@ -45227,6 +45227,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 diff --git a/api/system-current.txt b/api/system-current.txt index 02718cbaac079..15d891bb00e50 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -7746,6 +7746,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); 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 diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index dfe36efcd5d13..e5bb41f2f1b10 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -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; /** @@ -2571,17 +2573,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 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 } diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index eab536f942901..7312f847a3084 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -10093,6 +10093,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. * diff --git a/telephony/java/com/android/internal/telephony/ISetOpportunisticDataCallback.aidl b/telephony/java/com/android/internal/telephony/ISetOpportunisticDataCallback.aidl new file mode 100644 index 0000000000000..7a78f3454aac7 --- /dev/null +++ b/telephony/java/com/android/internal/telephony/ISetOpportunisticDataCallback.aidl @@ -0,0 +1,25 @@ +/* + * Copyright 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.telephony; + +/** + * Callback to provide asynchronous result of setPreferredOpportunisticData. + * @hide + */ +oneway interface ISetOpportunisticDataCallback { + void onComplete(int result); +} diff --git a/telephony/java/com/android/internal/telephony/ISub.aidl b/telephony/java/com/android/internal/telephony/ISub.aidl index 6ce9de4ca6778..75a4d8227e23d 100755 --- a/telephony/java/com/android/internal/telephony/ISub.aidl +++ b/telephony/java/com/android/internal/telephony/ISub.aidl @@ -17,6 +17,7 @@ package com.android.internal.telephony; import android.telephony.SubscriptionInfo; +import com.android.internal.telephony.ISetOpportunisticDataCallback; interface ISub { /** @@ -217,10 +218,14 @@ interface ISub { * designed to overwrite default data subscription temporarily. * * @param subId which subscription is preferred to for cellular data. + * @param needValidation whether validation is needed before switching. + * @param callback callback upon request completion. + * * @hide * */ - void setPreferredDataSubscriptionId(int subId); + void setPreferredDataSubscriptionId(int subId, boolean needValidation, + ISetOpportunisticDataCallback callback); /** * Get which subscription is preferred for cellular data.