OSDN Git Service

Show Autofill Service icon on Save UI.
authorFelipe Leme <felipeal@google.com>
Fri, 8 Sep 2017 23:37:23 +0000 (16:37 -0700)
committerFelipe Leme <felipeal@google.com>
Tue, 12 Sep 2017 01:39:45 +0000 (18:39 -0700)
Test: cts-tradefed run commandAndExit cts-dev -m CtsAutoFillServiceTestCases

Bug: 65465974

Change-Id: Ic495be94763dda1de0edced3f9371190d09783ef

core/res/res/layout/autofill_save.xml
core/res/res/values/dimens.xml
core/res/res/values/symbols.xml
services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
services/autofill/java/com/android/server/autofill/Session.java
services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java
services/autofill/java/com/android/server/autofill/ui/SaveUi.java

index 50ff50f..63675ab 100644 (file)
                 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"
index 9b1ebc8..9be00f7 100644 (file)
     <!-- 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>
index 8c10a8d..09d8c75 100644 (file)
   <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"/>
index 512e128..2b7a671 100644 (file)
@@ -34,6 +34,7 @@ import android.content.pm.ApplicationInfo;
 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 @@ final class AutofillManagerServiceImpl {
         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}.
index e0e379f..dd0c874 100644 (file)
@@ -970,8 +970,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                 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 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
 
     /**
      * 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());
index a6f6713..cac2bff 100644 (file)
@@ -22,6 +22,7 @@ import android.annotation.NonNull;
 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 @@ public final class AutoFillUI {
     /**
      * 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 @@ public final class AutoFillUI {
                 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);
index 160c84c..d0b2e92 100644 (file)
@@ -22,10 +22,14 @@ import static com.android.server.autofill.Helper.sVerbose;
 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.ViewGroup.LayoutParams;
 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 @@ final class SaveUi {
     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 @@ final class SaveUi {
         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 @@ final class SaveUi {
         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.
      *