Snap for 4399706 from ffa3095aca to pi-release
Change-Id: I66c00aabfb811d8293ea737ca1e59b817ad92292
This commit is contained in:
25
res/xml/security_settings_advanced_button.xml
Normal file
25
res/xml/security_settings_advanced_button.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||
android:key="security_dashboard_page"
|
||||
android:title="@string/security_settings_title"
|
||||
settings:initialExpandedChildrenCount="9">
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -59,6 +59,7 @@ import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.TrustAgentUtils.TrustAgentComponentInfo;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.dashboard.ProgressiveDisclosureMixin;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyPreferenceController;
|
||||
import com.android.settings.enterprise.ManageDeviceAdminPreferenceController;
|
||||
@@ -275,7 +276,11 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
if (root != null) {
|
||||
root.removeAll();
|
||||
}
|
||||
addPreferencesFromResource(R.xml.security_settings);
|
||||
if (ProgressiveDisclosureMixin.isV2Enabled()) {
|
||||
addPreferencesFromResource(R.xml.security_settings);
|
||||
} else {
|
||||
addPreferencesFromResource(R.xml.security_settings_advanced_button);
|
||||
}
|
||||
root = getPreferenceScreen();
|
||||
|
||||
// Add category for security status
|
||||
|
||||
@@ -133,10 +133,10 @@ public class DefaultAppSettings extends DashboardFragment {
|
||||
return;
|
||||
}
|
||||
CharSequence summary = concatSummaryText(
|
||||
mDefaultSmsPreferenceController.getDefaultAppLabel(),
|
||||
mDefaultBrowserPreferenceController.getDefaultAppLabel());
|
||||
summary = concatSummaryText(summary,
|
||||
mDefaultBrowserPreferenceController.getDefaultAppLabel(),
|
||||
mDefaultPhonePreferenceController.getDefaultAppLabel());
|
||||
summary = concatSummaryText(summary,
|
||||
mDefaultSmsPreferenceController.getDefaultAppLabel());
|
||||
if (!TextUtils.isEmpty(summary)) {
|
||||
mSummaryLoader.setSummary(this, summary);
|
||||
}
|
||||
|
||||
@@ -106,7 +106,11 @@ public class ProgressiveDisclosureMixin implements Preference.OnPreferenceClickL
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return !FeatureFlagUtils.isEnabled(FEATURE_FLAG_NEW_ADVANCE_BUTTON);
|
||||
return !isV2Enabled();
|
||||
}
|
||||
|
||||
public static boolean isV2Enabled() {
|
||||
return FeatureFlagUtils.isEnabled(FEATURE_FLAG_NEW_ADVANCE_BUTTON);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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.ActivityManager;
|
||||
import android.app.IActivityManager;
|
||||
import android.content.Context;
|
||||
import android.os.RemoteException;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
||||
|
||||
public class BackgroundProcessLimitPreferenceController extends
|
||||
DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
|
||||
PreferenceControllerMixin {
|
||||
|
||||
private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit";
|
||||
|
||||
private final String[] mListValues;
|
||||
private final String[] mListSummaries;
|
||||
private ListPreference mPreference;
|
||||
|
||||
public BackgroundProcessLimitPreferenceController(Context context) {
|
||||
super(context);
|
||||
|
||||
mListValues = context.getResources().getStringArray(R.array.app_process_limit_values);
|
||||
mListSummaries = context.getResources().getStringArray(R.array.app_process_limit_entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return APP_PROCESS_LIMIT_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
mPreference = (ListPreference) screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
writeAppProcessLimitOptions(newValue);
|
||||
updateAppProcessLimitOptions();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
updateAppProcessLimitOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchEnabled() {
|
||||
mPreference.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchDisabled() {
|
||||
writeAppProcessLimitOptions(null);
|
||||
mPreference.setEnabled(false);
|
||||
}
|
||||
|
||||
private void updateAppProcessLimitOptions() {
|
||||
try {
|
||||
final int limit = getActivityManagerService().getProcessLimit();
|
||||
int index = 0; // default
|
||||
for (int i = 0; i < mListValues.length; i++) {
|
||||
int val = Integer.parseInt(mListValues[i]);
|
||||
if (val >= limit) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mPreference.setValue(mListValues[index]);
|
||||
mPreference.setSummary(mListSummaries[index]);
|
||||
} catch (RemoteException e) {
|
||||
// intentional no-op
|
||||
}
|
||||
}
|
||||
|
||||
private void writeAppProcessLimitOptions(Object newValue) {
|
||||
try {
|
||||
final int limit = newValue != null ? Integer.parseInt(newValue.toString()) : -1;
|
||||
getActivityManagerService().setProcessLimit(limit);
|
||||
updateAppProcessLimitOptions();
|
||||
} catch (RemoteException e) {
|
||||
// intentional no-op
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
IActivityManager getActivityManagerService() {
|
||||
return ActivityManager.getService();
|
||||
}
|
||||
}
|
||||
@@ -154,6 +154,13 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
mSwitchBarController = new DevelopmentSwitchBarController(
|
||||
this /* DevelopmentSettings */, mSwitchBar, mIsAvailable, getLifecycle());
|
||||
mSwitchBar.show();
|
||||
|
||||
// Restore UI state based on whether developer options is enabled
|
||||
if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext())) {
|
||||
enableDeveloperOptions();
|
||||
} else {
|
||||
disableDeveloperOptions();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -197,17 +204,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
if (isChecked) {
|
||||
EnableDevelopmentSettingWarningDialog.show(this /* host */);
|
||||
} else {
|
||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), false);
|
||||
final SystemPropPoker poker = SystemPropPoker.getInstance();
|
||||
poker.blockPokes();
|
||||
for (AbstractPreferenceController controller : mPreferenceControllers) {
|
||||
if (controller instanceof DeveloperOptionsPreferenceController) {
|
||||
((DeveloperOptionsPreferenceController) controller)
|
||||
.onDeveloperOptionsDisabled();
|
||||
}
|
||||
}
|
||||
poker.unblockPokes();
|
||||
poker.poke();
|
||||
disableDeveloperOptions();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -318,7 +315,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
getActivity().unregisterReceiver(mBluetoothA2dpReceiver);
|
||||
}
|
||||
|
||||
void onEnableDevelopmentOptionsConfirmed() {
|
||||
private void enableDeveloperOptions() {
|
||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true);
|
||||
for (AbstractPreferenceController controller : mPreferenceControllers) {
|
||||
if (controller instanceof DeveloperOptionsPreferenceController) {
|
||||
@@ -327,6 +324,24 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
}
|
||||
}
|
||||
|
||||
private void disableDeveloperOptions() {
|
||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), false);
|
||||
final SystemPropPoker poker = SystemPropPoker.getInstance();
|
||||
poker.blockPokes();
|
||||
for (AbstractPreferenceController controller : mPreferenceControllers) {
|
||||
if (controller instanceof DeveloperOptionsPreferenceController) {
|
||||
((DeveloperOptionsPreferenceController) controller)
|
||||
.onDeveloperOptionsDisabled();
|
||||
}
|
||||
}
|
||||
poker.unblockPokes();
|
||||
poker.poke();
|
||||
}
|
||||
|
||||
void onEnableDevelopmentOptionsConfirmed() {
|
||||
enableDeveloperOptions();
|
||||
}
|
||||
|
||||
void onEnableDevelopmentOptionsRejected() {
|
||||
// Reset the toggle
|
||||
mSwitchBar.setChecked(false);
|
||||
@@ -401,18 +416,19 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
controllers.add(new ForceMSAAPreferenceController(context));
|
||||
controllers.add(new HardwareOverlaysPreferenceController(context));
|
||||
controllers.add(new SimulateColorSpacePreferenceController(context));
|
||||
// set gpu renderer
|
||||
controllers.add(new SetGpuRendererPreferenceController(context));
|
||||
controllers.add(new UsbAudioRoutingPreferenceController(context));
|
||||
controllers.add(new StrictModePreferenceController(context));
|
||||
// profile gpu rendering
|
||||
controllers.add(new ProfileGpuRenderingPreferenceController(context));
|
||||
controllers.add(new KeepActivitiesPreferenceController(context));
|
||||
// background process limit
|
||||
controllers.add(new BackgroundProcessLimitPreferenceController(context));
|
||||
// background check
|
||||
controllers.add(new AppsNotRespondingPreferenceController(context));
|
||||
controllers.add(new NotificationChannelWarningsPreferenceController(context));
|
||||
// inactive apps
|
||||
controllers.add(new AllowAppsOnExternalPreferenceController(context));
|
||||
controllers.add(new ResizableActivityPreferenceController(context));
|
||||
controllers.add(new FreeformWindowsPreferenceController(context));
|
||||
controllers.add(new ShortcutManagerThrottlingPreferenceController(context));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
||||
|
||||
public class FreeformWindowsPreferenceController extends
|
||||
DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
|
||||
PreferenceControllerMixin {
|
||||
|
||||
private static final String ENABLE_FREEFORM_SUPPORT_KEY = "enable_freeform_support";
|
||||
|
||||
@VisibleForTesting
|
||||
static final int SETTING_VALUE_OFF = 0;
|
||||
@VisibleForTesting
|
||||
static final int SETTING_VALUE_ON = 1;
|
||||
@VisibleForTesting
|
||||
static final String USER_BUILD_TYPE = "user";
|
||||
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
public FreeformWindowsPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return !TextUtils.equals(USER_BUILD_TYPE, getBuildType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return ENABLE_FREEFORM_SUPPORT_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
mPreference = (SwitchPreference) screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean isEnabled = (Boolean) newValue;
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT,
|
||||
isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, SETTING_VALUE_OFF);
|
||||
mPreference.setChecked(mode != SETTING_VALUE_OFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchEnabled() {
|
||||
mPreference.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchDisabled() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, SETTING_VALUE_OFF);
|
||||
mPreference.setEnabled(false);
|
||||
mPreference.setChecked(false);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String getBuildType() {
|
||||
return Build.TYPE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.os.SystemProperties;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
import android.view.ThreadedRenderer;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
||||
import com.android.settingslib.development.SystemPropPoker;
|
||||
|
||||
public class ProfileGpuRenderingPreferenceController extends
|
||||
DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
|
||||
PreferenceControllerMixin {
|
||||
|
||||
private static final String TRACK_FRAME_TIME_KEY = "track_frame_time";
|
||||
|
||||
private final String[] mListValues;
|
||||
private final String[] mListSummaries;
|
||||
private ListPreference mPreference;
|
||||
|
||||
public ProfileGpuRenderingPreferenceController(Context context) {
|
||||
super(context);
|
||||
|
||||
mListValues = context.getResources().getStringArray(R.array.track_frame_time_values);
|
||||
mListSummaries = context.getResources().getStringArray(R.array.track_frame_time_entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return TRACK_FRAME_TIME_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
mPreference = (ListPreference) screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
writeTrackFrameTimeOptions(newValue);
|
||||
updateTrackFrameTimeOptions();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
updateTrackFrameTimeOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchEnabled() {
|
||||
mPreference.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchDisabled() {
|
||||
mPreference.setEnabled(false);
|
||||
}
|
||||
|
||||
private void writeTrackFrameTimeOptions(Object newValue) {
|
||||
SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY,
|
||||
newValue == null ? "" : newValue.toString());
|
||||
SystemPropPoker.getInstance().poke();
|
||||
}
|
||||
|
||||
private void updateTrackFrameTimeOptions() {
|
||||
final String value = SystemProperties.get(
|
||||
ThreadedRenderer.PROFILE_PROPERTY, "" /* default */);
|
||||
int index = 0; // default
|
||||
for (int i = 0; i < mListValues.length; i++) {
|
||||
if (TextUtils.equals(value, mListValues[i])) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mPreference.setValue(mListValues[index]);
|
||||
mPreference.setSummary(mListSummaries[index]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.os.SystemProperties;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
import android.view.ThreadedRenderer;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
||||
import com.android.settingslib.development.SystemPropPoker;
|
||||
|
||||
public class SetGpuRendererPreferenceController extends
|
||||
DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
|
||||
PreferenceControllerMixin {
|
||||
|
||||
private static final String DEBUG_HW_RENDERER_KEY = "debug_hw_renderer";
|
||||
|
||||
private final String[] mListValues;
|
||||
private final String[] mListSummaries;
|
||||
private ListPreference mPreference;
|
||||
|
||||
public SetGpuRendererPreferenceController(Context context) {
|
||||
super(context);
|
||||
|
||||
mListValues = context.getResources().getStringArray(R.array.debug_hw_renderer_values);
|
||||
mListSummaries = context.getResources().getStringArray(R.array.debug_hw_renderer_entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return DEBUG_HW_RENDERER_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
mPreference = (ListPreference) screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
writeDebugHwRendererOptions(newValue);
|
||||
updateDebugHwRendererOptions();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
updateDebugHwRendererOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchEnabled() {
|
||||
mPreference.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchDisabled() {
|
||||
mPreference.setEnabled(false);
|
||||
}
|
||||
|
||||
private void writeDebugHwRendererOptions(Object newValue) {
|
||||
SystemProperties.set(ThreadedRenderer.DEBUG_RENDERER_PROPERTY,
|
||||
newValue == null ? "" : newValue.toString());
|
||||
SystemPropPoker.getInstance().poke();
|
||||
}
|
||||
|
||||
private void updateDebugHwRendererOptions() {
|
||||
final String value = SystemProperties.get(
|
||||
ThreadedRenderer.DEBUG_RENDERER_PROPERTY, "" /* default */);
|
||||
int index = 0; // default
|
||||
for (int i = 0; i < mListValues.length; i++) {
|
||||
if (TextUtils.equals(value, mListValues[i])) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mPreference.setValue(mListValues[index]);
|
||||
mPreference.setSummary(mListSummaries[index]);
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,7 @@ public class PaymentBackend {
|
||||
|
||||
public void onResume() {
|
||||
mSettingsPackageMonitor.register(mContext, mContext.getMainLooper(), false);
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
|
||||
@@ -95,7 +95,7 @@ public class DefaultAppSettingsTest {
|
||||
when(defaultBrowser.getDefaultAppLabel()).thenReturn("Browser1");
|
||||
when(defaultPhone.getDefaultAppLabel()).thenReturn("Phone1");
|
||||
summaryProvider.setListening(true);
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Sms1, Browser1, Phone1");
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Browser1, Phone1, Sms1");
|
||||
|
||||
// 2 available
|
||||
when(defaultSms.getDefaultAppLabel()).thenReturn(null);
|
||||
@@ -108,13 +108,13 @@ public class DefaultAppSettingsTest {
|
||||
when(defaultBrowser.getDefaultAppLabel()).thenReturn(null);
|
||||
when(defaultPhone.getDefaultAppLabel()).thenReturn("Phone1");
|
||||
summaryProvider.setListening(true);
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Sms1, Phone1");
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Phone1, Sms1");
|
||||
|
||||
when(defaultSms.getDefaultAppLabel()).thenReturn("Sms1");
|
||||
when(defaultBrowser.getDefaultAppLabel()).thenReturn("Browser1");
|
||||
when(defaultPhone.getDefaultAppLabel()).thenReturn(null);
|
||||
summaryProvider.setListening(true);
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Sms1, Browser1");
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Phone1, Sms1");
|
||||
|
||||
// 1 available
|
||||
when(defaultSms.getDefaultAppLabel()).thenReturn(null);
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.IActivityManager;
|
||||
import android.content.Context;
|
||||
import android.os.RemoteException;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
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.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)
|
||||
public class BackgroundProcessLimitPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private IActivityManager mActivityManager;
|
||||
@Mock
|
||||
private ListPreference mPreference;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
/**
|
||||
* 0: Standard limit
|
||||
* 1: No Background processes
|
||||
* 2: At most 1 process
|
||||
* 3: At most 2 processes
|
||||
* 4: At most 3 processes
|
||||
* 5: At most 4 processes
|
||||
*/
|
||||
private String[] mListValues;
|
||||
private String[] mListSummaries;
|
||||
private Context mContext;
|
||||
private BackgroundProcessLimitPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mListValues = mContext.getResources().getStringArray(R.array.app_process_limit_values);
|
||||
mListSummaries = mContext.getResources().getStringArray(R.array.app_process_limit_entries);
|
||||
mController = spy(new BackgroundProcessLimitPreferenceController(mContext));
|
||||
doReturn(mActivityManager).when(mController).getActivityManagerService();
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_noBackgroundProcessSet_shouldSetToNoBackgroundProcess()
|
||||
throws RemoteException {
|
||||
mController.onPreferenceChange(mPreference, mListValues[1]);
|
||||
|
||||
verify(mActivityManager).setProcessLimit(Integer.valueOf(mListValues[1]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_1ProcessSet_shouldSetTo1BackgroundProcess()
|
||||
throws RemoteException {
|
||||
mController.onPreferenceChange(mPreference, mListValues[2]);
|
||||
|
||||
verify(mActivityManager).setProcessLimit(Integer.valueOf(mListValues[2]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_noBackgroundProcessSet_shouldSetPreferenceToNoBackgroundProcess()
|
||||
throws RemoteException {
|
||||
when(mActivityManager.getProcessLimit()).thenReturn(Integer.valueOf(mListValues[1]));
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setValue(mListValues[1]);
|
||||
verify(mPreference).setSummary(mListSummaries[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_1ProcessSet_shouldSetPreference1BackgroundProcess()
|
||||
throws RemoteException {
|
||||
when(mActivityManager.getProcessLimit()).thenReturn(Integer.valueOf(mListValues[2]));
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setValue(mListValues[2]);
|
||||
verify(mPreference).setSummary(mListSummaries[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_veryHighLimit_shouldDefaultToStandardLimit() throws RemoteException {
|
||||
when(mActivityManager.getProcessLimit()).thenReturn(Integer.MAX_VALUE);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setValue(mListValues[0]);
|
||||
verify(mPreference).setSummary(mListSummaries[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() {
|
||||
mController.onDeveloperOptionsSwitchEnabled();
|
||||
|
||||
verify(mPreference).setEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsSwitchDisabled_shouldDisableAndResetPreference()
|
||||
throws RemoteException {
|
||||
mController.onDeveloperOptionsSwitchDisabled();
|
||||
|
||||
verify(mPreference).setEnabled(false);
|
||||
verify(mActivityManager).setProcessLimit(-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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.android.settings.development.FreeformWindowsPreferenceController
|
||||
.SETTING_VALUE_OFF;
|
||||
import static com.android.settings.development.FreeformWindowsPreferenceController.SETTING_VALUE_ON;
|
||||
import static com.android.settings.development.FreeformWindowsPreferenceController.USER_BUILD_TYPE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
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.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)
|
||||
public class FreeformWindowsPreferenceControllerTest {
|
||||
|
||||
private static final String ENG_BUILD_TYPE = "eng";
|
||||
|
||||
@Mock
|
||||
private SwitchPreference mPreference;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private Context mContext;
|
||||
private FreeformWindowsPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new FreeformWindowsPreferenceController(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_engBuild_shouldBeTrue() {
|
||||
mController = spy(mController);
|
||||
doReturn(ENG_BUILD_TYPE).when(mController).getBuildType();
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvaiable_userBuild_shouldBeFalse() {
|
||||
mController = spy(mController);
|
||||
doReturn(USER_BUILD_TYPE).when(mController).getBuildType();
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_switchEnabled_shouldEnableFreeformWindows() {
|
||||
mController.onPreferenceChange(mPreference, true /* new value */);
|
||||
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, -1 /* default */);
|
||||
assertThat(mode).isEqualTo(SETTING_VALUE_ON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_switchDisabled_shouldDisableFreeformWindows() {
|
||||
mController.onPreferenceChange(mPreference, false /* new value */);
|
||||
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, -1 /* default */);
|
||||
assertThat(mode).isEqualTo(SETTING_VALUE_OFF);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_settingEnabled_preferenceShouldBeChecked() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, SETTING_VALUE_ON);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, SETTING_VALUE_OFF);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() {
|
||||
mController.onDeveloperOptionsSwitchEnabled();
|
||||
|
||||
verify(mPreference).setEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
|
||||
mController.onDeveloperOptionsSwitchDisabled();
|
||||
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, -1 /* default */);
|
||||
assertThat(mode).isEqualTo(SETTING_VALUE_OFF);
|
||||
verify(mPreference).setEnabled(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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 static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.view.ThreadedRenderer;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
||||
|
||||
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 ProfileGpuRenderingPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private ListPreference mPreference;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
/**
|
||||
* 0: Off
|
||||
* 1: On screen as bars
|
||||
* 2: In adb shell dumpsys gfxinfo
|
||||
*/
|
||||
private String[] mListValues;
|
||||
private String[] mListSummaries;
|
||||
private Context mContext;
|
||||
private ProfileGpuRenderingPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mListValues = mContext.getResources().getStringArray(R.array.track_frame_time_values);
|
||||
mListSummaries = mContext.getResources().getStringArray(R.array.track_frame_time_entries);
|
||||
mController = new ProfileGpuRenderingPreferenceController(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() {
|
||||
SettingsShadowSystemProperties.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_noValueSet_shouldSetEmptyString() {
|
||||
mController.onPreferenceChange(mPreference, null /* new value */);
|
||||
|
||||
String mode = SystemProperties.get(
|
||||
ThreadedRenderer.PROFILE_PROPERTY);
|
||||
assertThat(mode).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_option1Selected_shouldSetOption1() {
|
||||
mController.onPreferenceChange(mPreference, mListValues[1]);
|
||||
|
||||
String mode = SystemProperties.get(
|
||||
ThreadedRenderer.PROFILE_PROPERTY);
|
||||
assertThat(mode).isEqualTo(mListValues[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_option1Set_shouldUpdatePreferenceToOption1() {
|
||||
SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY,
|
||||
mListValues[1]);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setValue(mListValues[1]);
|
||||
verify(mPreference).setSummary(mListSummaries[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_option2Set_shouldUpdatePreferenceToOption2() {
|
||||
SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY,
|
||||
mListValues[2]);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setValue(mListValues[2]);
|
||||
verify(mPreference).setSummary(mListSummaries[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_noOptionSet_shouldDefaultToOption0() {
|
||||
SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY, null);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setValue(mListValues[0]);
|
||||
verify(mPreference).setSummary(mListSummaries[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
|
||||
mController.onDeveloperOptionsSwitchDisabled();
|
||||
|
||||
verify(mPreference).setEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() {
|
||||
mController.onDeveloperOptionsSwitchEnabled();
|
||||
|
||||
verify(mPreference).setEnabled(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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 static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.view.ThreadedRenderer;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
||||
|
||||
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 SetGpuRendererPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private ListPreference mPreference;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
/**
|
||||
* 0: OpenGl (Default)
|
||||
* 1: OpenGl (Skia)
|
||||
*/
|
||||
private String[] mListValues;
|
||||
private String[] mListSummaries;
|
||||
private Context mContext;
|
||||
private SetGpuRendererPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mListValues = mContext.getResources().getStringArray(R.array.debug_hw_renderer_values);
|
||||
mListSummaries = mContext.getResources().getStringArray(R.array.debug_hw_renderer_entries);
|
||||
mController = new SetGpuRendererPreferenceController(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() {
|
||||
SettingsShadowSystemProperties.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_noValueSet_shouldSetEmptyString() {
|
||||
mController.onPreferenceChange(mPreference, null /* new value */);
|
||||
|
||||
String mode = SystemProperties.get(
|
||||
ThreadedRenderer.DEBUG_RENDERER_PROPERTY);
|
||||
assertThat(mode).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_option1Selected_shouldSetOption1() {
|
||||
mController.onPreferenceChange(mPreference, mListValues[1]);
|
||||
|
||||
String mode = SystemProperties.get(
|
||||
ThreadedRenderer.DEBUG_RENDERER_PROPERTY);
|
||||
assertThat(mode).isEqualTo(mListValues[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_option1Set_shouldUpdatePreferenceToOption1() {
|
||||
SystemProperties.set(ThreadedRenderer.DEBUG_RENDERER_PROPERTY,
|
||||
mListValues[1]);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setValue(mListValues[1]);
|
||||
verify(mPreference).setSummary(mListSummaries[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_option0Set_shouldUpdatePreferenceToOption0() {
|
||||
SystemProperties.set(ThreadedRenderer.DEBUG_RENDERER_PROPERTY,
|
||||
mListValues[0]);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setValue(mListValues[0]);
|
||||
verify(mPreference).setSummary(mListSummaries[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_noOptionSet_shouldDefaultToOption0() {
|
||||
SystemProperties.set(ThreadedRenderer.DEBUG_RENDERER_PROPERTY, null);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setValue(mListValues[0]);
|
||||
verify(mPreference).setSummary(mListSummaries[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
|
||||
mController.onDeveloperOptionsSwitchDisabled();
|
||||
|
||||
verify(mPreference).setEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() {
|
||||
mController.onDeveloperOptionsSwitchEnabled();
|
||||
|
||||
verify(mPreference).setEnabled(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user