diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubService.java b/services/core/java/com/android/server/location/contexthub/ContextHubService.java index 4d302b19d89b8..350a30195700f 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubService.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubService.java @@ -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> hubInfo; + Pair, List> hubInfo; try { hubInfo = mContextHubWrapper.getHubs(); } catch (RemoteException e) { diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java b/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java index 70f50c3c60f8e..d0e00c481e430 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java @@ -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 createContextHubInfoMap(List hubList) { + static HashMap createContextHubInfoMap(List hubList) { HashMap 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; diff --git a/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java b/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java index 7be47a4e52a89..4b6d093e4dc49 100644 --- a/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java +++ b/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java @@ -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> getHubs() throws RemoteException; + public abstract Pair, List> 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> getHubs() throws RemoteException { - return new Pair(mHub.getHubs(), new ArrayList()); + public Pair, List> getHubs() throws RemoteException { + ArrayList hubInfoList = new ArrayList<>(); + for (ContextHub hub : mHub.getHubs()) { + hubInfoList.add(new ContextHubInfo(hub)); + } + return new Pair(hubInfoList, new ArrayList()); } public void registerCallback( @@ -214,8 +219,12 @@ public abstract class IContextHubWrapper { mHub = hub; } - public Pair, List> getHubs() throws RemoteException { - return new Pair(mHub.getHubs(), new ArrayList()); + public Pair, List> getHubs() throws RemoteException { + ArrayList hubInfoList = new ArrayList<>(); + for (ContextHub hub : mHub.getHubs()) { + hubInfoList.add(new ContextHubInfo(hub)); + } + return new Pair(hubInfoList, new ArrayList()); } 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> mHubInfo = + private Pair, List> 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 hubs, ArrayList supportedPermissions) { - mHubInfo = new Pair(hubs, supportedPermissions); + ArrayList hubInfoList = new ArrayList<>(); + for (ContextHub hub : hubs) { + hubInfoList.add(new ContextHubInfo(hub)); + } + mHubInfo = new Pair(hubInfoList, supportedPermissions); } - public Pair, List> getHubs() throws RemoteException { + public Pair, List> getHubs() throws RemoteException { mHub.getHubs_1_2(this); return mHubInfo; }