Merge "Show Autofill Service icon on Save UI." into oc-mr1-dev
am: 0f6599887c
Change-Id: Ic2b8972f6089346ae4b721414213809c4d3ae6bc
diff --git a/core/res/res/layout/autofill_save.xml b/core/res/res/layout/autofill_save.xml
index 50ff50f..63675ab 100644
--- a/core/res/res/layout/autofill_save.xml
+++ b/core/res/res/layout/autofill_save.xml
@@ -44,8 +44,14 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
+ <ImageView
+ android:id="@+id/autofill_save_icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
+
<TextView
android:id="@+id/autofill_save_title"
+ android:paddingLeft="8dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/autofill_save_title"
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index 9b1ebc8..9be00f7 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -604,4 +604,7 @@
<!-- Max height of the the autofill save custom subtitle as a fraction of the screen width/height -->
<dimen name="autofill_save_custom_subtitle_max_height">20%</dimen>
+ <!-- Max (absolute) dimensions (both width and height) of autofill service icon on autofill save affordance -->
+ <dimen name="autofill_save_icon_max_size">100dp</dimen>
+
</resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 655a7f1..16a9297 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2901,8 +2901,9 @@
<java-symbol type="id" name="autofill_dataset_list"/>
<java-symbol type="id" name="autofill" />
<java-symbol type="id" name="autofill_save_custom_subtitle" />
- <java-symbol type="id" name="autofill_save_title" />
+ <java-symbol type="id" name="autofill_save_icon" />
<java-symbol type="id" name="autofill_save_no" />
+ <java-symbol type="id" name="autofill_save_title" />
<java-symbol type="id" name="autofill_save_yes" />
<java-symbol type="string" name="autofill_error_cannot_autofill" />
<java-symbol type="string" name="autofill_picker_no_suggestions" />
@@ -2926,6 +2927,7 @@
<java-symbol type="style" name="AutofillSaveAnimation" />
<java-symbol type="dimen" name="autofill_dataset_picker_max_size"/>
<java-symbol type="dimen" name="autofill_save_custom_subtitle_max_height"/>
+ <java-symbol type="dimen" name="autofill_save_icon_max_size"/>
<java-symbol type="dimen" name="notification_big_picture_max_height"/>
<java-symbol type="dimen" name="notification_big_picture_max_width"/>
diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
index 512e128..2b7a671 100644
--- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
+++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
@@ -34,6 +34,7 @@
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.Bundle;
@@ -481,10 +482,16 @@
sendStateToClients(true);
}
+ @NonNull
CharSequence getServiceLabel() {
return mInfo.getServiceInfo().loadLabel(mContext.getPackageManager());
}
+ @NonNull
+ Drawable getServiceIcon() {
+ return mInfo.getServiceInfo().loadIcon(mContext.getPackageManager());
+ }
+
/**
* Initializes the last fill selection after an autofill service returned a new
* {@link FillResponse}.
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index e0e379f..dd0c874 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -970,8 +970,8 @@
mService.logSaveShown(id);
final IAutoFillManagerClient client = getClient();
mPendingSaveUi = new PendingUi(mActivityToken, id, client);
- getUiForShowing().showSaveUi(mService.getServiceLabel(), saveInfo,
- valueFinder, mPackageName, this, mPendingSaveUi);
+ getUiForShowing().showSaveUi(mService.getServiceLabel(), mService.getServiceIcon(),
+ saveInfo, valueFinder, mPackageName, this, mPendingSaveUi);
if (client != null) {
try {
client.setSaveUiState(id, true);
@@ -1774,7 +1774,8 @@
/**
* Checks whether this session is hiding the Save UI to handle a custom description link for
- * a specific {@code token} created by {@link PendingUi#PendingUi(IBinder)}.
+ * a specific {@code token} created by
+ * {@link PendingUi#PendingUi(IBinder, int, IAutoFillManagerClient)}.
*/
boolean isSaveUiPendingForToken(@NonNull IBinder token) {
return isSaveUiPending() && token.equals(mPendingSaveUi.getToken());
diff --git a/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java b/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java
index a6f6713..cac2bff 100644
--- a/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java
+++ b/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java
@@ -22,6 +22,7 @@
import android.annotation.Nullable;
import android.content.Context;
import android.content.IntentSender;
+import android.graphics.drawable.Drawable;
import android.metrics.LogMaker;
import android.os.Bundle;
import android.os.Handler;
@@ -244,8 +245,8 @@
/**
* Shows the UI asking the user to save for autofill.
*/
- public void showSaveUi(@NonNull CharSequence providerLabel, @NonNull SaveInfo info,
- @NonNull ValueFinder valueFinder, @NonNull String packageName,
+ public void showSaveUi(@NonNull CharSequence serviceLabel, @NonNull Drawable serviceIcon,
+ @NonNull SaveInfo info,@NonNull ValueFinder valueFinder, @NonNull String packageName,
@NonNull AutoFillUiCallback callback, @NonNull PendingUi pendingSaveUi) {
if (sVerbose) Slog.v(TAG, "showSaveUi() for " + packageName + ": " + info);
int numIds = 0;
@@ -261,8 +262,8 @@
return;
}
hideAllUiThread(callback);
- mSaveUi = new SaveUi(mContext, pendingSaveUi, providerLabel, info, valueFinder,
- mOverlayControl, new SaveUi.OnSaveListener() {
+ mSaveUi = new SaveUi(mContext, pendingSaveUi, serviceLabel, serviceIcon, info,
+ valueFinder, mOverlayControl, new SaveUi.OnSaveListener() {
@Override
public void onSave() {
log.setType(MetricsProto.MetricsEvent.TYPE_ACTION);
diff --git a/services/autofill/java/com/android/server/autofill/ui/SaveUi.java b/services/autofill/java/com/android/server/autofill/ui/SaveUi.java
index 160c84c..d0b2e92 100644
--- a/services/autofill/java/com/android/server/autofill/ui/SaveUi.java
+++ b/services/autofill/java/com/android/server/autofill/ui/SaveUi.java
@@ -22,10 +22,14 @@
import android.annotation.NonNull;
import android.app.Dialog;
import android.app.PendingIntent;
-import android.app.PendingIntent.CanceledException;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
@@ -43,7 +47,7 @@
import android.view.Window;
import android.view.WindowManager;
import android.view.autofill.AutofillManager;
-import android.view.autofill.IAutoFillManagerClient;
+import android.widget.ImageView;
import android.widget.RemoteViews;
import android.widget.ScrollView;
import android.widget.TextView;
@@ -121,9 +125,9 @@
private boolean mDestroyed;
SaveUi(@NonNull Context context, @NonNull PendingUi pendingUi,
- @NonNull CharSequence providerLabel, @NonNull SaveInfo info,
- @NonNull ValueFinder valueFinder, @NonNull OverlayControl overlayControl,
- @NonNull OnSaveListener listener) {
+ @NonNull CharSequence serviceLabel, @NonNull Drawable serviceIcon,
+ @NonNull SaveInfo info, @NonNull ValueFinder valueFinder,
+ @NonNull OverlayControl overlayControl, @NonNull OnSaveListener listener) {
mPendingUi= pendingUi;
mListener = new OneTimeListener(listener);
mOverlayControl = overlayControl;
@@ -155,24 +159,25 @@
switch (types.size()) {
case 1:
mTitle = Html.fromHtml(context.getString(R.string.autofill_save_title_with_type,
- types.valueAt(0), providerLabel), 0);
+ types.valueAt(0), serviceLabel), 0);
break;
case 2:
mTitle = Html.fromHtml(context.getString(R.string.autofill_save_title_with_2types,
- types.valueAt(0), types.valueAt(1), providerLabel), 0);
+ types.valueAt(0), types.valueAt(1), serviceLabel), 0);
break;
case 3:
mTitle = Html.fromHtml(context.getString(R.string.autofill_save_title_with_3types,
- types.valueAt(0), types.valueAt(1), types.valueAt(2), providerLabel), 0);
+ types.valueAt(0), types.valueAt(1), types.valueAt(2), serviceLabel), 0);
break;
default:
// Use generic if more than 3 or invalid type (size 0).
mTitle = Html.fromHtml(
- context.getString(R.string.autofill_save_title, providerLabel), 0);
+ context.getString(R.string.autofill_save_title, serviceLabel), 0);
}
-
titleView.setText(mTitle);
+ setServiceIcon(context, view, serviceIcon);
+
ScrollView subtitleContainer = null;
final CustomDescription customDescription = info.getCustomDescription();
if (customDescription != null) {
@@ -284,6 +289,30 @@
show();
}
+ private void setServiceIcon(Context context, View view, Drawable serviceIcon) {
+ final ImageView iconView = view.findViewById(R.id.autofill_save_icon);
+ final Resources res = context.getResources();
+
+ final int maxWidth = res.getDimensionPixelSize(R.dimen.autofill_save_icon_max_size);
+ final int maxHeight = maxWidth;
+ final int actualWidth = serviceIcon.getMinimumWidth();
+ final int actualHeight = serviceIcon.getMinimumHeight();
+
+ if (actualWidth <= maxWidth && actualHeight <= maxHeight) {
+ if (sDebug) {
+ Slog.d(TAG, "Addingservice icon "
+ + "(" + actualWidth + "x" + actualHeight + ") as it's less than maximum "
+ + "(" + maxWidth + "x" + maxHeight + ").");
+ }
+ iconView.setImageDrawable(serviceIcon);
+ } else {
+ Slog.w(TAG, "Not adding service icon of size "
+ + "(" + actualWidth + "x" + actualHeight + ") because maximum is "
+ + "(" + maxWidth + "x" + maxHeight + ").");
+ iconView.setVisibility(View.INVISIBLE);
+ }
+ }
+
/**
* Update the pending UI, if any.
*