Avoid oem-unlock preference controller crash

Openning developer options will crash if the device doesn't support
oem_unlock module. We added a condition to check that the
oem_unlock_supported property is existing before getting OemLockManager.

Fixes: 136108893
Test: robotests
Test: lunch aosp_cf_x86_phone-eng; m dist; acloud create --local-image
Test: lunch sdk_gphone_x86-eng; make; emulator
Change-Id: I2c1821fbdd18e3e8162a492e1e15dd34c8aec803
This commit is contained in:
Mill Chen
2019-06-28 17:24:22 +08:00
parent 68aa24d365
commit e8bb058d14
2 changed files with 18 additions and 14 deletions

View File

@@ -22,11 +22,13 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.service.oemlock.OemLockManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -43,6 +45,9 @@ public class OemUnlockPreferenceController extends DeveloperOptionsPreferenceCon
private static final String PREFERENCE_KEY = "oem_unlock_enable";
private static final String TAG = "OemUnlockPreferenceController";
private static final String OEM_UNLOCK_SUPPORTED_KEY = "ro.oem_unlock_supported";
private static final String UNSUPPORTED = "-9999";
private static final String SUPPORTED = "1";
private final OemLockManager mOemLockManager;
private final UserManager mUserManager;
@@ -55,8 +60,10 @@ public class OemUnlockPreferenceController extends DeveloperOptionsPreferenceCon
DevelopmentSettingsDashboardFragment fragment) {
super(context);
if (Build.IS_EMULATOR && Build.IS_ENG) {
if (!TextUtils.equals(SystemProperties.get(OEM_UNLOCK_SUPPORTED_KEY, UNSUPPORTED),
SUPPORTED)) {
mOemLockManager = null;
Log.w(TAG, "oem_unlock not supported.");
} else {
mOemLockManager = (OemLockManager) context.getSystemService(Context.OEM_LOCK_SERVICE);
}