Enable OEM unlock checkbox in Developer Settings
For Volantis+ devices, we will give users
the ability to enable OEM unlock through
Developer Settings. To do so, we must write
the value to the last byte of a special partition
that does not get erased even after factory reset.
This feature will only be available on devices
with the persistent data partition, thus the checkbox
is only visible for devices that meet this requirement.
This depends on
https://googleplex-android-review.git.corp.google.com/#/c/495350/
DD: go/factory-reset
Bug: 14288780
Change-Id: I8f80b950bc101a1067912faf221391bf0dd826b7
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index 00a0b92..4c2b90d 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -26,7 +26,6 @@
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -40,7 +39,6 @@
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcel;
-import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.StrictMode;
@@ -53,6 +51,7 @@
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
+import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
@@ -64,11 +63,13 @@
import android.widget.Switch;
import android.widget.TextView;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
import com.android.settings.widget.SwitchBar;
import dalvik.system.VMRuntime;
-import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@@ -77,7 +78,7 @@
*/
public class DevelopmentSettings extends SettingsPreferenceFragment
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
- OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener {
+ OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable {
private static final String TAG = "DevelopmentSettings";
/**
@@ -95,6 +96,7 @@
private static final String ENABLE_TERMINAL = "enable_terminal";
private static final String KEEP_SCREEN_ON = "keep_screen_on";
private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log";
+ private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable";
private static final String ALLOW_MOCK_LOCATION = "allow_mock_location";
private static final String HDCP_CHECKING_KEY = "hdcp_checking";
private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking";
@@ -160,6 +162,8 @@
private static final int RESULT_DEBUG_APP = 1000;
+ private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
+
private static String DEFAULT_LOG_RING_BUFFER_SIZE_IN_BYTES = "262144"; // 256K
private IWindowManager mWindowManager;
@@ -180,9 +184,10 @@
private CheckBoxPreference mBugreportInPower;
private CheckBoxPreference mKeepScreenOn;
private CheckBoxPreference mBtHciSnoopLog;
+ private CheckBoxPreference mEnableOemUnlock;
private CheckBoxPreference mAllowMockLocation;
- private PreferenceScreen mPassword;
+ private PreferenceScreen mPassword;
private String mDebugApp;
private Preference mDebugAppPref;
private CheckBoxPreference mWaitForDebugger;
@@ -190,8 +195,8 @@
private CheckBoxPreference mWifiDisplayCertification;
private CheckBoxPreference mWifiVerboseLogging;
private CheckBoxPreference mWifiAggressiveHandover;
- private CheckBoxPreference mWifiAllowScansWithTraffic;
+ private CheckBoxPreference mWifiAllowScansWithTraffic;
private CheckBoxPreference mStrictMode;
private CheckBoxPreference mPointerLocation;
private CheckBoxPreference mShowTouches;
@@ -213,11 +218,12 @@
private ListPreference mAnimatorDurationScale;
private ListPreference mOverlayDisplayDevices;
private ListPreference mOpenGLTraces;
+
private ListPreference mSimulateColorSpace;
private CheckBoxPreference mUseNuplayer;
-
private CheckBoxPreference mImmediatelyDestroyActivities;
+
private ListPreference mAppProcessLimit;
private CheckBoxPreference mShowAllANRs;
@@ -225,19 +231,18 @@
private CheckBoxPreference mWebViewDataReductionProxy;
private PreferenceScreen mProcessStats;
-
private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
+
private final ArrayList<CheckBoxPreference> mResetCbPrefs
= new ArrayList<CheckBoxPreference>();
private final HashSet<Preference> mDisabledPrefs = new HashSet<Preference>();
-
// To track whether a confirmation dialog was clicked.
private boolean mDialogClicked;
private Dialog mEnableDialog;
private Dialog mAdbDialog;
- private Dialog mAdbKeysDialog;
+ private Dialog mAdbKeysDialog;
private boolean mUnavailable;
@Override
@@ -282,10 +287,15 @@
mBugreportInPower = findAndInitCheckboxPref(BUGREPORT_IN_POWER_KEY);
mKeepScreenOn = findAndInitCheckboxPref(KEEP_SCREEN_ON);
mBtHciSnoopLog = findAndInitCheckboxPref(BT_HCI_SNOOP_LOG);
+ mEnableOemUnlock = findAndInitCheckboxPref(ENABLE_OEM_UNLOCK);
+ if (!showEnableOemUnlockPreference()) {
+ removePreference(mEnableOemUnlock);
+ }
mAllowMockLocation = findAndInitCheckboxPref(ALLOW_MOCK_LOCATION);
mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD);
mAllPrefs.add(mPassword);
+
if (!android.os.Process.myUserHandle().equals(UserHandle.OWNER)) {
disableForUser(mEnableAdb);
disableForUser(mClearAdbKeys);
@@ -500,6 +510,7 @@
Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
updateCheckBox(mBtHciSnoopLog, Settings.Secure.getInt(cr,
Settings.Secure.BLUETOOTH_HCI_LOG, 0) != 0);
+ updateCheckBox(mEnableOemUnlock, Utils.isOemUnlockEnabled(getActivity()));
updateCheckBox(mAllowMockLocation, Settings.Secure.getInt(cr,
Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
updateHdcpValues();
@@ -674,6 +685,10 @@
Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
}
+ private static boolean showEnableOemUnlockPreference() {
+ return !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("");
+ }
+
private void updateBugreportOptions() {
if ("user".equals(Build.TYPE)) {
final ContentResolver resolver = getActivity().getContentResolver();
@@ -1317,9 +1332,11 @@
Settings.Global.putInt(getActivity().getContentResolver(),
Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
mKeepScreenOn.isChecked() ?
- (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
+ (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
} else if (preference == mBtHciSnoopLog) {
writeBtHciSnoopLogOptions();
+ } else if (preference == mEnableOemUnlock) {
+ Utils.setOemUnlockEnabled(getActivity(), mEnableOemUnlock.isChecked());
} else if (preference == mAllowMockLocation) {
Settings.Secure.putInt(getActivity().getContentResolver(),
Settings.Secure.ALLOW_MOCK_LOCATION,
@@ -1535,4 +1552,27 @@
return false;
}
}
+
+ /**
+ * For Search.
+ */
+ public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+ @Override
+ public List<SearchIndexableResource> getXmlResourcesToIndex(
+ Context context, boolean enabled) {
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.development_prefs;
+ return Arrays.asList(sir);
+ }
+
+ @Override
+ public List<String> getNonIndexableKeys(Context context) {
+ final List<String> keys = new ArrayList<String>();
+ if (!showEnableOemUnlockPreference()) {
+ keys.add(ENABLE_OEM_UNLOCK);
+ }
+ return keys;
+ }
+ };
}
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 692d8f3..8211816 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -18,14 +18,12 @@
import android.app.ActivityManager;
import android.app.AlertDialog;
-import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.Fragment;
import android.app.IActivityManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -55,6 +53,7 @@
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.Profile;
import android.provider.ContactsContract.RawContacts;
+import android.service.persistentdata.PersistentDataBlockManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
@@ -62,8 +61,6 @@
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TabWidget;
-
-import com.android.settings.R.string;
import com.android.settings.dashboard.DashboardCategory;
import com.android.settings.dashboard.DashboardTile;
@@ -670,4 +667,23 @@
.create();
return dlg;
}
+
+ /**
+ * Returns whether or not this device is able to be OEM unlocked.
+ */
+ static boolean isOemUnlockEnabled(Context context) {
+ PersistentDataBlockManager manager =(PersistentDataBlockManager)
+ context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
+ return manager.getOemUnlockEnabled();
+ }
+
+ /**
+ * Allows enabling or disabling OEM unlock on this device. OEM unlocked
+ * devices allow users to flash other OSes to them.
+ */
+ static void setOemUnlockEnabled(Context context, boolean enabled) {
+ PersistentDataBlockManager manager =(PersistentDataBlockManager)
+ context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
+ manager.setOemUnlockEnabled(enabled);
+ }
}
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 287d78f..4e35a72 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -245,7 +245,7 @@
sResMap.put(DevelopmentSettings.class.getName(),
new SearchIndexableResource(
Ranking.getRankForClassName(DevelopmentSettings.class.getName()),
- R.xml.development_prefs,
+ NO_DATA_RES_ID,
DevelopmentSettings.class.getName(),
R.drawable.ic_settings_development));