Fix thread safety issues;

There are two threads can modify "mLastChanged" and "mScreenState" variables:
1. onFinishedWakingUp()/onFinishedGoingToSleep() are called from main thread in system_server;
2. setDeviceFolded() is called from android.display thread in
system_server.

Otherwise, NullPointerException might be throw when invoke method 'long java.lang.Long.longValue()'.

Test: press power key to wake up the device and fold the device at the
same time.

Change-Id: I3a0f1862548f2e567baa8a4a615906dbf87a8243
Signed-off-by: jiayongqiang <jiayongqiang@xiaomi.com>
This commit is contained in:
jiayongqiang
2021-08-11 10:12:50 +08:00
parent 5a5c3d7562
commit 079495ac63

View File

@@ -44,8 +44,8 @@ class DisplayFoldDurationLogger {
@Retention(RetentionPolicy.SOURCE)
public @interface ScreenState {}
private @ScreenState int mScreenState = SCREEN_STATE_UNKNOWN;
private Long mLastChanged = null;
private volatile @ScreenState int mScreenState = SCREEN_STATE_UNKNOWN;
private volatile Long mLastChanged = null;
private static final int LOG_SUBTYPE_UNFOLDED = 0;
private static final int LOG_SUBTYPE_FOLDED = 1;