diff options
Diffstat (limited to 'src/com/android/settings/DevelopmentSettings.java')
-rw-r--r-- | src/com/android/settings/DevelopmentSettings.java | 108 |
1 files changed, 88 insertions, 20 deletions
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java index d7a4145..b5b89cb 100644 --- a/src/com/android/settings/DevelopmentSettings.java +++ b/src/com/android/settings/DevelopmentSettings.java @@ -79,12 +79,14 @@ import android.widget.TextView; 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; @@ -177,6 +179,8 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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"; @@ -210,6 +214,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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; @@ -288,6 +295,8 @@ public class DevelopmentSettings extends SettingsPreferenceFragment private PreferenceScreen mDevelopmentTools; private ColorModePreference mColorModePreference; + private Preference mRootAppops; + private SwitchPreference mAdvancedReboot; private SwitchPreference mUpdateRecovery; @@ -473,8 +482,20 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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); @@ -498,6 +519,15 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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) { @@ -733,7 +763,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment updateRootAccessOptions(); updateAdvancedRebootOptions(); updateDevelopmentShortcutOptions(); - updateUpdateRecoveryOptions(); + if (mUpdateRecovery != null) { + updateUpdateRecoveryOptions(); + } if (mColorTemperaturePreference != null) { updateColorTemperature(); } @@ -809,7 +841,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment resetAdbNotifyOptions(); resetVerifyAppsOverUsbOptions(); resetDevelopmentShortcutOptions(); - resetUpdateRecoveryOptions(); + if (mUpdateRecovery != null) { + resetUpdateRecoveryOptions(); + } writeAnimationScaleOption(0, mWindowAnimationScale, null); writeAnimationScaleOption(1, mTransitionAnimationScale, null); writeAnimationScaleOption(2, mAnimatorDurationScale, null); @@ -830,6 +864,21 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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() { @@ -845,10 +894,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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(); } @@ -858,10 +907,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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(); } @@ -920,6 +969,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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 { @@ -1576,14 +1629,15 @@ public class DevelopmentSettings extends SettingsPreferenceFragment updateLogdSizeValues(); } - private void updateUsbConfigurationValues() { + private void updateUsbConfigurationValues(boolean isUnlocked) { if (mUsbConfiguration != null) { UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); String[] values = getResources().getStringArray(R.array.usb_configuration_values); String[] titles = getResources().getStringArray(R.array.usb_configuration_titles); int index = 0; - for (int i = 0; i < titles.length; i++) { + // Assume if !isUnlocked -> charging, which should be at index 0 + for (int i = 0; i < titles.length && isUnlocked; i++) { if (manager.isFunctionEnabled(values[i])) { index = i; break; @@ -1598,10 +1652,11 @@ public class DevelopmentSettings extends SettingsPreferenceFragment private void writeUsbConfigurationOption(Object newValue) { UsbManager manager = (UsbManager)getActivity().getSystemService(Context.USB_SERVICE); String function = newValue.toString(); - manager.setCurrentFunction(function); if (function.equals("none")) { + manager.setCurrentFunction(null); manager.setUsbDataUnlocked(false); } else { + manager.setCurrentFunction(function); manager.setUsbDataUnlocked(true); } } @@ -1756,10 +1811,12 @@ public class DevelopmentSettings extends SettingsPreferenceFragment } 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(); } }; @@ -1767,8 +1824,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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(); } @@ -1787,6 +1845,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment .setMessage(R.string.confirm_enable_multi_window_text) .setPositiveButton(R.string.enable_text, onConfirmListener) .setNegativeButton(android.R.string.cancel, onConfirmListener) + .setCancelable(false) .create() .show(); } @@ -1809,8 +1868,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment } } - 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(); } } @@ -1882,6 +1942,13 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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; } @@ -2263,7 +2330,8 @@ public class DevelopmentSettings extends SettingsPreferenceFragment private BroadcastReceiver mUsbReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - updateUsbConfigurationValues(); + boolean isUnlocked = intent.getBooleanExtra(UsbManager.USB_DATA_UNLOCKED, false); + updateUsbConfigurationValues(isUnlocked); } }; |