Merge "Introduce LogdSizePreferenceControllerV2"
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index 5bd0f32..39e3d03 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -269,7 +269,7 @@
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 b12884c..8ee3405 100644
--- a/src/com/android/settings/development/LogdSizePreferenceController.java
+++ b/src/com/android/settings/development/LogdSizePreferenceController.java
@@ -21,6 +21,10 @@
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 0000000..8194c48
--- /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 0000000..71766c3
--- /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);
+ }
+}