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

Commit cfe0f426 authored by Sahil Sonar's avatar Sahil Sonar 💬 Committed by Nishith Khanna
Browse files

oemlock: Skip OEM unlock check for Samsung devices

  - When parental control is enabled "DISALLOW_FACTORY_RESET" disables OEM unlocking.
  - This fixes Samsung devices failing to boot with "red state".
parent 5c65c7fc
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.annotation.Nullable;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.SystemProperties;
@@ -41,6 +42,8 @@ import com.android.server.pm.UserManagerInternal;
import com.android.server.pm.UserManagerInternal.UserRestrictionsListener;
import com.android.server.pm.UserRestrictionsUtils;

import java.util.Locale;

/**
 * Service for managing the OEM lock state of the device.
 *
@@ -98,6 +101,7 @@ public class OemLockService extends SystemService {
        @Override
        public void onUserRestrictionsChanged(int userId, Bundle newRestrictions,
                Bundle prevRestrictions) {
            if (isSamsungDevice()) return;
            // The admin can prevent OEM unlock with the DISALLOW_FACTORY_RESET user restriction
            if (UserRestrictionsUtils.restrictionsChanged(prevRestrictions, newRestrictions,
                     UserManager.DISALLOW_FACTORY_RESET)) {
@@ -258,6 +262,10 @@ public class OemLockService extends SystemService {
                .hasUserRestriction(UserManager.DISALLOW_FACTORY_RESET, UserHandle.SYSTEM);
    }

    private boolean isSamsungDevice() {
        return Build.MANUFACTURER.toLowerCase(Locale.US).contains("samsung");
    }

    private void enforceUserIsAdmin() {
        final int userId = UserHandle.getCallingUserId();
        final long token = Binder.clearCallingIdentity();