Merge "Update Computer dialog UI" into tm-dev

This commit is contained in:
Evan Chen
2022-03-22 23:00:50 +00:00
committed by Android (Google) Code Review
9 changed files with 76 additions and 44 deletions

View File

@@ -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>

View File

@@ -59,9 +59,9 @@
android:gravity="end"> android:gravity="end">
<Button <Button
android:id="@+id/btn_ok" android:id="@+id/btn_back"
style="@style/VendorHelperOkButton" style="@style/VendorHelperBackButton"
android:text="@string/consent_ok" /> android:text="@string/consent_back" />
</LinearLayout> </LinearLayout>

View File

@@ -43,7 +43,7 @@
<ImageButton <ImageButton
android:id="@+id/vendor_header_button" android:id="@+id/vendor_header_button"
style="?android:attr/actionOverflowButtonStyle" android:background="@drawable/ic_info"
android:layout_width="31dp" android:layout_width="31dp"
android:layout_height="32dp" android:layout_height="32dp"
android:layout_alignParentRight="true" /> android:layout_alignParentRight="true" />

View File

@@ -47,20 +47,11 @@
<!-- Confirmation for associating an application with a companion device of APP_STREAMING profile (type) [CHAR LIMIT=NONE] --> <!-- 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> <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]. --> <!-- Title of the helper dialog for APP_STREAMING profile [CHAR LIMIT=30]. -->
<string name="helper_title_app_streaming">Cross-device services</string> <string name="helper_title_app_streaming">Cross-device services</string>
<!-- Description of the helper dialog for APP_STREAMING profile. [CHAR LIMIT=NONE] --> <!-- 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 ================= --> <!-- ================= DEVICE_PROFILE_AUTOMOTIVE_PROJECTION ================= -->
@@ -94,10 +85,7 @@
<string name="helper_title_computer">Google Play services</string> <string name="helper_title_computer">Google Play services</string>
<!-- Description of the helper dialog for COMPUTER profile. [CHAR LIMIT=NONE] --> <!-- 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> <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>
<!-- 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>
<!-- ================= null profile ================= --> <!-- ================= null profile ================= -->
@@ -115,8 +103,8 @@
<!-- Negative button for the device-app association consent dialog [CHAR LIMIT=30] --> <!-- Negative button for the device-app association consent dialog [CHAR LIMIT=30] -->
<string name="consent_no">Don\u2019t allow</string> <string name="consent_no">Don\u2019t allow</string>
<!-- Ok button for the helper consent dialog [CHAR LIMIT=30] --> <!-- Back button for the helper consent dialog [CHAR LIMIT=30] -->
<string name="consent_ok">OK</string> <string name="consent_back">Back</string>
<!-- ================== System data transfer ==================== --> <!-- ================== System data transfer ==================== -->
<!-- Title of the permission sync confirmation dialog. [CHAR LIMIT=60] --> <!-- Title of the permission sync confirmation dialog. [CHAR LIMIT=60] -->

View File

@@ -57,13 +57,14 @@
<item name="android:textColor">?android:attr/textColorSecondary</item> <item name="android:textColor">?android:attr/textColorSecondary</item>
</style> </style>
<style name="VendorHelperOkButton" <style name="VendorHelperBackButton"
parent="@android:style/Widget.Material.Button.Borderless.Colored"> 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_height">36dp</item>
<item name="android:layout_marginTop">20dp</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: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>
<style name="PositiveButton" <style name="PositiveButton"

View File

@@ -38,6 +38,7 @@ import static com.android.companiondevicemanager.Utils.getHtmlFromResources;
import static com.android.companiondevicemanager.Utils.getIcon; import static com.android.companiondevicemanager.Utils.getIcon;
import static com.android.companiondevicemanager.Utils.getVendorHeaderIcon; import static com.android.companiondevicemanager.Utils.getVendorHeaderIcon;
import static com.android.companiondevicemanager.Utils.getVendorHeaderName; import static com.android.companiondevicemanager.Utils.getVendorHeaderName;
import static com.android.companiondevicemanager.Utils.hasVendorIcon;
import static com.android.companiondevicemanager.Utils.prepareResultReceiverForIpc; import static com.android.companiondevicemanager.Utils.prepareResultReceiverForIpc;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
@@ -285,7 +286,7 @@ public class CompanionDeviceActivity extends FragmentActivity implements
mVendorHeaderButton.setOnClickListener(this::onShowHelperDialog); mVendorHeaderButton.setOnClickListener(this::onShowHelperDialog);
if (mRequest.isSelfManaged()) { if (mRequest.isSelfManaged()) {
initUiForSelfManagedAssociation(appLabel); initUiForSelfManagedAssociation();
} else if (mRequest.isSingleDevice()) { } else if (mRequest.isSingleDevice()) {
initUiForSingleDevice(appLabel); initUiForSingleDevice(appLabel);
} else { } else {
@@ -396,7 +397,7 @@ public class CompanionDeviceActivity extends FragmentActivity implements
finish(); finish();
} }
private void initUiForSelfManagedAssociation(CharSequence appLabel) { private void initUiForSelfManagedAssociation() {
if (DEBUG) Log.i(TAG, "initUiFor_SelfManaged_Association()"); if (DEBUG) Log.i(TAG, "initUiFor_SelfManaged_Association()");
final CharSequence deviceName = mRequest.getDisplayName(); final CharSequence deviceName = mRequest.getDisplayName();
@@ -412,6 +413,12 @@ public class CompanionDeviceActivity extends FragmentActivity implements
try { try {
vendorIcon = getVendorHeaderIcon(this, packageName, userId); vendorIcon = getVendorHeaderIcon(this, packageName, userId);
vendorName = getVendorHeaderName(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) { } catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Package u" + userId + "/" + packageName + " not found."); Log.e(TAG, "Package u" + userId + "/" + packageName + " not found.");
setResultAndFinish(null, RESULT_INTERNAL_ERROR); setResultAndFinish(null, RESULT_INTERNAL_ERROR);
@@ -446,9 +453,7 @@ public class CompanionDeviceActivity extends FragmentActivity implements
mPermissionListRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mPermissionListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mTitle.setText(title); mTitle.setText(title);
mVendorHeaderImage.setImageDrawable(vendorIcon);
mVendorHeaderName.setText(vendorName); mVendorHeaderName.setText(vendorName);
mDeviceListRecyclerView.setVisibility(View.GONE); mDeviceListRecyclerView.setVisibility(View.GONE);
mProfileIcon.setVisibility(View.GONE); mProfileIcon.setVisibility(View.GONE);
mVendorHeader.setVisibility(View.VISIBLE); mVendorHeader.setVisibility(View.VISIBLE);
@@ -586,8 +591,7 @@ public class CompanionDeviceActivity extends FragmentActivity implements
private void onShowHelperDialog(View view) { private void onShowHelperDialog(View view) {
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
CompanionVendorHelperDialogFragment fragmentDialog = CompanionVendorHelperDialogFragment fragmentDialog =
CompanionVendorHelperDialogFragment.newInstance(mRequest.getPackageName(), CompanionVendorHelperDialogFragment.newInstance(mRequest);
mRequest.getUserId(), mRequest.getDeviceProfile());
mAssociationConfirmationDialog.setVisibility(View.INVISIBLE); mAssociationConfirmationDialog.setVisibility(View.INVISIBLE);

View File

@@ -23,6 +23,7 @@ import static com.android.companiondevicemanager.Utils.getApplicationIcon;
import static com.android.companiondevicemanager.Utils.getHtmlFromResources; import static com.android.companiondevicemanager.Utils.getHtmlFromResources;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.companion.AssociationRequest;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@@ -44,10 +45,7 @@ import androidx.fragment.app.DialogFragment;
*/ */
public class CompanionVendorHelperDialogFragment extends DialogFragment { public class CompanionVendorHelperDialogFragment extends DialogFragment {
private static final String TAG = CompanionVendorHelperDialogFragment.class.getSimpleName(); private static final String TAG = CompanionVendorHelperDialogFragment.class.getSimpleName();
private static final String ASSOCIATION_REQUEST_EXTRA = "association_request";
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 CompanionVendorHelperDialogListener mListener; private CompanionVendorHelperDialogListener mListener;
// Only present for selfManaged devices. // Only present for selfManaged devices.
@@ -63,15 +61,12 @@ public class CompanionVendorHelperDialogFragment extends DialogFragment {
private CompanionVendorHelperDialogFragment() {} private CompanionVendorHelperDialogFragment() {}
static CompanionVendorHelperDialogFragment newInstance(String packageName, static CompanionVendorHelperDialogFragment newInstance(AssociationRequest request) {
int userId, String deviceProfile) {
CompanionVendorHelperDialogFragment fragmentDialog = CompanionVendorHelperDialogFragment fragmentDialog =
new CompanionVendorHelperDialogFragment(); new CompanionVendorHelperDialogFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(PACKAGE_NAME_EXTRA, packageName); bundle.putParcelable(ASSOCIATION_REQUEST_EXTRA, request);
bundle.putInt(USER_ID_EXTRA, userId);
bundle.putString(DEVICE_PROFILE_EXTRA, deviceProfile);
fragmentDialog.setArguments(bundle); fragmentDialog.setArguments(bundle);
return fragmentDialog; return fragmentDialog;
@@ -102,9 +97,13 @@ public class CompanionVendorHelperDialogFragment extends DialogFragment {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
Drawable applicationIcon; Drawable applicationIcon;
String packageName = getArguments().getString(PACKAGE_NAME_EXTRA); AssociationRequest request = getArguments().getParcelable(
String deviceProfile = getArguments().getString(DEVICE_PROFILE_EXTRA); ASSOCIATION_REQUEST_EXTRA, AssociationRequest.class);
int userId = getArguments().getInt(USER_ID_EXTRA);
final String deviceProfile = request.getDeviceProfile();
final String packageName = request.getPackageName();
final CharSequence displayName = request.getDisplayName();
final int userId = request.getUserId();
try { try {
applicationIcon = getApplicationIcon(getContext(), packageName); applicationIcon = getApplicationIcon(getContext(), packageName);
@@ -117,7 +116,7 @@ public class CompanionVendorHelperDialogFragment extends DialogFragment {
mTitle = view.findViewById(R.id.helper_title); mTitle = view.findViewById(R.id.helper_title);
mSummary = view.findViewById(R.id.helper_summary); mSummary = view.findViewById(R.id.helper_summary);
mAppIcon = view.findViewById(R.id.app_icon); 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 title;
final Spanned summary; final Spanned summary;
@@ -125,12 +124,14 @@ public class CompanionVendorHelperDialogFragment extends DialogFragment {
switch (deviceProfile) { switch (deviceProfile) {
case DEVICE_PROFILE_APP_STREAMING: case DEVICE_PROFILE_APP_STREAMING:
title = getHtmlFromResources(getContext(), R.string.helper_title_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; break;
case DEVICE_PROFILE_COMPUTER: case DEVICE_PROFILE_COMPUTER:
title = getHtmlFromResources(getContext(), R.string.helper_title_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; break;
default: default:

View File

@@ -108,6 +108,18 @@ class Utils {
return appInfo.metaData.getCharSequence(COMPANION_DEVICE_ACTIVITY_VENDOR_NAME, ""); 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. * Getting ApplicationInfo from meta-data.
*/ */