Merge "Creates DataUtils to convert data"
diff --git a/nearby/service/java/com/android/server/nearby/fastpair/FastPairAdvHandler.java b/nearby/service/java/com/android/server/nearby/fastpair/FastPairAdvHandler.java
index fd44e37..3f7ad2a 100644
--- a/nearby/service/java/com/android/server/nearby/fastpair/FastPairAdvHandler.java
+++ b/nearby/service/java/com/android/server/nearby/fastpair/FastPairAdvHandler.java
@@ -30,14 +30,12 @@
import com.android.server.nearby.common.locator.Locator;
import com.android.server.nearby.fastpair.halfsheet.FastPairHalfSheetManager;
import com.android.server.nearby.provider.FastPairDataProvider;
+import com.android.server.nearby.util.DataUtils;
import com.android.server.nearby.util.FastPairDecoder;
import com.android.server.nearby.util.Hex;
-import com.google.protobuf.ByteString;
-
import java.util.List;
-import service.proto.Cache;
import service.proto.Data;
import service.proto.Rpcs;
@@ -80,11 +78,8 @@
Rpcs.GetObservedDeviceResponse response =
FastPairDataProvider.getInstance()
.loadFastPairAntispoofkeyDeviceMetadata(model);
- ByteString publicKey = response.getDevice().getAntiSpoofingKeyPair().getPublicKey();
Locator.get(mContext, FastPairHalfSheetManager.class).showHalfSheet(
- Cache.ScanFastPairStoreItem.newBuilder().setAddress(mBleAddress)
- .setAntiSpoofingPublicKey(publicKey)
- .build());
+ DataUtils.toScanFastPairStoreItem(response, mBleAddress));
} catch (IllegalStateException e) {
Log.e(TAG, "OEM does not construct fast pair data proxy correctly");
}
diff --git a/nearby/service/java/com/android/server/nearby/util/DataUtils.java b/nearby/service/java/com/android/server/nearby/util/DataUtils.java
new file mode 100644
index 0000000..c67d2f3
--- /dev/null
+++ b/nearby/service/java/com/android/server/nearby/util/DataUtils.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.nearby.util;
+
+import service.proto.Cache.ScanFastPairStoreItem;
+import service.proto.Cache.StoredDiscoveryItem;
+import service.proto.FastPairString.FastPairStrings;
+import service.proto.Rpcs.Device;
+import service.proto.Rpcs.GetObservedDeviceResponse;
+import service.proto.Rpcs.ObservedDeviceStrings;
+
+/**
+ * Utils class converts different data types {@link ScanFastPairStoreItem},
+ * {@link StoredDiscoveryItem} and {@link GetObservedDeviceResponse},
+ *
+ */
+public final class DataUtils {
+
+ /**
+ * Converts a {@link GetObservedDeviceResponse} to a {@link ScanFastPairStoreItem}.
+ */
+ public static ScanFastPairStoreItem toScanFastPairStoreItem(
+ GetObservedDeviceResponse observedDeviceResponse, String bleAddress) {
+ Device device = observedDeviceResponse.getDevice();
+ ScanFastPairStoreItem item = ScanFastPairStoreItem.newBuilder()
+ .setAddress(bleAddress)
+ .setActionUrl(device.getIntentUri())
+ .setDeviceName(device.getName())
+ .setIconPng(observedDeviceResponse.getImage())
+ .setIconFifeUrl(device.getImageUrl())
+ .setAntiSpoofingPublicKey(device.getAntiSpoofingKeyPair().getPublicKey())
+ .setFastPairStrings(getFastPairStrings(observedDeviceResponse))
+ .build();
+ return item;
+ }
+
+ private static FastPairStrings getFastPairStrings(GetObservedDeviceResponse response) {
+ ObservedDeviceStrings strings = response.getStrings();
+ return FastPairStrings.newBuilder()
+ .setTapToPairWithAccount(strings.getInitialNotificationDescription())
+ .setTapToPairWithoutAccount(
+ strings.getInitialNotificationDescriptionNoAccount())
+ .setInitialPairingDescription(strings.getInitialPairingDescription())
+ .setPairingFinishedCompanionAppInstalled(
+ strings.getConnectSuccessCompanionAppInstalled())
+ .setPairingFinishedCompanionAppNotInstalled(
+ strings.getConnectSuccessCompanionAppNotInstalled())
+ .setSubsequentPairingDescription(strings.getSubsequentPairingDescription())
+ .setRetroactivePairingDescription(strings.getRetroactivePairingDescription())
+ .setWaitAppLaunchDescription(strings.getWaitLaunchCompanionAppDescription())
+ .setPairingFailDescription(strings.getFailConnectGoToSettingsDescription())
+ .setAssistantHalfSheetDescription(strings.getAssistantSetupHalfSheet())
+ .setAssistantNotificationDescription(strings.getAssistantSetupNotification())
+ .setFastPairTvConnectDeviceNoAccountDescription(
+ strings.getFastPairTvConnectDeviceNoAccountDescription())
+ .build();
+ }
+}