DO NOT MERGE Fix mTrustManager NPE

When isDeviceLocked function is called in KeyguardManager, mTrustManager
can be null. To prevent NPE during this call, moved the mTrustManager
access to a synchronized getter.

Test: run cts -c android.print.cts.PageRangeAdjustmentTest -m testWantedPagesAlreadyWrittenForPreview
Test: run cts -c android.accessibilityservice.cts.AccessibilityEndToEndTest -m testTypeViewTextChangedAccessibilityEvent
Test: run cts -c com.android.cts.appsecurity.DocumentsTest -m testCreateExisting
Test: run cts -c com.android.cts.devicepolicy.ManagedProfileTest -m testCrossProfileCopyPaste
Test: run cts -c android.text.method.cts.PasswordTransformationMethodTest

Bug: 69471788
Change-Id: I4b4a0bb3b127424fecdad85ba559ce861af165e4
This commit is contained in:
Siyamed Sinir
2017-11-28 13:29:18 -08:00
parent 4158c9fbf3
commit a381c4ced3

View File

@@ -249,7 +249,7 @@ public class KeyguardManager {
*/
public boolean isDeviceLocked(int userId) {
try {
return mTrustManager.isDeviceLocked(userId);
return getTrustManager().isDeviceLocked(userId);
} catch (RemoteException e) {
return false;
}
@@ -274,12 +274,20 @@ public class KeyguardManager {
*/
public boolean isDeviceSecure(int userId) {
try {
return mTrustManager.isDeviceSecure(userId);
return getTrustManager().isDeviceSecure(userId);
} catch (RemoteException e) {
return false;
}
}
private synchronized ITrustManager getTrustManager() {
if (mTrustManager == null) {
mTrustManager = ITrustManager.Stub.asInterface(
ServiceManager.getService(Context.TRUST_SERVICE));
}
return mTrustManager;
}
/**
* @deprecated Use {@link android.view.WindowManager.LayoutParams#FLAG_DISMISS_KEYGUARD}
* and/or {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED}