Merge "Revert switchBar if enable / disable subscription fails." into qt-dev
am: 81f31ef4d3
Change-Id: I50d58d53ecd2f56fbd43bb616253c0433085d1c6
This commit is contained in:
@@ -22,6 +22,7 @@ import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
@@ -80,8 +81,9 @@ public class MobileNetworkSwitchController extends BasePreferenceController impl
|
|||||||
R.string.mobile_network_use_sim_off);
|
R.string.mobile_network_use_sim_off);
|
||||||
|
|
||||||
mSwitchBar.addOnSwitchChangeListener((switchView, isChecked) -> {
|
mSwitchBar.addOnSwitchChangeListener((switchView, isChecked) -> {
|
||||||
if (mSubscriptionManager.isSubscriptionEnabled(mSubId) != isChecked) {
|
if (mSubscriptionManager.isSubscriptionEnabled(mSubId) != isChecked
|
||||||
mSubscriptionManager.setSubscriptionEnabled(mSubId, isChecked);
|
&& (!mSubscriptionManager.setSubscriptionEnabled(mSubId, isChecked))) {
|
||||||
|
mSwitchBar.setChecked(!isChecked);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
update();
|
update();
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.network.telephony;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
@@ -71,6 +72,8 @@ public class MobileNetworkSwitchControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||||
|
when(mSubscriptionManager.setSubscriptionEnabled(eq(mSubId), anyBoolean()))
|
||||||
|
.thenReturn(true);
|
||||||
|
|
||||||
mLifecycleOwner = () -> mLifecycle;
|
mLifecycleOwner = () -> mLifecycle;
|
||||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||||
@@ -128,6 +131,19 @@ public class MobileNetworkSwitchControllerTest {
|
|||||||
verify(mSubscriptionManager).setSubscriptionEnabled(eq(mSubId), eq(false));
|
verify(mSubscriptionManager).setSubscriptionEnabled(eq(mSubId), eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void switchChangeListener_fromEnabledToDisabled_setSubscriptionEnabledFailed() {
|
||||||
|
when(mSubscriptionManager.setSubscriptionEnabled(eq(mSubId), anyBoolean()))
|
||||||
|
.thenReturn(false);
|
||||||
|
when(mSubscriptionManager.isSubscriptionEnabled(mSubId)).thenReturn(true);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
assertThat(mSwitchBar.isShowing()).isTrue();
|
||||||
|
assertThat(mSwitchBar.isChecked()).isTrue();
|
||||||
|
mSwitchBar.setChecked(false);
|
||||||
|
verify(mSubscriptionManager).setSubscriptionEnabled(eq(mSubId), eq(false));
|
||||||
|
assertThat(mSwitchBar.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void switchChangeListener_fromDisabledToEnabled_setSubscriptionEnabledCalledCorrectly() {
|
public void switchChangeListener_fromDisabledToEnabled_setSubscriptionEnabledCalledCorrectly() {
|
||||||
when(mSubscriptionManager.isSubscriptionEnabled(mSubId)).thenReturn(false);
|
when(mSubscriptionManager.isSubscriptionEnabled(mSubId)).thenReturn(false);
|
||||||
|
Reference in New Issue
Block a user