Do not toggle OEM unlock if bootloader unlocked

Bug: 30681215
Change-Id: Ia0fd55dd7b6b731d6f5733fc733621e99bd7b153
This commit is contained in:
Esteban Talavera
2016-08-11 11:23:40 +01:00
parent 8437fce56d
commit c48b20f8f1
3 changed files with 13 additions and 10 deletions

View File

@@ -614,7 +614,8 @@ public class UserManager {
/**
* Specifies if a user is not allowed to enable the oem unlock setting. The default value is
* <code>false</code>.
* <code>false</code>. Setting this restriction has no effect if the bootloader is already
* unlocked.
*
* @see DevicePolicyManager#addUserRestriction(ComponentName, String)
* @see DevicePolicyManager#clearUserRestriction(ComponentName, String)

View File

@@ -163,10 +163,9 @@ public class PersistentDataBlockManager {
/**
* Retrieves available information about this device's flash lock state.
*
* @return FLASH_LOCK_STATE_LOCKED if device bootloader is locked,
* FLASH_LOCK_STATE_UNLOCKED if device bootloader is unlocked,
* or FLASH_LOCK_STATE unknown if this information cannot be ascertained
* on this device.
* @return {@link #FLASH_LOCK_LOCKED} if device bootloader is locked,
* {@link #FLASH_LOCK_UNLOCKED} if device bootloader is unlocked, or {@link #FLASH_LOCK_UNKNOWN}
* if this information cannot be ascertained on this device.
*/
@FlashLockState
public int getFlashLockState() {

View File

@@ -26,11 +26,9 @@ import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.service.persistentdata.PersistentDataBlockManager;
@@ -188,8 +186,7 @@ public class UserRestrictionsUtils {
serializer.endTag(null, tag);
}
public static void readRestrictions(XmlPullParser parser, Bundle restrictions)
throws IOException {
public static void readRestrictions(XmlPullParser parser, Bundle restrictions) {
for (String key : USER_RESTRICTIONS) {
final String value = parser.getAttributeValue(null, key);
if (value != null) {
@@ -437,7 +434,13 @@ public class UserRestrictionsUtils {
if (newValue) {
PersistentDataBlockManager manager = (PersistentDataBlockManager) context
.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
if (manager != null && manager.getOemUnlockEnabled()) {
if (manager != null
&& manager.getOemUnlockEnabled()
&& manager.getFlashLockState()
!= PersistentDataBlockManager.FLASH_LOCK_UNLOCKED) {
// Only disable OEM unlock if the bootloader is locked. If it's already
// unlocked, setting the OEM unlock enabled flag to false has no effect
// (the bootloader would remain unlocked).
manager.setOemUnlockEnabled(false);
}
}