Use the new OemLockService to get OEM lock state.
Previously, the PersistentDataBlockService but that is only one possible implementation of the OEM lock. The new service abstracts the implementation so is the API that should be used. Test: Manual Bug: 34766843 Change-Id: I5f9cb94996f84c4c082d152f05cd8aef566edc66
This commit is contained in:
@@ -73,6 +73,7 @@
|
|||||||
<uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" />
|
<uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" />
|
||||||
<uses-permission android:name="android.permission.READ_SEARCH_INDEXABLES" />
|
<uses-permission android:name="android.permission.READ_SEARCH_INDEXABLES" />
|
||||||
<uses-permission android:name="android.permission.OEM_UNLOCK_STATE" />
|
<uses-permission android:name="android.permission.OEM_UNLOCK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.MANAGE_USER_OEM_UNLOCK_STATE" />
|
||||||
<uses-permission android:name="android.permission.OVERRIDE_WIFI_CONFIG" />
|
<uses-permission android:name="android.permission.OVERRIDE_WIFI_CONFIG" />
|
||||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||||
<uses-permission android:name="android.permission.MANAGE_FINGERPRINT" />
|
<uses-permission android:name="android.permission.MANAGE_FINGERPRINT" />
|
||||||
|
@@ -25,6 +25,7 @@ import android.os.Bundle;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.service.oemlock.OemLockManager;
|
||||||
import android.service.persistentdata.PersistentDataBlockManager;
|
import android.service.persistentdata.PersistentDataBlockManager;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -67,12 +68,14 @@ public class MasterClearConfirm extends OptionsMenuFragment {
|
|||||||
|
|
||||||
final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
|
final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
|
||||||
getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
|
getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
|
||||||
|
final OemLockManager oemLockManager = (OemLockManager)
|
||||||
|
getActivity().getSystemService(Context.OEM_LOCK_SERVICE);
|
||||||
|
|
||||||
if (pdbManager != null && !pdbManager.getOemUnlockEnabled() &&
|
if (pdbManager != null && !oemLockManager.isOemUnlockAllowed() &&
|
||||||
Utils.isDeviceProvisioned(getActivity())) {
|
Utils.isDeviceProvisioned(getActivity())) {
|
||||||
// if OEM unlock is enabled, this will be wiped during FR process. If disabled, it
|
// if OEM unlock is allowed, the persistent data block will be wiped during FR
|
||||||
// will be wiped here, unless the device is still being provisioned, in which case
|
// process. If disabled, it will be wiped here, unless the device is still being
|
||||||
// the persistent data block will be preserved.
|
// provisioned, in which case the persistent data block will be preserved.
|
||||||
new AsyncTask<Void, Void, Void>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
int mOldOrientation;
|
int mOldOrientation;
|
||||||
ProgressDialog mProgressDialog;
|
ProgressDialog mProgressDialog;
|
||||||
|
@@ -59,7 +59,7 @@ import android.os.UserManager;
|
|||||||
import android.os.storage.IStorageManager;
|
import android.os.storage.IStorageManager;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.service.persistentdata.PersistentDataBlockManager;
|
import android.service.oemlock.OemLockManager;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.support.v7.preference.ListPreference;
|
import android.support.v7.preference.ListPreference;
|
||||||
@@ -238,7 +238,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
private static final int RESULT_DEBUG_APP = 1000;
|
private static final int RESULT_DEBUG_APP = 1000;
|
||||||
private static final int RESULT_MOCK_LOCATION_APP = 1001;
|
private static final int RESULT_MOCK_LOCATION_APP = 1001;
|
||||||
|
|
||||||
private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
|
|
||||||
private static final String FLASH_LOCKED_PROP = "ro.boot.flash.locked";
|
private static final String FLASH_LOCKED_PROP = "ro.boot.flash.locked";
|
||||||
|
|
||||||
private static final String SHORTCUT_MANAGER_RESET_KEY = "reset_shortcut_manager_throttling";
|
private static final String SHORTCUT_MANAGER_RESET_KEY = "reset_shortcut_manager_throttling";
|
||||||
@@ -252,7 +251,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
private IWebViewUpdateService mWebViewUpdateService;
|
private IWebViewUpdateService mWebViewUpdateService;
|
||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
private WifiManager mWifiManager;
|
private WifiManager mWifiManager;
|
||||||
private PersistentDataBlockManager mOemUnlockManager;
|
private OemLockManager mOemLockManager;
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
private SwitchBar mSwitchBar;
|
private SwitchBar mSwitchBar;
|
||||||
@@ -383,8 +382,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
mBackupManager = IBackupManager.Stub.asInterface(
|
mBackupManager = IBackupManager.Stub.asInterface(
|
||||||
ServiceManager.getService(Context.BACKUP_SERVICE));
|
ServiceManager.getService(Context.BACKUP_SERVICE));
|
||||||
mWebViewUpdateService = WebViewFactory.getUpdateService();
|
mWebViewUpdateService = WebViewFactory.getUpdateService();
|
||||||
mOemUnlockManager = (PersistentDataBlockManager) getActivity()
|
mOemLockManager = (OemLockManager) getSystemService(Context.OEM_LOCK_SERVICE);
|
||||||
.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
|
|
||||||
mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
|
||||||
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
|
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||||
@@ -431,7 +429,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
mKeepScreenOn = (RestrictedSwitchPreference) findAndInitSwitchPref(KEEP_SCREEN_ON);
|
mKeepScreenOn = (RestrictedSwitchPreference) findAndInitSwitchPref(KEEP_SCREEN_ON);
|
||||||
mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG);
|
mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG);
|
||||||
mEnableOemUnlock = (RestrictedSwitchPreference) findAndInitSwitchPref(ENABLE_OEM_UNLOCK);
|
mEnableOemUnlock = (RestrictedSwitchPreference) findAndInitSwitchPref(ENABLE_OEM_UNLOCK);
|
||||||
if (!showEnableOemUnlockPreference()) {
|
if (!showEnableOemUnlockPreference(getActivity())) {
|
||||||
removePreference(mEnableOemUnlock);
|
removePreference(mEnableOemUnlock);
|
||||||
mEnableOemUnlock = null;
|
mEnableOemUnlock = null;
|
||||||
}
|
}
|
||||||
@@ -1070,18 +1068,17 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
|
Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean showEnableOemUnlockPreference() {
|
private static boolean showEnableOemUnlockPreference(Context context) {
|
||||||
return !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("");
|
return context.getSystemService(Context.OEM_LOCK_SERVICE) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean enableOemUnlockPreference() {
|
private boolean enableOemUnlockPreference() {
|
||||||
return !isBootloaderUnlocked() && OemUnlockUtils.isOemUnlockAllowed(mUm);
|
return !isBootloaderUnlocked() && mOemLockManager.canUserAllowOemUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateOemUnlockOptions() {
|
private void updateOemUnlockOptions() {
|
||||||
if (mEnableOemUnlock != null) {
|
if (mEnableOemUnlock != null) {
|
||||||
updateSwitchPreference(mEnableOemUnlock,
|
updateSwitchPreference(mEnableOemUnlock, mOemLockManager.isOemUnlockAllowed());
|
||||||
OemUnlockUtils.isOemUnlockEnabled(getActivity()));
|
|
||||||
updateOemUnlockSettingDescription();
|
updateOemUnlockSettingDescription();
|
||||||
// Showing mEnableOemUnlock preference as device has persistent data block.
|
// Showing mEnableOemUnlock preference as device has persistent data block.
|
||||||
mEnableOemUnlock.setDisabledByAdmin(null);
|
mEnableOemUnlock.setDisabledByAdmin(null);
|
||||||
@@ -2339,7 +2336,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||||
OemUnlockUtils.setOemUnlockEnabled(getActivity(), true);
|
mOemLockManager.setOemUnlockAllowedByUser(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2410,7 +2407,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
if (mEnableOemUnlock.isChecked()) {
|
if (mEnableOemUnlock.isChecked()) {
|
||||||
confirmEnableOemUnlock();
|
confirmEnableOemUnlock();
|
||||||
} else {
|
} else {
|
||||||
OemUnlockUtils.setOemUnlockEnabled(getActivity(), false);
|
mOemLockManager.setOemUnlockAllowedByUser(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -2480,7 +2477,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
confirmEnableOemUnlock();
|
confirmEnableOemUnlock();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
OemUnlockUtils.setOemUnlockEnabled(getActivity(), false);
|
mOemLockManager.setOemUnlockAllowedByUser(false);
|
||||||
}
|
}
|
||||||
} else if (preference == mMockLocationAppPref) {
|
} else if (preference == mMockLocationAppPref) {
|
||||||
Intent intent = new Intent(getActivity(), AppPicker.class);
|
Intent intent = new Intent(getActivity(), AppPicker.class);
|
||||||
@@ -2821,7 +2818,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
final List<String> keys = new ArrayList<String>();
|
final List<String> keys = new ArrayList<String>();
|
||||||
if (!showEnableOemUnlockPreference()) {
|
if (!showEnableOemUnlockPreference(context)) {
|
||||||
keys.add(ENABLE_OEM_UNLOCK);
|
keys.add(ENABLE_OEM_UNLOCK);
|
||||||
}
|
}
|
||||||
return keys;
|
return keys;
|
||||||
@@ -2849,11 +2846,10 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_bootloader_unlocked;
|
oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_bootloader_unlocked;
|
||||||
} else if (isSimLockedDevice()) {
|
} else if (isSimLockedDevice()) {
|
||||||
oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_sim_locked_device;
|
oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_sim_locked_device;
|
||||||
} else if (!OemUnlockUtils.isOemUnlockAllowed(mUm)) {
|
} else if (!mOemLockManager.canUserAllowOemUnlock()) {
|
||||||
// If the device isn't SIM-locked but OEM unlock is disabled by the system via the
|
// If the device isn't SIM-locked but OEM unlock is disallowed by some party, this
|
||||||
// user restriction, this means either some other carrier restriction is in place or
|
// means either some other carrier restriction is in place or the device hasn't been
|
||||||
// the device hasn't been able to confirm which restrictions (SIM-lock or otherwise)
|
// able to confirm which restrictions (SIM-lock or otherwise) apply.
|
||||||
// apply.
|
|
||||||
oemUnlockSummary =
|
oemUnlockSummary =
|
||||||
R.string.oem_unlock_enable_disabled_summary_connectivity_or_locked;
|
R.string.oem_unlock_enable_disabled_summary_connectivity_or_locked;
|
||||||
}
|
}
|
||||||
@@ -2876,12 +2872,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
* Returns {@code true} if the bootloader has been unlocked. Otherwise, returns {code false}.
|
* Returns {@code true} if the bootloader has been unlocked. Otherwise, returns {code false}.
|
||||||
*/
|
*/
|
||||||
private boolean isBootloaderUnlocked() {
|
private boolean isBootloaderUnlocked() {
|
||||||
int flashLockState = PersistentDataBlockManager.FLASH_LOCK_UNKNOWN;
|
return mOemLockManager.isDeviceOemUnlocked();
|
||||||
if (mOemUnlockManager != null) {
|
|
||||||
flashLockState = mOemUnlockManager.getFlashLockState();
|
|
||||||
}
|
|
||||||
|
|
||||||
return flashLockState == PersistentDataBlockManager.FLASH_LOCK_UNLOCKED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,61 +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.UserHandle;
|
|
||||||
import android.os.UserManager;
|
|
||||||
import android.service.persistentdata.PersistentDataBlockManager;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
public class OemUnlockUtils {
|
|
||||||
private static final String TAG = "OemUnlockUtils";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
try {
|
|
||||||
PersistentDataBlockManager manager = (PersistentDataBlockManager)
|
|
||||||
context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
|
|
||||||
manager.setOemUnlockEnabled(enabled);
|
|
||||||
} catch (SecurityException e) {
|
|
||||||
Log.e(TAG, "Fail to set oem unlock.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns {@code true} if OEM unlock is disallowed by user restriction
|
|
||||||
* {@link UserManager#DISALLOW_FACTORY_RESET} or {@link UserManager#DISALLOW_OEM_UNLOCK}.
|
|
||||||
* Otherwise, returns {@code false}.
|
|
||||||
*/
|
|
||||||
static boolean isOemUnlockAllowed(UserManager um) {
|
|
||||||
final UserHandle userHandle = UserHandle.of(UserHandle.myUserId());
|
|
||||||
return !(um.hasBaseUserRestriction(UserManager.DISALLOW_OEM_UNLOCK, userHandle)
|
|
||||||
|| um.hasBaseUserRestriction(UserManager.DISALLOW_FACTORY_RESET, userHandle));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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 android.service.oemlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make OemLockManager available to Robolectric.
|
||||||
|
*/
|
||||||
|
public class OemLockManager {
|
||||||
|
public void setOemUnlockAllowedByCarrier(boolean allowed, byte[] signature) {}
|
||||||
|
|
||||||
|
public boolean isOemUnlockAllowedByCarrier() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOemUnlockAllowedByUser(boolean allowed) {}
|
||||||
|
|
||||||
|
public boolean isOemUnlockAllowedByUser() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canUserAllowOemUnlock() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public boolean isOemUnlockAllowed() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDeviceOemUnlocked() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user