From ce249fe38ddf8da562a0e92c58a7bb216a23c0bb Mon Sep 17 00:00:00 2001 From: Andres Morales Date: Mon, 7 Jul 2014 16:58:16 -0700 Subject: [PATCH] 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 --- AndroidManifest.xml | 1 + res/values/strings.xml | 4 ++ res/xml/development_prefs.xml | 5 ++ .../android/settings/DevelopmentSettings.java | 62 +++++++++++++++---- src/com/android/settings/Utils.java | 24 +++++-- .../search/SearchIndexableResources.java | 2 +- 6 files changed, 82 insertions(+), 16 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b645f9f4186..30be2551dbe 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -68,6 +68,7 @@ + Enable Bluetooth HCI snoop log Capture all bluetooth HCI packets in a file + + Enable OEM unlock + + Allow the device to be OEM unlocked Wireless display certification diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml index ba93c7a2240..854aa97b407 100644 --- a/res/xml/development_prefs.xml +++ b/res/xml/development_prefs.xml @@ -49,6 +49,11 @@ android:title="@string/bt_hci_snoop_log" android:summary="@string/bt_hci_snoop_log_summary"/> + + mAllPrefs = new ArrayList(); + private final ArrayList mResetCbPrefs = new ArrayList(); private final HashSet mDisabledPrefs = new HashSet(); - // 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 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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 @@ public class DevelopmentSettings extends SettingsPreferenceFragment 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 @@ public class DevelopmentSettings extends SettingsPreferenceFragment return false; } } + + /** + * For Search. + */ + public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + @Override + public List getXmlResourcesToIndex( + Context context, boolean enabled) { + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.development_prefs; + return Arrays.asList(sir); + } + + @Override + public List getNonIndexableKeys(Context context) { + final List keys = new ArrayList(); + 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 692d8f3bc6b..82118168d9b 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -18,14 +18,12 @@ package com.android.settings; 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.Contacts; 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.View; 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 @@ public final class Utils { .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 287d78f59e1..4e35a726737 100644 --- a/src/com/android/settings/search/SearchIndexableResources.java +++ b/src/com/android/settings/search/SearchIndexableResources.java @@ -245,7 +245,7 @@ public final class SearchIndexableResources { 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));