aboutsummaryrefslogtreecommitdiff
path: root/TrustAgent/src
diff options
context:
space:
mode:
authorHongwei Wang <hwwang@google.com>2018-03-20 10:26:03 -0700
committerHongwei Wang <hwwang@google.com>2018-04-09 10:22:36 -0700
commitfb1e3ec6d10ba3a426c9d09bf653b1b360c9ac2d (patch)
treeedf7cfb55f275b08f89e0282eee924439de8b669 /TrustAgent/src
parent3f22a073729192cb43d0c6312c716b06190a3177 (diff)
downloadCar-fb1e3ec6d10ba3a426c9d09bf653b1b360c9ac2d.tar.gz
Run CarTrustAgentService in singleUser mode
Bug: 76009740 Test: pair and unlock w/ Mojave Change-Id: Id436a7c26b1680a53126615b77899859e7de69a7
Diffstat (limited to 'TrustAgent/src')
-rw-r--r--TrustAgent/src/com/android/car/trust/CarBleTrustAgent.java35
-rw-r--r--TrustAgent/src/com/android/car/trust/SimpleBleServer.java12
2 files changed, 25 insertions, 22 deletions
diff --git a/TrustAgent/src/com/android/car/trust/CarBleTrustAgent.java b/TrustAgent/src/com/android/car/trust/CarBleTrustAgent.java
index 1e73ab89b7..9be4198e98 100644
--- a/TrustAgent/src/com/android/car/trust/CarBleTrustAgent.java
+++ b/TrustAgent/src/com/android/car/trust/CarBleTrustAgent.java
@@ -78,13 +78,13 @@ public class CarBleTrustAgent extends TrustAgentService {
revokeTrust();
} else if (ACTION_ADD_TOKEN.equals(action)) {
byte[] token = intent.getByteArrayExtra(INTENT_EXTRA_ESCROW_TOKEN);
- addEscrowToken(token, getCurrentUserHandle());
+ addEscrowToken(token, getForegroundUserHandle());
} else if (ACTION_IS_TOKEN_ACTIVE.equals(action)) {
long handle = intent.getLongExtra(INTENT_EXTRA_TOKEN_HANDLE, -1);
- isEscrowTokenActive(handle, getCurrentUserHandle());
+ isEscrowTokenActive(handle, getForegroundUserHandle());
} else if (ACTION_REMOVE_TOKEN.equals(action)) {
long handle = intent.getLongExtra(INTENT_EXTRA_TOKEN_HANDLE, -1);
- removeEscrowToken(handle, getCurrentUserHandle());
+ removeEscrowToken(handle, getForegroundUserHandle());
}
}
};
@@ -151,7 +151,7 @@ public class CarBleTrustAgent extends TrustAgentService {
// If the user is already unlocked, don't bother starting the BLE service.
UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
- if (!um.isUserUnlocked()) {
+ if (!um.isUserUnlocked(getForegroundUserHandle())) {
Log.d(Utils.LOG_TAG, "User locked, will now bind CarUnlockService");
Intent intent = new Intent(this, CarUnlockService.class);
@@ -190,14 +190,7 @@ public class CarBleTrustAgent extends TrustAgentService {
// to start the rest of the BLE services.
if (mGattServer == null) {
Log.e(Utils.LOG_TAG, "Gatt not available, will try again...in " + BLE_RETRY_MS + "ms");
-
- Handler handler = new Handler();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- maybeStartBleUnlockService();
- }
- }, BLE_RETRY_MS);
+ new Handler().postDelayed(() -> maybeStartBleUnlockService(), BLE_RETRY_MS);
} else {
mGattServer.close();
Log.d(Utils.LOG_TAG, "GATT available, starting up UnlockService");
@@ -207,16 +200,19 @@ public class CarBleTrustAgent extends TrustAgentService {
private void unlock(byte[] token, long handle) {
UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
+ // STOPSHIP: get the actual user to unlock by token
+ UserHandle userHandle = getForegroundUserHandle();
- Log.d(Utils.LOG_TAG, "About to unlock user. Current handle: " + handle
+ Log.d(Utils.LOG_TAG, "About to unlock user. Handle: " + handle
+ " Time: " + System.currentTimeMillis());
- unlockUserWithToken(handle, token, getCurrentUserHandle());
+ unlockUserWithToken(handle, token, userHandle);
- Log.d(Utils.LOG_TAG, "Attempted to unlock user, is user unlocked? " + um.isUserUnlocked()
+ Log.d(Utils.LOG_TAG, "Attempted to unlock user, is user unlocked: "
+ + um.isUserUnlocked(userHandle)
+ " Time: " + System.currentTimeMillis());
setManagingTrust(true);
- if (um.isUserUnlocked()) {
+ if (um.isUserUnlocked(userHandle)) {
Log.d(Utils.LOG_TAG, getString(R.string.trust_granted_explanation));
grantTrust("Granting trust from escrow token",
TRUST_DURATION_MS, FLAG_GRANT_TRUST_DISMISS_KEYGUARD);
@@ -253,7 +249,12 @@ public class CarBleTrustAgent extends TrustAgentService {
mLocalBroadcastManager.sendBroadcast(intent);
}
- private UserHandle getCurrentUserHandle() {
+ /**
+ * STOPSHIP: return the {@link UserHandle} of foreground user.
+ * CarTrustAgentService itself runs as user-0
+ */
+ private UserHandle getForegroundUserHandle() {
+ Log.d(Utils.LOG_TAG, "getForegroundUserHandle for " + UserHandle.myUserId());
return UserHandle.of(UserHandle.myUserId());
}
}
diff --git a/TrustAgent/src/com/android/car/trust/SimpleBleServer.java b/TrustAgent/src/com/android/car/trust/SimpleBleServer.java
index 2ed0c8f46c..074776901a 100644
--- a/TrustAgent/src/com/android/car/trust/SimpleBleServer.java
+++ b/TrustAgent/src/com/android/car/trust/SimpleBleServer.java
@@ -15,6 +15,8 @@
*/
package com.android.car.trust;
+import static android.bluetooth.BluetoothProfile.GATT_SERVER;
+
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@@ -108,7 +110,9 @@ public abstract class SimpleBleServer extends Service {
private final Set<ConnectionCallback> mConnectionCallbacks = new HashSet<>();
+ private BluetoothManager mBluetoothManager;
private BluetoothLeAdvertiser mAdvertiser;
+
protected BluetoothGattServer mGattServer;
/**
@@ -123,10 +127,8 @@ public abstract class SimpleBleServer extends Service {
return;
}
- BluetoothManager btManager =
- (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
-
- mGattServer = btManager.openGattServer(this, mGattServerCallback);
+ mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
+ mGattServer = mBluetoothManager.openGattServer(this, mGattServerCallback);
if (mGattServer == null) {
Log.e(Utils.LOG_TAG, "Gatt Server not created");
return;
@@ -168,7 +170,7 @@ public abstract class SimpleBleServer extends Service {
if (mGattServer != null) {
mGattServer.clearServices();
try {
- for (BluetoothDevice d : mGattServer.getConnectedDevices()) {
+ for (BluetoothDevice d : mBluetoothManager.getConnectedDevices(GATT_SERVER)) {
mGattServer.cancelConnection(d);
}
} catch (UnsupportedOperationException e) {