Merge changes from topics 'SystemPropPoker', 'DevSettingsPrefsFile'

* changes:
  Refactor SystemPropPoker
  Remove development settings prefs file
This commit is contained in:
Tony Mantler
2017-08-01 16:12:14 +00:00
committed by Android (Google) Code Review
9 changed files with 70 additions and 293 deletions

View File

@@ -1,105 +0,0 @@
/*
* 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 com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
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)
public class DevelopmentSettingsEnablerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private SharedPreferences mDevelopmentPreferences;
private Context mContext;
private DevelopmentSettingsEnabler mEnabler;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mEnabler = new DevelopmentSettingsEnabler(mContext, null);
ReflectionHelpers.setField(mEnabler, "mDevelopmentPreferences", mDevelopmentPreferences);
}
@Test
public void constructor_shouldInitEnabledState() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
mEnabler = new DevelopmentSettingsEnabler(mContext, null);
assertThat(mEnabler.getLastEnabledState()).isTrue();
}
@Test
public void onResume_shouldReadStateFromSettingProvider() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
mEnabler.onResume();
assertThat(mEnabler.getLastEnabledState()).isTrue();
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
mEnabler.onResume();
assertThat(mEnabler.getLastEnabledState()).isFalse();
}
@Test
public void disable_shouldChangeSettingProviderValue() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
mEnabler.disableDevelopmentSettings();
assertThat(mEnabler.getLastEnabledState()).isFalse();
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1)).isEqualTo(0);
}
@Test
public void enable_shouldChangeSettingProviderValue() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
mEnabler.enableDevelopmentSettings();
assertThat(mEnabler.getLastEnabledState()).isTrue();
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0)).isEqualTo(1);
}
}

View File

@@ -28,6 +28,7 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import com.android.settingslib.drawer.CategoryKey;
import org.junit.Before;
@@ -113,8 +114,7 @@ public class DevelopmentSettingsTest {
@Test
public void searchIndex_pageDisabled_shouldAddAllKeysToNonIndexable() {
final Context appContext = RuntimeEnvironment.application;
new DevelopmentSettingsEnabler(appContext, null /* lifecycle */)
.disableDevelopmentSettings();
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(appContext, false);
final List<String> nonIndexableKeys =
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(appContext);
@@ -125,8 +125,7 @@ public class DevelopmentSettingsTest {
@Test
public void searchIndex_pageEnabled_shouldNotAddKeysToNonIndexable() {
final Context appContext = RuntimeEnvironment.application;
new DevelopmentSettingsEnabler(appContext, null /* lifecycle */)
.enableDevelopmentSettings();
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(appContext, true);
final List<String> nonIndexableKeys =
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(appContext);

View File

@@ -17,6 +17,7 @@
package com.android.settings.deviceinfo;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
@@ -38,12 +39,12 @@ import android.text.BidiFormatter;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.TestConfig;
import com.android.settings.development.DevelopmentSettings;
import com.android.settings.search.DatabaseIndexingManager;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import org.junit.After;
import org.junit.Before;
@@ -176,8 +177,8 @@ public class BuildNumberPreferenceControllerTest {
null);
assertThat(activityResultHandled).isFalse();
verify(mContext, never())
.getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE);
assertThat(DevelopmentSettingsEnabler
.isDevelopmentSettingsEnabled(RuntimeEnvironment.application)).isFalse();
}
@Test
@@ -188,8 +189,8 @@ public class BuildNumberPreferenceControllerTest {
null);
assertThat(activityResultHandled).isTrue();
verify(mContext, never())
.getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE);
assertThat(DevelopmentSettingsEnabler
.isDevelopmentSettingsEnabled(RuntimeEnvironment.application)).isFalse();
}
@Test
@@ -208,9 +209,8 @@ public class BuildNumberPreferenceControllerTest {
null);
assertThat(activityResultHandled).isTrue();
assertThat(context.getSharedPreferences(DevelopmentSettings.PREF_FILE,
Context.MODE_PRIVATE).getBoolean(DevelopmentSettings.PREF_SHOW, false))
.isTrue();
assertThat(DevelopmentSettingsEnabler
.isDevelopmentSettingsEnabled(RuntimeEnvironment.application)).isTrue();
}
}