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
This commit is contained in:
@@ -269,7 +269,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
|||||||
controllers.add(new SelectDebugAppPreferenceController(context, fragment));
|
controllers.add(new SelectDebugAppPreferenceController(context, fragment));
|
||||||
controllers.add(new WaitForDebuggerPreferenceController(context));
|
controllers.add(new WaitForDebuggerPreferenceController(context));
|
||||||
controllers.add(new VerifyAppsOverUsbPreferenceControllerV2(context));
|
controllers.add(new VerifyAppsOverUsbPreferenceControllerV2(context));
|
||||||
// logger buffer sizes
|
controllers.add(new LogdSizePreferenceControllerV2(context));
|
||||||
// store logger data persistently on device
|
// store logger data persistently on device
|
||||||
controllers.add(new ConnectivityMonitorPreferenceControllerV2(context));
|
controllers.add(new ConnectivityMonitorPreferenceControllerV2(context));
|
||||||
controllers.add(new CameraLaserSensorPreferenceControllerV2(context));
|
controllers.add(new CameraLaserSensorPreferenceControllerV2(context));
|
||||||
|
@@ -21,6 +21,10 @@ import android.content.Context;
|
|||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settingslib.development.AbstractLogdSizePreferenceController;
|
import com.android.settingslib.development.AbstractLogdSizePreferenceController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deprecated in favor of {@link LogdSizePreferenceControllerV2}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public class LogdSizePreferenceController extends AbstractLogdSizePreferenceController
|
public class LogdSizePreferenceController extends AbstractLogdSizePreferenceController
|
||||||
implements PreferenceControllerMixin {
|
implements PreferenceControllerMixin {
|
||||||
|
|
||||||
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user