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
This commit is contained in:
Malcolm Chen
2019-02-05 17:19:48 -08:00
parent 1f2f4687e1
commit b2b88b3735
7 changed files with 83 additions and 5 deletions

View File

@@ -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",

View File

@@ -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

View File

@@ -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<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

View File

@@ -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<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
}

View File

@@ -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.
*

View File

@@ -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);
}

View File

@@ -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.