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

Commit 1b2f57a0 authored by Oliver Scott's avatar Oliver Scott Committed by Mohammed Althaf T
Browse files

SetupWizard: Turn off OEM unlocking during initial setup if bootloader is locked

* Some /e/ OS devices is meant to be used with a locked bootloader, and
  OEM unlocking set to off.
* Does what Settings -> Developer Options -> OEM unlocking off does but silently,
  wihout having to enable Developer Options.
* If you've locked the bootloader, and the device has booted into SetupWizard,
  it should be safe to run this since at that point you can most definitely
  get into Settings and run this yourself as well, and we do have the same
  kinds of checks here.
* Additionally grant missing permissions which was missing in CalyxOS.

Change-Id: I739d0808fc5c66656128f755451441de96764a90
parent 2e769e16
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@
    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
    <uses-permission android:name="android.permission.MANAGE_USERS" />
    <uses-permission android:name="android.permission.MANAGE_USERS" />
    <uses-permission android:name="android.permission.MANAGE_USER_OEM_UNLOCK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
    <uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
    <uses-permission android:name="lineageos.permission.HARDWARE_ABSTRACTION_ACCESS" />
    <uses-permission android:name="lineageos.permission.HARDWARE_ABSTRACTION_ACCESS" />
+1 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@
        <permission name="android.permission.INTERACT_ACROSS_USERS"/>
        <permission name="android.permission.INTERACT_ACROSS_USERS"/>
        <permission name="android.permission.LOCAL_MAC_ADDRESS"/>
        <permission name="android.permission.LOCAL_MAC_ADDRESS"/>
        <permission name="android.permission.MANAGE_USERS"/>
        <permission name="android.permission.MANAGE_USERS"/>
        <permission name="android.permission.MANAGE_USER_OEM_UNLOCK_STATE" />
        <permission name="android.permission.READ_PRIVILEGED_PHONE_STATE"/>
        <permission name="android.permission.READ_PRIVILEGED_PHONE_STATE"/>
        <permission name="android.permission.SET_TIME"/>
        <permission name="android.permission.SET_TIME"/>
        <permission name="android.permission.SET_TIME_ZONE"/>
        <permission name="android.permission.SET_TIME_ZONE"/>
+8 −0
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2013 The CyanogenMod Project
 * Copyright (C) 2013 The CyanogenMod Project
 * Copyright (C) 2017-2021 The LineageOS Project
 * Copyright (C) 2017-2021 The LineageOS Project
 * Copyright (C) 2022 The Calyx Institute
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with 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.app.Application;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
import android.service.oemlock.OemLockManager;
import android.util.Log;
import android.util.Log;


import org.lineageos.setupwizard.util.NetworkMonitor;
import org.lineageos.setupwizard.util.NetworkMonitor;
@@ -97,6 +99,12 @@ public class SetupWizardApp extends Application {
        SetupWizardUtils.disableComponentsForMissingFeatures(this);
        SetupWizardUtils.disableComponentsForMissingFeatures(this);
        SetupWizardUtils.setMobileDataEnabled(this, false);
        SetupWizardUtils.setMobileDataEnabled(this, false);
        mHandler.postDelayed(mRadioTimeoutRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
        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() {
    public boolean isRadioReady() {
+18 −0
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2013 The CyanogenMod Project
 * Copyright (C) 2013 The CyanogenMod Project
 * Copyright (C) 2017 The LineageOS Project
 * Copyright (C) 2017 The LineageOS Project
 * Copyright (C) 2022 The Calyx Institute
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with 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.os.UserHandle;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager;
import android.provider.Settings;
import android.provider.Settings;
import android.service.oemlock.OemLockManager;
import android.telephony.ServiceState;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
@@ -258,6 +260,22 @@ public class SetupWizardUtils {
        return PhoneMonitor.getInstance().simMissing();
        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) {
    public static void disableComponentsForMissingFeatures(Context context) {
        if (!hasLeanback(context)) {
        if (!hasLeanback(context)) {
            disableComponent(context, BluetoothSetupActivity.class);
            disableComponent(context, BluetoothSetupActivity.class);