CDM UI cleanUp

1. Introduce some common style.
2. Make the borders full fill the view for multiple device
3. Increasing the width of cdm dilog.

Test: atest CtsCompanionDeviceManagerCoreTestCases
      atest CtsCompanionDeviceManagerUiAutomationTestCases
      atest CtsOsTestCases:CompanionDeviceManagerTest

Bug: 216638097
Change-Id: I848adf9287a5505882f3a9fb6c9cc45c30ae6d00
diff --git a/packages/CompanionDeviceManager/res/color/selector.xml b/packages/CompanionDeviceManager/res/color/selector.xml
index 56e5dca..aebc5d5 100644
--- a/packages/CompanionDeviceManager/res/color/selector.xml
+++ b/packages/CompanionDeviceManager/res/color/selector.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
diff --git a/packages/CompanionDeviceManager/res/drawable/btn_negative_multiple_devices.xml b/packages/CompanionDeviceManager/res/drawable/btn_negative_multiple_devices.xml
index ece7bba..ebe16a7 100644
--- a/packages/CompanionDeviceManager/res/drawable/btn_negative_multiple_devices.xml
+++ b/packages/CompanionDeviceManager/res/drawable/btn_negative_multiple_devices.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
diff --git a/packages/CompanionDeviceManager/res/drawable/btn_negative_top.xml b/packages/CompanionDeviceManager/res/drawable/btn_negative_top.xml
index 55e96f6..3cd7929 100644
--- a/packages/CompanionDeviceManager/res/drawable/btn_negative_top.xml
+++ b/packages/CompanionDeviceManager/res/drawable/btn_negative_top.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
diff --git a/packages/CompanionDeviceManager/res/drawable/btn_positive_bottom.xml b/packages/CompanionDeviceManager/res/drawable/btn_positive_bottom.xml
index 7df92bb..2cff473 100644
--- a/packages/CompanionDeviceManager/res/drawable/btn_positive_bottom.xml
+++ b/packages/CompanionDeviceManager/res/drawable/btn_positive_bottom.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
diff --git a/packages/CompanionDeviceManager/res/drawable/helper_ok_button.xml b/packages/CompanionDeviceManager/res/drawable/helper_ok_button.xml
index f9ec5d0..8e92051f 100644
--- a/packages/CompanionDeviceManager/res/drawable/helper_ok_button.xml
+++ b/packages/CompanionDeviceManager/res/drawable/helper_ok_button.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
diff --git a/packages/CompanionDeviceManager/res/drawable/ic_apps.xml b/packages/CompanionDeviceManager/res/drawable/ic_apps.xml
index 93a0cba..d1ec863 100644
--- a/packages/CompanionDeviceManager/res/drawable/ic_apps.xml
+++ b/packages/CompanionDeviceManager/res/drawable/ic_apps.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
diff --git a/packages/CompanionDeviceManager/res/drawable/ic_device_other.xml b/packages/CompanionDeviceManager/res/drawable/ic_device_other.xml
index f8515c3..2a8eb24 100644
--- a/packages/CompanionDeviceManager/res/drawable/ic_device_other.xml
+++ b/packages/CompanionDeviceManager/res/drawable/ic_device_other.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
diff --git a/packages/CompanionDeviceManager/res/drawable/ic_notifications.xml b/packages/CompanionDeviceManager/res/drawable/ic_notifications.xml
index 4ac4d04..e5825bc 100644
--- a/packages/CompanionDeviceManager/res/drawable/ic_notifications.xml
+++ b/packages/CompanionDeviceManager/res/drawable/ic_notifications.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
diff --git a/packages/CompanionDeviceManager/res/drawable/ic_storage.xml b/packages/CompanionDeviceManager/res/drawable/ic_storage.xml
index d8b7f59..406a3b5 100644
--- a/packages/CompanionDeviceManager/res/drawable/ic_storage.xml
+++ b/packages/CompanionDeviceManager/res/drawable/ic_storage.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
diff --git a/packages/CompanionDeviceManager/res/drawable/ic_watch.xml b/packages/CompanionDeviceManager/res/drawable/ic_watch.xml
index 44a40b9f..d7a28d9 100644
--- a/packages/CompanionDeviceManager/res/drawable/ic_watch.xml
+++ b/packages/CompanionDeviceManager/res/drawable/ic_watch.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
diff --git a/packages/CompanionDeviceManager/res/layout/activity_confirmation.xml b/packages/CompanionDeviceManager/res/layout/activity_confirmation.xml
index ecda733..c37054e 100644
--- a/packages/CompanionDeviceManager/res/layout/activity_confirmation.xml
+++ b/packages/CompanionDeviceManager/res/layout/activity_confirmation.xml
@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- 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
@@ -20,35 +19,26 @@
     <!-- A header for selfManaged devices only. -->
     <include layout="@layout/vendor_header" />
 
+    <!-- Do NOT change the ID of the root LinearLayout above: it's referenced in CTS tests. -->
+
     <ImageView
         android:id="@+id/profile_icon"
         android:layout_width="match_parent"
         android:layout_height="32dp"
         android:gravity="center"
-        android:layout_marginBottom="12dp"
-        android:layout_marginTop="1dp"
+        android:layout_marginTop="18dp"
         android:tint="@android:color/system_accent1_600"/>
 
-    <!-- Do NOT change the ID of the root LinearLayout above: it's referenced in CTS tests. -->
+    <LinearLayout style="@style/Description">
+        <TextView
+            android:id="@+id/title"
+            style="@style/DescriptionTitle" />
 
-    <TextView
-        android:id="@+id/title"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:gravity="center"
-        android:paddingHorizontal="12dp"
-        android:layout_marginBottom="12dp"
-        style="@*android:style/TextAppearance.Widget.Toolbar.Title" />
+        <TextView
+            android:id="@+id/summary"
+            style="@style/DescriptionSummary" />
 
-    <TextView
-        android:id="@+id/summary"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="12dp"
-        android:layout_marginBottom="12dp"
-        android:gravity="center"
-        android:textColor="?android:attr/textColorSecondary"
-        android:textSize="14sp" />
+    </LinearLayout>
 
     <RelativeLayout
         android:layout_width="match_parent"
@@ -59,18 +49,20 @@
             android:id="@+id/multiple_device_list"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
+            android:layout_marginTop="12dp"
+            android:layout_marginBottom="12dp"
             android:orientation="vertical"
             android:visibility="gone">
 
             <View
                 android:id="@+id/border_top"
-                android:layout_marginTop="12dp"
                 style="@style/DeviceListBorder" />
 
             <androidx.recyclerview.widget.RecyclerView
                 android:id="@+id/device_list"
                 android:layout_width="match_parent"
                 android:scrollbars="vertical"
+                android:layout_marginBottom="12dp"
                 android:layout_height="200dp" />
 
             <View
@@ -99,8 +91,9 @@
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:gravity="center"
         android:orientation="vertical"
-        android:layout_marginTop="24dp">
+        android:layout_marginTop="16dp">
 
         <!-- Do NOT change the IDs of the buttons: they are referenced in CTS tests. -->
 
@@ -111,18 +104,28 @@
 
         <Button
             android:id="@+id/btn_negative"
+            android:layout_marginBottom="12dp"
             style="@style/NegativeButton"
             android:text="@string/consent_no" />
 
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:gravity="bottom|right"
+        android:orientation="vertical"
+        android:layout_marginRight="16dp"
+        android:layout_marginBottom="16dp">
+
+        <!-- Do NOT change the IDs of the buttons: they are referenced in CTS tests. -->
+
         <Button
             android:id="@+id/btn_negative_multiple_devices"
-            android:layout_marginLeft="170dp"
-            android:layout_marginBottom="10dp"
             style="@style/NegativeButtonMultipleDevices"
-            android:textColor = "?android:textColorPrimary"
+            android:textColor="?android:textColorPrimary"
             android:visibility="gone"
             android:text="@string/consent_no" />
-
     </LinearLayout>
 
 </LinearLayout>
\ No newline at end of file
diff --git a/packages/CompanionDeviceManager/res/layout/data_transfer_confirmation.xml b/packages/CompanionDeviceManager/res/layout/data_transfer_confirmation.xml
index 7c50814..3d08493 100644
--- a/packages/CompanionDeviceManager/res/layout/data_transfer_confirmation.xml
+++ b/packages/CompanionDeviceManager/res/layout/data_transfer_confirmation.xml
@@ -15,54 +15,42 @@
   ~ limitations under the License.
   -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-              android:id="@+id/activity_confirmation"
-              android:layout_width="match_parent"
-              android:layout_height="wrap_content"
-              android:background="@drawable/dialog_background"
-              android:elevation="16dp"
-              android:maxHeight="400dp"
-              android:orientation="vertical"
-              android:padding="18dp"
-              android:layout_gravity="center">
+              android:id="@+id/data_transfer_confirmation"
+              style="@style/ContainerLayout">
 
     <!-- Do NOT change the ID of the root LinearLayout above: it's referenced in CTS tests. -->
 
-    <TextView
-        android:id="@+id/title"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:gravity="center"
-        android:paddingHorizontal="12dp"
-        style="@*android:style/TextAppearance.Widget.Toolbar.Title"/>
+    <LinearLayout style="@style/Description">
+        <TextView
+            android:id="@+id/title"
+            style="@style/DescriptionTitle" />
 
-    <TextView
-        android:id="@+id/summary"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="12dp"
-        android:layout_marginBottom="12dp"
-        android:gravity="center"
-        android:textColor="?android:attr/textColorSecondary"
-        android:textSize="14sp" />
+        <TextView
+            android:id="@+id/summary"
+            style="@style/DescriptionSummary" />
+
+    </LinearLayout>
 
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:gravity="center"
         android:orientation="vertical"
-        android:layout_marginTop="24dp">
+        android:layout_marginTop="16dp">
 
         <!-- Do NOT change the IDs of the buttons: they are referenced in CTS tests. -->
 
         <Button
-            android:id="@+id/btn_negative"
-            style="@style/NegativeButton"
-            android:text="@string/consent_no" />
-
-        <Button
             android:id="@+id/btn_positive"
             style="@style/PositiveButton"
             android:text="@string/consent_yes" />
 
+        <Button
+            android:id="@+id/btn_negative"
+            android:layout_marginBottom="12dp"
+            style="@style/NegativeButton"
+            android:text="@string/consent_no" />
+
     </LinearLayout>
 
 </LinearLayout>
\ No newline at end of file
diff --git a/packages/CompanionDeviceManager/res/layout/helper_confirmation.xml b/packages/CompanionDeviceManager/res/layout/helper_confirmation.xml
index c177039..a22ca94 100644
--- a/packages/CompanionDeviceManager/res/layout/helper_confirmation.xml
+++ b/packages/CompanionDeviceManager/res/layout/helper_confirmation.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
@@ -17,6 +18,7 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:id="@+id/helper_confirmation"
               android:theme="@style/ChooserActivity"
+              android:padding="12dp"
               style="@style/ContainerLayout">
 
     <ImageView
@@ -24,8 +26,8 @@
         android:layout_width="match_parent"
         android:layout_height="32dp"
         android:gravity="center"
-        android:layout_marginBottom="12dp"
-        android:layout_marginTop="1dp"/>
+        android:layout_marginTop="12dp"
+        android:layout_marginBottom="12dp"/>
 
     <TextView
         android:id="@+id/helper_title"
@@ -33,17 +35,18 @@
         android:layout_height="wrap_content"
         android:gravity="center"
         android:paddingHorizontal="12dp"
-        style="@*android:style/TextAppearance.Widget.Toolbar.Title"
-        android:textSize="20sp" />
+        android:textColor="?android:attr/textColorPrimary"
+        android:textSize="22sp" />
 
     <TextView
         android:id="@+id/helper_summary"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:layout_marginLeft="24dp"
+        android:layout_marginRight="24dp"
         android:layout_marginTop="12dp"
-        android:layout_marginLeft="20dp"
         android:layout_marginBottom="24dp"
-        android:gravity="start"
+        android:gravity="center"
         android:textColor="?android:attr/textColorSecondary"
         android:textSize="14sp" />
 
@@ -51,6 +54,8 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
+        android:layout_marginRight="12dp"
+        android:layout_marginBottom="12dp"
         android:gravity="end">
 
         <Button
diff --git a/packages/CompanionDeviceManager/res/layout/list_item_device.xml b/packages/CompanionDeviceManager/res/layout/list_item_device.xml
index 3c8a81f..eeb988f 100644
--- a/packages/CompanionDeviceManager/res/layout/list_item_device.xml
+++ b/packages/CompanionDeviceManager/res/layout/list_item_device.xml
@@ -28,6 +28,7 @@
         android:id="@android:id/icon"
         android:layout_width="24dp"
         android:layout_height="24dp"
+        android:layout_marginLeft="24dp"
         android:layout_marginRight="12dp"
         android:tint="@android:color/system_accent1_600"/>
 
diff --git a/packages/CompanionDeviceManager/res/layout/list_item_permission.xml b/packages/CompanionDeviceManager/res/layout/list_item_permission.xml
index 79aa4e7..3dce38d 100644
--- a/packages/CompanionDeviceManager/res/layout/list_item_permission.xml
+++ b/packages/CompanionDeviceManager/res/layout/list_item_permission.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
@@ -19,13 +20,15 @@
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:orientation="horizontal"
-              android:padding="5dp">
+              android:paddingLeft="32dp"
+              android:paddingRight="32dp"
+              android:paddingBottom="14dp">
 
     <ImageView
         android:id="@+id/permission_icon"
         android:layout_width="24dp"
         android:layout_height="24dp"
-        android:layout_marginTop="7dp"
+        android:layout_marginTop="8dp"
         android:layout_marginEnd="12dp"
         android:tint="@android:color/system_accent1_600"
         android:contentDescription="Permission Icon"/>
@@ -48,6 +51,7 @@
             android:id="@+id/permission_summary"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
+            android:paddingRight="24dp"
             android:textSize="14sp"
             android:textColor="?android:attr/textColorSecondary"/>
 
diff --git a/packages/CompanionDeviceManager/res/layout/vendor_header.xml b/packages/CompanionDeviceManager/res/layout/vendor_header.xml
index d04eadf..5f6aa94 100644
--- a/packages/CompanionDeviceManager/res/layout/vendor_header.xml
+++ b/packages/CompanionDeviceManager/res/layout/vendor_header.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
@@ -21,7 +22,10 @@
     android:layout_height="wrap_content"
     android:orientation="horizontal"
     android:layout_gravity="center"
-    android:layout_marginBottom="16dp"
+    android:paddingTop="24dp"
+    android:paddingBottom="4dp"
+    android:paddingLeft="24dp"
+    android:paddingRight="24dp"
     android:visibility="gone" >
 
     <ImageView
@@ -42,7 +46,6 @@
         style="?android:attr/actionOverflowButtonStyle"
         android:layout_width="31dp"
         android:layout_height="32dp"
-        android:layout_marginLeft="100dp"
         android:layout_alignParentRight="true" />
 
 </RelativeLayout>
\ No newline at end of file
diff --git a/packages/CompanionDeviceManager/res/values/styles.xml b/packages/CompanionDeviceManager/res/values/styles.xml
index cadea6e..a55f30c9 100644
--- a/packages/CompanionDeviceManager/res/values/styles.xml
+++ b/packages/CompanionDeviceManager/res/values/styles.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!--
   ~ Copyright (C) 2022 The Android Open Source Project
   ~
@@ -16,20 +17,50 @@
 
 <resources>
     <style name="ContainerLayout">
-        <item name="android:padding">18dp</item>
-        <item name="android:elevation">16dp</item>
-        <item name="android:maxHeight">400dp</item>
-        <item name="android:orientation">vertical</item>
-        <item name="android:layout_gravity">center</item>
         <item name="android:layout_width">match_parent</item>
         <item name="android:layout_height">wrap_content</item>
+        <item name="android:orientation">vertical</item>
+        <item name="android:layout_gravity">center</item>
+        <item name="android:minWidth">340dp</item>
         <item name="android:background">@drawable/dialog_background</item>
     </style>
 
+    <style name="Description">
+        <item name="android:layout_width">match_parent</item>
+        <item name="android:layout_height">wrap_content</item>
+        <item name="android:orientation">vertical</item>
+        <item name="android:layout_marginTop">18dp</item>
+        <item name="android:layout_marginBottom">18dp</item>
+        <item name="android:layout_marginLeft">24dp</item>
+        <item name="android:layout_marginRight">24dp</item>
+    </style>
+
+    <style name="DescriptionTitle"
+           parent="@*android:style/TextAppearance.Widget.Toolbar.Title">
+        <item name="android:layout_width">match_parent</item>
+        <item name="android:layout_height">wrap_content</item>
+        <item name="android:gravity">center</item>
+        <item name="android:layout_marginLeft">14dp</item>
+        <item name="android:layout_marginRight">14dp</item>
+        <item name="android:textSize">20sp</item>
+        <item name="android:textColor">?android:attr/textColorPrimary</item>
+    </style>
+
+    <style name="DescriptionSummary">
+        <item name="android:layout_width">match_parent</item>
+        <item name="android:layout_height">wrap_content</item>
+        <item name="android:gravity">center</item>
+        <item name="android:layout_marginTop">18dp</item>
+        <item name="android:layout_marginLeft">18dp</item>
+        <item name="android:layout_marginRight">18dp</item>
+        <item name="android:textSize">14sp</item>
+        <item name="android:textColor">?android:attr/textColorSecondary</item>
+    </style>
+
     <style name="VendorHelperOkButton"
            parent="@android:style/Widget.Material.Button.Borderless.Colored">
         <item name="android:layout_width">50dp</item>
-        <item name="android:layout_height">35dp</item>
+        <item name="android:layout_height">36dp</item>
         <item name="android:layout_marginTop">20dp</item>
         <item name="android:textColor">@android:color/system_neutral1_900</item>
         <item name="android:background">@drawable/helper_ok_button</item>
@@ -37,8 +68,11 @@
 
     <style name="PositiveButton"
            parent="@android:style/Widget.Material.Button.Borderless.Colored">
-        <item name="android:layout_width">match_parent</item>
-        <item name="android:layout_height">wrap_content</item>
+        <item name="android:layout_width">300dp</item>
+        <item name="android:layout_height">56dp</item>
+        <item name="android:layout_marginLeft">24dp</item>
+        <item name="android:layout_marginRight">24dp</item>
+        <item name="android:layout_marginBottom">2dp</item>
         <item name="android:textAllCaps">false</item>
         <item name="android:textSize">14sp</item>
         <item name="android:textColor">@android:color/system_neutral1_900</item>
@@ -47,8 +81,11 @@
 
     <style name="NegativeButton"
            parent="@android:style/Widget.Material.Button.Borderless.Colored">
-        <item name="android:layout_width">match_parent</item>
-        <item name="android:layout_height">wrap_content</item>
+        <item name="android:layout_width">300dp</item>
+        <item name="android:layout_height">56dp</item>
+        <item name="android:layout_marginLeft">24dp</item>
+        <item name="android:layout_marginRight">24dp</item>
+        <item name="android:layout_marginTop">2dp</item>
         <item name="android:textAllCaps">false</item>
         <item name="android:textSize">14sp</item>
         <item name="android:textColor">@android:color/system_neutral1_900</item>
@@ -59,8 +96,7 @@
     <style name="NegativeButtonMultipleDevices"
            parent="@android:style/Widget.Material.Button.Colored">
         <item name="android:layout_width">100dp</item>
-        <item name="android:layout_height">35dp</item>
-        <item name="android:layout_marginTop">20dp</item>
+        <item name="android:layout_height">36dp</item>
         <item name="android:textAllCaps">false</item>
         <item name="android:background">@drawable/btn_negative_multiple_devices</item>
     </style>
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
index 8124853..0bdf65d 100644
--- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
+++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
@@ -511,7 +511,7 @@
         CompanionDeviceDiscoveryService.getScanResult().observe(this,
                 deviceFilterPairs -> {
                     // Dismiss the progress bar once there's one device found for multiple devices.
-                    if (deviceFilterPairs.size() == 1) {
+                    if (deviceFilterPairs.size() >= 1) {
                         mProgressIndicator.setVisibility(View.GONE);
                     }
 
@@ -571,7 +571,7 @@
                 CompanionVendorHelperDialogFragment.newInstance(mRequest.getPackageName(),
                         mRequest.getUserId(), mRequest.getDeviceProfile());
 
-        mAssociationConfirmationDialog.setVisibility(View.GONE);
+        mAssociationConfirmationDialog.setVisibility(View.INVISIBLE);
 
         fragmentDialog.show(fragmentManager, /* Tag */ FRAGMENT_DIALOG_TAG);
     }
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceDiscoveryService.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceDiscoveryService.java
index 5f07fcf..e8a1a5c 100644
--- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceDiscoveryService.java
+++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceDiscoveryService.java
@@ -150,6 +150,8 @@
         mBtAdapter = mBtManager.getAdapter();
         mBleScanner = mBtAdapter.getBluetoothLeScanner();
         mWifiManager = getSystemService(WifiManager.class);
+
+        sScanResultsLiveData.setValue(Collections.emptyList());
     }
 
     @Override
@@ -186,7 +188,6 @@
         mStopAfterFirstMatch = request.isSingleDevice();
         mDiscoveryStarted = true;
         sStateLiveData.setValue(DiscoveryState.DISCOVERY_IN_PROGRESS);
-        sScanResultsLiveData.setValue(Collections.emptyList());
 
         final List<DeviceFilter<?>> allFilters = request.getDeviceFilters();
         final List<BluetoothDeviceFilter> btFilters =