Loading core/java/android/app/trust/ITrustListener.aidl +4 −1 Original line number Diff line number Diff line Loading @@ -16,13 +16,16 @@ */ package android.app.trust; import java.util.List; /** * Private API to be notified about trust changes. * * {@hide} */ oneway interface ITrustListener { void onTrustChanged(boolean enabled, int userId, int flags); void onTrustChanged(boolean enabled, int userId, int flags, in List<String> trustGrantedMessages); void onTrustManagedChanged(boolean managed, int userId); void onTrustError(in CharSequence message); } No newline at end of file core/java/android/app/trust/TrustManager.java +15 −4 Original line number Diff line number Diff line Loading @@ -29,6 +29,9 @@ import android.os.Message; import android.os.RemoteException; import android.util.ArrayMap; import java.util.ArrayList; import java.util.List; /** * See {@link com.android.server.trust.TrustManagerService} * @hide Loading @@ -43,6 +46,7 @@ public class TrustManager { private static final String TAG = "TrustManager"; private static final String DATA_FLAGS = "initiatedByUser"; private static final String DATA_MESSAGE = "message"; private static final String DATA_GRANTED_MESSAGES = "grantedMessages"; private final ITrustManager mService; private final ArrayMap<TrustListener, ITrustListener> mTrustListeners; Loading Loading @@ -152,12 +156,15 @@ public class TrustManager { try { ITrustListener.Stub iTrustListener = new ITrustListener.Stub() { @Override public void onTrustChanged(boolean enabled, int userId, int flags) { public void onTrustChanged(boolean enabled, int userId, int flags, List<String> trustGrantedMessages) { Message m = mHandler.obtainMessage(MSG_TRUST_CHANGED, (enabled ? 1 : 0), userId, trustListener); if (flags != 0) { m.getData().putInt(DATA_FLAGS, flags); } m.getData().putCharSequenceArrayList( DATA_GRANTED_MESSAGES, (ArrayList) trustGrantedMessages); m.sendToTarget(); } Loading Loading @@ -244,7 +251,8 @@ public class TrustManager { switch(msg.what) { case MSG_TRUST_CHANGED: int flags = msg.peekData() != null ? msg.peekData().getInt(DATA_FLAGS) : 0; ((TrustListener)msg.obj).onTrustChanged(msg.arg1 != 0, msg.arg2, flags); ((TrustListener) msg.obj).onTrustChanged(msg.arg1 != 0, msg.arg2, flags, msg.getData().getStringArrayList(DATA_GRANTED_MESSAGES)); break; case MSG_TRUST_MANAGED_CHANGED: ((TrustListener)msg.obj).onTrustManagedChanged(msg.arg1 != 0, msg.arg2); Loading @@ -265,8 +273,11 @@ public class TrustManager { * @param flags Flags specified by the trust agent when granting trust. See * {@link android.service.trust.TrustAgentService#grantTrust(CharSequence, long, int) * TrustAgentService.grantTrust(CharSequence, long, int)}. * @param trustGrantedMessages Messages to display to the user when trust has been granted * by one or more trust agents. */ void onTrustChanged(boolean enabled, int userId, int flags); void onTrustChanged(boolean enabled, int userId, int flags, List<String> trustGrantedMessages); /** * Reports that whether trust is managed has changed Loading packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +15 −1 Original line number Diff line number Diff line Loading @@ -437,7 +437,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } @Override public void onTrustChanged(boolean enabled, int userId, int flags) { public void onTrustChanged(boolean enabled, int userId, int flags, List<String> trustGrantedMessages) { Assert.isMainThread(); boolean wasTrusted = mUserHasTrust.get(userId, false); mUserHasTrust.put(userId, enabled); Loading @@ -459,6 +460,19 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } } } if (KeyguardUpdateMonitor.getCurrentUser() == userId && getUserHasTrust(userId)) { CharSequence message = null; if (trustGrantedMessages != null && trustGrantedMessages.size() > 0) { message = trustGrantedMessages.get(0); // for now only shows the first in the list } for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { cb.showTrustGrantedMessage(message); } } } } @Override Loading packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java +7 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import android.os.SystemClock; import android.telephony.TelephonyManager; import android.view.WindowManagerPolicyConstants; import androidx.annotation.Nullable; import com.android.settingslib.fuelgauge.BatteryStatus; import com.android.systemui.statusbar.KeyguardIndicationController; Loading Loading @@ -215,6 +217,11 @@ public class KeyguardUpdateMonitorCallback { */ public void onTrustGrantedWithFlags(int flags, int userId) { } /** * Called when setting the trust granted message. */ public void showTrustGrantedMessage(@Nullable CharSequence message) { } /** * Called when a biometric has been acquired. * <p> Loading packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java +22 −4 Original line number Diff line number Diff line Loading @@ -107,6 +107,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.MockitoSession; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicBoolean; Loading Loading @@ -175,6 +176,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { private LatencyTracker mLatencyTracker; @Captor private ArgumentCaptor<StatusBarStateController.StateListener> mStatusBarStateListenerCaptor; @Mock private KeyguardUpdateMonitorCallback mTestCallback; // Direct executor private Executor mBackgroundExecutor = Runnable::run; private Executor mMainExecutor = Runnable::run; Loading Loading @@ -252,11 +255,13 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { verify(mStatusBarStateController).addCallback(mStatusBarStateListenerCaptor.capture()); mStatusBarStateListener = mStatusBarStateListenerCaptor.getValue(); mKeyguardUpdateMonitor.registerCallback(mTestCallback); } @After public void tearDown() { mMockitoSession.finishMocking(); mKeyguardUpdateMonitor.removeCallback(mTestCallback); mKeyguardUpdateMonitor.destroy(); } Loading Loading @@ -596,7 +601,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { mTestableLooper.processAllMessages(); when(mKeyguardBypassController.canBypass()).thenReturn(true); mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */); KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */, new ArrayList<>()); mKeyguardUpdateMonitor.onKeyguardVisibilityChanged(true); verify(mFaceManager).authenticate(any(), any(), any(), any(), anyInt(), anyBoolean()); } Loading @@ -606,7 +612,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { mKeyguardUpdateMonitor.dispatchStartedWakingUp(); mTestableLooper.processAllMessages(); mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */); KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */, new ArrayList<>()); mKeyguardUpdateMonitor.onKeyguardVisibilityChanged(true); verify(mFaceManager, never()).authenticate(any(), any(), any(), any(), anyInt(), anyBoolean()); Loading Loading @@ -751,7 +757,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { @Test public void testGetUserCanSkipBouncer_whenTrust() { int user = KeyguardUpdateMonitor.getCurrentUser(); mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, user, 0 /* flags */); mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, user, 0 /* flags */, new ArrayList<>()); assertThat(mKeyguardUpdateMonitor.getUserCanSkipBouncer(user)).isTrue(); } Loading Loading @@ -982,7 +989,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { // WHEN trust is enabled (ie: via smartlock) mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */); KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */, new ArrayList<>()); // THEN we shouldn't listen for udfps assertThat(mKeyguardUpdateMonitor.shouldListenForFingerprint(true)).isEqualTo(false); Loading Loading @@ -1066,6 +1073,17 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { anyBoolean()); } @Test public void testShowTrustGrantedMessage_onTrustGranted() { // WHEN trust is enabled (ie: via some trust agent) with a trustGranted string mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */, Arrays.asList("Unlocked by wearable")); // THEN the showTrustGrantedMessage should be called with the first message verify(mTestCallback).showTrustGrantedMessage("Unlocked by wearable"); } private void setKeyguardBouncerVisibility(boolean isVisible) { mKeyguardUpdateMonitor.sendKeyguardBouncerChanged(isVisible); mTestableLooper.processAllMessages(); Loading Loading
core/java/android/app/trust/ITrustListener.aidl +4 −1 Original line number Diff line number Diff line Loading @@ -16,13 +16,16 @@ */ package android.app.trust; import java.util.List; /** * Private API to be notified about trust changes. * * {@hide} */ oneway interface ITrustListener { void onTrustChanged(boolean enabled, int userId, int flags); void onTrustChanged(boolean enabled, int userId, int flags, in List<String> trustGrantedMessages); void onTrustManagedChanged(boolean managed, int userId); void onTrustError(in CharSequence message); } No newline at end of file
core/java/android/app/trust/TrustManager.java +15 −4 Original line number Diff line number Diff line Loading @@ -29,6 +29,9 @@ import android.os.Message; import android.os.RemoteException; import android.util.ArrayMap; import java.util.ArrayList; import java.util.List; /** * See {@link com.android.server.trust.TrustManagerService} * @hide Loading @@ -43,6 +46,7 @@ public class TrustManager { private static final String TAG = "TrustManager"; private static final String DATA_FLAGS = "initiatedByUser"; private static final String DATA_MESSAGE = "message"; private static final String DATA_GRANTED_MESSAGES = "grantedMessages"; private final ITrustManager mService; private final ArrayMap<TrustListener, ITrustListener> mTrustListeners; Loading Loading @@ -152,12 +156,15 @@ public class TrustManager { try { ITrustListener.Stub iTrustListener = new ITrustListener.Stub() { @Override public void onTrustChanged(boolean enabled, int userId, int flags) { public void onTrustChanged(boolean enabled, int userId, int flags, List<String> trustGrantedMessages) { Message m = mHandler.obtainMessage(MSG_TRUST_CHANGED, (enabled ? 1 : 0), userId, trustListener); if (flags != 0) { m.getData().putInt(DATA_FLAGS, flags); } m.getData().putCharSequenceArrayList( DATA_GRANTED_MESSAGES, (ArrayList) trustGrantedMessages); m.sendToTarget(); } Loading Loading @@ -244,7 +251,8 @@ public class TrustManager { switch(msg.what) { case MSG_TRUST_CHANGED: int flags = msg.peekData() != null ? msg.peekData().getInt(DATA_FLAGS) : 0; ((TrustListener)msg.obj).onTrustChanged(msg.arg1 != 0, msg.arg2, flags); ((TrustListener) msg.obj).onTrustChanged(msg.arg1 != 0, msg.arg2, flags, msg.getData().getStringArrayList(DATA_GRANTED_MESSAGES)); break; case MSG_TRUST_MANAGED_CHANGED: ((TrustListener)msg.obj).onTrustManagedChanged(msg.arg1 != 0, msg.arg2); Loading @@ -265,8 +273,11 @@ public class TrustManager { * @param flags Flags specified by the trust agent when granting trust. See * {@link android.service.trust.TrustAgentService#grantTrust(CharSequence, long, int) * TrustAgentService.grantTrust(CharSequence, long, int)}. * @param trustGrantedMessages Messages to display to the user when trust has been granted * by one or more trust agents. */ void onTrustChanged(boolean enabled, int userId, int flags); void onTrustChanged(boolean enabled, int userId, int flags, List<String> trustGrantedMessages); /** * Reports that whether trust is managed has changed Loading
packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +15 −1 Original line number Diff line number Diff line Loading @@ -437,7 +437,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } @Override public void onTrustChanged(boolean enabled, int userId, int flags) { public void onTrustChanged(boolean enabled, int userId, int flags, List<String> trustGrantedMessages) { Assert.isMainThread(); boolean wasTrusted = mUserHasTrust.get(userId, false); mUserHasTrust.put(userId, enabled); Loading @@ -459,6 +460,19 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } } } if (KeyguardUpdateMonitor.getCurrentUser() == userId && getUserHasTrust(userId)) { CharSequence message = null; if (trustGrantedMessages != null && trustGrantedMessages.size() > 0) { message = trustGrantedMessages.get(0); // for now only shows the first in the list } for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { cb.showTrustGrantedMessage(message); } } } } @Override Loading
packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java +7 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import android.os.SystemClock; import android.telephony.TelephonyManager; import android.view.WindowManagerPolicyConstants; import androidx.annotation.Nullable; import com.android.settingslib.fuelgauge.BatteryStatus; import com.android.systemui.statusbar.KeyguardIndicationController; Loading Loading @@ -215,6 +217,11 @@ public class KeyguardUpdateMonitorCallback { */ public void onTrustGrantedWithFlags(int flags, int userId) { } /** * Called when setting the trust granted message. */ public void showTrustGrantedMessage(@Nullable CharSequence message) { } /** * Called when a biometric has been acquired. * <p> Loading
packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java +22 −4 Original line number Diff line number Diff line Loading @@ -107,6 +107,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.MockitoSession; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicBoolean; Loading Loading @@ -175,6 +176,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { private LatencyTracker mLatencyTracker; @Captor private ArgumentCaptor<StatusBarStateController.StateListener> mStatusBarStateListenerCaptor; @Mock private KeyguardUpdateMonitorCallback mTestCallback; // Direct executor private Executor mBackgroundExecutor = Runnable::run; private Executor mMainExecutor = Runnable::run; Loading Loading @@ -252,11 +255,13 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { verify(mStatusBarStateController).addCallback(mStatusBarStateListenerCaptor.capture()); mStatusBarStateListener = mStatusBarStateListenerCaptor.getValue(); mKeyguardUpdateMonitor.registerCallback(mTestCallback); } @After public void tearDown() { mMockitoSession.finishMocking(); mKeyguardUpdateMonitor.removeCallback(mTestCallback); mKeyguardUpdateMonitor.destroy(); } Loading Loading @@ -596,7 +601,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { mTestableLooper.processAllMessages(); when(mKeyguardBypassController.canBypass()).thenReturn(true); mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */); KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */, new ArrayList<>()); mKeyguardUpdateMonitor.onKeyguardVisibilityChanged(true); verify(mFaceManager).authenticate(any(), any(), any(), any(), anyInt(), anyBoolean()); } Loading @@ -606,7 +612,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { mKeyguardUpdateMonitor.dispatchStartedWakingUp(); mTestableLooper.processAllMessages(); mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */); KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */, new ArrayList<>()); mKeyguardUpdateMonitor.onKeyguardVisibilityChanged(true); verify(mFaceManager, never()).authenticate(any(), any(), any(), any(), anyInt(), anyBoolean()); Loading Loading @@ -751,7 +757,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { @Test public void testGetUserCanSkipBouncer_whenTrust() { int user = KeyguardUpdateMonitor.getCurrentUser(); mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, user, 0 /* flags */); mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, user, 0 /* flags */, new ArrayList<>()); assertThat(mKeyguardUpdateMonitor.getUserCanSkipBouncer(user)).isTrue(); } Loading Loading @@ -982,7 +989,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { // WHEN trust is enabled (ie: via smartlock) mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */); KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */, new ArrayList<>()); // THEN we shouldn't listen for udfps assertThat(mKeyguardUpdateMonitor.shouldListenForFingerprint(true)).isEqualTo(false); Loading Loading @@ -1066,6 +1073,17 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { anyBoolean()); } @Test public void testShowTrustGrantedMessage_onTrustGranted() { // WHEN trust is enabled (ie: via some trust agent) with a trustGranted string mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */, Arrays.asList("Unlocked by wearable")); // THEN the showTrustGrantedMessage should be called with the first message verify(mTestCallback).showTrustGrantedMessage("Unlocked by wearable"); } private void setKeyguardBouncerVisibility(boolean isVisible) { mKeyguardUpdateMonitor.sendKeyguardBouncerChanged(isVisible); mTestableLooper.processAllMessages(); Loading