import android.widget.Toast;
import com.android.internal.logging.MetricsLogger;
+import com.android.settings.Settings.AppOpsSummaryActivity;
import com.android.settings.fuelgauge.InactiveApps;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.widget.SwitchBar;
import cyanogenmod.providers.CMSettings;
+import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
private static final String ROOT_ACCESS_KEY = "root_access";
private static final String ROOT_ACCESS_PROPERTY = "persist.sys.root_access";
+ private static final String ROOT_APPOPS_KEY = "root_appops";
+
private static final String UPDATE_RECOVERY_KEY = "update_recovery";
private static final String UPDATE_RECOVERY_PROPERTY = "persist.sys.recovery_update";
private static final int[] MOCK_LOCATION_APP_OPS = new int[] {AppOpsManager.OP_MOCK_LOCATION};
private static final String MULTI_WINDOW_SYSTEM_PROPERTY = "persist.sys.debug.multi_window";
+
+ private static final String SUPERUSER_BINARY_PATH = "/system/xbin/su";
+
private IWindowManager mWindowManager;
private IBackupManager mBackupManager;
private DevicePolicyManager mDpm;
private PreferenceScreen mDevelopmentTools;
private ColorModePreference mColorModePreference;
+ private Preference mRootAppops;
+
private SwitchPreference mAdvancedReboot;
private SwitchPreference mUpdateRecovery;
mRootAccess = (ListPreference) findPreference(ROOT_ACCESS_KEY);
mRootAccess.setOnPreferenceChangeListener(this);
+
+ mRootAppops = (Preference) findPreference(ROOT_APPOPS_KEY);
+ mRootAppops.setOnPreferenceClickListener(this);
+
if (!removeRootOptionsIfRequired()) {
+ if (isRootForAppsAvailable()) {
+ mRootAccess.setEntries(R.array.root_access_entries);
+ mRootAccess.setEntryValues(R.array.root_access_values);
+ } else {
+ mRootAccess.setEntries(R.array.root_access_entries_adb);
+ mRootAccess.setEntryValues(R.array.root_access_values_adb);
+ }
mAllPrefs.add(mRootAccess);
+ mAllPrefs.add(mRootAppops);
}
mDevelopmentTools = (PreferenceScreen) findPreference(DEVELOPMENT_TOOLS);
removePreference(COLOR_TEMPERATURE_KEY);
mColorTemperaturePreference = null;
}
+
+ if (!getResources().getBoolean(R.bool.config_enableRecoveryUpdater)) {
+ removePreference(mUpdateRecovery);
+ mUpdateRecovery = null;
+ if (SystemProperties.getBoolean(UPDATE_RECOVERY_PROPERTY, false)) {
+ SystemProperties.set(UPDATE_RECOVERY_PROPERTY, "false");
+ pokeSystemProperties();
+ }
+ }
}
private ListPreference addListPreference(String prefKey) {
updateRootAccessOptions();
updateAdvancedRebootOptions();
updateDevelopmentShortcutOptions();
- updateUpdateRecoveryOptions();
+ if (mUpdateRecovery != null) {
+ updateUpdateRecoveryOptions();
+ }
if (mColorTemperaturePreference != null) {
updateColorTemperature();
}
resetAdbNotifyOptions();
resetVerifyAppsOverUsbOptions();
resetDevelopmentShortcutOptions();
- resetUpdateRecoveryOptions();
+ if (mUpdateRecovery != null) {
+ resetUpdateRecoveryOptions();
+ }
writeAnimationScaleOption(0, mWindowAnimationScale, null);
writeAnimationScaleOption(1, mTransitionAnimationScale, null);
writeAnimationScaleOption(2, mAnimatorDurationScale, null);
mRootAccess.setValue(value);
mRootAccess.setSummary(getResources()
.getStringArray(R.array.root_access_entries)[Integer.valueOf(value)]);
+
+ if (mRootAppops != null) {
+ mRootAppops.setEnabled(isRootForAppsEnabled());
+ }
+ }
+
+ private boolean isRootForAppsAvailable() {
+ boolean exists = false;
+ try {
+ File f = new File(SUPERUSER_BINARY_PATH);
+ exists = f.exists();
+ } catch (SecurityException e) {
+ // Ignore
+ }
+ return exists;
}
public static boolean isRootForAppsEnabled() {
if (Integer.valueOf(newValue.toString()) < 2 && !oldValue.equals(newValue)
&& "1".equals(SystemProperties.get("service.adb.root", "0"))) {
SystemProperties.set("service.adb.root", "0");
- Settings.Secure.putInt(getActivity().getContentResolver(),
- Settings.Secure.ADB_ENABLED, 0);
- Settings.Secure.putInt(getActivity().getContentResolver(),
- Settings.Secure.ADB_ENABLED, 1);
+ Settings.Global.putInt(getActivity().getContentResolver(),
+ Settings.Global.ADB_ENABLED, 0);
+ Settings.Global.putInt(getActivity().getContentResolver(),
+ Settings.Global.ADB_ENABLED, 1);
}
updateRootAccessOptions();
}
SystemProperties.set(ROOT_ACCESS_PROPERTY, "0");
if (!oldValue.equals("0") && "1".equals(SystemProperties.get("service.adb.root", "0"))) {
SystemProperties.set("service.adb.root", "0");
- Settings.Secure.putInt(getActivity().getContentResolver(),
- Settings.Secure.ADB_ENABLED, 0);
- Settings.Secure.putInt(getActivity().getContentResolver(),
- Settings.Secure.ADB_ENABLED, 1);
+ Settings.Global.putInt(getActivity().getContentResolver(),
+ Settings.Global.ADB_ENABLED, 0);
+ Settings.Global.putInt(getActivity().getContentResolver(),
+ Settings.Global.ADB_ENABLED, 1);
}
updateRootAccessOptions();
}
private void updatePasswordSummary() {
try {
+ if (mBackupManager == null) {
+ Log.e(TAG, "Backup Manager is unavailable!");
+ return;
+ }
if (mBackupManager.hasBackupPassword()) {
mPassword.setSummary(R.string.local_backup_password_summary_change);
} else {
}
private void confirmEnableOemUnlock() {
- DialogInterface.OnClickListener onConfirmListener = new DialogInterface.OnClickListener() {
+ DialogInterface.OnClickListener onEnableOemListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- Utils.setOemUnlockEnabled(getActivity(), true);
+ if (which == DialogInterface.BUTTON_POSITIVE) {
+ Utils.setOemUnlockEnabled(getActivity(), true);
+ }
updateAllOptions();
}
};
new AlertDialog.Builder(getActivity())
.setTitle(R.string.confirm_enable_oem_unlock_title)
.setMessage(R.string.confirm_enable_oem_unlock_text)
- .setPositiveButton(R.string.enable_text, onConfirmListener)
- .setNegativeButton(android.R.string.cancel, null)
+ .setPositiveButton(R.string.enable_text, onEnableOemListener)
+ .setNegativeButton(android.R.string.cancel, onEnableOemListener)
+ .setCancelable(false)
.create()
.show();
}
.setMessage(R.string.confirm_enable_multi_window_text)
.setPositiveButton(R.string.enable_text, onConfirmListener)
.setNegativeButton(android.R.string.cancel, onConfirmListener)
+ .setCancelable(false)
.create()
.show();
}
}
}
- public static void initializeUpdateRecoveryOption() {
- if (TextUtils.isEmpty(SystemProperties.get(UPDATE_RECOVERY_PROPERTY))) {
+ public static void initializeUpdateRecoveryOption(Context context) {
+ if (TextUtils.isEmpty(SystemProperties.get(UPDATE_RECOVERY_PROPERTY)) &&
+ context.getResources().getBoolean(R.bool.config_enableRecoveryUpdater)) {
resetUpdateRecoveryOptions();
}
}
preference == mTransitionAnimationScale ||
preference == mAnimatorDurationScale) {
((AnimationScalePreference) preference).click();
+ } else if (preference == mRootAppops) {
+ Activity mActivity = getActivity();
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.putExtra("appops_tab", getString(R.string.app_ops_categories_su));
+ intent.setClass(mActivity, AppOpsSummaryActivity.class);
+ mActivity.startActivity(intent);
+ return true;
}
return false;
}