[Fast Pair] Add base FastPairNotificationBuilder
See nearby/discovery/ui/DiscoveryNotificationCompatBuilder.java
e2e video: https://photos.app.goo.gl/WawkcRm9eND3HfBb7
Test: -m
Bug: 247152236
Ignore-AOSP-First: nearby_not_in_aosp_yet
Change-Id: Ia03dd79417c0004f85427dba8d1e07848a6e4641
diff --git a/nearby/tests/unit/Android.bp b/nearby/tests/unit/Android.bp
index 9b35452..8a8aeab 100644
--- a/nearby/tests/unit/Android.bp
+++ b/nearby/tests/unit/Android.bp
@@ -29,6 +29,7 @@
"android.test.base",
"android.test.mock",
"android.test.runner",
+ "HalfSheetUX",
],
compile_multilib: "both",
diff --git a/nearby/tests/unit/src/com/android/server/nearby/fastpair/notification/FastPairNotificationBuilderTest.java b/nearby/tests/unit/src/com/android/server/nearby/fastpair/notification/FastPairNotificationBuilderTest.java
new file mode 100644
index 0000000..b644c91
--- /dev/null
+++ b/nearby/tests/unit/src/com/android/server/nearby/fastpair/notification/FastPairNotificationBuilderTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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.fastpair.notification;
+
+import static com.android.server.nearby.fastpair.notification.FastPairNotificationBuilder.NOTIFICATION_OVERRIDE_NAME_EXTRA;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.app.Notification;
+import android.content.Context;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import com.android.nearby.halfsheet.R;
+import com.android.server.nearby.fastpair.HalfSheetResources;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class FastPairNotificationBuilderTest {
+
+ private static final String STRING_DEVICE = "Devices";
+ private static final String STRING_NEARBY = "Nearby";
+
+ @Mock private Context mContext;
+ @Mock private PackageManager mPackageManager;
+ @Mock private Resources mResources;
+
+ private ResolveInfo mResolveInfo;
+ private List<ResolveInfo> mResolveInfoList;
+ private ApplicationInfo mApplicationInfo;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ HalfSheetResources.setResourcesContextForTest(mContext);
+
+ mResolveInfo = new ResolveInfo();
+ mResolveInfoList = new ArrayList<>();
+ mResolveInfo.activityInfo = new ActivityInfo();
+ mApplicationInfo = new ApplicationInfo();
+ mPackageManager = mock(PackageManager.class);
+
+ when(mContext.getResources()).thenReturn(mResources);
+ when(mContext.getApplicationInfo())
+ .thenReturn(InstrumentationRegistry
+ .getInstrumentation().getContext().getApplicationInfo());
+ when(mContext.getContentResolver()).thenReturn(
+ InstrumentationRegistry.getInstrumentation().getContext().getContentResolver());
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(mResolveInfoList);
+ when(mPackageManager.canRequestPackageInstalls()).thenReturn(false);
+ mApplicationInfo.sourceDir = "/apex/com.android.nearby";
+ mApplicationInfo.packageName = "test.package";
+ mResolveInfo.activityInfo.applicationInfo = mApplicationInfo;
+ mResolveInfoList.add(mResolveInfo);
+
+ when(mResources.getString(eq(R.string.common_devices))).thenReturn(STRING_DEVICE);
+ when(mResources.getString(eq(R.string.common_nearby_title))).thenReturn(STRING_NEARBY);
+ }
+
+ @Test
+ public void setIsDevice_true() {
+ Notification notification =
+ new FastPairNotificationBuilder(mContext, "channelId")
+ .setIsDevice(true).build();
+ assertThat(notification.extras.getString(NOTIFICATION_OVERRIDE_NAME_EXTRA))
+ .isEqualTo(STRING_DEVICE);
+ }
+
+ @Test
+ public void setIsDevice_false() {
+ Notification notification =
+ new FastPairNotificationBuilder(mContext, "channelId")
+ .setIsDevice(false).build();
+ assertThat(notification.extras.getString(NOTIFICATION_OVERRIDE_NAME_EXTRA))
+ .isEqualTo(STRING_NEARBY);
+ }
+}