Show reboot dialog when tunring off developer option

The toggle button "Disable Bluetooth A2DP hardware offload" in developer
options need reboot to take effect when value changed. Otherwise, the
A2DP will not work until user reboot the device.

If we want this toggle button change back to default value when turning
off developer options, we need reboot device as well.

This patch will check the property value of A2DP hardware offload. If
turning off developer options will change the value, show a dialog to
force the user to reboot device.

Bug: 80449594
Test: make -j50 RunSettingsRoboTests

Change-Id: Ibace1ff72c1b41bd55444242a74e3f0b49187668
This commit is contained in:
Chienyuan
2018-11-07 16:55:24 +08:00
parent 4c3251ebab
commit eda2987b86
4 changed files with 169 additions and 2 deletions

View File

@@ -28,10 +28,15 @@ import android.content.Context;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.ToggleSwitch;
@@ -47,12 +52,14 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadows.androidx.fragment.FragmentController;
import org.robolectric.util.ReflectionHelpers;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = ShadowUserManager.class)
@Config(shadows = {ShadowUserManager.class, ShadowAlertDialogCompat.class,
SettingsShadowResourcesImpl.class})
public class DevelopmentSettingsDashboardFragmentTest {
private ToggleSwitch mSwitch;
@@ -178,6 +185,29 @@ public class DevelopmentSettingsDashboardFragmentTest {
assertThat(DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)).isFalse();
}
@Test
@Config(shadows = ShadowDisableDevSettingsDialogFragment.class)
public void onSwitchChanged_turnOff_andOffloadIsNotDefaultValue_shouldShowWarningDialog() {
final BluetoothA2dpHwOffloadPreferenceController controller =
mock(BluetoothA2dpHwOffloadPreferenceController.class);
when(mDashboard.getContext()).thenReturn(mContext);
when(mDashboard.getDevelopmentOptionsController(
BluetoothA2dpHwOffloadPreferenceController.class)).thenReturn(controller);
when(controller.isDefaultValue()).thenReturn(false);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
mDashboard.onSwitchChanged(mSwitch, false /* isChecked */);
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
assertThat(dialog).isNotNull();
ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
assertThat(shadowDialog.getTitle()).isEqualTo(
mContext.getString(R.string.bluetooth_disable_a2dp_hw_offload_dialog_title));
assertThat(shadowDialog.getMessage()).isEqualTo(
mContext.getString(R.string.bluetooth_disable_a2dp_hw_offload_dialog_message));
}
@Test
public void onOemUnlockDialogConfirmed_shouldCallControllerOemConfirmed() {
final OemUnlockPreferenceController controller = mock(OemUnlockPreferenceController.class);
@@ -264,6 +294,18 @@ public class DevelopmentSettingsDashboardFragmentTest {
}
}
@Implements(DisableDevSettingsDialogFragment.class)
public static class ShadowDisableDevSettingsDialogFragment {
@Implementation
public static void show(DevelopmentSettingsDashboardFragment host) {
DisableDevSettingsDialogFragment mFragment =
spy(DisableDevSettingsDialogFragment.newInstance());
FragmentController.setupFragment(mFragment, FragmentActivity.class,
0 /* containerViewId */, null /* bundle */);
}
}
@Implements(PictureColorModePreferenceController.class)
public static class ShadowPictureColorModePreferenceController {
@Implementation