Merge "Support reset IMS stack in Reset Mobile Network flow" into main
This commit is contained in:
@@ -104,6 +104,7 @@ android_library {
|
|||||||
"settings-telephony-protos-lite",
|
"settings-telephony-protos-lite",
|
||||||
"statslog-settings",
|
"statslog-settings",
|
||||||
"androidx.test.rules",
|
"androidx.test.rules",
|
||||||
|
"telephony_flags_core_java_lib",
|
||||||
],
|
],
|
||||||
|
|
||||||
plugins: ["androidx.room_room-compiler-plugin"],
|
plugins: ["androidx.room_room-compiler-plugin"],
|
||||||
|
@@ -44,6 +44,7 @@ import androidx.activity.result.contract.ActivityResultContracts;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import com.android.internal.telephony.flags.Flags;
|
||||||
import com.android.settings.core.InstrumentedFragment;
|
import com.android.settings.core.InstrumentedFragment;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.network.ResetNetworkRestrictionViewBuilder;
|
import com.android.settings.network.ResetNetworkRestrictionViewBuilder;
|
||||||
@@ -121,16 +122,22 @@ public class ResetNetwork extends InstrumentedFragment {
|
|||||||
void showFinalConfirmation() {
|
void showFinalConfirmation() {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
||||||
ResetNetworkRequest request = new ResetNetworkRequest(
|
// TODO(b/317276437) Simplify the logic once flag is released
|
||||||
ResetNetworkRequest.RESET_CONNECTIVITY_MANAGER |
|
int resetOptions = ResetNetworkRequest.RESET_CONNECTIVITY_MANAGER
|
||||||
ResetNetworkRequest.RESET_VPN_MANAGER
|
| ResetNetworkRequest.RESET_VPN_MANAGER;
|
||||||
);
|
if (Flags.resetMobileNetworkSettings()) {
|
||||||
|
resetOptions |= ResetNetworkRequest.RESET_IMS_STACK;
|
||||||
|
}
|
||||||
|
ResetNetworkRequest request = new ResetNetworkRequest(resetOptions);
|
||||||
if (mSubscriptions != null && mSubscriptions.size() > 0) {
|
if (mSubscriptions != null && mSubscriptions.size() > 0) {
|
||||||
int selectedIndex = mSubscriptionSpinner.getSelectedItemPosition();
|
int selectedIndex = mSubscriptionSpinner.getSelectedItemPosition();
|
||||||
SubscriptionInfo subscription = mSubscriptions.get(selectedIndex);
|
SubscriptionInfo subscription = mSubscriptions.get(selectedIndex);
|
||||||
int subId = subscription.getSubscriptionId();
|
int subId = subscription.getSubscriptionId();
|
||||||
request.setResetTelephonyAndNetworkPolicyManager(subId)
|
request.setResetTelephonyAndNetworkPolicyManager(subId)
|
||||||
.setResetApn(subId);
|
.setResetApn(subId);
|
||||||
|
if (Flags.resetMobileNetworkSettings()) {
|
||||||
|
request.setResetImsSubId(subId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (mEsimContainer.getVisibility() == View.VISIBLE && mEsimCheckbox.isChecked()) {
|
if (mEsimContainer.getVisibility() == View.VISIBLE && mEsimCheckbox.isChecked()) {
|
||||||
request.setResetEsim(getContext().getPackageName())
|
request.setResetEsim(getContext().getPackageName())
|
||||||
|
@@ -48,11 +48,23 @@ public class ResetNetworkRequest {
|
|||||||
/* Reset option - reset BluetoothManager */
|
/* Reset option - reset BluetoothManager */
|
||||||
public static final int RESET_BLUETOOTH_MANAGER = 0x10;
|
public static final int RESET_BLUETOOTH_MANAGER = 0x10;
|
||||||
|
|
||||||
/* Subscription ID for not performing reset TelephonyAndNetworkPolicy or reset APN */
|
/* Reset option - reset IMS stack */
|
||||||
|
public static final int RESET_IMS_STACK = 0x20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscription ID indicates NOT resetting any of the components below:
|
||||||
|
* - TelephonyAndNetworkPolicy
|
||||||
|
* - APN
|
||||||
|
* - IMS
|
||||||
|
*/
|
||||||
public static final int INVALID_SUBSCRIPTION_ID = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
public static final int INVALID_SUBSCRIPTION_ID = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
/* Subscription ID for performing reset TelephonyAndNetworkPolicy or reset APN
|
/**
|
||||||
on all subscriptions */
|
* Subscription ID indicates resetting components below for ALL subscriptions:
|
||||||
|
* - TelephonyAndNetworkPolicy
|
||||||
|
* - APN
|
||||||
|
* - IMS
|
||||||
|
*/
|
||||||
public static final int ALL_SUBSCRIPTION_ID = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
|
public static final int ALL_SUBSCRIPTION_ID = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
/* Key within Bundle. To store some connectivity options for reset */
|
/* Key within Bundle. To store some connectivity options for reset */
|
||||||
@@ -75,10 +87,14 @@ public class ResetNetworkRequest {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected static final String KEY_APN_SUBID = "resetApnSubId";
|
protected static final String KEY_APN_SUBID = "resetApnSubId";
|
||||||
|
|
||||||
|
/** Key within Bundle. To store subscription ID for resetting IMS. */
|
||||||
|
protected static final String KEY_RESET_IMS_SUBID = "resetImsSubId";
|
||||||
|
|
||||||
private int mResetOptions = RESET_NONE;
|
private int mResetOptions = RESET_NONE;
|
||||||
private String mResetEsimPackageName;
|
private String mResetEsimPackageName;
|
||||||
private int mResetTelephonyManager = INVALID_SUBSCRIPTION_ID;
|
private int mResetTelephonyManager = INVALID_SUBSCRIPTION_ID;
|
||||||
private int mResetApn = INVALID_SUBSCRIPTION_ID;
|
private int mResetApn = INVALID_SUBSCRIPTION_ID;
|
||||||
|
private int mSubscriptionIdToResetIms = INVALID_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reconstruct based on keys stored within Bundle.
|
* Reconstruct based on keys stored within Bundle.
|
||||||
@@ -93,6 +109,8 @@ public class ResetNetworkRequest {
|
|||||||
mResetTelephonyManager = optionsFromBundle.getInt(
|
mResetTelephonyManager = optionsFromBundle.getInt(
|
||||||
KEY_TELEPHONY_NET_POLICY_MANAGER_SUBID, INVALID_SUBSCRIPTION_ID);
|
KEY_TELEPHONY_NET_POLICY_MANAGER_SUBID, INVALID_SUBSCRIPTION_ID);
|
||||||
mResetApn = optionsFromBundle.getInt(KEY_APN_SUBID, INVALID_SUBSCRIPTION_ID);
|
mResetApn = optionsFromBundle.getInt(KEY_APN_SUBID, INVALID_SUBSCRIPTION_ID);
|
||||||
|
mSubscriptionIdToResetIms = optionsFromBundle.getInt(KEY_RESET_IMS_SUBID,
|
||||||
|
INVALID_SUBSCRIPTION_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,6 +190,29 @@ public class ResetNetworkRequest {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the subscription ID applied for resetting IMS.
|
||||||
|
* @return subscription ID.
|
||||||
|
* {@code ALL_SUBSCRIPTION_ID} for applying to all subscriptions.
|
||||||
|
* {@code INVALID_SUBSCRIPTION_ID} means resetting IMS
|
||||||
|
* is not part of the option within this request.
|
||||||
|
*/
|
||||||
|
public int getResetImsSubId() {
|
||||||
|
return mSubscriptionIdToResetIms;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the subscription ID applied for resetting APN.
|
||||||
|
* @param subId is the subscription ID referenced from SubscriptionManager.
|
||||||
|
* {@code ALL_SUBSCRIPTION_ID} for applying to all subscriptions.
|
||||||
|
* {@code INVALID_SUBSCRIPTION_ID} means resetting IMS will not take place.
|
||||||
|
* @return this
|
||||||
|
*/
|
||||||
|
public ResetNetworkRequest setResetImsSubId(int subId) {
|
||||||
|
mSubscriptionIdToResetIms = subId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a copy of this request into Bundle given.
|
* Store a copy of this request into Bundle given.
|
||||||
* @param writeToBundle is a Bundle for storing configurations of this request.
|
* @param writeToBundle is a Bundle for storing configurations of this request.
|
||||||
@@ -182,6 +223,7 @@ public class ResetNetworkRequest {
|
|||||||
writeToBundle.putString(KEY_ESIM_PACKAGE, mResetEsimPackageName);
|
writeToBundle.putString(KEY_ESIM_PACKAGE, mResetEsimPackageName);
|
||||||
writeToBundle.putInt(KEY_TELEPHONY_NET_POLICY_MANAGER_SUBID, mResetTelephonyManager);
|
writeToBundle.putInt(KEY_TELEPHONY_NET_POLICY_MANAGER_SUBID, mResetTelephonyManager);
|
||||||
writeToBundle.putInt(KEY_APN_SUBID, mResetApn);
|
writeToBundle.putInt(KEY_APN_SUBID, mResetApn);
|
||||||
|
writeToBundle.putInt(KEY_RESET_IMS_SUBID, mSubscriptionIdToResetIms);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,6 +261,9 @@ public class ResetNetworkRequest {
|
|||||||
if (mResetApn != INVALID_SUBSCRIPTION_ID) {
|
if (mResetApn != INVALID_SUBSCRIPTION_ID) {
|
||||||
builder.resetApn(mResetApn);
|
builder.resetApn(mResetApn);
|
||||||
}
|
}
|
||||||
|
if ((mResetOptions & RESET_IMS_STACK) != 0) {
|
||||||
|
builder.resetIms(mSubscriptionIdToResetIms);
|
||||||
|
}
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,8 +23,8 @@ import android.util.Log;
|
|||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
@@ -53,8 +53,8 @@ public class ResetSubscriptionContract implements AutoCloseable {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
// Only keeps specific subscription ID required to perform reset operation
|
// Only keeps specific subscription ID required to perform reset operation
|
||||||
IntStream subIdStream = IntStream.of(
|
IntStream subIdStream = IntStream.of(
|
||||||
resetRequest.getResetTelephonyAndNetworkPolicyManager()
|
resetRequest.getResetTelephonyAndNetworkPolicyManager(),
|
||||||
, resetRequest.getResetApnSubId());
|
resetRequest.getResetApnSubId(), resetRequest.getResetImsSubId());
|
||||||
mResetSubscriptionIds = subIdStream.sorted().distinct()
|
mResetSubscriptionIds = subIdStream.sorted().distinct()
|
||||||
.filter(id -> SubscriptionManager.isUsableSubscriptionId(id))
|
.filter(id -> SubscriptionManager.isUsableSubscriptionId(id))
|
||||||
.toArray();
|
.toArray();
|
||||||
|
@@ -33,6 +33,7 @@ import android.telephony.SubscriptionManager;
|
|||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.settings.ResetNetworkRequest;
|
||||||
import com.android.settings.network.apn.ApnSettings;
|
import com.android.settings.network.apn.ApnSettings;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -212,6 +213,32 @@ public class ResetNetworkOperationBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append a step of resetting IMS stack.
|
||||||
|
*
|
||||||
|
* @return this
|
||||||
|
*/
|
||||||
|
public ResetNetworkOperationBuilder resetIms(int subId) {
|
||||||
|
attachSystemServiceWork(Context.TELEPHONY_SERVICE,
|
||||||
|
(Consumer<TelephonyManager>) tm -> {
|
||||||
|
if (subId == ResetNetworkRequest.INVALID_SUBSCRIPTION_ID) {
|
||||||
|
// Do nothing
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (subId == ResetNetworkRequest.ALL_SUBSCRIPTION_ID) {
|
||||||
|
// Reset IMS for all slots
|
||||||
|
for (int slotIndex = 0; slotIndex < tm.getActiveModemCount(); slotIndex++) {
|
||||||
|
tm.resetIms(slotIndex);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Reset IMS for the slot specified by the sucriptionId.
|
||||||
|
final int slotIndex = SubscriptionManager.getSlotIndex(subId);
|
||||||
|
tm.resetIms(slotIndex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a Runnable containing all operations appended.
|
* Construct a Runnable containing all operations appended.
|
||||||
* @return Runnable
|
* @return Runnable
|
||||||
|
@@ -16,12 +16,12 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
import static org.mockito.Mockito.any;
|
|
||||||
import static org.mockito.Mockito.anyInt;
|
import static org.mockito.Mockito.anyInt;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
@@ -34,6 +34,8 @@ import android.telephony.TelephonyManager;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.ResetNetworkRequest;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -129,4 +131,44 @@ public class ResetNetworkOperationBuilderTest {
|
|||||||
verify(mTelephonyManager).resetSettings();
|
verify(mTelephonyManager).resetSettings();
|
||||||
verify(mNetworkPolicyManager).factoryReset(imsi);
|
verify(mNetworkPolicyManager).factoryReset(imsi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void resetIms_performReset_whenBuildAndRun_withSingleValidSubId() {
|
||||||
|
final int subId = 1;
|
||||||
|
doReturn(mTelephonyManager).when(mTelephonyManager)
|
||||||
|
.createForSubscriptionId(anyInt());
|
||||||
|
doReturn(mTelephonyManager).when(mContext)
|
||||||
|
.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
|
||||||
|
mBuilder.resetIms(subId).build().run();
|
||||||
|
|
||||||
|
verify(mTelephonyManager).resetIms(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void resetIms_performReset_whenBuildAndRun_withInvalidSubId() {
|
||||||
|
final int subId = ResetNetworkRequest.INVALID_SUBSCRIPTION_ID;
|
||||||
|
doReturn(mTelephonyManager).when(mTelephonyManager)
|
||||||
|
.createForSubscriptionId(anyInt());
|
||||||
|
doReturn(mTelephonyManager).when(mContext)
|
||||||
|
.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
|
||||||
|
mBuilder.resetIms(subId).build().run();
|
||||||
|
|
||||||
|
verify(mTelephonyManager, never()).resetIms(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void resetIms_performReset_whenBuildAndRun_withAllValidSubId() {
|
||||||
|
final int subId = ResetNetworkRequest.ALL_SUBSCRIPTION_ID;
|
||||||
|
doReturn(mTelephonyManager).when(mTelephonyManager)
|
||||||
|
.createForSubscriptionId(anyInt());
|
||||||
|
doReturn(mTelephonyManager).when(mContext)
|
||||||
|
.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
doReturn(2).when(mTelephonyManager).getActiveModemCount();
|
||||||
|
|
||||||
|
mBuilder.resetIms(subId).build().run();
|
||||||
|
|
||||||
|
verify(mTelephonyManager, times(2)).resetIms(anyInt());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user