diff options
author | jeffreyhuang <jeffreyhuang@google.com> | 2017-10-09 16:22:40 -0700 |
---|---|---|
committer | jeffreyhuang <jeffreyhuang@google.com> | 2017-10-10 16:05:32 -0700 |
commit | 60ab063ea324e5126044482832fdc556a4c23a3d (patch) | |
tree | c2f0a4dceb56f1722d19b5db260ff7461c3ec984 | |
parent | cafce68bc2c16f6ab68735ba6df58b5a7de000e8 (diff) | |
download | packages_apps_Settings-60ab063ea324e5126044482832fdc556a4c23a3d.tar.gz packages_apps_Settings-60ab063ea324e5126044482832fdc556a4c23a3d.tar.bz2 packages_apps_Settings-60ab063ea324e5126044482832fdc556a4c23a3d.zip |
Introduce LogPersistPreferenceControllerV2
- Create new LogPersistPreferenceControllerV2
- Deprecate LogPersistPreferenceController
- Add DisableLogPersistWarningDialog
- Create controller inside the DashboardFragment
- Port logic from DevelopmentSettings into the controller
Bug: 34203528
Test: make RunSettingsRoboTests -j40
Change-Id: I8ff49ec4ece15cad2d0c60bd21488e3f5d55ee98
8 files changed, 333 insertions, 2 deletions
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java index 39e3d03eb7..41c177b2d5 100644 --- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java @@ -52,7 +52,7 @@ import java.util.List; public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFragment implements SwitchBar.OnSwitchChangeListener, OemUnlockDialogHost, AdbDialogHost, - AdbClearKeysDialogHost { + AdbClearKeysDialogHost, LogPersistDialogHost { private static final String TAG = "DevSettingsDashboard"; @@ -180,6 +180,20 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra } @Override + public void onDisableLogPersistDialogConfirmed() { + final LogPersistPreferenceControllerV2 controller = getDevelopmentOptionsController( + LogPersistPreferenceControllerV2.class); + controller.onDisableLogPersistDialogConfirmed(); + } + + @Override + public void onDisableLogPersistDialogRejected() { + final LogPersistPreferenceControllerV2 controller = getDevelopmentOptionsController( + LogPersistPreferenceControllerV2.class); + controller.onDisableLogPersistDialogRejected(); + } + + @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { boolean handledResult = false; for (AbstractPreferenceController controller : mPreferenceControllers) { @@ -270,7 +284,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new WaitForDebuggerPreferenceController(context)); controllers.add(new VerifyAppsOverUsbPreferenceControllerV2(context)); controllers.add(new LogdSizePreferenceControllerV2(context)); - // store logger data persistently on device + controllers.add(new LogPersistPreferenceControllerV2(context, fragment, lifecycle)); controllers.add(new ConnectivityMonitorPreferenceControllerV2(context)); controllers.add(new CameraLaserSensorPreferenceControllerV2(context)); controllers.add(new CameraHalHdrPlusPreferenceControllerV2(context)); diff --git a/src/com/android/settings/development/DisableLogPersistWarningDialog.java b/src/com/android/settings/development/DisableLogPersistWarningDialog.java new file mode 100644 index 0000000000..1ab3a92a69 --- /dev/null +++ b/src/com/android/settings/development/DisableLogPersistWarningDialog.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2017 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.development; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.Fragment; +import android.app.FragmentManager; +import android.content.DialogInterface; +import android.os.Bundle; + +import com.android.internal.logging.nano.MetricsProto; +import com.android.settings.R; +import com.android.settings.core.instrumentation.InstrumentedDialogFragment; + +public class DisableLogPersistWarningDialog extends InstrumentedDialogFragment implements + DialogInterface.OnClickListener, DialogInterface.OnDismissListener { + + public static final String TAG = "DisableLogPersistDlg"; + + public static void show(LogPersistDialogHost host) { + if (!(host instanceof Fragment)) { + return; + } + final Fragment hostFragment = (Fragment) host; + final FragmentManager manager = hostFragment.getActivity().getFragmentManager(); + if (manager.findFragmentByTag(TAG) == null) { + final DisableLogPersistWarningDialog dialog = + new DisableLogPersistWarningDialog(); + dialog.setTargetFragment(hostFragment, 0 /* requestCode */); + dialog.show(manager, TAG); + } + } + + @Override + public int getMetricsCategory() { + return MetricsProto.MetricsEvent.DIALOG_LOG_PERSIST; + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + return new AlertDialog.Builder(getActivity()) + .setTitle(R.string.dev_logpersist_clear_warning_title) + .setMessage(R.string.dev_logpersist_clear_warning_message) + .setPositiveButton(android.R.string.yes, this /* onClickListener */) + .setNegativeButton(android.R.string.no, this /* onClickListener */) + .create(); + } + + @Override + public void onClick(DialogInterface dialog, int which) { + final LogPersistDialogHost host = (LogPersistDialogHost) getTargetFragment(); + if (host == null) { + return; + } + if (which == DialogInterface.BUTTON_POSITIVE) { + host.onDisableLogPersistDialogConfirmed(); + } else { + host.onDisableLogPersistDialogRejected(); + } + } +} diff --git a/src/com/android/settings/development/LogPersistDialogHost.java b/src/com/android/settings/development/LogPersistDialogHost.java new file mode 100644 index 0000000000..0187e0370a --- /dev/null +++ b/src/com/android/settings/development/LogPersistDialogHost.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2017 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.development; + +/** + * Interface for LogPersistDialogFragment callbacks. + */ +public interface LogPersistDialogHost { + + /** + * Called when the user presses yes on the warning dialog. + */ + void onDisableLogPersistDialogConfirmed(); + + /** + * Called when the user presses no on the warning dialog. + */ + void onDisableLogPersistDialogRejected(); +} diff --git a/src/com/android/settings/development/LogPersistPreferenceControllerV2.java b/src/com/android/settings/development/LogPersistPreferenceControllerV2.java new file mode 100644 index 0000000000..537b71bbc5 --- /dev/null +++ b/src/com/android/settings/development/LogPersistPreferenceControllerV2.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2017 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.development; + +import android.content.Context; +import android.support.annotation.Nullable; +import android.support.v7.preference.ListPreference; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceScreen; + +import com.android.settings.core.PreferenceControllerMixin; +import com.android.settingslib.core.lifecycle.Lifecycle; +import com.android.settingslib.development.AbstractLogpersistPreferenceController; + +public class LogPersistPreferenceControllerV2 extends + AbstractLogpersistPreferenceController implements PreferenceControllerMixin { + + private final DevelopmentSettingsDashboardFragment mFragment; + private ListPreference mPreference; + + + public LogPersistPreferenceControllerV2(Context context, + DevelopmentSettingsDashboardFragment fragment, Lifecycle lifecycle) { + super(context, lifecycle); + + mFragment = fragment; + } + + @Override + public void showConfirmationDialog(@Nullable Preference preference) { + DisableLogPersistWarningDialog.show(mFragment); + } + + @Override + public void dismissConfirmationDialog() { + // intentional no-op + } + + @Override + public boolean isConfirmationDialogShowing() { + return false; + } + + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + + mPreference = (ListPreference) screen.findPreference(getPreferenceKey()); + } + + @Override + public void updateState(Preference preference) { + updateLogpersistValues(); + } + + @Override + protected void onDeveloperOptionsSwitchEnabled() { + mPreference.setEnabled(true); + } + + @Override + protected void onDeveloperOptionsSwitchDisabled() { + writeLogpersistOption(null /* new value */, true); + mPreference.setEnabled(false); + } + + public void onDisableLogPersistDialogConfirmed() { + setLogpersistOff(true); + updateLogpersistValues(); + } + + public void onDisableLogPersistDialogRejected() { + updateLogpersistValues(); + } +} diff --git a/src/com/android/settings/development/LogpersistPreferenceController.java b/src/com/android/settings/development/LogpersistPreferenceController.java index a1ca186cca..26ab878452 100644 --- a/src/com/android/settings/development/LogpersistPreferenceController.java +++ b/src/com/android/settings/development/LogpersistPreferenceController.java @@ -27,6 +27,10 @@ import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.development.AbstractLogpersistPreferenceController; +/** + * depreacted in favor of {@link LogdSizePreferenceControllerV2} + */ +@Deprecated public class LogpersistPreferenceController extends AbstractLogpersistPreferenceController implements PreferenceControllerMixin { diff --git a/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java index ec51868817..ac09418a2f 100644 --- a/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java @@ -17,6 +17,7 @@ package com.android.settings.development; import static com.google.common.truth.Truth.assertThat; + import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -220,6 +221,28 @@ public class DevelopmentSettingsDashboardFragmentTest { verify(controller).onClearAdbKeysConfirmed(); } + @Test + public void onDisableLogPersistDialogConfirmed_shouldCallControllerDialogConfirmed() { + final LogPersistPreferenceControllerV2 controller = mock( + LogPersistPreferenceControllerV2.class); + doReturn(controller).when(mDashboard).getDevelopmentOptionsController( + LogPersistPreferenceControllerV2.class); + mDashboard.onDisableLogPersistDialogConfirmed(); + + verify(controller).onDisableLogPersistDialogConfirmed(); + } + + @Test + public void onDisableLogPersistDialogRejected_shouldCallControllerDialogRejected() { + final LogPersistPreferenceControllerV2 controller = mock( + LogPersistPreferenceControllerV2.class); + doReturn(controller).when(mDashboard).getDevelopmentOptionsController( + LogPersistPreferenceControllerV2.class); + mDashboard.onDisableLogPersistDialogRejected(); + + verify(controller).onDisableLogPersistDialogRejected(); + } + @Implements(EnableDevelopmentSettingWarningDialog.class) public static class ShadowEnableDevelopmentSettingWarningDialog { diff --git a/tests/robotests/src/com/android/settings/development/LogPersistPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/development/LogPersistPreferenceControllerV2Test.java new file mode 100644 index 0000000000..3a7604aa78 --- /dev/null +++ b/tests/robotests/src/com/android/settings/development/LogPersistPreferenceControllerV2Test.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2017 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.development; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.os.SystemProperties; +import android.support.v4.content.LocalBroadcastManager; +import android.support.v7.preference.ListPreference; +import android.support.v7.preference.PreferenceScreen; + +import com.android.settings.TestConfig; +import com.android.settings.testutils.SettingsRobolectricTestRunner; +import com.android.settings.testutils.shadow.SettingsShadowSystemProperties; +import com.android.settingslib.R; +import com.android.settingslib.core.lifecycle.Lifecycle; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; +import org.robolectric.util.ReflectionHelpers; + +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, + sdk = TestConfig.SDK_VERSION, + shadows = {SettingsShadowSystemProperties.class}) +public class LogPersistPreferenceControllerV2Test { + + @Mock + private ListPreference mPreference; + @Mock + private PreferenceScreen mScreen; + @Mock + private DevelopmentSettingsDashboardFragment mFragment; + + private Context mContext; + private LogPersistPreferenceControllerV2 mController; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + mContext = RuntimeEnvironment.application; + mController = new LogPersistPreferenceControllerV2(mContext, mFragment, new Lifecycle()); + when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); + SystemProperties.set("ro.debuggable", "1"); + mController.displayPreference(mScreen); + } + + @After + public void teardown() { + SettingsShadowSystemProperties.clear(); + } + + @Test + public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() { + mController.onDeveloperOptionsSwitchDisabled(); + + verify(mPreference).setEnabled(false); + } + + @Test + public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() { + mController.onDeveloperOptionsSwitchEnabled(); + + verify(mPreference).setEnabled(true); + } +} diff --git a/tests/robotests/src/com/android/settings/development/LogpersistPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/LogpersistPreferenceControllerTest.java index 450f29da69..379890e634 100644 --- a/tests/robotests/src/com/android/settings/development/LogpersistPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/LogpersistPreferenceControllerTest.java @@ -32,6 +32,10 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; +/** + * deprecated in favor of {@link LogPersistPreferenceControllerV2} + */ +@Deprecated @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) public class LogpersistPreferenceControllerTest { |