Update Computer dialog UI

1. Replaced the three dots button to info icon
2. set tint color for header image button and
application icon
3. Make sure only set tint color if application
provides the metadata.
4. Including App name in the more info dialog.
5. Change the Ok button to Back

Test: atest CtsCompanionDeviceManagerCoreTestCases
      atest CtsCompanionDeviceManagerUiAutomationTestCases
      atest CtsOsTestCases:CompanionDeviceManagerTest

Bug: 216638097
Change-Id: Idba23ebc5cc21fc35676b0cccdb8d5b6ddf7af0a
diff --git a/packages/CompanionDeviceManager/res/drawable/helper_ok_button.xml b/packages/CompanionDeviceManager/res/drawable/helper_back_button.xml
similarity index 100%
rename from packages/CompanionDeviceManager/res/drawable/helper_ok_button.xml
rename to packages/CompanionDeviceManager/res/drawable/helper_back_button.xml
diff --git a/packages/CompanionDeviceManager/res/drawable/ic_info.xml b/packages/CompanionDeviceManager/res/drawable/ic_info.xml
new file mode 100644
index 0000000..d9f6a27
--- /dev/null
+++ b/packages/CompanionDeviceManager/res/drawable/ic_info.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24"
+        android:viewportHeight="24"
+        android:tint="@android:color/system_accent1_600">
+    <path android:fillColor="@android:color/white"
+          android:pathData="M11,17H13V11H11ZM12,9Q12.425,9 12.713,8.712Q13,8.425 13,8Q13,7.575 12.713,7.287Q12.425,7 12,7Q11.575,7 11.288,7.287Q11,7.575 11,8Q11,8.425 11.288,8.712Q11.575,9 12,9ZM12,22Q9.925,22 8.1,21.212Q6.275,20.425 4.925,19.075Q3.575,17.725 2.788,15.9Q2,14.075 2,12Q2,9.925 2.788,8.1Q3.575,6.275 4.925,4.925Q6.275,3.575 8.1,2.787Q9.925,2 12,2Q14.075,2 15.9,2.787Q17.725,3.575 19.075,4.925Q20.425,6.275 21.212,8.1Q22,9.925 22,12Q22,14.075 21.212,15.9Q20.425,17.725 19.075,19.075Q17.725,20.425 15.9,21.212Q14.075,22 12,22ZM12,12Q12,12 12,12Q12,12 12,12Q12,12 12,12Q12,12 12,12Q12,12 12,12Q12,12 12,12Q12,12 12,12Q12,12 12,12ZM12,20Q15.325,20 17.663,17.663Q20,15.325 20,12Q20,8.675 17.663,6.337Q15.325,4 12,4Q8.675,4 6.338,6.337Q4,8.675 4,12Q4,15.325 6.338,17.663Q8.675,20 12,20Z"/>
+</vector>
\ 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 a22ca94..a9ace44 100644
--- a/packages/CompanionDeviceManager/res/layout/helper_confirmation.xml
+++ b/packages/CompanionDeviceManager/res/layout/helper_confirmation.xml
@@ -59,9 +59,9 @@
         android:gravity="end">
 
         <Button
-            android:id="@+id/btn_ok"
-            style="@style/VendorHelperOkButton"
-            android:text="@string/consent_ok" />
+            android:id="@+id/btn_back"
+            style="@style/VendorHelperBackButton"
+            android:text="@string/consent_back" />
 
     </LinearLayout>
 
diff --git a/packages/CompanionDeviceManager/res/layout/vendor_header.xml b/packages/CompanionDeviceManager/res/layout/vendor_header.xml
index 5f6aa94..c35f59e 100644
--- a/packages/CompanionDeviceManager/res/layout/vendor_header.xml
+++ b/packages/CompanionDeviceManager/res/layout/vendor_header.xml
@@ -43,7 +43,7 @@
 
     <ImageButton
         android:id="@+id/vendor_header_button"
-        style="?android:attr/actionOverflowButtonStyle"
+        android:background="@drawable/ic_info"
         android:layout_width="31dp"
         android:layout_height="32dp"
         android:layout_alignParentRight="true" />
diff --git a/packages/CompanionDeviceManager/res/values/strings.xml b/packages/CompanionDeviceManager/res/values/strings.xml
index 67fc6c2..586a022 100644
--- a/packages/CompanionDeviceManager/res/values/strings.xml
+++ b/packages/CompanionDeviceManager/res/values/strings.xml
@@ -47,20 +47,11 @@
     <!-- Confirmation for associating an application with a companion device of APP_STREAMING profile (type) [CHAR LIMIT=NONE] -->
     <string name="title_app_streaming">Allow &lt;strong&gt;<xliff:g id="app_name" example="Exo">%1$s</xliff:g>&lt;/strong&gt; to access this information from your phone</string>
 
-    <!-- Description of the privileges the application will get if associated with the companion device of APP_STREAMING profile (type) [CHAR LIMIT=NONE] -->
-    <string name="summary_app_streaming" product="default">Let &lt;strong&gt;<xliff:g id="app_name" example="Exo">%1$s</xliff:g>&lt;/strong&gt; to provide &lt;strong&gt;<xliff:g id="device_name" example="Pixelbook Go">%2$s</xliff:g>&lt;/strong&gt; remote access to access to applications installed on this phone when connected.</string>
-
-    <!-- Description of the privileges the application will get if associated with the companion device of APP_STREAMING profile (type) [CHAR LIMIT=NONE] -->
-    <string name="summary_app_streaming" product="tablet">Let &lt;strong&gt;<xliff:g id="app_name" example="Exo">%1$s</xliff:g>&lt;/strong&gt; to provide &lt;strong&gt;<xliff:g id="device_name" example="Pixelbook Go">%2$s</xliff:g>&lt;/strong&gt; remote access to access to applications installed on this tablet when connected.</string>
-
-    <!-- Description of the privileges the application will get if associated with the companion device of APP_STREAMING profile (type) [CHAR LIMIT=NONE] -->
-    <string name="summary_app_streaming" product="device">Let &lt;strong&gt;<xliff:g id="app_name" example="Exo">%1$s</xliff:g>&lt;/strong&gt; to provide &lt;strong&gt;<xliff:g id="device_name" example="Pixelbook Go">%2$s</xliff:g>&lt;/strong&gt; remote access to access to applications installed on this device when connected.</string>
-
     <!-- Title of the helper dialog for APP_STREAMING profile [CHAR LIMIT=30]. -->
     <string name="helper_title_app_streaming">Cross-device services</string>
 
     <!-- Description of the helper dialog for APP_STREAMING profile. [CHAR LIMIT=NONE] -->
-    <string name="helper_summary_app_streaming">This service is used to stream apps between your devices</string>
+    <string name="helper_summary_app_streaming"><xliff:g id="app_name" example="GMS">%1$s</xliff:g> is requesting permission on behalf of your <xliff:g id="device_type" example="Chromebook">%2$s</xliff:g> to access your phone\u2019s photos, media, and notifications</string>
 
     <!-- ================= DEVICE_PROFILE_AUTOMOTIVE_PROJECTION ================= -->
 
@@ -94,10 +85,7 @@
     <string name="helper_title_computer">Google Play services</string>
 
     <!-- Description of the helper dialog for COMPUTER profile. [CHAR LIMIT=NONE] -->
-    <string name="helper_summary_computer" product="default">This service shares photos, media, and notifications form your phone to other devices</string>
-
-    <!-- Description of the helper dialog for COMPUTER profile. [CHAR LIMIT=NONE] -->
-    <string name="helper_summary_computer" product="tablet">This service shares photos, media, and notifications form your phone to other devices</string>
+    <string name="helper_summary_computer"> <xliff:g id="app_name" example="GMS">%1$s</xliff:g> is requesting permission on behalf of your <xliff:g id="device_type" example="Chromebook">%2$s</xliff:g> to stream apps between your devices</string>
 
     <!-- ================= null profile ================= -->
 
@@ -115,8 +103,8 @@
     <!-- Negative button for the device-app association consent dialog [CHAR LIMIT=30] -->
     <string name="consent_no">Don\u2019t allow</string>
 
-    <!-- Ok button for the helper consent dialog [CHAR LIMIT=30] -->
-    <string name="consent_ok">OK</string>
+    <!-- Back button for the helper consent dialog [CHAR LIMIT=30] -->
+    <string name="consent_back">Back</string>
 
     <!-- ================== System data transfer ==================== -->
     <!-- Title of the permission sync confirmation dialog. [CHAR LIMIT=60] -->
diff --git a/packages/CompanionDeviceManager/res/values/styles.xml b/packages/CompanionDeviceManager/res/values/styles.xml
index a55f30c9..faa3032 100644
--- a/packages/CompanionDeviceManager/res/values/styles.xml
+++ b/packages/CompanionDeviceManager/res/values/styles.xml
@@ -57,13 +57,14 @@
         <item name="android:textColor">?android:attr/textColorSecondary</item>
     </style>
 
-    <style name="VendorHelperOkButton"
+    <style name="VendorHelperBackButton"
            parent="@android:style/Widget.Material.Button.Borderless.Colored">
-        <item name="android:layout_width">50dp</item>
+        <item name="android:layout_width">60dp</item>
         <item name="android:layout_height">36dp</item>
         <item name="android:layout_marginTop">20dp</item>
+        <item name="android:textAllCaps">false</item>
         <item name="android:textColor">@android:color/system_neutral1_900</item>
-        <item name="android:background">@drawable/helper_ok_button</item>
+        <item name="android:background">@drawable/helper_back_button</item>
     </style>
 
     <style name="PositiveButton"
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
index 0bdf65d..08c52fb 100644
--- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
+++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
@@ -32,6 +32,7 @@
 import static com.android.companiondevicemanager.Utils.getIcon;
 import static com.android.companiondevicemanager.Utils.getVendorHeaderIcon;
 import static com.android.companiondevicemanager.Utils.getVendorHeaderName;
+import static com.android.companiondevicemanager.Utils.hasVendorIcon;
 import static com.android.companiondevicemanager.Utils.prepareResultReceiverForIpc;
 
 import static java.util.Objects.requireNonNull;
@@ -282,7 +283,7 @@
         mVendorHeaderButton.setOnClickListener(this::onShowHelperDialog);
 
         if (mRequest.isSelfManaged()) {
-            initUiForSelfManagedAssociation(appLabel);
+            initUiForSelfManagedAssociation();
         } else if (mRequest.isSingleDevice()) {
             initUiForSingleDevice(appLabel);
         } else {
@@ -378,7 +379,7 @@
         finish();
     }
 
-    private void initUiForSelfManagedAssociation(CharSequence appLabel) {
+    private void initUiForSelfManagedAssociation() {
         if (DEBUG) Log.i(TAG, "initUiFor_SelfManaged_Association()");
 
         final CharSequence deviceName = mRequest.getDisplayName();
@@ -394,6 +395,12 @@
         try {
             vendorIcon = getVendorHeaderIcon(this, packageName, userId);
             vendorName = getVendorHeaderName(this, packageName, userId);
+
+            mVendorHeaderImage.setImageDrawable(vendorIcon);
+            if (hasVendorIcon(this, packageName, userId)) {
+                mVendorHeaderImage.setColorFilter(getResources().getColor(
+                                android.R.color.system_accent1_600, /* Theme= */null));
+            }
         } catch (PackageManager.NameNotFoundException e) {
             Log.e(TAG, "Package u" + userId + "/" + packageName + " not found.");
             setResultAndFinish(null, RESULT_INTERNAL_ERROR);
@@ -428,9 +435,7 @@
         mPermissionListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
 
         mTitle.setText(title);
-        mVendorHeaderImage.setImageDrawable(vendorIcon);
         mVendorHeaderName.setText(vendorName);
-
         mDeviceListRecyclerView.setVisibility(View.GONE);
         mProfileIcon.setVisibility(View.GONE);
         mVendorHeader.setVisibility(View.VISIBLE);
@@ -568,8 +573,7 @@
     private void onShowHelperDialog(View view) {
         FragmentManager fragmentManager = getSupportFragmentManager();
         CompanionVendorHelperDialogFragment fragmentDialog =
-                CompanionVendorHelperDialogFragment.newInstance(mRequest.getPackageName(),
-                        mRequest.getUserId(), mRequest.getDeviceProfile());
+                CompanionVendorHelperDialogFragment.newInstance(mRequest);
 
         mAssociationConfirmationDialog.setVisibility(View.INVISIBLE);
 
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionVendorHelperDialogFragment.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionVendorHelperDialogFragment.java
index 728e5e5..f2f6cb0 100644
--- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionVendorHelperDialogFragment.java
+++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionVendorHelperDialogFragment.java
@@ -23,6 +23,7 @@
 import static com.android.companiondevicemanager.Utils.getHtmlFromResources;
 
 import android.annotation.Nullable;
+import android.companion.AssociationRequest;
 import android.content.DialogInterface;
 import android.content.pm.PackageManager;
 import android.graphics.drawable.Drawable;
@@ -44,10 +45,7 @@
  */
 public class CompanionVendorHelperDialogFragment extends DialogFragment {
     private static final String TAG = CompanionVendorHelperDialogFragment.class.getSimpleName();
-
-    private static final String PACKAGE_NAME_EXTRA = "packageName";
-    private static final String DEVICE_PROFILE_EXTRA = "deviceProfile";
-    private static final String USER_ID_EXTRA = "userId";
+    private static final String ASSOCIATION_REQUEST_EXTRA = "association_request";
 
     private CompanionVendorHelperDialogListener mListener;
     // Only present for selfManaged devices.
@@ -63,15 +61,12 @@
 
     private CompanionVendorHelperDialogFragment() {}
 
-    static CompanionVendorHelperDialogFragment newInstance(String packageName,
-            int userId, String deviceProfile) {
+    static CompanionVendorHelperDialogFragment newInstance(AssociationRequest request) {
         CompanionVendorHelperDialogFragment fragmentDialog =
                 new CompanionVendorHelperDialogFragment();
 
         Bundle bundle = new Bundle();
-        bundle.putString(PACKAGE_NAME_EXTRA, packageName);
-        bundle.putInt(USER_ID_EXTRA, userId);
-        bundle.putString(DEVICE_PROFILE_EXTRA, deviceProfile);
+        bundle.putParcelable(ASSOCIATION_REQUEST_EXTRA, request);
         fragmentDialog.setArguments(bundle);
 
         return fragmentDialog;
@@ -102,9 +97,13 @@
         super.onViewCreated(view, savedInstanceState);
 
         Drawable applicationIcon;
-        String packageName = getArguments().getString(PACKAGE_NAME_EXTRA);
-        String deviceProfile = getArguments().getString(DEVICE_PROFILE_EXTRA);
-        int userId = getArguments().getInt(USER_ID_EXTRA);
+        AssociationRequest request = getArguments().getParcelable(
+                ASSOCIATION_REQUEST_EXTRA, AssociationRequest.class);
+
+        final String deviceProfile = request.getDeviceProfile();
+        final String packageName = request.getPackageName();
+        final CharSequence displayName = request.getDisplayName();
+        final int userId = request.getUserId();
 
         try {
             applicationIcon = getApplicationIcon(getContext(), packageName);
@@ -117,7 +116,7 @@
         mTitle = view.findViewById(R.id.helper_title);
         mSummary = view.findViewById(R.id.helper_summary);
         mAppIcon = view.findViewById(R.id.app_icon);
-        mButton = view.findViewById(R.id.btn_ok);
+        mButton = view.findViewById(R.id.btn_back);
 
         final Spanned title;
         final Spanned summary;
@@ -125,12 +124,14 @@
         switch (deviceProfile) {
             case DEVICE_PROFILE_APP_STREAMING:
                 title = getHtmlFromResources(getContext(), R.string.helper_title_app_streaming);
-                summary = getHtmlFromResources(getContext(), R.string.helper_summary_app_streaming);
+                summary = getHtmlFromResources(
+                        getContext(), R.string.helper_summary_app_streaming, title, displayName);
                 break;
 
             case DEVICE_PROFILE_COMPUTER:
                 title = getHtmlFromResources(getContext(), R.string.helper_title_computer);
-                summary = getHtmlFromResources(getContext(), R.string.helper_summary_computer);
+                summary = getHtmlFromResources(
+                        getContext(), R.string.helper_summary_computer, title, displayName);
                 break;
 
             default:
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/Utils.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/Utils.java
index 1852e82..fceca91 100644
--- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/Utils.java
+++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/Utils.java
@@ -108,6 +108,18 @@
         return appInfo.metaData.getCharSequence(COMPANION_DEVICE_ACTIVITY_VENDOR_NAME, "");
     }
 
+    static boolean hasVendorIcon(@NonNull Context context,
+            @NonNull String packageName, int userId) throws PackageManager.NameNotFoundException {
+        final ApplicationInfo appInfo = getApplicationInfo(context, packageName, userId);
+        final Bundle bundle = appInfo.metaData;
+
+        if (bundle == null) {
+            return false;
+        } else {
+            return bundle.getInt(COMPANION_DEVICE_ACTIVITY_VENDOR_ICON) != 0;
+        }
+    }
+
     /**
      * Getting ApplicationInfo from meta-data.
      */