From f1c7648abfab8902597dd689472f16e8d3af6c25 Mon Sep 17 00:00:00 2001 From: Howard Chen Date: Thu, 6 Jun 2019 11:36:48 +0800 Subject: [PATCH] Stub the oemlock operations when the PersistentDataBlock is not supported The PersistentDataBlockService is not a compulsory component of framework thus we need to handle cases when the PersistentDataBlockService is unavailable. Bug: 132943408 Bug: 123777418 Test: toggle the oemlock in setting menu. Change-Id: I59eec0a4905b588bf261b8447ad4b4e26ba5278d --- .../server/oemlock/PersistentDataBlockLock.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/services/core/java/com/android/server/oemlock/PersistentDataBlockLock.java b/services/core/java/com/android/server/oemlock/PersistentDataBlockLock.java index a1c27d6432f1c..2474b2aa91848 100644 --- a/services/core/java/com/android/server/oemlock/PersistentDataBlockLock.java +++ b/services/core/java/com/android/server/oemlock/PersistentDataBlockLock.java @@ -73,6 +73,10 @@ class PersistentDataBlockLock extends OemLock { // unlocked but doesn't actually do any unlocking. final PersistentDataBlockManager pdbm = (PersistentDataBlockManager) mContext.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE); + if (pdbm == null) { + Slog.w(TAG, "PersistentDataBlock is not supported on this device"); + return; + } pdbm.setOemUnlockEnabled(allowedByDevice); } @@ -80,6 +84,10 @@ class PersistentDataBlockLock extends OemLock { boolean isOemUnlockAllowedByDevice() { final PersistentDataBlockManager pdbm = (PersistentDataBlockManager) mContext.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE); + if (pdbm == null) { + Slog.w(TAG, "PersistentDataBlock is not supported on this device"); + return false; + } return pdbm.getOemUnlockEnabled(); } @@ -91,6 +99,10 @@ class PersistentDataBlockLock extends OemLock { private void disallowUnlockIfNotUnlocked() { final PersistentDataBlockManager pdbm = (PersistentDataBlockManager) mContext.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE); + if (pdbm == null) { + Slog.w(TAG, "PersistentDataBlock is not supported on this device"); + return; + } if (pdbm.getFlashLockState() != PersistentDataBlockManager.FLASH_LOCK_UNLOCKED) { pdbm.setOemUnlockEnabled(false); }