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:
jeffreyhuang
2017-11-17 11:19:44 -08:00
parent 1eaf52aad4
commit cb823d5983
27 changed files with 27 additions and 4683 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}
}

View File

@@ -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));
}
}

View File

@@ -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

View File

@@ -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());
mSwitchBar.setChecked(developmentEnabledState);
mSwitchBar.addOnSwitchChangeListener(mNewSettings);
}
final boolean developmentEnabledState = DevelopmentSettingsEnabler
.isDevelopmentSettingsEnabled(mSettings.getContext());
mSwitchBar.setChecked(developmentEnabledState);
mSwitchBar.addOnSwitchChangeListener(mSettings);
}
@Override
public void onStop() {
if (mSettings != null) {
mSwitchBar.removeOnSwitchChangeListener(mSettings);
}
if (mNewSettings != null) {
mSwitchBar.removeOnSwitchChangeListener(mNewSettings);
}
mSwitchBar.removeOnSwitchChangeListener(mSettings);
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}