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"
<!-- 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>
<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" />
<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"/>
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;
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}.
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);
/**
* 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());
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;
/**
* 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;
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);
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;
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;
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;
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) {
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.
*