summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorLucas Dupin <dupin@google.com>2018-01-03 16:03:07 -0800
committerLucas Dupin <dupin@google.com>2018-01-10 14:07:56 -0800
commitef886544599f43e7ffc18b11b2d512b88709527c (patch)
tree768a7b90b33970b7eb02fe907feea3091a329b5c /core/java
parent6198ec6303494026bb1b5b0a6af422defc25e50d (diff)
Allow custom keyguard transient message
TrustAgentServices can now present a transient message on the lock screen or AoD. Bug: 63940122 Test: call TrustAgentService#showKeyguardErrorMessage via service, lock device, wait for message to show up. Change-Id: I222118787a1afb526ce7c90d46c41d0f20d8d912
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/KeyguardManager.java2
-rw-r--r--core/java/android/app/trust/ITrustListener.aidl1
-rw-r--r--core/java/android/app/trust/TrustManager.java29
-rw-r--r--core/java/android/service/trust/ITrustAgentServiceCallback.aidl1
-rw-r--r--core/java/android/service/trust/TrustAgentService.java29
5 files changed, 55 insertions, 7 deletions
diff --git a/core/java/android/app/KeyguardManager.java b/core/java/android/app/KeyguardManager.java
index d0f84c8ee0bb..ed85ca78023e 100644
--- a/core/java/android/app/KeyguardManager.java
+++ b/core/java/android/app/KeyguardManager.java
@@ -499,7 +499,7 @@ public class KeyguardManager {
}
});
} catch (RemoteException e) {
- Log.i(TAG, "Failed to dismiss keyguard: " + e);
+ throw e.rethrowFromSystemServer();
}
}
diff --git a/core/java/android/app/trust/ITrustListener.aidl b/core/java/android/app/trust/ITrustListener.aidl
index 506dd12a36a0..65b024999a5b 100644
--- a/core/java/android/app/trust/ITrustListener.aidl
+++ b/core/java/android/app/trust/ITrustListener.aidl
@@ -24,4 +24,5 @@ package android.app.trust;
oneway interface ITrustListener {
void onTrustChanged(boolean enabled, int userId, int flags);
void onTrustManagedChanged(boolean managed, int userId);
+ void onTrustError(in CharSequence message);
} \ No newline at end of file
diff --git a/core/java/android/app/trust/TrustManager.java b/core/java/android/app/trust/TrustManager.java
index 852cb8e09ddb..8ab0b706a1e2 100644
--- a/core/java/android/app/trust/TrustManager.java
+++ b/core/java/android/app/trust/TrustManager.java
@@ -36,9 +36,11 @@ public class TrustManager {
private static final int MSG_TRUST_CHANGED = 1;
private static final int MSG_TRUST_MANAGED_CHANGED = 2;
+ private static final int MSG_TRUST_ERROR = 3;
private static final String TAG = "TrustManager";
private static final String DATA_FLAGS = "initiatedByUser";
+ private static final String DATA_MESSAGE = "message";
private final ITrustManager mService;
private final ArrayMap<TrustListener, ITrustListener> mTrustListeners;
@@ -148,6 +150,13 @@ public class TrustManager {
mHandler.obtainMessage(MSG_TRUST_MANAGED_CHANGED, (managed ? 1 : 0), userId,
trustListener).sendToTarget();
}
+
+ @Override
+ public void onTrustError(CharSequence message) {
+ Message m = mHandler.obtainMessage(MSG_TRUST_ERROR);
+ m.getData().putCharSequence(DATA_MESSAGE, message);
+ m.sendToTarget();
+ }
};
mService.registerTrustListener(iTrustListener);
mTrustListeners.put(trustListener, iTrustListener);
@@ -221,6 +230,10 @@ public class TrustManager {
break;
case MSG_TRUST_MANAGED_CHANGED:
((TrustListener)msg.obj).onTrustManagedChanged(msg.arg1 != 0, msg.arg2);
+ break;
+ case MSG_TRUST_ERROR:
+ final CharSequence message = msg.peekData().getCharSequence(DATA_MESSAGE);
+ ((TrustListener)msg.obj).onTrustError(message);
}
}
};
@@ -229,9 +242,9 @@ public class TrustManager {
/**
* Reports that the trust state has changed.
- * @param enabled if true, the system believes the environment to be trusted.
- * @param userId the user, for which the trust changed.
- * @param flags flags specified by the trust agent when granting trust. See
+ * @param enabled If true, the system believes the environment to be trusted.
+ * @param userId The user, for which the trust changed.
+ * @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)}.
*/
@@ -239,9 +252,15 @@ public class TrustManager {
/**
* Reports that whether trust is managed has changed
- * @param enabled if true, at least one trust agent is managing trust.
- * @param userId the user, for which the state changed.
+ * @param enabled If true, at least one trust agent is managing trust.
+ * @param userId The user, for which the state changed.
*/
void onTrustManagedChanged(boolean enabled, int userId);
+
+ /**
+ * Reports that an error happened on a TrustAgentService.
+ * @param message A message that should be displayed on the UI.
+ */
+ void onTrustError(CharSequence message);
}
}
diff --git a/core/java/android/service/trust/ITrustAgentServiceCallback.aidl b/core/java/android/service/trust/ITrustAgentServiceCallback.aidl
index 14df7cb9e1a1..220e498df8a8 100644
--- a/core/java/android/service/trust/ITrustAgentServiceCallback.aidl
+++ b/core/java/android/service/trust/ITrustAgentServiceCallback.aidl
@@ -32,4 +32,5 @@ oneway interface ITrustAgentServiceCallback {
void isEscrowTokenActive(long handle, int userId);
void removeEscrowToken(long handle, int userId);
void unlockUserWithToken(long handle, in byte[] token, int userId);
+ void showKeyguardErrorMessage(in CharSequence message);
}
diff --git a/core/java/android/service/trust/TrustAgentService.java b/core/java/android/service/trust/TrustAgentService.java
index 4bade9f9f9ca..40e84b9604e7 100644
--- a/core/java/android/service/trust/TrustAgentService.java
+++ b/core/java/android/service/trust/TrustAgentService.java
@@ -18,6 +18,7 @@ package android.service.trust;
import android.Manifest;
import android.annotation.IntDef;
+import android.annotation.NonNull;
import android.annotation.SdkConstant;
import android.annotation.SystemApi;
import android.app.Service;
@@ -37,6 +38,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
import android.util.Slog;
+
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
@@ -301,7 +303,7 @@ public class TrustAgentService extends Service {
public void onDeviceUnlockLockout(long timeoutMs) {
}
- /**
+ /**
* Called when an escrow token is added for user userId.
*
* @param token the added token
@@ -561,6 +563,31 @@ public class TrustAgentService extends Service {
}
}
+ /**
+ * Request showing a transient error message on the keyguard.
+ * The message will be visible on the lock screen or always on display if possible but can be
+ * overridden by other keyguard events of higher priority - eg. fingerprint auth error.
+ * Other trust agents may override your message if posted simultaneously.
+ *
+ * @param message Message to show.
+ */
+ public final void showKeyguardErrorMessage(@NonNull CharSequence message) {
+ if (message == null) {
+ throw new IllegalArgumentException("message cannot be null");
+ }
+ synchronized (mLock) {
+ if (mCallback == null) {
+ Slog.w(TAG, "Cannot show message because service is not connected to framework.");
+ throw new IllegalStateException("Trust agent is not connected");
+ }
+ try {
+ mCallback.showKeyguardErrorMessage(message);
+ } catch (RemoteException e) {
+ onError("calling showKeyguardErrorMessage");
+ }
+ }
+ }
+
@Override
public final IBinder onBind(Intent intent) {
if (DEBUG) Slog.v(TAG, "onBind() intent = " + intent);