diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9a3f3d7bb92db76cec44f5d26f7ef1a3f22f3eea..8b5016bf4566d5958e32cc8097543eeb740e6d0a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -37,6 +37,7 @@
+
diff --git a/privapp_whitelist_org.lineageos.setupwizard.xml b/privapp_whitelist_org.lineageos.setupwizard.xml
index 98e0a0f4dfe96298ea827e7bbe92d63e4f44b8b2..b17cd818d1014d2330934be5f1fcc41c844604fe 100644
--- a/privapp_whitelist_org.lineageos.setupwizard.xml
+++ b/privapp_whitelist_org.lineageos.setupwizard.xml
@@ -23,6 +23,7 @@
+
diff --git a/src/org/lineageos/setupwizard/SetupWizardApp.java b/src/org/lineageos/setupwizard/SetupWizardApp.java
index 3bfaa2d25b350e0ea20e6ab5b6bd573afa0ab5e5..c40c8a53297f94e96eb9b08d728e9d56cb956266 100644
--- a/src/org/lineageos/setupwizard/SetupWizardApp.java
+++ b/src/org/lineageos/setupwizard/SetupWizardApp.java
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2013 The CyanogenMod Project
* Copyright (C) 2017-2021 The LineageOS Project
+ * Copyright (C) 2022 The Calyx Institute
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +22,7 @@ package org.lineageos.setupwizard;
import android.app.Application;
import android.os.Bundle;
import android.os.Handler;
+import android.service.oemlock.OemLockManager;
import android.util.Log;
import org.lineageos.setupwizard.util.NetworkMonitor;
@@ -97,6 +99,12 @@ public class SetupWizardApp extends Application {
SetupWizardUtils.disableComponentsForMissingFeatures(this);
SetupWizardUtils.setMobileDataEnabled(this, false);
mHandler.postDelayed(mRadioTimeoutRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
+ // If the bootloader is locked, and OEM unlocking is allowed, turn it off
+ if (SetupWizardUtils.isOwner()
+ && !SetupWizardUtils.isBootloaderUnlocked(this)
+ && SetupWizardUtils.isOemunlockAllowed(this)) {
+ getSystemService(OemLockManager.class).setOemUnlockAllowedByUser(false);
+ }
}
public boolean isRadioReady() {
diff --git a/src/org/lineageos/setupwizard/WelcomeActivity.java b/src/org/lineageos/setupwizard/WelcomeActivity.java
index eb60f275fa794f63a9fbdf3720ca596b9f4d46eb..63dcc54ed7d529d427f3e6a11561935ceb095279 100644
--- a/src/org/lineageos/setupwizard/WelcomeActivity.java
+++ b/src/org/lineageos/setupwizard/WelcomeActivity.java
@@ -18,13 +18,10 @@
package org.lineageos.setupwizard;
import android.os.Bundle;
-import android.os.Handler;
-import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import org.lineageos.setupwizard.util.EnableAccessibilityController;
-import org.lineageos.setupwizard.util.SetupWizardUtils;
public class WelcomeActivity extends BaseSetupWizardActivity {
@@ -33,9 +30,6 @@ public class WelcomeActivity extends BaseSetupWizardActivity {
private View mRootView;
private EnableAccessibilityController mEnableAccessibilityController;
- private int mVolumeUpCount = 0;
- private Handler mHandler = new Handler();
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -58,30 +52,6 @@ public class WelcomeActivity extends BaseSetupWizardActivity {
startEmergencyDialer();
}
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
- mVolumeUpCount++;
- if (mVolumeUpCount == 1) {
- // Schedule a runnable to reset the count after 1 second
- mHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- mVolumeUpCount = 0;
- }
- }, 1000); // 1 second delay
- }
- } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && mVolumeUpCount == 2) {
- // If the volume down key is pressed and the volume up count is 2
- // Finish the setup wizard and enable the status bar
- SetupWizardUtils.finishSetupWizard(getApplicationContext());
- SetupWizardUtils.enableStatusBar(getApplicationContext());
- finish();
- }
-
- return super.onKeyDown(keyCode, event);
- }
-
@Override
protected int getLayoutResId() {
return R.layout.welcome_activity;
diff --git a/src/org/lineageos/setupwizard/util/SetupWizardUtils.java b/src/org/lineageos/setupwizard/util/SetupWizardUtils.java
index e9a597833613a01d07f9e4822638a5d45b9e0b9e..e16124f438e6c540b5e7661c74a09f39b41909a7 100644
--- a/src/org/lineageos/setupwizard/util/SetupWizardUtils.java
+++ b/src/org/lineageos/setupwizard/util/SetupWizardUtils.java
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2013 The CyanogenMod Project
* Copyright (C) 2017 The LineageOS Project
+ * Copyright (C) 2022 The Calyx Institute
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,6 +50,7 @@ import android.os.SystemProperties;
import android.os.UserHandle;
import android.net.ConnectivityManager;
import android.provider.Settings;
+import android.service.oemlock.OemLockManager;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -258,6 +260,22 @@ public class SetupWizardUtils {
return PhoneMonitor.getInstance().simMissing();
}
+ public static boolean isBootloaderUnlocked(Context context) {
+ OemLockManager oemLockManager = context.getSystemService(OemLockManager.class);
+ if (oemLockManager != null) {
+ return oemLockManager.isDeviceOemUnlocked();
+ }
+ return true; // Default to unlocked
+ }
+
+ public static boolean isOemunlockAllowed(Context context) {
+ OemLockManager oemLockManager = context.getSystemService(OemLockManager.class);
+ if (oemLockManager != null) {
+ return oemLockManager.isOemUnlockAllowed();
+ }
+ return true; // Default to unlock allowed
+ }
+
public static void disableComponentsForMissingFeatures(Context context) {
if (!hasLeanback(context)) {
disableComponent(context, BluetoothSetupActivity.class);