Merge "Implement off state for SIM details page" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
62d580d5b4
@@ -24,6 +24,12 @@
|
|||||||
android:layout="@layout/styled_switch_bar"
|
android:layout="@layout/styled_switch_bar"
|
||||||
settings:controller="com.android.settings.network.telephony.MobileNetworkSwitchController"/>
|
settings:controller="com.android.settings.network.telephony.MobileNetworkSwitchController"/>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="enabled_state_container"
|
||||||
|
android:title="@string/summary_placeholder"
|
||||||
|
settings:controller="com.android.settings.network.telephony.DisabledSubscriptionController"
|
||||||
|
android:layout="@layout/preference_category_no_label">
|
||||||
|
|
||||||
<com.android.settings.datausage.DataUsageSummaryPreference
|
<com.android.settings.datausage.DataUsageSummaryPreference
|
||||||
android:key="status_header"
|
android:key="status_header"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
@@ -33,19 +39,19 @@
|
|||||||
android:key="calls_preference"
|
android:key="calls_preference"
|
||||||
android:title="@string/calls_preference"
|
android:title="@string/calls_preference"
|
||||||
settings:controller="com.android.settings.network.telephony.CallsDefaultSubscriptionController"
|
settings:controller="com.android.settings.network.telephony.CallsDefaultSubscriptionController"
|
||||||
settings:allowDividerAbove="true" />
|
settings:allowDividerAbove="true"/>
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="sms_preference"
|
android:key="sms_preference"
|
||||||
android:title="@string/sms_preference"
|
android:title="@string/sms_preference"
|
||||||
settings:controller="com.android.settings.network.telephony.SmsDefaultSubscriptionController" />
|
settings:controller="com.android.settings.network.telephony.SmsDefaultSubscriptionController"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="cdma_lte_data_service_key"
|
android:key="cdma_lte_data_service_key"
|
||||||
android:title="@string/cdma_lte_data_service"
|
android:title="@string/cdma_lte_data_service"
|
||||||
settings:controller="com.android.settings.network.telephony.DataServiceSetupPreferenceController"
|
settings:controller="com.android.settings.network.telephony.DataServiceSetupPreferenceController"
|
||||||
settings:allowDividerAbove="true"
|
settings:allowDividerAbove="true"
|
||||||
settings:allowDividerBelow="false" />
|
settings:allowDividerBelow="false"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="mobile_data_enable"
|
android:key="mobile_data_enable"
|
||||||
@@ -71,13 +77,13 @@
|
|||||||
<com.android.settings.datausage.BillingCyclePreference
|
<com.android.settings.datausage.BillingCyclePreference
|
||||||
android:key="billing_preference"
|
android:key="billing_preference"
|
||||||
android:title="@string/billing_cycle"
|
android:title="@string/billing_cycle"
|
||||||
settings:controller="com.android.settings.datausage.BillingCyclePreferenceController" />
|
settings:controller="com.android.settings.datausage.BillingCyclePreferenceController"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="mms_message"
|
android:key="mms_message"
|
||||||
android:title="@string/mms_message_title"
|
android:title="@string/mms_message_title"
|
||||||
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
|
<SwitchPreference
|
||||||
android:key="enhanced_4g_lte"
|
android:key="enhanced_4g_lte"
|
||||||
@@ -108,7 +114,7 @@
|
|||||||
android:key="carrier_settings_version_key"
|
android:key="carrier_settings_version_key"
|
||||||
android:title="@string/carrier_settings_version"
|
android:title="@string/carrier_settings_version"
|
||||||
settings:controller="com.android.settings.network.telephony.CarrierSettingsVersionPreferenceController"
|
settings:controller="com.android.settings.network.telephony.CarrierSettingsVersionPreferenceController"
|
||||||
settings:enableCopying="true" />
|
settings:enableCopying="true"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="calling_category"
|
android:key="calling_category"
|
||||||
@@ -117,11 +123,11 @@
|
|||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
android:key="wifi_calling_key"
|
android:key="wifi_calling_key"
|
||||||
android:title="@string/wifi_calling_settings_title"
|
android:title="@string/wifi_calling_settings_title"
|
||||||
settings:controller="com.android.settings.network.telephony.WifiCallingPreferenceController" >
|
settings:controller="com.android.settings.network.telephony.WifiCallingPreferenceController">
|
||||||
<intent android:action="android.intent.action.MAIN"
|
<intent android:action="android.intent.action.MAIN"
|
||||||
android:targetPackage="com.android.settings"
|
android:targetPackage="com.android.settings"
|
||||||
android:targetClass="com.android.settings.Settings$WifiCallingSettingsActivity">
|
android:targetClass="com.android.settings.Settings$WifiCallingSettingsActivity">
|
||||||
<extra android:name="show_drawer_menu" android:value="true" />
|
<extra android:name="show_drawer_menu" android:value="true"/>
|
||||||
</intent>
|
</intent>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
@@ -129,7 +135,7 @@
|
|||||||
android:key="video_calling_key"
|
android:key="video_calling_key"
|
||||||
android:title="@string/video_calling_settings_title"
|
android:title="@string/video_calling_settings_title"
|
||||||
android:persistent="true"
|
android:persistent="true"
|
||||||
settings:controller="com.android.settings.network.telephony.VideoCallingPreferenceController" />
|
settings:controller="com.android.settings.network.telephony.VideoCallingPreferenceController"/>
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
@@ -182,4 +188,6 @@
|
|||||||
settings:controller="com.android.settings.network.telephony.CarrierPreferenceController">
|
settings:controller="com.android.settings.network.telephony.CarrierPreferenceController">
|
||||||
</Preference>
|
</Preference>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* 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 androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.network.SubscriptionsChangeListener;
|
||||||
|
|
||||||
|
public class DisabledSubscriptionController extends BasePreferenceController implements
|
||||||
|
SubscriptionsChangeListener.SubscriptionsChangeListenerClient, LifecycleObserver {
|
||||||
|
private PreferenceCategory mCategory;
|
||||||
|
private int mSubId;
|
||||||
|
private SubscriptionsChangeListener mChangeListener;
|
||||||
|
private SubscriptionManager mSubscriptionManager;
|
||||||
|
|
||||||
|
public DisabledSubscriptionController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
mSubscriptionManager = mContext.getSystemService(SubscriptionManager.class);
|
||||||
|
mChangeListener = new SubscriptionsChangeListener(context, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(Lifecycle lifecycle, int subId) {
|
||||||
|
lifecycle.addObserver(this);
|
||||||
|
mSubId = subId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent(ON_RESUME)
|
||||||
|
public void onResume() {
|
||||||
|
mChangeListener.start();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent(ON_PAUSE)
|
||||||
|
public void onPause() {
|
||||||
|
mChangeListener.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mCategory = screen.findPreference(getPreferenceKey());
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void update() {
|
||||||
|
if (mCategory == null || mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mCategory.setVisible(mSubscriptionManager.isSubscriptionEnabled(mSubId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE_UNSEARCHABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAirplaneModeChanged(boolean airplaneModeEnabled) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSubscriptionsChanged() {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
@@ -137,6 +137,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(DisabledSubscriptionController.class).init(getLifecycle(), mSubId);
|
||||||
}
|
}
|
||||||
use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
|
use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
|
||||||
use(RoamingPreferenceController.class).init(getFragmentManager(), mSubId);
|
use(RoamingPreferenceController.class).init(getFragmentManager(), mSubId);
|
||||||
|
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.telephony.SubscriptionManager;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class DisabledSubscriptionControllerTest {
|
||||||
|
|
||||||
|
private static final String KEY = "disabled_subscription_category";
|
||||||
|
private static final int SUB_ID = 111;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private SubscriptionManager mSubscriptionManager;
|
||||||
|
@Mock
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
|
private PreferenceCategory mCategory;
|
||||||
|
private Context mContext;
|
||||||
|
private Lifecycle mLifecycle;
|
||||||
|
private DisabledSubscriptionController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
LifecycleOwner lifecycleOwner = () -> mLifecycle;
|
||||||
|
mLifecycle = new Lifecycle(lifecycleOwner);
|
||||||
|
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
|
||||||
|
mCategory = new PreferenceCategory(mContext);
|
||||||
|
doReturn(mCategory).when(mScreen).findPreference(KEY);
|
||||||
|
mController = new DisabledSubscriptionController(mContext, KEY);
|
||||||
|
mController.init(mLifecycle, SUB_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPreference_subscriptionEnabled_categoryIsVisible() {
|
||||||
|
doReturn(true).when(mSubscriptionManager).isSubscriptionEnabled(SUB_ID);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
assertThat(mCategory.isVisible()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPreference_subscriptionDisabled_categoryIsNotVisible() {
|
||||||
|
doReturn(false).when(mSubscriptionManager).isSubscriptionEnabled(SUB_ID);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
assertThat(mCategory.isVisible()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSubscriptionsChanged_subscriptionBecomesDisabled_categoryIsNotVisible() {
|
||||||
|
doReturn(true).when(mSubscriptionManager).isSubscriptionEnabled(SUB_ID);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
doReturn(false).when(mSubscriptionManager).isSubscriptionEnabled(SUB_ID);
|
||||||
|
mController.onSubscriptionsChanged();
|
||||||
|
assertThat(mCategory.isVisible()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSubscriptionsChanged_subscriptionBecomesEnabled_categoryIsVisible() {
|
||||||
|
doReturn(false).when(mSubscriptionManager).isSubscriptionEnabled(SUB_ID);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
doReturn(true).when(mSubscriptionManager).isSubscriptionEnabled(SUB_ID);
|
||||||
|
mController.onSubscriptionsChanged();
|
||||||
|
assertThat(mCategory.isVisible()).isTrue();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user