Disallow_airplane_mode should not disable mobile network.

Found mobile_network_settings preference is dependent on toggle_airplane
preference so once Disallow_airplane_mode is turned on,  toggle_airplane
preference will be set disabled, and mobile_network_settings preference
is also set disabled because of the dependence. Can fix this bug moving
the dependance and let MobileNetworkPreferenceController listen to
Settings.Global.AIRPLANE_MODE_ON.

Bug: 76468718
Test: manually but TestDpc
Change-Id: I137938766557d7bc5ae0795bc3359a6bfbae17e3
This commit is contained in:
yuemingw
2018-03-27 16:56:24 +01:00
parent d467a8bc0f
commit 6e78482016
3 changed files with 69 additions and 1 deletions

View File

@@ -29,6 +29,8 @@ import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.net.ConnectivityManager;
import android.os.UserManager;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.telephony.PhoneStateListener;
@@ -38,6 +40,8 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsWrapper;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
@@ -138,4 +142,36 @@ public class MobileNetworkPreferenceControllerTest {
// Carrier name should be set.
verify(mPreference).setSummary(testCarrierName);
}
@Test
public void airplaneModeTurnedOn_shouldDisablePreference() {
Settings.Global.putInt(mContext.getContentResolver(),
Global.AIRPLANE_MODE_ON, 1);
mController = spy(new MobileNetworkPreferenceController(mContext));
final RestrictedPreference mPreference = new RestrictedPreference(mContext);
mController.updateState(mPreference);
assertThat(mPreference.isEnabled()).isFalse();
}
@Test
public void airplaneModeTurnedOffAndNoUserRestriction_shouldEnablePreference() {
Settings.Global.putInt(mContext.getContentResolver(),
Global.AIRPLANE_MODE_ON, 0);
mController = spy(new MobileNetworkPreferenceController(mContext));
final RestrictedPreference mPreference = new RestrictedPreference(mContext);
mPreference.setDisabledByAdmin(null);
mController.updateState(mPreference);
assertThat(mPreference.isEnabled()).isTrue();
}
@Test
public void airplaneModeTurnedOffAndHasUserRestriction_shouldDisablePreference() {
Settings.Global.putInt(mContext.getContentResolver(),
Global.AIRPLANE_MODE_ON, 0);
mController = spy(new MobileNetworkPreferenceController(mContext));
final RestrictedPreference mPreference = new RestrictedPreference(mContext);
mPreference.setDisabledByAdmin(EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN);
mController.updateState(mPreference);
assertThat(mPreference.isEnabled()).isFalse();
}
}