Refactors IContextHubWrapper to use ContextHubInfo

This is the first part of a series of CLs that will abstract out the
HIDL semantics of the Context Hub HAL proxies. In this CL, we rewrite
the getHubs() interface in the IContextHubWrapper to use the framework
semantics (ContextHubInfo).

Bug: 194285834
Test: Presubmit
Change-Id: I4d45aee965d5e46a301186578b83b5367b839f3d
This commit is contained in:
Arthur Ishiguro
2021-08-27 15:45:59 -07:00
parent 02c6b6cc9e
commit d452e39f94
3 changed files with 25 additions and 14 deletions

View File

@@ -28,7 +28,6 @@ import android.database.ContentObserver;
import android.hardware.SensorPrivacyManager;
import android.hardware.SensorPrivacyManagerInternal;
import android.hardware.contexthub.V1_0.AsyncEventType;
import android.hardware.contexthub.V1_0.ContextHub;
import android.hardware.contexthub.V1_0.ContextHubMsg;
import android.hardware.contexthub.V1_0.Result;
import android.hardware.contexthub.V1_0.TransactionResult;
@@ -200,7 +199,7 @@ public class ContextHubService extends IContextHubService.Stub {
return;
}
Pair<List<ContextHub>, List<String>> hubInfo;
Pair<List<ContextHubInfo>, List<String>> hubInfo;
try {
hubInfo = mContextHubWrapper.getHubs();
} catch (RemoteException e) {

View File

@@ -20,7 +20,6 @@ import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import android.Manifest;
import android.content.Context;
import android.hardware.contexthub.V1_0.ContextHub;
import android.hardware.contexthub.V1_0.ContextHubMsg;
import android.hardware.contexthub.V1_0.HostEndPoint;
import android.hardware.contexthub.V1_0.Result;
@@ -52,10 +51,10 @@ import java.util.List;
* @return the HashMap object
*/
/* package */
static HashMap<Integer, ContextHubInfo> createContextHubInfoMap(List<ContextHub> hubList) {
static HashMap<Integer, ContextHubInfo> createContextHubInfoMap(List<ContextHubInfo> hubList) {
HashMap<Integer, ContextHubInfo> contextHubIdToInfoMap = new HashMap<>();
for (ContextHub contextHub : hubList) {
contextHubIdToInfoMap.put(contextHub.hubId, new ContextHubInfo(contextHub));
for (ContextHubInfo contextHubInfo : hubList) {
contextHubIdToInfoMap.put(contextHubInfo.getId(), contextHubInfo);
}
return contextHubIdToInfoMap;

View File

@@ -20,6 +20,7 @@ import android.hardware.contexthub.V1_0.ContextHub;
import android.hardware.contexthub.V1_1.Setting;
import android.hardware.contexthub.V1_1.SettingValue;
import android.hardware.contexthub.V1_2.IContexthubCallback;
import android.hardware.location.ContextHubInfo;
import android.os.RemoteException;
import android.util.Log;
import android.util.Pair;
@@ -95,7 +96,7 @@ public abstract class IContextHubWrapper {
/**
* Calls the appropriate getHubs function depending on the HAL version.
*/
public abstract Pair<List<ContextHub>, List<String>> getHubs() throws RemoteException;
public abstract Pair<List<ContextHubInfo>, List<String>> getHubs() throws RemoteException;
/**
* Calls the appropriate registerCallback function depending on the HAL version.
@@ -165,8 +166,12 @@ public abstract class IContextHubWrapper {
mHub = hub;
}
public Pair<List<ContextHub>, List<String>> getHubs() throws RemoteException {
return new Pair(mHub.getHubs(), new ArrayList<String>());
public Pair<List<ContextHubInfo>, List<String>> getHubs() throws RemoteException {
ArrayList<ContextHubInfo> hubInfoList = new ArrayList<>();
for (ContextHub hub : mHub.getHubs()) {
hubInfoList.add(new ContextHubInfo(hub));
}
return new Pair(hubInfoList, new ArrayList<String>());
}
public void registerCallback(
@@ -214,8 +219,12 @@ public abstract class IContextHubWrapper {
mHub = hub;
}
public Pair<List<ContextHub>, List<String>> getHubs() throws RemoteException {
return new Pair(mHub.getHubs(), new ArrayList<String>());
public Pair<List<ContextHubInfo>, List<String>> getHubs() throws RemoteException {
ArrayList<ContextHubInfo> hubInfoList = new ArrayList<>();
for (ContextHub hub : mHub.getHubs()) {
hubInfoList.add(new ContextHubInfo(hub));
}
return new Pair(hubInfoList, new ArrayList<String>());
}
public void registerCallback(
@@ -266,7 +275,7 @@ public abstract class IContextHubWrapper {
implements android.hardware.contexthub.V1_2.IContexthub.getHubs_1_2Callback {
private final android.hardware.contexthub.V1_2.IContexthub mHub;
private Pair<List<ContextHub>, List<String>> mHubInfo =
private Pair<List<ContextHubInfo>, List<String>> mHubInfo =
new Pair<>(Collections.emptyList(), Collections.emptyList());
ContextHubWrapperV1_2(android.hardware.contexthub.V1_2.IContexthub hub) {
@@ -275,10 +284,14 @@ public abstract class IContextHubWrapper {
@Override
public void onValues(ArrayList<ContextHub> hubs, ArrayList<String> supportedPermissions) {
mHubInfo = new Pair(hubs, supportedPermissions);
ArrayList<ContextHubInfo> hubInfoList = new ArrayList<>();
for (ContextHub hub : hubs) {
hubInfoList.add(new ContextHubInfo(hub));
}
mHubInfo = new Pair(hubInfoList, supportedPermissions);
}
public Pair<List<ContextHub>, List<String>> getHubs() throws RemoteException {
public Pair<List<ContextHubInfo>, List<String>> getHubs() throws RemoteException {
mHub.getHubs_1_2(this);
return mHubInfo;
}