From 2b5d4ed3a35e90c15a1eaaec1d3ea7ede3f31d62 Mon Sep 17 00:00:00 2001 From: ning Zhu Date: Fri, 21 Oct 2022 16:09:43 +0800 Subject: [PATCH] Move "mVold.onSecureKeyguardStateChanged" to handler thread When insert a U disk or sdcard, if fsck or mount takes a long time, it will take several seconds for the screen to light up because the lock of vold process cannot be obtained, so we move the time-consuming method into the handler thread and use the new and old values of mSecureKeyguardShowing to determine whether a binder call is required. Test: Manual test Bug: 259900790 Change-Id: Ie0285d95c49bf37504ccc2821b856774d04806f7 Signed-off-by: zhuning3 --- .../android/server/StorageManagerService.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index f7b05f2b895a0..115e3409327d3 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -734,6 +734,7 @@ class StorageManagerService extends IStorageManager.Stub private static final int H_COMPLETE_UNLOCK_USER = 14; private static final int H_VOLUME_STATE_CHANGED = 15; private static final int H_CLOUD_MEDIA_PROVIDER_CHANGED = 16; + private static final int H_SECURE_KEYGUARD_STATE_CHANGED = 17; class StorageManagerServiceHandler extends Handler { public StorageManagerServiceHandler(Looper looper) { @@ -873,6 +874,14 @@ class StorageManagerService extends IStorageManager.Stub } break; } + case H_SECURE_KEYGUARD_STATE_CHANGED: { + try { + mVold.onSecureKeyguardStateChanged((boolean) msg.obj); + } catch (Exception e) { + Slog.wtf(TAG, e); + } + break; + } } } } @@ -1332,12 +1341,12 @@ class StorageManagerService extends IStorageManager.Stub public void onKeyguardStateChanged(boolean isShowing) { // Push down current secure keyguard status so that we ignore malicious // USB devices while locked. - mSecureKeyguardShowing = isShowing + boolean isSecureKeyguardShowing = isShowing && mContext.getSystemService(KeyguardManager.class).isDeviceSecure(mCurrentUserId); - try { - mVold.onSecureKeyguardStateChanged(mSecureKeyguardShowing); - } catch (Exception e) { - Slog.wtf(TAG, e); + if (mSecureKeyguardShowing != isSecureKeyguardShowing) { + mSecureKeyguardShowing = isSecureKeyguardShowing; + mHandler.obtainMessage(H_SECURE_KEYGUARD_STATE_CHANGED, mSecureKeyguardShowing) + .sendToTarget(); } }