Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f89b0298 authored by Mahaver Chopra's avatar Mahaver Chopra Committed by android-build-merger
Browse files

Merge "Disallow OEM unlock when DISALLOW_FACTORY_RESET applies" into nyc-mr1-dev am: dd86aa14

am: 4545f913

* commit '4545f913':
  Disallow OEM unlock when DISALLOW_FACTORY_RESET applies

Change-Id: Ic9d53692abb6b7cd6bdfbf6ce0b666c395d16a07
parents d458c41b 4545f913
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -146,6 +146,15 @@ public class PersistentDataBlockService extends SystemService {
                    "Only the Admin user is allowed to change OEM unlock state");
        }
    }

    private void enforceFactoryResetAllowed() {
        final boolean isOemUnlockRestricted = UserManager.get(mContext)
                .hasUserRestriction(UserManager.DISALLOW_FACTORY_RESET);
        if (isOemUnlockRestricted) {
            throw new SecurityException("OEM unlock is disallowed by DISALLOW_FACTORY_RESET");
        }
    }

    private int getTotalDataSizeLocked(DataInputStream inputStream) throws IOException {
        // skip over checksum
        inputStream.skipBytes(DIGEST_SIZE_BYTES);
@@ -452,7 +461,9 @@ public class PersistentDataBlockService extends SystemService {
                    Settings.Global.OEM_UNLOCK_DISALLOWED, 0) == 1) {
                throw new SecurityException("OEM unlock has been disallowed.");
            }

            if (enabled) {
                enforceFactoryResetAllowed();
            }
            synchronized (mLock) {
                doSetOemUnlockEnabledLocked(enabled);
                computeAndWriteDigestLocked();
+9 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.service.persistentdata.PersistentDataBlockManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.util.Log;
@@ -424,6 +425,14 @@ public class UserRestrictionsUtils {
                            android.provider.Settings.Global.SAFE_BOOT_DISALLOWED,
                            newValue ? 1 : 0);
                    break;
                case UserManager.DISALLOW_FACTORY_RESET:
                    if (newValue) {
                        PersistentDataBlockManager manager = (PersistentDataBlockManager) context
                                .getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
                        if (manager != null) {
                            manager.setOemUnlockEnabled(false);
                        }
                    }
            }
        } finally {
            Binder.restoreCallingIdentity(id);