summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2020-07-22 23:36:34 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2020-07-22 23:36:34 +0000
commit618218a6dd90005204a8bd8eee83b6aca0738642 (patch)
tree831523b7fdb28ea774e314d770f0e29813482181
parent56bd085ce7fa5a87188348bcc555e2ed17c246f8 (diff)
parentebdbf1ec2b84030103b2ad68f777b2b82e33e2ac (diff)
downloadCompanionDeviceSupport-618218a6dd90005204a8bd8eee83b6aca0738642.tar.gz
Snap for 6701292 from ebdbf1ec2b84030103b2ad68f777b2b82e33e2ac to rvc-qpr1-release
Change-Id: I6cea11bc6d3d6d1afd4d104234961f4e8456ad5c
-rw-r--r--src/com/android/car/companiondevicesupport/feature/trust/TrustedDeviceAgentService.java75
-rw-r--r--src/com/android/car/companiondevicesupport/feature/trust/ui/TrustedDeviceActivity.java2
2 files changed, 58 insertions, 19 deletions
diff --git a/src/com/android/car/companiondevicesupport/feature/trust/TrustedDeviceAgentService.java b/src/com/android/car/companiondevicesupport/feature/trust/TrustedDeviceAgentService.java
index b57868b..be1f658 100644
--- a/src/com/android/car/companiondevicesupport/feature/trust/TrustedDeviceAgentService.java
+++ b/src/com/android/car/companiondevicesupport/feature/trust/TrustedDeviceAgentService.java
@@ -18,12 +18,15 @@ package com.android.car.companiondevicesupport.feature.trust;
import static com.android.car.connecteddevice.util.SafeLog.logd;
import static com.android.car.connecteddevice.util.SafeLog.loge;
+import static com.android.car.connecteddevice.util.SafeLog.logw;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.os.Handler;
+import android.os.HandlerThread;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;
@@ -32,6 +35,8 @@ import android.service.trust.TrustAgentService;
import com.android.car.companiondevicesupport.api.internal.trust.ITrustedDeviceAgentDelegate;
import com.android.car.companiondevicesupport.api.internal.trust.ITrustedDeviceManager;
+import java.time.Duration;
+
/** Service to provide TrustAgent functionality to the trusted device feature. */
public class TrustedDeviceAgentService extends TrustAgentService {
@@ -40,8 +45,20 @@ public class TrustedDeviceAgentService extends TrustAgentService {
/** Keep device in trusted state. */
private static final long TRUST_DURATION_MS = 0L;
+ private static final String RETRY_HANDLER_THREAD_NAME = "trusted_device_retry";
+
+ private static int MAX_RETRIES = 200;
+
+ private final Duration mRetryDuration = Duration.ofMillis(10);
+
+ private HandlerThread mRetryThread;
+
+ private Handler mRetryHandler;
+
private ITrustedDeviceManager mTrustedDeviceManager;
+ private int mRetries;
+
@Override
public void onCreate() {
super.onCreate();
@@ -49,6 +66,9 @@ public class TrustedDeviceAgentService extends TrustAgentService {
TrustedDeviceEventLog.onTrustAgentStarted();
Intent intent = new Intent(this, TrustedDeviceManagerService.class);
bindServiceAsUser(intent, mServiceConnection, Context.BIND_AUTO_CREATE, UserHandle.SYSTEM);
+ mRetryThread = new HandlerThread(RETRY_HANDLER_THREAD_NAME);
+ mRetryThread.start();
+ mRetryHandler = new Handler(mRetryThread.getLooper());
}
@Override
@@ -60,6 +80,9 @@ public class TrustedDeviceAgentService extends TrustAgentService {
loge(TAG, "Error while disconnecting from TrustedDeviceManager.");
}
unbindService(mServiceConnection);
+ if (mRetryThread != null) {
+ mRetryThread.quit();
+ }
super.onDestroy();
}
@@ -116,25 +139,39 @@ public class TrustedDeviceAgentService extends TrustAgentService {
private final ITrustedDeviceAgentDelegate mTrustedDeviceAgentDelegate =
new ITrustedDeviceAgentDelegate.Stub() {
- @Override
- public void addEscrowToken(byte[] token, int userId) {
- logd(TAG, "Adding new escrow token for user " + userId + ".");
- TrustedDeviceAgentService.this.addEscrowToken(token, UserHandle.of(userId));
- }
- @Override
- public void unlockUserWithToken(byte[] token, long handle, int userId) {
- setManagingTrust(true);
- TrustedDeviceAgentService.this.unlockUserWithToken(handle, token,
- UserHandle.of(userId));
- grantTrust("Granting trust from escrow token for user " + userId + ".",
- TRUST_DURATION_MS, FLAG_GRANT_TRUST_DISMISS_KEYGUARD);
- }
-
- @Override
- public void removeEscrowToken(long handle, int userId) {
- logd(TAG, "Removing escrow token for user " + userId + ".");
- TrustedDeviceAgentService.this.removeEscrowToken(handle, UserHandle.of(userId));
- }
+ @Override
+ public void addEscrowToken(byte[] token, int userId) {
+ logd(TAG, "Adding new escrow token for user " + userId + ".");
+ try {
+ TrustedDeviceAgentService.this.addEscrowToken(token, UserHandle.of(userId));
+ return;
+ } catch (IllegalStateException e) {
+ if (++mRetries > MAX_RETRIES) {
+ loge(TAG, "Maximum number of retries for adding an escrow token has "
+ + "been exceeded. Aborting.", e);
+ return;
+ }
+ }
+
+ logw(TAG, "Trust agent has not been bound to yet. Retry #" + mRetries + ".");
+ mRetryHandler.postDelayed(() -> addEscrowToken(token, userId),
+ mRetryDuration.toMillis());
+ }
+
+ @Override
+ public void unlockUserWithToken(byte[] token, long handle, int userId) {
+ setManagingTrust(true);
+ TrustedDeviceAgentService.this.unlockUserWithToken(handle, token,
+ UserHandle.of(userId));
+ grantTrust("Granting trust from escrow token for user " + userId + ".",
+ TRUST_DURATION_MS, FLAG_GRANT_TRUST_DISMISS_KEYGUARD);
+ }
+
+ @Override
+ public void removeEscrowToken(long handle, int userId) {
+ logd(TAG, "Removing escrow token for user " + userId + ".");
+ TrustedDeviceAgentService.this.removeEscrowToken(handle, UserHandle.of(userId));
+ }
};
}
diff --git a/src/com/android/car/companiondevicesupport/feature/trust/ui/TrustedDeviceActivity.java b/src/com/android/car/companiondevicesupport/feature/trust/ui/TrustedDeviceActivity.java
index e53e821..254a600 100644
--- a/src/com/android/car/companiondevicesupport/feature/trust/ui/TrustedDeviceActivity.java
+++ b/src/com/android/car/companiondevicesupport/feature/trust/ui/TrustedDeviceActivity.java
@@ -299,10 +299,12 @@ public class TrustedDeviceActivity extends FragmentActivity {
logd(TAG, "Validating credentials to activate token.");
KeyguardManager keyguardManager = getKeyguardManager();
if (keyguardManager == null) {
+ logd(TAG, "KeyguardManager was null. Aborting.");
return;
}
if (!mIsStartedForEnrollment.get()) {
mHasPendingCredential.set(true);
+ logd(TAG, "Activity not started for enrollment. Credentials are pending.");
return;
}
if (mIsScreenLockNewlyCreated.get()) {