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

Commit 7b1ec94f authored by Mill Chen's avatar Mill Chen
Browse files

Default to enable oem-unlocking preference

Whether the device supports carriorlock or not, oem-unlocking preference
will be enabled by default, except sdk_gphone_x86-eng target.

Fixes: 129982117
Test: emulator, robotest
Change-Id: I02af50e425fe5a93c244bbf8fe8bd2682275974f
parent 3d46fcd5
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -21,13 +21,12 @@ import static com.android.settings.development.DevelopmentOptionsActivityRequest
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Build;
import android.os.UserHandle;
import android.os.UserManager;
import android.service.oemlock.OemLockManager;
import android.telephony.TelephonyManager;
import android.util.Log;

import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -56,15 +55,11 @@ public class OemUnlockPreferenceController extends DeveloperOptionsPreferenceCon
            DevelopmentSettingsDashboardFragment fragment) {
        super(context);

        if (context.getPackageManager().hasSystemFeature(PackageManager
                    .FEATURE_TELEPHONY_CARRIERLOCK)) {
            mOemLockManager = (OemLockManager) context.getSystemService(Context.OEM_LOCK_SERVICE);
        } else {
        if (Build.IS_EMULATOR && Build.IS_ENG) {
            mOemLockManager = null;
            Log.i(TAG, "Missing FEATURE_TELEPHONY_CARRIERLOCK, OemUnlock Preference" +
                    " Controller disabled.");
        } else {
            mOemLockManager = (OemLockManager) context.getSystemService(Context.OEM_LOCK_SERVICE);
        }

        mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
        mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        mFragment = fragment;
+16 −5
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Build;
import android.os.UserManager;
import android.service.oemlock.OemLockManager;
import android.telephony.TelephonyManager;
@@ -48,6 +49,8 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;

@RunWith(RobolectricTestRunner.class)
public class OemUnlockPreferenceControllerTest {
@@ -93,11 +96,19 @@ public class OemUnlockPreferenceControllerTest {
    }

    @Test
    public void OemUnlockPreferenceController_shouldNotCrashWhenMissingFEATURE_TELEPHONY_CARRIERLOCK() {
        when(mContext.getPackageManager().hasSystemFeature(PackageManager
                    .FEATURE_TELEPHONY_CARRIERLOCK)).thenReturn(false);
        when(mContext.getSystemService(Context.OEM_LOCK_SERVICE)).thenThrow
            (new RuntimeException());
    @Config(qualifiers = "mcc999")
    public void OemUnlockPreferenceController_shouldNotCrashInEmulatorEngBuild() {
        ReflectionHelpers.setStaticField(Build.class, "IS_EMULATOR", true);
        ReflectionHelpers.setStaticField(Build.class, "IS_ENG", true);

        new OemUnlockPreferenceController(mContext, mActivity, mFragment);
    }

    @Test
    @Config(qualifiers = "mcc999")
    public void OemUnlockPreferenceController_shouldNotCrashInOtherBuild() {
        ReflectionHelpers.setStaticField(Build.class, "IS_EMULATOR", false);
        ReflectionHelpers.setStaticField(Build.class, "IS_ENG", false);

        new OemUnlockPreferenceController(mContext, mActivity, mFragment);
    }