Merge "Add data level CTS test for FastPairDataProviderBase to ensure getter/setter correctness."
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 6538462..a792c0b 100644
--- a/nearby/service/java/com/android/server/nearby/fastpair/FastPairAdvHandler.java
+++ b/nearby/service/java/com/android/server/nearby/fastpair/FastPairAdvHandler.java
@@ -23,12 +23,14 @@
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.FastPairDecoder;
import com.android.server.nearby.util.Hex;
import com.google.protobuf.ByteString;
import service.proto.Cache;
+import service.proto.Rpcs;
/**
* Handler that handle fast pair related broadcast.
@@ -59,10 +61,12 @@
Log.d("FastPairService",
"On discovery model id" + Hex.bytesToStringLowercase(model));
// Use api to get anti spoofing key from model id.
+ Rpcs.GetObservedDeviceResponse response =
+ FastPairDataProvider.getInstance().loadFastPairDeviceMetadata(model);
+ ByteString publicKey = response.getDevice().getAntiSpoofingKeyPair().getPublicKey();
Locator.get(mContext, FastPairHalfSheetManager.class).showHalfSheet(
- Cache.ScanFastPairStoreItem.newBuilder()
- .setAddress(mBleAddress)
- .setAntiSpoofingPublicKey(ByteString.EMPTY)
+ Cache.ScanFastPairStoreItem.newBuilder().setAddress(mBleAddress)
+ .setAntiSpoofingPublicKey(publicKey)
.build());
}
}
diff --git a/nearby/service/java/com/android/server/nearby/fastpair/FastPairManager.java b/nearby/service/java/com/android/server/nearby/fastpair/FastPairManager.java
index 41b6da7..bc1603e 100644
--- a/nearby/service/java/com/android/server/nearby/fastpair/FastPairManager.java
+++ b/nearby/service/java/com/android/server/nearby/fastpair/FastPairManager.java
@@ -48,14 +48,10 @@
import com.android.server.nearby.fastpair.cache.DiscoveryItem;
import com.android.server.nearby.fastpair.cache.FastPairCacheManager;
import com.android.server.nearby.fastpair.footprint.FootprintsDeviceManager;
-import com.android.server.nearby.fastpair.halfsheet.FastPairHalfSheetManager;
import com.android.server.nearby.fastpair.pairinghandler.PairingProgressHandlerBase;
-import com.android.server.nearby.provider.FastPairDataProvider;
import com.android.server.nearby.util.FastPairDecoder;
import com.android.server.nearby.util.Hex;
-import com.google.protobuf.ByteString;
-
import java.security.GeneralSecurityException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
@@ -65,7 +61,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import service.proto.Cache;
import service.proto.Rpcs;
/**
@@ -79,10 +74,6 @@
/** A notification ID which should be dismissed */
public static final String EXTRA_NOTIFICATION_ID = ACTION_PREFIX + "EXTRA_NOTIFICATION_ID";
public static final String ACTION_RESOURCES_APK = "android.nearby.SHOW_HALFSHEET";
- // Temp action deleted when the scanner is ready
- public static final String ACTION_START_PAIRING = "NEARBY_START_PAIRING";
- public static final String EXTRA_MODEL_ID = "MODELID";
- public static final String EXTRA_ADDRESS = "ADDRESS";
private static Executor sFastPairExecutor;
@@ -110,17 +101,6 @@
Log.d("FastPairService", " the nearby manager is null");
}
- } else if (intent.getAction().equals(ACTION_START_PAIRING)) {
- byte[] model = intent.getByteArrayExtra(EXTRA_MODEL_ID);
- String address = intent.getStringExtra(EXTRA_ADDRESS);
- Log.d("FastPairService", "start pair " + address);
- Rpcs.GetObservedDeviceResponse response =
- FastPairDataProvider.getInstance().loadFastPairDeviceMetadata(model);
- ByteString publicKey = response.getDevice().getAntiSpoofingKeyPair().getPublicKey();
- Locator.get(mLocatorContextWrapper, FastPairHalfSheetManager.class).showHalfSheet(
- Cache.ScanFastPairStoreItem.newBuilder().setAddress(address)
- .setAntiSpoofingPublicKey(publicKey)
- .build());
} else {
Log.d("FastPairService", " screen off");
}
@@ -166,7 +146,6 @@
public void initiate() {
mIntentFilter.addAction(Intent.ACTION_SCREEN_ON);
mIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
- mIntentFilter.addAction(ACTION_START_PAIRING);
mLocatorContextWrapper.getContext()
.registerReceiver(mScreenBroadcastReceiver, mIntentFilter);
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyFrameworkInitializerTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyFrameworkInitializerTest.java
new file mode 100644
index 0000000..c062e84
--- /dev/null
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyFrameworkInitializerTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2021 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 android.nearby.cts;
+
+import android.annotation.TargetApi;
+import android.nearby.NearbyFrameworkInitializer;
+import android.os.Build;
+
+import androidx.annotation.RequiresApi;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+// NearbyFrameworkInitializer was added in T
+@RunWith(AndroidJUnit4.class)
+@RequiresApi(Build.VERSION_CODES.TIRAMISU)
+@TargetApi(Build.VERSION_CODES.TIRAMISU)
+public class NearbyFrameworkInitializerTest {
+
+// // TODO(b/215435710) This test cannot pass now because our test cannot access system API.
+// // run "adb root && adb shell setenforce permissive" and uncomment testServicesRegistered,
+// // test passes.
+// @Test
+// public void testServicesRegistered() {
+// Context ctx = InstrumentationRegistry.getInstrumentation().getContext();
+// assertNotNull( "NearbyManager not registered",
+// ctx.getSystemService(Context.NEARBY_SERVICE));
+// }
+
+ // registerServiceWrappers can only be called during initialization and should throw otherwise
+ @Test(expected = IllegalStateException.class)
+ public void testThrowsException() {
+ NearbyFrameworkInitializer.registerServiceWrappers();
+ }
+}