From cafce68bc2c16f6ab68735ba6df58b5a7de000e8 Mon Sep 17 00:00:00 2001 From: jeffreyhuang Date: Wed, 4 Oct 2017 15:36:38 -0700 Subject: [PATCH] Introduce LogdSizePreferenceControllerV2 - Create new LogdSizePreferenceControllerV2 - Deprecate LogdSizePreferenceController - Create controller inside the DashboardFragment - Port logic from DevelopmentSettings into the controller Bug: 34203528 Test: make RunSettingsRoboTests -j40 Change-Id: I4bc03ee8481d01e553b8a4df9f9ec03b53d4eee4 --- .../DevelopmentSettingsDashboardFragment.java | 2 +- .../LogdSizePreferenceController.java | 4 + .../LogdSizePreferenceControllerV2.java | 58 +++++++++++ .../LogdSizePreferenceControllerV2Test.java | 97 +++++++++++++++++++ 4 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 src/com/android/settings/development/LogdSizePreferenceControllerV2.java create mode 100644 tests/robotests/src/com/android/settings/development/LogdSizePreferenceControllerV2Test.java diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java index 5bd0f32a0b4..39e3d03eb75 100644 --- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java @@ -269,7 +269,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new SelectDebugAppPreferenceController(context, fragment)); controllers.add(new WaitForDebuggerPreferenceController(context)); controllers.add(new VerifyAppsOverUsbPreferenceControllerV2(context)); - // logger buffer sizes + controllers.add(new LogdSizePreferenceControllerV2(context)); // store logger data persistently on device controllers.add(new ConnectivityMonitorPreferenceControllerV2(context)); controllers.add(new CameraLaserSensorPreferenceControllerV2(context)); diff --git a/src/com/android/settings/development/LogdSizePreferenceController.java b/src/com/android/settings/development/LogdSizePreferenceController.java index b12884ce5d8..8ee3405f03b 100644 --- a/src/com/android/settings/development/LogdSizePreferenceController.java +++ b/src/com/android/settings/development/LogdSizePreferenceController.java @@ -21,6 +21,10 @@ import android.content.Context; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.development.AbstractLogdSizePreferenceController; +/** + * deprecated in favor of {@link LogdSizePreferenceControllerV2} + */ +@Deprecated public class LogdSizePreferenceController extends AbstractLogdSizePreferenceController implements PreferenceControllerMixin { diff --git a/src/com/android/settings/development/LogdSizePreferenceControllerV2.java b/src/com/android/settings/development/LogdSizePreferenceControllerV2.java new file mode 100644 index 00000000000..8194c485439 --- /dev/null +++ b/src/com/android/settings/development/LogdSizePreferenceControllerV2.java @@ -0,0 +1,58 @@ +/* + * 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.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.development.AbstractLogdSizePreferenceController; + +public class LogdSizePreferenceControllerV2 extends AbstractLogdSizePreferenceController implements + Preference.OnPreferenceChangeListener, PreferenceControllerMixin { + + private ListPreference mPreference; + + public LogdSizePreferenceControllerV2(Context context) { + super(context); + } + + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + + mPreference = (ListPreference) screen.findPreference(getPreferenceKey()); + } + + @Override + public void updateState(Preference preference) { + updateLogdSizeValues(); + } + + @Override + protected void onDeveloperOptionsSwitchEnabled() { + mPreference.setEnabled(true); + } + + @Override + protected void onDeveloperOptionsSwitchDisabled() { + writeLogdSizeOption(null /* new value */); + mPreference.setEnabled(false); + } +} diff --git a/tests/robotests/src/com/android/settings/development/LogdSizePreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/development/LogdSizePreferenceControllerV2Test.java new file mode 100644 index 00000000000..71766c378e8 --- /dev/null +++ b/tests/robotests/src/com/android/settings/development/LogdSizePreferenceControllerV2Test.java @@ -0,0 +1,97 @@ +/* + * 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.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 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; + +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, + sdk = TestConfig.SDK_VERSION, + shadows = {SettingsShadowSystemProperties.class}) +public class LogdSizePreferenceControllerV2Test { + + @Mock + private PreferenceScreen mScreen; + @Mock + private ListPreference mPreference; + + /** + * List Values + * + * 0: off + * 1: 64k + * 2: 256k + * 3: 1M + * 4: 4M + * 5: 16M + */ + private String[] mListValues; + private String[] mListSummaries; + private Context mContext; + private LogdSizePreferenceControllerV2 mController; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + mContext = RuntimeEnvironment.application; + mListValues = mContext.getResources().getStringArray(R.array.select_logd_size_values); + mListSummaries = mContext.getResources().getStringArray(R.array.select_logd_size_summaries); + mController = new LogdSizePreferenceControllerV2(mContext); + when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); + mController.displayPreference(mScreen); + } + + @After + public void teardown() { + SettingsShadowSystemProperties.clear(); + } + + @Test + public void onDeveloperOptionsSwitchDisabled_shouldDisableAndResetPreferenceToDefault() { + mController.onDeveloperOptionsSwitchDisabled(); + + verify(mPreference).setValue(mListValues[2]); + verify(mPreference).setSummary(mListSummaries[2]); + verify(mPreference).setEnabled(false); + } + + @Test + public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() { + mController.onDeveloperOptionsSwitchEnabled(); + + verify(mPreference).setEnabled(true); + } +}