[uwb] Initizlize transport and secure components
Bug: 197341285
Test: atest ServiceUwbTests
Change-Id: I358f7f8a10a4f85de746f2359154721e2ba8a038
diff --git a/service/java/com/android/server/uwb/discovery/info/DiscoveryInfo.java b/service/java/com/android/server/uwb/discovery/info/DiscoveryInfo.java
index 0a742a9..1aa8728 100644
--- a/service/java/com/android/server/uwb/discovery/info/DiscoveryInfo.java
+++ b/service/java/com/android/server/uwb/discovery/info/DiscoveryInfo.java
@@ -42,5 +42,5 @@
public final Optional<AdvertiseInfo> advertiseInfo;
- public final Optional<TransportClientInfo> transportClientInfo;
+ public Optional<TransportClientInfo> transportClientInfo;
}
diff --git a/service/java/com/android/server/uwb/pm/PacsControleeSession.java b/service/java/com/android/server/uwb/pm/PacsControleeSession.java
index 4961f96..2bdc8f4 100644
--- a/service/java/com/android/server/uwb/pm/PacsControleeSession.java
+++ b/service/java/com/android/server/uwb/pm/PacsControleeSession.java
@@ -16,6 +16,9 @@
package com.android.server.uwb.pm;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.bluetooth.le.AdvertisingSetParameters;
import android.content.AttributionSource;
import android.content.Context;
import android.os.Handler;
@@ -32,14 +35,29 @@
import com.android.server.uwb.data.UwbConfig;
import com.android.server.uwb.discovery.DiscoveryAdvertiseProvider;
import com.android.server.uwb.discovery.DiscoveryAdvertiseService;
+import com.android.server.uwb.discovery.TransportServerProvider;
+import com.android.server.uwb.discovery.TransportServerService;
+import com.android.server.uwb.discovery.ble.DiscoveryAdvertisement;
+import com.android.server.uwb.discovery.info.AdvertiseInfo;
import com.android.server.uwb.discovery.info.DiscoveryInfo;
+import com.android.server.uwb.secure.SecureFactory;
+import com.android.server.uwb.secure.SecureSession;
+import com.android.server.uwb.transport.Transport;
+import com.android.server.uwb.util.ObjectIdentifier;
+import java.nio.ByteBuffer;
+import java.util.List;
import java.util.Optional;
/** Session for PACS profile controlee */
public class PacsControleeSession extends RangingSessionController {
private static final String TAG = "PacsControleeSession";
private final PacsAdvertiseCallback mAdvertiseCallback;
+ // TODO populate before calling secureSessionInit()
+ private PacsControleeSessionInfo mControleeSessionInfo;
+ private final PacsControleeSessionCallback mControleeSessionCallback;
+ private final Transport mControleeTransport;
+ private final TransportServerProvider.TransportServerCallback mServerCallback;
public PacsControleeSession(
SessionHandle sessionHandle,
@@ -48,7 +66,8 @@
UwbInjector uwbInjector,
ServiceProfileInfo serviceProfileInfo,
IUwbRangingCallbacks rangingCallbacks,
- Handler handler) {
+ Handler handler,
+ String chipId) {
super(
sessionHandle,
attributionSource,
@@ -56,8 +75,14 @@
uwbInjector,
serviceProfileInfo,
rangingCallbacks,
- handler);
+ handler,
+ chipId);
mAdvertiseCallback = new PacsAdvertiseCallback(this);
+ mControleeSessionInfo = new PacsControleeSessionInfo(this);
+ mControleeSessionCallback = new PacsControleeSessionCallback(this);
+ // TODO: Modify based on OOB transport implementation
+ mControleeTransport = null;
+ mServerCallback = null;
}
@Override
@@ -91,24 +116,42 @@
}
private DiscoveryAdvertiseService mDiscoveryAdvertiseService;
+ private DiscoveryInfo mDiscoveryInfo;
+ private TransportServerService mTransportServerService;
+ private SecureSession mSecureSession;
+ private DiscoveryAdvertisement mDiscoveryAdvertisement;
+ private AdvertisingSetParameters mAdvertisingSetParameters;
+
+ public void setDiscoveryAdvertisement(
+ DiscoveryAdvertisement discoveryAdvertisement) {
+ mDiscoveryAdvertisement = discoveryAdvertisement;
+ }
+
+ public void setAdvertisingSetParameters(
+ AdvertisingSetParameters advertisingSetParameters) {
+ mAdvertisingSetParameters = advertisingSetParameters;
+ }
/** Advertise capabilities */
public void startAdvertising() {
- DiscoveryInfo discoveryInfo =
- new DiscoveryInfo(
- DiscoveryInfo.TransportType.BLE,
- Optional.empty(),
- Optional.empty(),
- Optional.empty());
+ AdvertiseInfo advertiseInfo =
+ new AdvertiseInfo(mAdvertisingSetParameters, mDiscoveryAdvertisement);
+
+ mDiscoveryInfo = new DiscoveryInfo(
+ DiscoveryInfo.TransportType.BLE,
+ Optional.empty(),
+ Optional.of(advertiseInfo),
+ Optional.empty());
mDiscoveryAdvertiseService =
new DiscoveryAdvertiseService(
mSessionInfo.mAttributionSource,
mSessionInfo.mContext,
new HandlerExecutor(mHandler),
- discoveryInfo,
+ mDiscoveryInfo,
mAdvertiseCallback);
mDiscoveryAdvertiseService.startDiscovery();
+ //sendMessage(TRANSPORT_INIT);
}
/** Stop advertising on ranging stopped or closed */
@@ -118,6 +161,36 @@
}
}
+ /** Initialize Transport server */
+ public void transportServerInit() {
+ mTransportServerService = new TransportServerService(
+ mSessionInfo.mAttributionSource,
+ mSessionInfo.mContext,
+ mDiscoveryInfo,
+ mServerCallback
+ );
+ sendMessage(TRANSPORT_STARTED);
+ }
+
+ /** Start Transport server */
+ public void transportServerStart() {
+ mTransportServerService.start();
+ }
+
+ /** Stop Transport server */
+ public void transportServerStop() {
+ mTransportServerService.stop();
+ }
+
+ /** Initialize controlee responder session */
+ public void secureSessionInit() {
+ mSecureSession = SecureFactory.makeResponderSecureSession(mSessionInfo.mContext,
+ mHandler.getLooper(),
+ mControleeSessionCallback,
+ mControleeSessionInfo,
+ mControleeTransport);
+ }
+
@Override
public UwbConfig getUwbConfig() {
return PacsProfile.getPacsControleeProfile();
@@ -140,12 +213,103 @@
}
}
+ public static class PacsControleeSessionInfo implements
+ RunningProfileSessionInfo {
+ public final PacsControleeSession mPacsControleeSession;
+ private ControlleeInfo mControlleeInfo;
+
+ public PacsControleeSessionInfo(
+ PacsControleeSession pacsControleeSession) {
+ mPacsControleeSession = pacsControleeSession;
+ }
+
+ public void setControlleeInfo(ControlleeInfo controlleeInfo) {
+ mControlleeInfo = controlleeInfo;
+ }
+
+ @NonNull
+ @Override
+ public ControlleeInfo getControlleeInfo() {
+ return mControlleeInfo;
+ }
+
+ @NonNull
+ @Override
+ public Optional<SessionData> getSessionDataForControllee(
+ ControlleeInfo controlleeInfoOfPeerDevice) {
+ return Optional.empty();
+ }
+
+ @NonNull
+ @Override
+ public ObjectIdentifier getOidOfProvisionedAdf() {
+ byte[] bytes = ByteBuffer.allocate(4).putInt(mPacsControleeSession
+ .mSessionInfo
+ .mServiceProfileInfo
+ .getServiceAdfID()).array();
+ return ObjectIdentifier.fromBytes(bytes);
+ }
+
+ @NonNull
+ @Override
+ public List<ObjectIdentifier> getSelectableOidsOfPeerDevice() {
+ return null;
+ }
+
+ @Override
+ public boolean isUwbController() {
+ return false;
+ }
+
+ @Override
+ public boolean isUnicast() {
+ return true;
+ }
+
+ @NonNull
+ @Override
+ public Optional<Integer> getSharedPrimarySessionId() {
+ return Optional.of(mPacsControleeSession.mSessionInfo.getSessionId());
+ }
+
+ @NonNull
+ @Override
+ public Optional<byte[]> getSecureBlob() {
+ return Optional.empty();
+ }
+ }
+
+ public static class PacsControleeSessionCallback implements
+ SecureSession.Callback {
+ public final PacsControleeSession mPacsControleeSession;
+
+ public PacsControleeSessionCallback(
+ PacsControleeSession pacsControleeSession) {
+ mPacsControleeSession = pacsControleeSession;
+ }
+
+ @Override
+ public void onSessionDataReady(int updatedSessionId, @Nullable byte[] sessionData,
+ boolean isSessionTerminated) {
+ mPacsControleeSession.sendMessage(RANGING_INIT);
+ }
+
+ @Override
+ public void onSessionAborted() {
+ }
+
+ @Override
+ public void onSessionTerminated() {
+ }
+ }
+
public class IdleState extends State {
@Override
public void enter() {
if (mVerboseLoggingEnabled) {
log("Enter IdleState");
}
+ getSpecificationInfo();
}
@Override
@@ -188,7 +352,6 @@
if (mVerboseLoggingEnabled) {
log("Enter DiscoveryState");
}
- startAdvertising();
sendMessage(DISCOVERY_STARTED);
}
@@ -205,6 +368,7 @@
case DISCOVERY_FAILED:
log("Failed to advertise");
break;
+ case DISCOVERY_STARTED:
case SESSION_START:
startAdvertising();
if (mVerboseLoggingEnabled) {
@@ -217,6 +381,9 @@
log("Stopped advertising");
}
break;
+ case TRANSPORT_INIT:
+ transitionTo(mTransportState);
+ break;
}
return true;
}
@@ -228,6 +395,7 @@
if (mVerboseLoggingEnabled) {
log("Enter TransportState");
}
+ transportServerInit();
}
@Override
@@ -239,7 +407,17 @@
@Override
public boolean processMessage(Message message) {
- transitionTo(mSecureSessionState);
+ switch (message.what) {
+ case TRANSPORT_STARTED:
+ transportServerStart();
+ break;
+ case SESSION_STOP:
+ case TRANSPORT_COMPLETED:
+ stopAdvertising();
+ transportServerStop();
+ transitionTo(mSecureSessionState);
+ break;
+ }
return true;
}
}
@@ -251,6 +429,7 @@
if (mVerboseLoggingEnabled) {
log("Enter SecureSessionState");
}
+ sendMessage(SECURE_SESSION_INIT);
}
@Override
@@ -262,7 +441,14 @@
@Override
public boolean processMessage(Message message) {
- transitionTo(mRangingState);
+ switch (message.what) {
+ case SECURE_SESSION_INIT:
+ secureSessionInit();
+ break;
+ case SECURE_SESSION_ESTABLISHED:
+ transitionTo(mRangingState);
+ break;
+ }
return true;
}
}
diff --git a/service/java/com/android/server/uwb/pm/PacsControllerSession.java b/service/java/com/android/server/uwb/pm/PacsControllerSession.java
index 4b6aa10..ba83d99 100644
--- a/service/java/com/android/server/uwb/pm/PacsControllerSession.java
+++ b/service/java/com/android/server/uwb/pm/PacsControllerSession.java
@@ -16,6 +16,10 @@
package com.android.server.uwb.pm;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.bluetooth.le.ScanFilter;
+import android.bluetooth.le.ScanSettings;
import android.content.AttributionSource;
import android.content.Context;
import android.os.Handler;
@@ -32,14 +36,29 @@
import com.android.server.uwb.data.UwbConfig;
import com.android.server.uwb.discovery.DiscoveryScanProvider;
import com.android.server.uwb.discovery.DiscoveryScanService;
+import com.android.server.uwb.discovery.TransportClientProvider;
+import com.android.server.uwb.discovery.TransportClientService;
import com.android.server.uwb.discovery.info.DiscoveryInfo;
+import com.android.server.uwb.discovery.info.FiraConnectorCapabilities;
+import com.android.server.uwb.discovery.info.ScanInfo;
+import com.android.server.uwb.discovery.info.TransportClientInfo;
+import com.android.server.uwb.secure.SecureFactory;
+import com.android.server.uwb.secure.SecureSession;
+import com.android.server.uwb.transport.Transport;
+import com.android.server.uwb.util.ObjectIdentifier;
+import java.util.List;
import java.util.Optional;
/** Session for PACS profile controller */
public class PacsControllerSession extends RangingSessionController {
private static final String TAG = "PACSControllerSession";
private final ScanCallback mScanCallback;
+ // TODO populate before calling secureSessionInit()
+ private PacsControllerSessionInfo mControllerSessionInfo;
+ private final PacsControllerSessionCallback mControllerSessionCallback;
+ private final Transport mControllerTransport;
+ private final TransportClientProvider.TransportClientCallback mClientCallback;
public PacsControllerSession(
SessionHandle sessionHandle,
@@ -48,7 +67,8 @@
UwbInjector uwbInjector,
ServiceProfileInfo serviceProfileInfo,
IUwbRangingCallbacks rangingCallbacks,
- Handler handler) {
+ Handler handler,
+ String chipId) {
super(
sessionHandle,
attributionSource,
@@ -56,40 +76,14 @@
uwbInjector,
serviceProfileInfo,
rangingCallbacks,
- handler);
- mIdleState = new IdleState();
- mDiscoveryState = new DiscoveryState();
- mTransportState = new TransportState();
- mSecureSessionState = new SecureSessionState();
- mRangingState = new RangingState();
- mEndSessionState = new EndSessionState();
+ handler,
+ chipId);
mScanCallback = new ScanCallback(this);
- }
-
- /** Scan for devices */
- public void startScan() {
- DiscoveryInfo discoveryInfo =
- new DiscoveryInfo(
- DiscoveryInfo.TransportType.BLE,
- Optional.empty(),
- Optional.empty(),
- Optional.empty());
-
- mDiscoveryScanService =
- new DiscoveryScanService(
- mSessionInfo.mAttributionSource,
- mSessionInfo.mContext,
- new HandlerExecutor(mHandler),
- discoveryInfo,
- mScanCallback);
- mDiscoveryScanService.startDiscovery();
- }
-
- /** Stop scanning on ranging stopped or closed */
- public void stopScan() {
- if (mDiscoveryScanService != null) {
- mDiscoveryScanService.stopDiscovery();
- }
+ mControllerSessionCallback = new PacsControllerSessionCallback(this);
+ mControllerSessionInfo = new PacsControllerSessionInfo(this);
+ // TODO: Modify based on OOB transport implementation
+ mControllerTransport = null;
+ mClientCallback = null;
}
@Override
@@ -123,6 +117,88 @@
}
private DiscoveryScanService mDiscoveryScanService;
+ private DiscoveryInfo mDiscoveryInfo;
+ private TransportClientService mTransportClientService;
+ private SecureSession mSecureSession;
+
+ private List<ScanFilter> mScanFilterList;
+ private ScanSettings mScanSettings;
+
+ public void setScanFilterList(List<ScanFilter> scanFilterList) {
+ mScanFilterList = scanFilterList;
+ }
+
+ public void setScanSettings(ScanSettings scanSettings) {
+ mScanSettings = scanSettings;
+ }
+
+ public void setTransportclientInfo(TransportClientInfo transportClientInfo) {
+ mDiscoveryInfo.transportClientInfo = Optional.of(transportClientInfo);
+ }
+
+ /** Scan for devices */
+ public void startScan() {
+ ScanInfo scanInfo = new ScanInfo(mScanFilterList, mScanSettings);
+ mDiscoveryInfo =
+ new DiscoveryInfo(
+ DiscoveryInfo.TransportType.BLE,
+ Optional.of(scanInfo),
+ Optional.empty(),
+ Optional.empty());
+
+ mDiscoveryScanService =
+ new DiscoveryScanService(
+ mSessionInfo.mAttributionSource,
+ mSessionInfo.mContext,
+ new HandlerExecutor(mHandler),
+ mDiscoveryInfo,
+ mScanCallback);
+ mDiscoveryScanService.startDiscovery();
+ }
+
+ /** Stop scanning on ranging stopped or closed */
+ public void stopScan() {
+ if (mDiscoveryScanService != null) {
+ mDiscoveryScanService.stopDiscovery();
+ }
+ }
+
+ /** Initialize transport client with updated TransportClientInfo */
+ public void transportClientInit() {
+ mTransportClientService = new TransportClientService(
+ mSessionInfo.mAttributionSource,
+ mSessionInfo.mContext,
+ new HandlerExecutor(mHandler),
+ mDiscoveryInfo,
+ mClientCallback
+ );
+
+ FiraConnectorCapabilities firaConnectorCapabilities =
+ new FiraConnectorCapabilities.Builder().build();
+ mTransportClientService.setCapabilites(firaConnectorCapabilities);
+ sendMessage(TRANSPORT_STARTED);
+ }
+
+ /** Start Transport client */
+ public void transportClientStart() {
+ mTransportClientService.start();
+ }
+
+ /** Stop Transport client */
+ public void transportClientStop() {
+ mTransportClientService.stop();
+ }
+
+ /** Initialize controller initiator session */
+ public void secureSessionInit() {
+ mSecureSession = SecureFactory.makeInitiatorSecureSession(
+ mSessionInfo.mContext,
+ mHandler.getLooper(),
+ mControllerSessionCallback,
+ mControllerSessionInfo,
+ mControllerTransport
+ );
+ }
@Override
public UwbConfig getUwbConfig() {
@@ -139,7 +215,12 @@
}
@Override
- public void onDiscovered(DiscoveryScanProvider.DiscoveryResult result) {}
+ public void onDiscovered(DiscoveryScanProvider.DiscoveryResult result) {
+ TransportClientInfo transportClientInfo =
+ new TransportClientInfo(result.scanResult);
+ mPacsControllerSession.setTransportclientInfo(transportClientInfo);
+ mPacsControllerSession.sendMessage(TRANSPORT_INIT);
+ }
@Override
public void onDiscoveryFailed(int errorCode) {
@@ -148,6 +229,90 @@
}
}
+ public static class PacsControllerSessionInfo implements
+ RunningProfileSessionInfo {
+
+ public final PacsControllerSession mPacsControllerSession;
+
+ public PacsControllerSessionInfo(
+ PacsControllerSession pacsControllerSession) {
+ mPacsControllerSession = pacsControllerSession;
+ }
+
+ @NonNull
+ @Override
+ public ControlleeInfo getControlleeInfo() {
+ return null;
+ }
+
+ @NonNull
+ @Override
+ public Optional<SessionData> getSessionDataForControllee(
+ ControlleeInfo controlleeInfoOfPeerDevice) {
+ return Optional.empty();
+ }
+
+ @NonNull
+ @Override
+ public ObjectIdentifier getOidOfProvisionedAdf() {
+ return null;
+ }
+
+ @NonNull
+ @Override
+ public List<ObjectIdentifier> getSelectableOidsOfPeerDevice() {
+ return null;
+ }
+
+ @Override
+ public boolean isUwbController() {
+ return true;
+ }
+
+ @Override
+ public boolean isUnicast() {
+ return false;
+ }
+
+ @NonNull
+ @Override
+ public Optional<Integer> getSharedPrimarySessionId() {
+ return Optional.of(mPacsControllerSession.mSessionInfo.getSessionId());
+ }
+
+ @NonNull
+ @Override
+ public Optional<byte[]> getSecureBlob() {
+ return Optional.empty();
+ }
+ }
+
+ public static class PacsControllerSessionCallback implements
+ SecureSession.Callback {
+
+ public final PacsControllerSession mPacsControllerSession;
+
+ public PacsControllerSessionCallback(
+ PacsControllerSession pacsControllerSession) {
+ mPacsControllerSession = pacsControllerSession;
+ }
+
+ @Override
+ public void onSessionDataReady(int updatedSessionId, @Nullable byte[] sessionData,
+ boolean isSessionTerminated) {
+ mPacsControllerSession.sendMessage(RANGING_INIT);
+ }
+
+ @Override
+ public void onSessionAborted() {
+ }
+
+ @Override
+ public void onSessionTerminated() {
+ }
+ }
+
+
public class IdleState extends State {
@Override
public void enter() {
@@ -224,6 +389,9 @@
log("Stopped scanning");
}
break;
+ case TRANSPORT_INIT:
+ transitionTo(mTransportState);
+ break;
}
return true;
}
@@ -235,6 +403,7 @@
if (mVerboseLoggingEnabled) {
log("Enter TransportState");
}
+ transportClientInit();
}
@Override
@@ -246,6 +415,17 @@
@Override
public boolean processMessage(Message message) {
+ switch (message.what) {
+ case TRANSPORT_STARTED:
+ transportClientStart();
+ break;
+ case SESSION_STOP:
+ case TRANSPORT_COMPLETED:
+ stopScan();
+ transportClientStop();
+ transitionTo(mSecureSessionState);
+ break;
+ }
return true;
}
}
@@ -257,6 +437,7 @@
if (mVerboseLoggingEnabled) {
log("Enter SecureSessionState");
}
+ sendMessage(SECURE_SESSION_INIT);
}
@Override
@@ -268,7 +449,14 @@
@Override
public boolean processMessage(Message message) {
- transitionTo(mRangingState);
+ switch (message.what) {
+ case SECURE_SESSION_INIT:
+ secureSessionInit();
+ break;
+ case SECURE_SESSION_ESTABLISHED:
+ transitionTo(mRangingState);
+ break;
+ }
return true;
}
}
@@ -288,6 +476,11 @@
}
}
+ /**
+ * TODO Once ranging starts with a client, controller should continue to scan
+ * for other devices as this is a multicast session. Transition to discovery state
+ * after session is started and add new devices discovered.
+ **/
@Override
public boolean processMessage(Message message) {
switch (message.what) {
diff --git a/service/java/com/android/server/uwb/pm/RangingSessionController.java b/service/java/com/android/server/uwb/pm/RangingSessionController.java
index 3f15240..9564aa9 100644
--- a/service/java/com/android/server/uwb/pm/RangingSessionController.java
+++ b/service/java/com/android/server/uwb/pm/RangingSessionController.java
@@ -32,6 +32,7 @@
import com.android.server.uwb.data.UwbConfig;
import com.google.uwb.support.fira.FiraOpenSessionParams;
+import com.google.uwb.support.generic.GenericSpecificationParams;
import java.util.ArrayList;
import java.util.List;
@@ -47,6 +48,7 @@
public SessionInfo mSessionInfo;
public Handler mHandler;
public UwbInjector mUwbInjector;
+ private boolean mFiraSpecificationParams;
protected boolean mVerboseLoggingEnabled = false;
protected State mIdleState = null;
@@ -87,11 +89,12 @@
UwbInjector uwbInjector,
ServiceProfileInfo serviceProfileInfo,
IUwbRangingCallbacks rangingCallbacks,
- Handler handler) {
+ Handler handler,
+ String chipId) {
super("RangingSessionController", handler);
mSessionInfo = new SessionInfo(attributionSource, sessionHandle,
- serviceProfileInfo, context, rangingCallbacks);
+ serviceProfileInfo, context, rangingCallbacks, chipId);
mIdleState = getIdleState();
mDiscoveryState = getDiscoveryState();
@@ -187,6 +190,12 @@
mUwbInjector.getUwbServiceCore().closeRanging(mSessionInfo.mSessionHandle);
}
+ // TODO Use this to fill in controlee info
+ protected void getSpecificationInfo() {
+ GenericSpecificationParams specificationParams =
+ mUwbInjector.getUwbServiceCore().getCachedSpecificationParams(mSessionInfo.mChipId);
+ }
+
/**
* Holds all session related information
*/
@@ -201,11 +210,13 @@
private UwbAddress mDeviceAddress;
public final List<UwbAddress> mDestAddressList;
public Optional<Integer> subSessionId;
+ public final String mChipId;
public SessionInfo(AttributionSource attributionSource, SessionHandle sessionHandle,
ServiceProfileInfo serviceProfileInfo,
Context context,
- IUwbRangingCallbacks rangingCallbacks) {
+ IUwbRangingCallbacks rangingCallbacks,
+ String chipId) {
mAttributionSource = attributionSource;
mSessionHandle = sessionHandle;
service_instance_id = serviceProfileInfo.serviceInstanceID;
@@ -214,6 +225,7 @@
mRangingCallbacks = rangingCallbacks;
mDestAddressList = new ArrayList<>();
subSessionId = Optional.empty();
+ mChipId = chipId;
}
public int getSessionId() {