diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c6c1d812d9e7be2f2addd7babb6f46d73e9a82c7..715bdff586f8cd7805b3b8fee1c0de386c1071b7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -38,6 +38,7 @@
+
diff --git a/privapp_whitelist_org.lineageos.setupwizard.xml b/privapp_whitelist_org.lineageos.setupwizard.xml
index 3b1e5b6dc78e6e3c5ac3c7218fb9204f4a71d5b6..955d1c47fa0e73dfa013ccd0c4b941e79dbfbb89 100644
--- a/privapp_whitelist_org.lineageos.setupwizard.xml
+++ b/privapp_whitelist_org.lineageos.setupwizard.xml
@@ -22,6 +22,7 @@
+
diff --git a/src/org/lineageos/setupwizard/SetupWizardApp.java b/src/org/lineageos/setupwizard/SetupWizardApp.java
index acab7cf554f82c6d979665a17bdab0ba61cd2fd0..9789ce1e14aa0b48e6740005f435af510c08295a 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 @@ import android.app.Application;
import android.app.StatusBarManager;
import android.os.Bundle;
import android.os.Handler;
+import android.service.oemlock.OemLockManager;
import android.util.Log;
import org.lineageos.setupwizard.util.NetworkMonitor;
@@ -101,6 +103,12 @@ public class SetupWizardApp extends Application {
SetupWizardUtils.setMobileDataEnabled(this, false);
sStatusBarManager = SetupWizardUtils.disableStatusBar(this);
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 static StatusBarManager getStatusBarManager() {
diff --git a/src/org/lineageos/setupwizard/WelcomeActivity.java b/src/org/lineageos/setupwizard/WelcomeActivity.java
index 665f47bee34846af8382298852fe512ce9f9d932..d550acafddd7fce0ddc9650c513bbd4f6672012c 100644
--- a/src/org/lineageos/setupwizard/WelcomeActivity.java
+++ b/src/org/lineageos/setupwizard/WelcomeActivity.java
@@ -18,15 +18,12 @@
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 com.google.android.setupcompat.util.SystemBarHelper;
import org.lineageos.setupwizard.util.EnableAccessibilityController;
-import org.lineageos.setupwizard.util.SetupWizardUtils;
public class WelcomeActivity extends BaseSetupWizardActivity {
@@ -35,9 +32,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);
@@ -61,30 +55,6 @@ public class WelcomeActivity extends BaseSetupWizardActivity {
public void onBackPressed() {
}
- @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 d29c9169055da8779a5192f6ba252091a3670cde..8b522d57fd4610db46da68852565ad5f0fbf7d59 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-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.
@@ -47,6 +48,7 @@ import android.os.Binder;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
+import android.service.oemlock.OemLockManager;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -289,6 +291,22 @@ public class SetupWizardUtils {
return PhoneMonitor.getInstance().isMultiSimDevice();
}
+ 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);