Delete DevelopmentSettings.java
- Remove the old DevelopmentSettings - Remove references to the feature flag Fixes: 65522949 Test: make RunSettingsRoboTests -j40 Change-Id: Ie2eb3465127d79a027de6bb58a47bb15e3094f89
This commit is contained in:
@@ -1889,31 +1889,6 @@
|
||||
android:value="com.android.settings.ApnEditor" />
|
||||
</activity>
|
||||
|
||||
<activity android:name="Settings$DevelopmentSettingsActivity"
|
||||
android:label="@string/development_settings_title"
|
||||
android:icon="@drawable/ic_settings_development"
|
||||
android:taskAffinity="com.android.settings"
|
||||
android:parentActivityName="Settings">
|
||||
<!-- Enable if we need to revert to the old development settings
|
||||
<intent-filter android:priority="1">
|
||||
<action android:name="android.settings.APPLICATION_DEVELOPMENT_SETTINGS" />
|
||||
<action android:name="com.android.settings.APPLICATION_DEVELOPMENT_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
-->
|
||||
<intent-filter android:priority="50">
|
||||
<action android:name="com.android.settings.action.SETTINGS" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.ia.system" />
|
||||
<meta-data android:name="com.android.settings.summary"
|
||||
android:resource="@string/summary_empty"/>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.development.DevelopmentSettings" />
|
||||
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
||||
android:value="true" />
|
||||
</activity>
|
||||
|
||||
<activity android:name="Settings$DevelopmentSettingsDashboardActivity"
|
||||
android:label="@string/development_settings_title"
|
||||
android:icon="@drawable/ic_settings_development"
|
||||
|
@@ -16,10 +16,7 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import static com.android.settings.core.FeatureFlags.DEV_OPTION_V1;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||
|
||||
@@ -60,16 +57,6 @@ public class Settings extends SettingsActivity {
|
||||
public static class HighPowerApplicationsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class BackgroundCheckSummaryActivity extends SettingsActivity { /* empty */ }
|
||||
public static class StorageUseActivity extends SettingsActivity { /* empty */ }
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link DevelopmentSettingsDashboardActivity}.
|
||||
*/
|
||||
@Deprecated
|
||||
public static class DevelopmentSettingsActivity extends SettingsActivity {
|
||||
public static final boolean isEnabled() {
|
||||
return FeatureFlagUtils.isEnabled(null /* context */, DEV_OPTION_V1);
|
||||
}
|
||||
}
|
||||
public static class DevelopmentSettingsDashboardActivity extends SettingsActivity { /* empty */ }
|
||||
public static class AccessibilitySettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class CaptioningSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
|
@@ -55,7 +55,6 @@ import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.Settings.WifiSettingsActivity;
|
||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
||||
import com.android.settings.backup.BackupSettingsActivity;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.core.gateway.SettingsGateway;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.core.instrumentation.SharedPreferencesLogger;
|
||||
@@ -827,16 +826,10 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
|
||||
final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)
|
||||
&& !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
|
||||
final boolean useDevOptionV1 = Settings.DevelopmentSettingsActivity.isEnabled();
|
||||
// Enable old Dev option if v2 is disabled
|
||||
somethingChanged = setTileEnabled(new ComponentName(packageName,
|
||||
Settings.DevelopmentSettingsActivity.class.getName()),
|
||||
showDev && useDevOptionV1, isAdmin)
|
||||
|| somethingChanged;
|
||||
// Enable new Dev option if v2 is enable
|
||||
|
||||
somethingChanged = setTileEnabled(new ComponentName(packageName,
|
||||
Settings.DevelopmentSettingsDashboardActivity.class.getName()),
|
||||
showDev && !useDevOptionV1, isAdmin)
|
||||
showDev, isAdmin)
|
||||
|| somethingChanged;
|
||||
|
||||
// Enable/disable backup settings depending on whether the user is admin.
|
||||
|
@@ -27,8 +27,8 @@ import android.support.v7.preference.PreferenceGroup;
|
||||
import android.text.BidiFormatter;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
|
@@ -21,7 +21,6 @@ package com.android.settings.core;
|
||||
*/
|
||||
public class FeatureFlags {
|
||||
public static final String DEVICE_INFO_V2 = "device_info_v2";
|
||||
public static final String DEV_OPTION_V1 = "dev_option_v1";
|
||||
public static final String SEARCH_V2 = "settings_search_v2";
|
||||
public static final String SUGGESTIONS_V2 = "new_settings_suggestion";
|
||||
}
|
||||
|
@@ -62,7 +62,6 @@ import com.android.settings.datausage.DataPlanUsageSummary;
|
||||
import com.android.settings.datausage.DataUsageList;
|
||||
import com.android.settings.datausage.DataUsageSummary;
|
||||
import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
|
||||
import com.android.settings.development.DevelopmentSettings;
|
||||
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
|
||||
import com.android.settings.deviceinfo.ImeiInformation;
|
||||
import com.android.settings.deviceinfo.PrivateVolumeForget;
|
||||
@@ -176,7 +175,6 @@ public class SettingsGateway {
|
||||
PrivateVolumeForget.class.getName(),
|
||||
PrivateVolumeSettings.class.getName(),
|
||||
PublicVolumeSettings.class.getName(),
|
||||
DevelopmentSettings.class.getName(),
|
||||
DevelopmentSettingsDashboardFragment.class.getName(),
|
||||
AndroidBeam.class.getName(),
|
||||
WifiDisplaySettings.class.getName(),
|
||||
|
@@ -19,13 +19,11 @@ package com.android.settings.dashboard;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import com.android.settings.DisplaySettings;
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.accounts.AccountDetailDashboardFragment;
|
||||
import com.android.settings.accounts.UserAndAccountDashboardFragment;
|
||||
import com.android.settings.applications.AppAndNotificationDashboardFragment;
|
||||
import com.android.settings.applications.DefaultAppSettings;
|
||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
||||
import com.android.settings.development.DevelopmentSettings;
|
||||
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
|
||||
import com.android.settings.deviceinfo.StorageDashboardFragment;
|
||||
import com.android.settings.fuelgauge.PowerUsageSummary;
|
||||
@@ -85,13 +83,8 @@ public class DashboardFragmentRegistry {
|
||||
SystemDashboardFragment.class.getName(), CategoryKey.CATEGORY_SYSTEM);
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(LanguageAndInputSettings.class.getName(),
|
||||
CategoryKey.CATEGORY_SYSTEM_LANGUAGE);
|
||||
if (Settings.DevelopmentSettingsActivity.isEnabled()) {
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(DevelopmentSettings.class.getName(),
|
||||
CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT);
|
||||
} else {
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(DevelopmentSettingsDashboardFragment.class.getName(),
|
||||
CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT);
|
||||
}
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(ConfigureNotificationSettings.class.getName(),
|
||||
CategoryKey.CATEGORY_NOTIFICATIONS);
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(LockscreenDashboardFragment.class.getName(),
|
||||
|
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
/**
|
||||
* deprecated in favor of {@link BugReportInPowerPreferenceControllerV2}
|
||||
*/
|
||||
@Deprecated
|
||||
public class BugReportInPowerPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin {
|
||||
|
||||
private static final String KEY_BUGREPORT_IN_POWER = "bugreport_in_power";
|
||||
|
||||
private UserManager mUserManager;
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
public BugReportInPowerPreferenceController(Context context) {
|
||||
super(context);
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (KEY_BUGREPORT_IN_POWER.equals(preference.getKey())) {
|
||||
final SwitchPreference switchPreference = (SwitchPreference) preference;
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.BUGREPORT_IN_POWER_MENU,
|
||||
switchPreference.isChecked() ? 1 : 0);
|
||||
setBugreportStorageProviderStatus();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
if (isAvailable()) {
|
||||
mPreference = (SwitchPreference) screen.findPreference(KEY_BUGREPORT_IN_POWER);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_BUGREPORT_IN_POWER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return !mUserManager.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
updatePreference();
|
||||
}
|
||||
|
||||
public void enablePreference(boolean enabled) {
|
||||
if (isAvailable()) {
|
||||
mPreference.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
public void resetPreference() {
|
||||
if (mPreference.isChecked()) {
|
||||
mPreference.setChecked(false);
|
||||
handlePreferenceTreeClick(mPreference);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updatePreference() {
|
||||
if (!isAvailable()) {
|
||||
return false;
|
||||
}
|
||||
final boolean enabled = Settings.Secure.getInt(
|
||||
mContext.getContentResolver(), Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0;
|
||||
mPreference.setChecked(enabled);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void updateBugreportOptions() {
|
||||
if (!isAvailable()) {
|
||||
return;
|
||||
}
|
||||
mPreference.setEnabled(true);
|
||||
setBugreportStorageProviderStatus();
|
||||
}
|
||||
|
||||
private void setBugreportStorageProviderStatus() {
|
||||
final ComponentName componentName = new ComponentName("com.android.shell",
|
||||
"com.android.shell.BugreportStorageProvider");
|
||||
final boolean enabled = mPreference.isChecked();
|
||||
mContext.getPackageManager().setComponentEnabledSetting(componentName,
|
||||
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
|
||||
: PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
|
||||
0);
|
||||
}
|
||||
|
||||
}
|
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
/**
|
||||
* deprecated in favor of {@link BugReportPreferenceControllerV2}
|
||||
*/
|
||||
@Deprecated
|
||||
public class BugReportPreferenceController extends AbstractPreferenceController implements
|
||||
PreferenceControllerMixin {
|
||||
|
||||
private static final String KEY_BUGREPORT = "bugreport";
|
||||
|
||||
private UserManager mUserManager;
|
||||
private Preference mPreference;
|
||||
|
||||
public BugReportPreferenceController(Context context) {
|
||||
super(context);
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
if (isAvailable()) {
|
||||
mPreference = screen.findPreference(KEY_BUGREPORT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_BUGREPORT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return !mUserManager.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
|
||||
}
|
||||
|
||||
public void enablePreference(boolean enabled) {
|
||||
if (isAvailable()) {
|
||||
mPreference.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,108 +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 android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
/**
|
||||
* deprecated in favor of {@link CameraLaserSensorPreferenceControllerV2}
|
||||
*/
|
||||
@Deprecated
|
||||
public class CameraLaserSensorPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin {
|
||||
|
||||
private static final String KEY_CAMERA_LASER_SENSOR_SWITCH = "camera_laser_sensor_switch";
|
||||
@VisibleForTesting
|
||||
static final String BUILD_TYPE = "ro.build.type";
|
||||
@VisibleForTesting
|
||||
static final String PROPERTY_CAMERA_LASER_SENSOR = "persist.camera.stats.disablehaf";
|
||||
@VisibleForTesting
|
||||
static final int ENABLED = 0;
|
||||
@VisibleForTesting
|
||||
static final int DISABLED = 2;
|
||||
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
public CameraLaserSensorPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = (SwitchPreference) screen.findPreference(KEY_CAMERA_LASER_SENSOR_SWITCH);
|
||||
updatePreference();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_CAMERA_LASER_SENSOR_SWITCH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
String buildType = SystemProperties.get(BUILD_TYPE);
|
||||
return mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor) &&
|
||||
(buildType.equals("userdebug") || buildType.equals("eng"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
updatePreference();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (KEY_CAMERA_LASER_SENSOR_SWITCH.equals(preference.getKey())) {
|
||||
final SwitchPreference switchPreference = (SwitchPreference)preference;
|
||||
String value = Integer.toString(switchPreference.isChecked() ? ENABLED : DISABLED);
|
||||
SystemProperties.set(PROPERTY_CAMERA_LASER_SENSOR, value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void enablePreference(boolean enabled) {
|
||||
if (isAvailable()) {
|
||||
mPreference.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updatePreference() {
|
||||
if (!isAvailable()) {
|
||||
return false;
|
||||
}
|
||||
final boolean enabled = isLaserSensorEnabled();
|
||||
mPreference.setChecked(enabled);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
private boolean isLaserSensorEnabled() {
|
||||
String prop = SystemProperties.get(PROPERTY_CAMERA_LASER_SENSOR, Integer.toString(ENABLED));
|
||||
return prop.equals(Integer.toString(ENABLED));
|
||||
}
|
||||
}
|
@@ -1,119 +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 android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
/**
|
||||
* deprecated in favor of {@link ConnectivityMonitorPreferenceControllerV2}
|
||||
*/
|
||||
@Deprecated
|
||||
public class ConnectivityMonitorPreferenceController extends AbstractPreferenceController implements
|
||||
PreferenceControllerMixin {
|
||||
|
||||
private static final String KEY_CONNECTIVITY_MONITOR_SWITCH = "connectivity_monitor_switch";
|
||||
@VisibleForTesting
|
||||
static final String BUILD_TYPE = "ro.build.type";
|
||||
@VisibleForTesting
|
||||
static final String PROPERTY_CONNECTIVITY_MONITOR = "persist.radio.enable_tel_mon";
|
||||
|
||||
@VisibleForTesting
|
||||
static final String ENABLED_STATUS = "enabled";
|
||||
@VisibleForTesting
|
||||
static final String DISABLED_STATUS = "disabled";
|
||||
@VisibleForTesting
|
||||
static final String USER_ENABLED_STATUS = "user_enabled";
|
||||
@VisibleForTesting
|
||||
static final String USER_DISABLED_STATUS = "user_disabled";
|
||||
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
public ConnectivityMonitorPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
if (isAvailable()) {
|
||||
mPreference = (SwitchPreference) screen.findPreference(KEY_CONNECTIVITY_MONITOR_SWITCH);
|
||||
mPreference.setChecked(isConnectivityMonitorEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_CONNECTIVITY_MONITOR_SWITCH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor) &&
|
||||
(SystemProperties.get(BUILD_TYPE).equals("userdebug") ||
|
||||
SystemProperties.get(BUILD_TYPE).equals("eng"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
updatePreference();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (KEY_CONNECTIVITY_MONITOR_SWITCH.equals(preference.getKey())) {
|
||||
final SwitchPreference switchPreference = (SwitchPreference) preference;
|
||||
SystemProperties.set(PROPERTY_CONNECTIVITY_MONITOR,
|
||||
switchPreference.isChecked() ? USER_ENABLED_STATUS : USER_DISABLED_STATUS);
|
||||
Toast.makeText(mContext, R.string.connectivity_monitor_toast,
|
||||
Toast.LENGTH_LONG).show();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void enablePreference(boolean enabled) {
|
||||
if (isAvailable()) {
|
||||
mPreference.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updatePreference() {
|
||||
if (!isAvailable()) {
|
||||
return false;
|
||||
}
|
||||
final boolean enabled = isConnectivityMonitorEnabled();
|
||||
mPreference.setChecked(enabled);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
private boolean isConnectivityMonitorEnabled() {
|
||||
final String cmStatus = SystemProperties.get(PROPERTY_CONNECTIVITY_MONITOR,
|
||||
DISABLED_STATUS);
|
||||
return ENABLED_STATUS.equals(cmStatus) || USER_ENABLED_STATUS.equals(cmStatus);
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -28,33 +30,13 @@ public class DevelopmentSwitchBarController implements LifecycleObserver, OnStar
|
||||
|
||||
private final SwitchBar mSwitchBar;
|
||||
private final boolean mIsAvailable;
|
||||
private final DevelopmentSettings mSettings;
|
||||
private final DevelopmentSettingsDashboardFragment mNewSettings;
|
||||
private final DevelopmentSettingsDashboardFragment mSettings;
|
||||
|
||||
/**
|
||||
* @deprecated in favor of the other constructor.
|
||||
*/
|
||||
@Deprecated
|
||||
public DevelopmentSwitchBarController(DevelopmentSettings settings, SwitchBar switchBar,
|
||||
boolean isAvailable, Lifecycle lifecycle) {
|
||||
mSwitchBar = switchBar;
|
||||
mIsAvailable = isAvailable && !Utils.isMonkeyRunning();
|
||||
mSettings = settings;
|
||||
mNewSettings = null;
|
||||
|
||||
if (mIsAvailable) {
|
||||
lifecycle.addObserver(this);
|
||||
} else {
|
||||
mSwitchBar.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public DevelopmentSwitchBarController(DevelopmentSettingsDashboardFragment settings,
|
||||
public DevelopmentSwitchBarController(@NonNull DevelopmentSettingsDashboardFragment settings,
|
||||
SwitchBar switchBar, boolean isAvailable, Lifecycle lifecycle) {
|
||||
mSwitchBar = switchBar;
|
||||
mIsAvailable = isAvailable && !Utils.isMonkeyRunning();
|
||||
mSettings = null;
|
||||
mNewSettings = settings;
|
||||
mSettings = settings;
|
||||
|
||||
if (mIsAvailable) {
|
||||
lifecycle.addObserver(this);
|
||||
@@ -65,24 +47,14 @@ public class DevelopmentSwitchBarController implements LifecycleObserver, OnStar
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (mSettings != null) {
|
||||
mSwitchBar.addOnSwitchChangeListener(mSettings);
|
||||
}
|
||||
if (mNewSettings != null) {
|
||||
final boolean developmentEnabledState = DevelopmentSettingsEnabler
|
||||
.isDevelopmentSettingsEnabled(mNewSettings.getContext());
|
||||
.isDevelopmentSettingsEnabled(mSettings.getContext());
|
||||
mSwitchBar.setChecked(developmentEnabledState);
|
||||
mSwitchBar.addOnSwitchChangeListener(mNewSettings);
|
||||
}
|
||||
mSwitchBar.addOnSwitchChangeListener(mSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mSettings != null) {
|
||||
mSwitchBar.removeOnSwitchChangeListener(mSettings);
|
||||
}
|
||||
if (mNewSettings != null) {
|
||||
mSwitchBar.removeOnSwitchChangeListener(mNewSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,84 +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 android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.development.AbstractEnableAdbPreferenceController;
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link AdbPreferenceController}
|
||||
*/
|
||||
@Deprecated
|
||||
public class EnableAdbPreferenceController extends AbstractEnableAdbPreferenceController
|
||||
implements PreferenceControllerMixin {
|
||||
|
||||
private Dialog mAdbDialog;
|
||||
private boolean mDialogClicked;
|
||||
|
||||
public EnableAdbPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showConfirmationDialog(@Nullable Preference preference) {
|
||||
if (preference == null) {
|
||||
return;
|
||||
}
|
||||
final TwoStatePreference twoStatePreference = (TwoStatePreference) preference;
|
||||
mDialogClicked = false;
|
||||
dismissConfirmationDialog();
|
||||
mAdbDialog = new AlertDialog.Builder(mContext).setMessage(
|
||||
mContext.getString(R.string.adb_warning_message))
|
||||
.setTitle(R.string.adb_warning_title)
|
||||
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
|
||||
mDialogClicked = true;
|
||||
writeAdbSetting(true);
|
||||
twoStatePreference.setChecked(true);
|
||||
})
|
||||
.setNegativeButton(android.R.string.no,
|
||||
(dialog, which) -> twoStatePreference.setChecked(false))
|
||||
.show();
|
||||
mAdbDialog.setOnDismissListener(dialog -> {
|
||||
// Assuming that onClick gets called first
|
||||
if (!mDialogClicked) {
|
||||
twoStatePreference.setChecked(false);
|
||||
}
|
||||
mAdbDialog = null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismissConfirmationDialog() {
|
||||
if (mAdbDialog != null) {
|
||||
mAdbDialog.dismiss();
|
||||
mAdbDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfirmationDialogShowing() {
|
||||
return mAdbDialog != null;
|
||||
}
|
||||
}
|
@@ -1,34 +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 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 {
|
||||
|
||||
public LogdSizePreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
}
|
@@ -1,70 +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 android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.development.AbstractLogpersistPreferenceController;
|
||||
|
||||
/**
|
||||
* depreacted in favor of {@link LogdSizePreferenceControllerV2}
|
||||
*/
|
||||
@Deprecated
|
||||
public class LogpersistPreferenceController extends AbstractLogpersistPreferenceController
|
||||
implements PreferenceControllerMixin {
|
||||
|
||||
private Dialog mLogpersistClearDialog;
|
||||
|
||||
LogpersistPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showConfirmationDialog(@Nullable Preference preference) {
|
||||
if (preference == null) {
|
||||
return;
|
||||
}
|
||||
if (mLogpersistClearDialog != null) dismissConfirmationDialog();
|
||||
mLogpersistClearDialog = new AlertDialog.Builder(mContext)
|
||||
.setMessage(R.string.dev_logpersist_clear_warning_message)
|
||||
.setTitle(R.string.dev_logpersist_clear_warning_title)
|
||||
.setPositiveButton(android.R.string.yes, (dialog, which) -> setLogpersistOff(true))
|
||||
.setNegativeButton(android.R.string.no, (dialog, which) -> updateLogpersistValues())
|
||||
.show();
|
||||
mLogpersistClearDialog.setOnDismissListener(dialog -> mLogpersistClearDialog = null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismissConfirmationDialog() {
|
||||
if (mLogpersistClearDialog != null) {
|
||||
mLogpersistClearDialog.dismiss();
|
||||
mLogpersistClearDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfirmationDialogShowing() {
|
||||
return mLogpersistClearDialog != null;
|
||||
}
|
||||
}
|
@@ -1,154 +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 android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controller to manage the state of "Verify apps over USB" toggle.
|
||||
*
|
||||
* deprecated in favor of {@link VerifyAppsOverUsbPreferenceControllerV2}
|
||||
*/
|
||||
@Deprecated
|
||||
public class VerifyAppsOverUsbPreferenceController extends AbstractPreferenceController implements
|
||||
PreferenceControllerMixin {
|
||||
private static final String VERIFY_APPS_OVER_USB_KEY = "verify_apps_over_usb";
|
||||
private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
|
||||
|
||||
private RestrictedSwitchPreference mPreference;
|
||||
|
||||
/**
|
||||
* Class for indirection of RestrictedLockUtils for testing purposes. It would be nice to mock
|
||||
* the appropriate methods in UserManager instead but they aren't accessible.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
class RestrictedLockUtilsDelegate {
|
||||
public EnforcedAdmin checkIfRestrictionEnforced(
|
||||
Context context, String userRestriction, int userId) {
|
||||
return RestrictedLockUtils.checkIfRestrictionEnforced(context, userRestriction, userId);
|
||||
}
|
||||
}
|
||||
// NB: This field is accessed using reflection in the test, please keep name in sync.
|
||||
private final RestrictedLockUtilsDelegate mRestrictedLockUtils =
|
||||
new RestrictedLockUtilsDelegate();
|
||||
|
||||
VerifyAppsOverUsbPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
if (isAvailable()) {
|
||||
mPreference = (RestrictedSwitchPreference)
|
||||
screen.findPreference(VERIFY_APPS_OVER_USB_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return VERIFY_APPS_OVER_USB_KEY;
|
||||
}
|
||||
|
||||
/** Saves the settings value when it is toggled. */
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (VERIFY_APPS_OVER_USB_KEY.equals(preference.getKey())) {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, mPreference.isChecked() ? 1 : 0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the toggle should be enabled depending on whether verify apps over USB is
|
||||
* possible currently. If ADB is disabled or if package verifier does not exist, the toggle
|
||||
* should be disabled.
|
||||
*/
|
||||
private boolean shouldBeEnabled() {
|
||||
final ContentResolver cr = mContext.getContentResolver();
|
||||
if (Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0) == 0) {
|
||||
return false;
|
||||
}
|
||||
if (Settings.Global.getInt(cr, Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) == 0) {
|
||||
return false;
|
||||
} else {
|
||||
final PackageManager pm = mContext.getPackageManager();
|
||||
final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
|
||||
verification.setType(PACKAGE_MIME_TYPE);
|
||||
verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0);
|
||||
if (receivers.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates position, enabled status and maybe admin message.
|
||||
*/
|
||||
public void updatePreference() {
|
||||
if (!isAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shouldBeEnabled()) {
|
||||
mPreference.setChecked(false);
|
||||
mPreference.setDisabledByAdmin(null);
|
||||
mPreference.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
final EnforcedAdmin enforcingAdmin = mRestrictedLockUtils.checkIfRestrictionEnforced(
|
||||
mContext, UserManager.ENSURE_VERIFY_APPS, UserHandle.myUserId());
|
||||
if (enforcingAdmin != null) {
|
||||
mPreference.setChecked(true);
|
||||
mPreference.setDisabledByAdmin(enforcingAdmin);
|
||||
return;
|
||||
}
|
||||
|
||||
mPreference.setEnabled(true);
|
||||
final boolean checked = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0;
|
||||
mPreference.setChecked(checked);
|
||||
}
|
||||
}
|
@@ -1,3 +1,2 @@
|
||||
com.android.settings.development.DevelopmentSettings
|
||||
com.android.settings.display.ScreenZoomPreferenceFragmentForSetupWizard
|
||||
com.android.settings.search.indexing.FakeSettingsFragment
|
||||
|
@@ -1,192 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserManager;
|
||||
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.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
/**
|
||||
* deprecated in favor of {@link BugReportInPowerPreferenceControllerV2}
|
||||
*/
|
||||
@Deprecated
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
|
||||
public class BugReportInPowerPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
private Context mContext;
|
||||
private SwitchPreference mPreference;
|
||||
private BugReportInPowerPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowApplication shadowContext = ShadowApplication.getInstance();
|
||||
shadowContext.setSystemService(Context.USER_SERVICE, mUserManager);
|
||||
mContext = spy(shadowContext.getApplicationContext());
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
mController = new BugReportInPowerPreferenceController(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_hasDebugRestriction_shouldRemovePreference() {
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_noDebugRestriction_shouldNotRemovePreference() {
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enablePreference_hasDebugRestriction_shouldNotEnable() {
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
|
||||
mController.displayPreference(mScreen);
|
||||
mPreference.setEnabled(false);
|
||||
|
||||
mController.enablePreference(true);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enablePreference_noDebugRestriction_shouldEnable() {
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
|
||||
mController.displayPreference(mScreen);
|
||||
mPreference.setEnabled(false);
|
||||
|
||||
mController.enablePreference(true);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resetPreference_shouldUncheck() {
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
|
||||
mController.displayPreference(mScreen);
|
||||
mPreference.setChecked(true);
|
||||
|
||||
mController.resetPreference();
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_shouldUpdateSettings() {
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.BUGREPORT_IN_POWER_MENU, 0);
|
||||
mPreference.setChecked(true);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.BUGREPORT_IN_POWER_MENU, 0)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_settingsOn_shouldCheck() {
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.BUGREPORT_IN_POWER_MENU, 1);
|
||||
mPreference.setChecked(false);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_settingsOff_shouldUncheck() {
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.BUGREPORT_IN_POWER_MENU, 0);
|
||||
mPreference.setChecked(true);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBugreportOptions_shouldEnable() {
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
|
||||
mPreference.setEnabled(false);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mController.updateBugreportOptions();
|
||||
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBugreportOptions_shouldEnableBugReportStorage() {
|
||||
final ComponentName componentName = new ComponentName("com.android.shell",
|
||||
"com.android.shell.BugreportStorageProvider");
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mController.updateBugreportOptions();
|
||||
|
||||
verify(mPackageManager).setComponentEnabledSetting(eq(componentName), anyInt(), anyInt());
|
||||
}
|
||||
}
|
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
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;
|
||||
|
||||
/**
|
||||
* deprecated in favor of {@link BugReportPreferenceControllerV2}
|
||||
*/
|
||||
@Deprecated
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
|
||||
public class BugReportPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
|
||||
private BugReportPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
mController = new BugReportPreferenceController(mContext);
|
||||
mPreference = new Preference(RuntimeEnvironment.application);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_hasDebugRestriction_shouldRemovePreference() {
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_noDebugRestriction_shouldNotRemovePreference() {
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enablePreference_hasDebugRestriction_shouldNotEnable() {
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.setEnabled(false);
|
||||
mController.enablePreference(true);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enablePreference_noDebugRestriction_shouldEnable() {
|
||||
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.setEnabled(false);
|
||||
mController.enablePreference(true);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
}
|
@@ -1,178 +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 android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
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.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* deprecated in favour of {@link CameraLaserSensorPreferenceControllerV2}
|
||||
*/
|
||||
@Deprecated
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {SettingsShadowSystemProperties.class})
|
||||
public class CameraLaserSensorPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
static final String USERDEBUG_BUILD = "userdebug";
|
||||
static final String ENG_BUILD = "eng";
|
||||
static final String USER_BUILD = "user";
|
||||
|
||||
private CameraLaserSensorPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new CameraLaserSensorPreferenceController(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowSystemProperties.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withConfigNoShow_shouldReturnFalse() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(false);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withUserdebugBuild_shouldReturnTrue() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withEngBuild_shouldReturnTrue() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.BUILD_TYPE, ENG_BUILD);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_withUserBuild_shouldReturnFalse() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.BUILD_TYPE, USER_BUILD);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_cameraLaserSensorEnabled_shouldCheckedPreference() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
|
||||
Integer.toString(CameraLaserSensorPreferenceController.ENABLED));
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_cameraLaserSensorEnabled_shouldUncheckedPreference() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
|
||||
Integer.toString(CameraLaserSensorPreferenceController.DISABLED));
|
||||
SettingsShadowSystemProperties.set(
|
||||
CameraLaserSensorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_preferenceChecked_shouldEnableCameraLaserSensor() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
when(mPreference.isChecked()).thenReturn(true);
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(Integer.toString(CameraLaserSensorPreferenceController.ENABLED).equals(
|
||||
SystemProperties.get(
|
||||
CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
|
||||
Integer.toString(CameraLaserSensorPreferenceController.ENABLED)))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_preferenceUnchecked_shouldDisableCameraLaserSensor() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor))
|
||||
.thenReturn(true);
|
||||
|
||||
when(mPreference.isChecked()).thenReturn(false);
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(Integer.toString(CameraLaserSensorPreferenceController.DISABLED).equals(
|
||||
SystemProperties.get(
|
||||
CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
|
||||
Integer.toString(CameraLaserSensorPreferenceController.ENABLED)))).isTrue();
|
||||
}
|
||||
}
|
@@ -1,229 +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 android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
||||
|
||||
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.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* deprecated in favor of {@link ConnectivityMonitorPreferenceControllerV2}
|
||||
*/
|
||||
@Deprecated
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ConnectivityMonitorPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
private ConnectivityMonitorPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
SettingsShadowSystemProperties.clear();
|
||||
mController = new ConnectivityMonitorPreferenceController(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void isAvailable_trueShowFlagWithUserdebugBuild_shouldReturnTrue() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
|
||||
.thenReturn(true);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.BUILD_TYPE, "userdebug");
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void isAvailable_trueShowFlagWithEngBuild_shouldReturnTrue() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
|
||||
.thenReturn(true);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.BUILD_TYPE, "eng");
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void isAvailable_trueShowFlagWithUserBuild_shouldReturnFalse() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
|
||||
.thenReturn(true);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.BUILD_TYPE, "user");
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void isAvailable_falseShowFlagWithUserdebugBuild_shouldReturnFalse() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
|
||||
.thenReturn(false);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.BUILD_TYPE, "userdebug");
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void isAvailable_falseShowFlagWithEngBuild_shouldReturnFalse() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
|
||||
.thenReturn(false);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.BUILD_TYPE, "eng");
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void isAvailable_falseShowFlagWithUserBuild_shouldReturnFalse() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
|
||||
.thenReturn(false);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.BUILD_TYPE, "user");
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void displayPreference_connectivityMonitorEnabled_shouldCheckedPreference() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
|
||||
.thenReturn(true);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
|
||||
ConnectivityMonitorPreferenceController.ENABLED_STATUS);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.BUILD_TYPE, "userdebug");
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setChecked(true);
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void displayPreference_connectivityMonitorUserEnabled_shouldCheckedPreference() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
|
||||
.thenReturn(true);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
|
||||
ConnectivityMonitorPreferenceController.USER_ENABLED_STATUS);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.BUILD_TYPE, "userdebug");
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setChecked(true);
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void displayPreference_connectivityMonitorDisabled_shouldUncheckedPreference() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
|
||||
.thenReturn(true);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
|
||||
ConnectivityMonitorPreferenceController.DISABLED_STATUS);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.BUILD_TYPE, "userdebug");
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void displayPreference_connectivityMonitorUserDisabled_shouldUncheckedPreference() {
|
||||
when(mContext.getResources().getBoolean(R.bool.config_show_connectivity_monitor))
|
||||
.thenReturn(true);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
|
||||
ConnectivityMonitorPreferenceController.USER_DISABLED_STATUS);
|
||||
SettingsShadowSystemProperties.set(
|
||||
ConnectivityMonitorPreferenceController.BUILD_TYPE, "userdebug");
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_preferenceChecked_shouldEnableConnectivityMonitor() {
|
||||
when(mPreference.isChecked()).thenReturn(true);
|
||||
|
||||
when(mContext.getResources().getString(R.string.connectivity_monitor_toast))
|
||||
.thenReturn("To apply connectivity monitor change, reboot device");
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(ConnectivityMonitorPreferenceController.USER_ENABLED_STATUS.equals(
|
||||
SystemProperties.get(
|
||||
ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
|
||||
ConnectivityMonitorPreferenceController.DISABLED_STATUS))).isTrue();
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_preferenceUnchecked_shouldDisableConnectivityMonitor() {
|
||||
when(mPreference.isChecked()).thenReturn(false);
|
||||
|
||||
when(mContext.getResources().getString(R.string.connectivity_monitor_toast))
|
||||
.thenReturn("To apply connectivity monitor change, reboot device");
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(ConnectivityMonitorPreferenceController.USER_DISABLED_STATUS.equals(
|
||||
SystemProperties.get(
|
||||
ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
|
||||
ConnectivityMonitorPreferenceController.DISABLED_STATUS))).isTrue();
|
||||
}
|
||||
|
||||
}
|
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.Activity;
|
||||
import android.content.Context;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
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;
|
||||
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.shadows.ShadowApplication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class
|
||||
})
|
||||
public class DevelopmentSettingsTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private PreferenceManager mPreferenceManager;
|
||||
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private DevelopmentSettings mSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mSettings = spy(new DevelopmentSettings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addDashboardCategoryPreference_shouldAddToScreen() {
|
||||
final List<Preference> preferences = new ArrayList<>();
|
||||
preferences.add(new Preference(ShadowApplication.getInstance().getApplicationContext()));
|
||||
preferences.add(new Preference(ShadowApplication.getInstance().getApplicationContext()));
|
||||
doReturn(mScreen).when(mSettings).getPreferenceScreen();
|
||||
doReturn(mPreferenceManager).when(mSettings).getPreferenceManager();
|
||||
doReturn(mActivity).when(mSettings).getActivity();
|
||||
when(mPreferenceManager.getContext()).thenReturn(mContext);
|
||||
when(mFeatureFactory.dashboardFeatureProvider.getPreferencesForCategory(
|
||||
mActivity, mContext, mSettings.getMetricsCategory(),
|
||||
CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT))
|
||||
.thenReturn(preferences);
|
||||
|
||||
mSettings.onAttach(mContext);
|
||||
mSettings.addDashboardCategoryPreferences();
|
||||
|
||||
verify(mScreen, times(2)).addPreference(any(Preference.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchIndex_shouldIndexFromPrefXml() {
|
||||
final List<SearchIndexableResource> index =
|
||||
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
|
||||
RuntimeEnvironment.application, true);
|
||||
|
||||
assertThat(index.size()).isEqualTo(1);
|
||||
assertThat(index.get(0).xmlResId).isEqualTo(R.xml.development_settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchIndex_pageDisabled_shouldAddAllKeysToNonIndexable() {
|
||||
final Context appContext = RuntimeEnvironment.application;
|
||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(appContext, false);
|
||||
|
||||
final List<String> nonIndexableKeys =
|
||||
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(appContext);
|
||||
|
||||
assertThat(nonIndexableKeys).contains("development_prefs_screen");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchIndex_pageEnabled_shouldNotAddKeysToNonIndexable() {
|
||||
final Context appContext = RuntimeEnvironment.application;
|
||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(appContext, true);
|
||||
|
||||
final List<String> nonIndexableKeys =
|
||||
DevelopmentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(appContext);
|
||||
|
||||
assertThat(nonIndexableKeys).doesNotContain("development_prefs_screen");
|
||||
}
|
||||
}
|
@@ -23,6 +23,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
@@ -49,9 +51,8 @@ import java.util.ArrayList;
|
||||
public class DevelopmentSwitchBarControllerTest {
|
||||
|
||||
@Mock
|
||||
private DevelopmentSettings mSettings;
|
||||
@Mock
|
||||
private DevelopmentSettingsDashboardFragment mNewSettings;
|
||||
private DevelopmentSettingsDashboardFragment mSettings;
|
||||
private Context mContext;
|
||||
private Lifecycle mLifecycle;
|
||||
private SwitchBar mSwitchBar;
|
||||
private DevelopmentSwitchBarController mController;
|
||||
@@ -59,8 +60,10 @@ public class DevelopmentSwitchBarControllerTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||
mSwitchBar = new SwitchBar(RuntimeEnvironment.application);
|
||||
mSwitchBar = new SwitchBar(mContext);
|
||||
when(mSettings.getContext()).thenReturn(mContext);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -69,7 +72,7 @@ public class DevelopmentSwitchBarControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runThroughLifecycle_isMonkeyRun_shouldNotRegisterListener() {
|
||||
public void runThroughLifecycle_v2_isMonkeyRun_shouldNotRegisterListener() {
|
||||
ShadowUtils.setIsUserAMonkey(true);
|
||||
mController = new DevelopmentSwitchBarController(mSettings, mSwitchBar,
|
||||
true /* isAvailable */, mLifecycle);
|
||||
@@ -83,21 +86,6 @@ public class DevelopmentSwitchBarControllerTest {
|
||||
assertThat(listeners).doesNotContain(mSettings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runThroughLifecycle_v2_isMonkeyRun_shouldNotRegisterListener() {
|
||||
ShadowUtils.setIsUserAMonkey(true);
|
||||
mController = new DevelopmentSwitchBarController(mNewSettings, mSwitchBar,
|
||||
true /* isAvailable */, mLifecycle);
|
||||
final ArrayList<SwitchBar.OnSwitchChangeListener> listeners =
|
||||
ReflectionHelpers.getField(mSwitchBar, "mSwitchChangeListeners");
|
||||
|
||||
mLifecycle.handleLifecycleEvent(ON_START);
|
||||
assertThat(listeners).doesNotContain(mNewSettings);
|
||||
|
||||
mLifecycle.handleLifecycleEvent(ON_STOP);
|
||||
assertThat(listeners).doesNotContain(mNewSettings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runThroughLifecycle_isNotMonkeyRun_shouldRegisterAndRemoveListener() {
|
||||
ShadowUtils.setIsUserAMonkey(false);
|
||||
@@ -115,18 +103,18 @@ public class DevelopmentSwitchBarControllerTest {
|
||||
|
||||
@Test
|
||||
public void runThroughLifecycle_v2_isNotMonkeyRun_shouldRegisterAndRemoveListener() {
|
||||
when(mNewSettings.getContext()).thenReturn(RuntimeEnvironment.application);
|
||||
when(mSettings.getContext()).thenReturn(RuntimeEnvironment.application);
|
||||
ShadowUtils.setIsUserAMonkey(false);
|
||||
mController = new DevelopmentSwitchBarController(mNewSettings, mSwitchBar,
|
||||
mController = new DevelopmentSwitchBarController(mSettings, mSwitchBar,
|
||||
true /* isAvailable */, mLifecycle);
|
||||
final ArrayList<SwitchBar.OnSwitchChangeListener> listeners =
|
||||
ReflectionHelpers.getField(mSwitchBar, "mSwitchChangeListeners");
|
||||
|
||||
mLifecycle.handleLifecycleEvent(ON_START);
|
||||
assertThat(listeners).contains(mNewSettings);
|
||||
assertThat(listeners).contains(mSettings);
|
||||
|
||||
mLifecycle.handleLifecycleEvent(ON_STOP);
|
||||
assertThat(listeners).doesNotContain(mNewSettings);
|
||||
assertThat(listeners).doesNotContain(mSettings);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -1,62 +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.support.v14.preference.SwitchPreference;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link AdbPreferenceController}
|
||||
*/
|
||||
@Deprecated
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class EnableAdbPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private SwitchPreference mSwitchPreference;
|
||||
|
||||
private EnableAdbPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController
|
||||
= new EnableAdbPreferenceController(RuntimeEnvironment.application);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsConfirmationDialogShowing() {
|
||||
assertThat(mController.isConfirmationDialogShowing()).isFalse();
|
||||
mController.showConfirmationDialog(mSwitchPreference);
|
||||
assertThat(mController.isConfirmationDialogShowing()).isTrue();
|
||||
mController.dismissConfirmationDialog();
|
||||
assertThat(mController.isConfirmationDialogShowing()).isFalse();
|
||||
}
|
||||
}
|
@@ -1,66 +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.support.v7.preference.ListPreference;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* deprecated in favor of {@link LogPersistPreferenceControllerV2}
|
||||
*/
|
||||
@Deprecated
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class LogpersistPreferenceControllerTest {
|
||||
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Mock
|
||||
private ListPreference mListPreference;
|
||||
|
||||
private LogpersistPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mLifecycle = new Lifecycle(() -> mLifecycle);
|
||||
mController
|
||||
= new LogpersistPreferenceController(RuntimeEnvironment.application, mLifecycle);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsConfirmationDialogShowing() {
|
||||
assertThat(mController.isConfirmationDialogShowing()).isFalse();
|
||||
mController.showConfirmationDialog(mListPreference);
|
||||
assertThat(mController.isConfirmationDialogShowing()).isTrue();
|
||||
mController.dismissConfirmationDialog();
|
||||
assertThat(mController.isConfirmationDialogShowing()).isFalse();
|
||||
}
|
||||
}
|
@@ -1,184 +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 org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.provider.Settings.Global;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* deprecated in favor of {@link VerifyAppsOverUsbPreferenceControllerV2}
|
||||
*/
|
||||
@Deprecated
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class VerifyAppsOverUsbPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private RestrictedSwitchPreference mPreference;
|
||||
|
||||
@Mock
|
||||
private VerifyAppsOverUsbPreferenceController.RestrictedLockUtilsDelegate
|
||||
mRestrictedLockUtilsDelegate;
|
||||
|
||||
private Context mContext;
|
||||
private VerifyAppsOverUsbPreferenceController mController;
|
||||
|
||||
/** Convenience class for setting global int settings. */
|
||||
class GlobalSetter {
|
||||
public GlobalSetter set(String setting, int value) {
|
||||
Global.putInt(mContext.getContentResolver(), setting, value);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private final GlobalSetter mGlobals = new GlobalSetter();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
final ShadowApplication shadowContext = ShadowApplication.getInstance();
|
||||
mContext = spy(shadowContext.getApplicationContext());
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
mController = new VerifyAppsOverUsbPreferenceController(mContext);
|
||||
ReflectionHelpers.setField(
|
||||
mController, "mRestrictedLockUtils", mRestrictedLockUtilsDelegate);
|
||||
}
|
||||
|
||||
private void setupVerifyBroadcastReceivers(boolean nonEmpty) {
|
||||
final List<ResolveInfo> resolveInfos = nonEmpty
|
||||
? Collections.singletonList(mock(ResolveInfo.class))
|
||||
: Collections.<ResolveInfo>emptyList();
|
||||
when(mPackageManager.queryBroadcastReceivers((Intent) any(), anyInt()))
|
||||
.thenReturn(resolveInfos);
|
||||
}
|
||||
|
||||
private void setupEnforcedAdmin(EnforcedAdmin result) {
|
||||
when(mRestrictedLockUtilsDelegate.checkIfRestrictionEnforced(
|
||||
(Context) any(), anyString(), anyInt())).thenReturn(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceCheckedWhenSettingIsOn() {
|
||||
setupVerifyBroadcastReceivers(true);
|
||||
setupEnforcedAdmin(null);
|
||||
mGlobals.set(Global.ADB_ENABLED, 1).set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updatePreference();
|
||||
verify(mPreference).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceUncheckedWhenSettingIsOff() {
|
||||
setupVerifyBroadcastReceivers(true);
|
||||
setupEnforcedAdmin(null);
|
||||
mGlobals.set(Global.ADB_ENABLED, 1).set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 0);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updatePreference();
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceUncheckedWhenNoAdb() {
|
||||
setupVerifyBroadcastReceivers(true);
|
||||
setupEnforcedAdmin(null);
|
||||
mGlobals.set(Global.ADB_ENABLED, 0).set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updatePreference();
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceUncheckedWhenVerifierIsOff() {
|
||||
setupVerifyBroadcastReceivers(true);
|
||||
setupEnforcedAdmin(null);
|
||||
mGlobals.set(Global.ADB_ENABLED, 1)
|
||||
.set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1)
|
||||
.set(Global.PACKAGE_VERIFIER_ENABLE, 0);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updatePreference();
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceUncheckedWhenNoVerifyBroadcastReceivers() {
|
||||
setupVerifyBroadcastReceivers(false);
|
||||
setupEnforcedAdmin(null);
|
||||
mGlobals.set(Global.ADB_ENABLED, 1)
|
||||
.set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updatePreference();
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceDisabledWhenRestrictedByAdmin() {
|
||||
setupVerifyBroadcastReceivers(true);
|
||||
final EnforcedAdmin admin = new EnforcedAdmin();
|
||||
setupEnforcedAdmin(admin);
|
||||
mGlobals.set(Global.ADB_ENABLED, 1)
|
||||
.set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updatePreference();
|
||||
verify(mPreference).setDisabledByAdmin(admin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceRemovedWhenVerifierSettingsVisibleIsOff() {
|
||||
setupVerifyBroadcastReceivers(true);
|
||||
mGlobals.set(Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 0);
|
||||
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||
when(mScreen.getPreferenceCount()).thenReturn(1);
|
||||
when(mScreen.getPreference(anyInt())).thenReturn(mPreference);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setVisible(false);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user