Add a "data during calls" preference

am: aeb1da0db9

Change-Id: I1b66985de2cc045953a52d647a3568e7a8d03f10
This commit is contained in:
Antony Sargent
2019-06-03 18:39:54 -07:00
committed by android-build-merger
5 changed files with 246 additions and 0 deletions

View File

@@ -85,6 +85,12 @@
android:summary="@string/mms_message_summary" android:summary="@string/mms_message_summary"
settings:controller="com.android.settings.network.telephony.MmsMessagePreferenceController"/> settings:controller="com.android.settings.network.telephony.MmsMessagePreferenceController"/>
<SwitchPreference
android:key="data_during_calls"
android:title="@string/data_during_calls_title"
android:summary="@string/data_during_calls_summary"
settings:controller="com.android.settings.network.telephony.DataDuringCallsPreferenceController"/>
<SwitchPreference <SwitchPreference
android:key="enhanced_4g_lte" android:key="enhanced_4g_lte"
android:title="@string/enhanced_4g_lte_mode_title" android:title="@string/enhanced_4g_lte_mode_title"

View File

@@ -0,0 +1,104 @@
/*
* Copyright (C) 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.settings.network.telephony;
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
import android.content.Context;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.settings.network.SubscriptionsChangeListener;
public class DataDuringCallsPreferenceController extends TelephonyTogglePreferenceController
implements LifecycleObserver,
SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
private SwitchPreference mPreference;
private SubscriptionsChangeListener mChangeListener;
private TelephonyManager mManager;
public DataDuringCallsPreferenceController(Context context,
String preferenceKey) {
super(context, preferenceKey);
mChangeListener = new SubscriptionsChangeListener(mContext, this);
}
public void init(Lifecycle lifecycle, int subId) {
this.mSubId = subId;
mManager = mContext.getSystemService(TelephonyManager.class).createForSubscriptionId(subId);
lifecycle.addObserver(this);
}
@OnLifecycleEvent(ON_RESUME)
public void onResume() {
mChangeListener.start();
}
@OnLifecycleEvent(ON_PAUSE)
public void onPause() {
mChangeListener.stop();
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
}
@Override
public boolean isChecked() {
return mManager.isDataAllowedInVoiceCall();
}
@Override
public boolean setChecked(boolean isChecked) {
mManager.setDataAllowedDuringVoiceCall(isChecked);
return true;
}
@Override
public int getAvailabilityStatus(int subId) {
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID ||
SubscriptionManager.getDefaultDataSubscriptionId() == mSubId) {
return CONDITIONALLY_UNAVAILABLE;
}
return AVAILABLE;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
preference.setVisible(isAvailable());
}
@Override
public void onAirplaneModeChanged(boolean airplaneModeEnabled) {}
@Override
public void onSubscriptionsChanged() {
updateState(mPreference);
}
}

View File

@@ -138,6 +138,7 @@ public class MobileNetworkSettings extends RestrictedDashboardFragment {
use(CarrierSettingsVersionPreferenceController.class).init(mSubId); use(CarrierSettingsVersionPreferenceController.class).init(mSubId);
use(BillingCyclePreferenceController.class).init(mSubId); use(BillingCyclePreferenceController.class).init(mSubId);
use(MmsMessagePreferenceController.class).init(mSubId); use(MmsMessagePreferenceController.class).init(mSubId);
use(DataDuringCallsPreferenceController.class).init(getLifecycle(), mSubId);
use(DisabledSubscriptionController.class).init(getLifecycle(), mSubId); use(DisabledSubscriptionController.class).init(getLifecycle(), mSubId);
use(DeleteSimProfilePreferenceController.class).init(mSubId, this, use(DeleteSimProfilePreferenceController.class).init(mSubId, this,
REQUEST_CODE_DELETE_SUBSCRIPTION); REQUEST_CODE_DELETE_SUBSCRIPTION);

View File

@@ -4,3 +4,4 @@ com.android.settings.testutils.FakeInvalidSliderController
com.android.settings.core.TogglePreferenceControllerTest$FakeToggle com.android.settings.core.TogglePreferenceControllerTest$FakeToggle
com.android.settings.accessibility.AccessibilitySlicePreferenceController com.android.settings.accessibility.AccessibilitySlicePreferenceController
com.android.settings.network.telephony.MmsMessagePreferenceController com.android.settings.network.telephony.MmsMessagePreferenceController
com.android.settings.network.telephony.DataDuringCallsPreferenceController

View File

@@ -0,0 +1,134 @@
/*
* Copyright (C) 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.settings.network;
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.telephony.TelephonyManager;
import androidx.lifecycle.Lifecycle;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.settings.network.telephony.DataDuringCallsPreferenceController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowSubscriptionManager;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowSubscriptionManager.class)
public class DataDuringCallsPreferenceControllerTest {
private static final String PREF_KEY = "pref_key";
private static final int SUB_ID_1 = 111;
private static final int SUB_ID_2 = 222;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private Lifecycle mLifecycle;
@Mock
private PreferenceScreen mPreferenceScreen;
private Context mContext;
private SwitchPreference mSwitchPreference;
private DataDuringCallsPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mTelephonyManager).when(mContext).getSystemService(eq(TelephonyManager.class));
when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
mSwitchPreference = new SwitchPreference(mContext);
when(mPreferenceScreen.findPreference(PREF_KEY)).thenReturn(mSwitchPreference);
mController = new DataDuringCallsPreferenceController(mContext, PREF_KEY);
mController.init(mLifecycle, SUB_ID_1);
}
@Test
public void getAvailabilityStatus_noInit_notAvailable() {
ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_1);
DataDuringCallsPreferenceController controller =
new DataDuringCallsPreferenceController(mContext, PREF_KEY);
// note that we purposely don't call init first on the controller
assertThat(controller.getAvailabilityStatus(INVALID_SUBSCRIPTION_ID)).isEqualTo(
CONDITIONALLY_UNAVAILABLE);
}
@Test
public void displayPreference_defaultForData_notAvailable() {
ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_1);
mController.displayPreference(mPreferenceScreen);
assertThat(mController.isAvailable()).isFalse();
assertThat(mSwitchPreference.isVisible()).isFalse();
}
@Test
public void displayPreference_notDefaultForData_available() {
ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_2);
mController.displayPreference(mPreferenceScreen);
assertThat(mController.isAvailable()).isTrue();
assertThat(mSwitchPreference.isVisible()).isTrue();
}
@Test
public void onSubscriptionsChanged_becomesDefaultForData_notAvailable() {
ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_2);
mController.displayPreference(mPreferenceScreen);
ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_1);
mController.onSubscriptionsChanged();
assertThat(mController.isAvailable()).isFalse();
assertThat(mSwitchPreference.isVisible()).isFalse();
}
@Test
public void onSubscriptionsChanged_noLongerDefaultForData_available() {
ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_1);
mController.displayPreference(mPreferenceScreen);
ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_2);
mController.onSubscriptionsChanged();
assertThat(mController.isAvailable()).isTrue();
assertThat(mSwitchPreference.isVisible()).isTrue();
}
}