Merge "launcher: use correct preference key on SettingsChangeLogger" into sc-v2-dev
diff --git a/go/quickstep/res/layout/niu_actions_confirmation_dialog.xml b/go/quickstep/res/layout/niu_actions_dialog.xml
similarity index 72%
rename from go/quickstep/res/layout/niu_actions_confirmation_dialog.xml
rename to go/quickstep/res/layout/niu_actions_dialog.xml
index 5dbcca5..6e944f8 100644
--- a/go/quickstep/res/layout/niu_actions_confirmation_dialog.xml
+++ b/go/quickstep/res/layout/niu_actions_dialog.xml
@@ -16,7 +16,8 @@
 
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/niu_actions_confirmation_dialog_layout"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/niu_actions_dialog_layout"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="horizontal"
@@ -41,29 +42,37 @@
 
         <TextView
             style="@style/ModalDialogTitle"
-            android:id="@+id/niu_actions_confirmation_header"
-            android:text="@string/niu_actions_confirmation_title"/>
+            android:id="@+id/niu_actions_dialog_header"/>
 
         <Space
             android:layout_width="0dp"
             android:layout_height="@dimen/modal_dialog_vertical_spacer"/>
 
-        <ScrollView
+        <androidx.constraintlayout.widget.ConstraintLayout
             android:layout_width="match_parent"
-            android:layout_height="@dimen/confirmation_dialog_text_height">
+            android:layout_height="wrap_content">
 
-            <TextView
-                style="@style/ModalDialogText"
-                android:id="@+id/niu_actions_confirmation_description"
-                android:text="@string/niu_actions_confirmation_text"/>
-        </ScrollView>
+            <ScrollView
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                app:layout_constraintTop_toTopOf="parent"
+                app:layout_constraintBottom_toBottomOf="parent"
+                app:layout_constrainedHeight="true"
+                app:layout_constraintHeight_max="@dimen/modal_dialog_text_height">
+
+                <TextView
+                    style="@style/ModalDialogText"
+                    android:id="@+id/niu_actions_dialog_description"/>
+            </ScrollView>
+
+        </androidx.constraintlayout.widget.ConstraintLayout>
+
 
         <Space
             android:layout_width="0dp"
             android:layout_height="@dimen/modal_dialog_vertical_spacer"/>
 
         <LinearLayout
-            android:id="@+id/niu_actions_confirmation_buttons"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:orientation="horizontal">
@@ -75,12 +84,12 @@
 
             <Button
                 style="@style/ModalDialogButton"
-                android:id="@+id/niu_actions_confirmation_reject"
+                android:id="@+id/niu_actions_dialog_button_1"
                 android:text="@string/dialog_cancel"/>
 
             <Button
                 style="@style/ModalDialogButton"
-                android:id="@+id/niu_actions_confirmation_accept"
+                android:id="@+id/niu_actions_dialog_button_2"
                 android:text="@string/dialog_acknowledge"/>
         </LinearLayout>
 
diff --git a/go/quickstep/res/values-land/dimens.xml b/go/quickstep/res/values-land/dimens.xml
index 5097016..6b5d0b4 100644
--- a/go/quickstep/res/values-land/dimens.xml
+++ b/go/quickstep/res/values-land/dimens.xml
@@ -18,5 +18,5 @@
 <resources>
     <!-- Modal Dialogs -->
     <dimen name="modal_dialog_width">360dp</dimen>
-    <dimen name="confirmation_dialog_text_height">168dp</dimen>
+    <dimen name="modal_dialog_text_height">168dp</dimen>
 </resources>
diff --git a/go/quickstep/res/values/dimens.xml b/go/quickstep/res/values/dimens.xml
index c14df50..84d7fe5 100644
--- a/go/quickstep/res/values/dimens.xml
+++ b/go/quickstep/res/values/dimens.xml
@@ -35,7 +35,7 @@
     <dimen name="modal_dialog_padding_bottom">8dp</dimen>
     <dimen name="modal_dialog_vertical_spacer">12dp</dimen>
     <dimen name="modal_dialog_corner_radius">8dp</dimen>
-    <dimen name="confirmation_dialog_text_height">216dp</dimen>
+    <dimen name="modal_dialog_text_height">216dp</dimen>
 
     <!-- Tooltip -->
     <dimen name="tooltip_corner_radius">8dp</dimen>
diff --git a/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java b/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java
index fc07162..91cab3c 100644
--- a/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java
+++ b/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java
@@ -21,6 +21,8 @@
 import static com.android.quickstep.views.OverviewActionsView.DISABLED_NO_THUMBNAIL;
 import static com.android.quickstep.views.OverviewActionsView.DISABLED_ROTATED;
 
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
 import android.annotation.SuppressLint;
 import android.app.AlertDialog;
 import android.app.assist.AssistContent;
@@ -32,6 +34,7 @@
 import android.graphics.Color;
 import android.graphics.Matrix;
 import android.graphics.drawable.ColorDrawable;
+import android.os.Bundle;
 import android.os.Handler;
 import android.os.SystemClock;
 import android.os.UserManager;
@@ -41,7 +44,9 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.Button;
+import android.widget.TextView;
 
+import androidx.annotation.IntDef;
 import androidx.annotation.VisibleForTesting;
 
 import com.android.launcher3.BaseActivity;
@@ -55,6 +60,8 @@
 import com.android.systemui.shared.recents.model.Task;
 import com.android.systemui.shared.recents.model.ThumbnailData;
 
+import java.lang.annotation.Retention;
+
 /**
  * Go-specific extension of the factory class that adds an overlay to TaskView
  */
@@ -69,11 +76,21 @@
     public static final int ERROR_PERMISSIONS_STRUCTURE = 1;
     public static final int ERROR_PERMISSIONS_SCREENSHOT = 2;
     private static final String NIU_ACTIONS_CONFIRMED = "launcher_go.niu_actions_confirmed";
+    private static final String ASSIST_SETTINGS_ARGS_BUNDLE = ":settings:show_fragment_args";
+    private static final String ASSIST_SETTINGS_ARGS_KEY = ":settings:fragment_args_key";
+    private static final String ASSIST_SETTINGS_PREFERENCE_KEY = "default_assist";
     private static final String TAG = "TaskOverlayFactoryGo";
 
     public static final String LISTEN_TOOL_TIP_SEEN = "launcher.go_listen_tip_seen";
     public static final String TRANSLATE_TOOL_TIP_SEEN = "launcher.go_translate_tip_seen";
 
+    @Retention(SOURCE)
+    @IntDef({PRIVACY_CONFIRMATION, ASSISTANT_NOT_SELECTED, ASSISTANT_NOT_SUPPORTED})
+    private @interface DialogType{}
+    private static final int PRIVACY_CONFIRMATION = 0;
+    private static final int ASSISTANT_NOT_SELECTED = 1;
+    private static final int ASSISTANT_NOT_SUPPORTED = 2;
+
     private AssistContentRequester mContentRequester;
 
     public TaskOverlayFactoryGo(Context context) {
@@ -99,8 +116,7 @@
         private boolean mAssistScreenshotPermitted;
         private AssistContentRequester mFactoryContentRequester;
         private SharedPreferences mSharedPreferences;
-        private String mPreviousAction;
-        private AlertDialog mConfirmationDialog;
+        private OverlayDialogGo mDialog;
 
         private TaskOverlayGo(TaskThumbnailView taskThumbnailView,
                 AssistContentRequester assistContentRequester) {
@@ -115,15 +131,14 @@
         @Override
         public void initOverlay(Task task, ThumbnailData thumbnail, Matrix matrix,
                 boolean rotated) {
-            if (mConfirmationDialog != null && mConfirmationDialog.isShowing()) {
+            if (mDialog != null && mDialog.isShowing()) {
                 // Redraw the dialog in case the layout changed
-                mConfirmationDialog.dismiss();
-                showConfirmationDialog();
+                mDialog.dismiss();
+                showDialog(mDialog.getAction(), mDialog.getType());
             }
 
             getActionsView().updateDisabledFlags(DISABLED_NO_THUMBNAIL, thumbnail == null);
-            checkSettings();
-            if (thumbnail == null || TextUtils.isEmpty(mNIUPackageName)) {
+            if (thumbnail == null) {
                 return;
             }
 
@@ -135,8 +150,10 @@
             getActionsView().setCallbacks(new OverlayUICallbacksGoImpl(isAllowedByPolicy, task));
             mTaskPackageName = task.key.getPackageName();
             mSharedPreferences = Utilities.getPrefs(mApplicationContext);
+            checkSettings();
 
-            if (!mAssistStructurePermitted || !mAssistScreenshotPermitted) {
+            if (!mAssistStructurePermitted || !mAssistScreenshotPermitted
+                    || TextUtils.isEmpty(mNIUPackageName)) {
                 return;
             }
 
@@ -179,9 +196,13 @@
          * Creates and sends an Intent corresponding to the button that was clicked
          */
         private void sendNIUIntent(String actionType) {
+            if (TextUtils.isEmpty(mNIUPackageName)) {
+                showDialog(actionType, ASSISTANT_NOT_SELECTED);
+                return;
+            }
+
             if (!mSharedPreferences.getBoolean(NIU_ACTIONS_CONFIRMED, false)) {
-                mPreviousAction = actionType;
-                showConfirmationDialog();
+                showDialog(actionType, PRIVACY_CONFIRMATION);
                 return;
             }
 
@@ -199,6 +220,7 @@
                     mApplicationContext.startActivity(intent);
                 } catch (ActivityNotFoundException e) {
                     Log.e(TAG, "No activity found to receive permission error intent");
+                    showDialog(actionType, ASSISTANT_NOT_SUPPORTED);
                 }
             }
         }
@@ -273,33 +295,86 @@
             mImageApi = imageActionsApi;
         }
 
-        private void showConfirmationDialog() {
+        // TODO (b/192406446): Test that these dialogs are shown at the appropriate times
+        private void showDialog(String action, @DialogType int type) {
+            switch (type) {
+                case PRIVACY_CONFIRMATION:
+                    showDialog(action, PRIVACY_CONFIRMATION,
+                            R.string.niu_actions_confirmation_title,
+                            R.string.niu_actions_confirmation_text, R.string.dialog_cancel,
+                            this::onDialogClickCancel, R.string.dialog_acknowledge,
+                            this::onNiuActionsConfirmationAccept);
+                    break;
+                case ASSISTANT_NOT_SELECTED:
+                    showDialog(action, ASSISTANT_NOT_SELECTED,
+                            R.string.assistant_not_selected_title,
+                            R.string.assistant_not_selected_text, R.string.dialog_cancel,
+                            this::onDialogClickCancel, R.string.dialog_settings,
+                            this::onDialogClickSettings);
+                    break;
+                case ASSISTANT_NOT_SUPPORTED:
+                    showDialog(action, ASSISTANT_NOT_SUPPORTED,
+                            R.string.assistant_not_supported_title,
+                            R.string.assistant_not_supported_text, R.string.dialog_cancel,
+                            this::onDialogClickCancel, R.string.dialog_settings,
+                            this::onDialogClickSettings);
+                    break;
+                default:
+                    Log.e(TAG, "Unexpected dialog type");
+            }
+        }
+
+        private void showDialog(String action, @DialogType int type, int titleTextID,
+                                int bodyTextID, int button1TextID,
+                                View.OnClickListener button1Callback, int button2TextID,
+                                View.OnClickListener button2Callback) {
             BaseDraggingActivity activity = BaseActivity.fromContext(getActionsView().getContext());
             LayoutInflater inflater = LayoutInflater.from(activity);
-            View view = inflater.inflate(R.layout.niu_actions_confirmation_dialog, /* root */ null);
+            View view = inflater.inflate(R.layout.niu_actions_dialog, /* root */ null);
 
-            Button acceptButton = view.findViewById(R.id.niu_actions_confirmation_accept);
-            acceptButton.setOnClickListener(this::onNiuActionsConfirmationAccept);
+            TextView dialogTitle = view.findViewById(R.id.niu_actions_dialog_header);
+            dialogTitle.setText(titleTextID);
 
-            Button rejectButton = view.findViewById(R.id.niu_actions_confirmation_reject);
-            rejectButton.setOnClickListener(this::onNiuActionsConfirmationReject);
+            TextView dialogBody = view.findViewById(R.id.niu_actions_dialog_description);
+            dialogBody.setText(bodyTextID);
 
-            mConfirmationDialog = new AlertDialog.Builder(activity)
-                    .setView(view)
-                    .create();
-            mConfirmationDialog.getWindow()
-                    .setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
-            mConfirmationDialog.show();
+            Button button1 = view.findViewById(R.id.niu_actions_dialog_button_1);
+            button1.setText(button1TextID);
+            button1.setOnClickListener(button1Callback);
+
+            Button button2 = view.findViewById(R.id.niu_actions_dialog_button_2);
+            button2.setText(button2TextID);
+            button2.setOnClickListener(button2Callback);
+
+            mDialog = new OverlayDialogGo(activity, type, action);
+            mDialog.setView(view);
+            mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
+            mDialog.show();
         }
 
         private void onNiuActionsConfirmationAccept(View v) {
-            mConfirmationDialog.dismiss();
+            mDialog.dismiss();
             mSharedPreferences.edit().putBoolean(NIU_ACTIONS_CONFIRMED, true).apply();
-            sendNIUIntent(mPreviousAction);
+            sendNIUIntent(mDialog.getAction());
         }
 
-        private void onNiuActionsConfirmationReject(View v) {
-            mConfirmationDialog.cancel();
+        private void onDialogClickCancel(View v) {
+            mDialog.cancel();
+        }
+
+        private void onDialogClickSettings(View v) {
+            mDialog.dismiss();
+
+            Bundle fragmentArgs = new Bundle();
+            fragmentArgs.putString(ASSIST_SETTINGS_ARGS_KEY, ASSIST_SETTINGS_PREFERENCE_KEY);
+            Intent intent = new Intent(Settings.ACTION_VOICE_INPUT_SETTINGS)
+                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
+                    .putExtra(ASSIST_SETTINGS_ARGS_BUNDLE, fragmentArgs);
+            try {
+                mApplicationContext.startActivity(intent);
+            } catch (ActivityNotFoundException e) {
+                Log.e(TAG, "No activity found to receive assistant settings intent");
+            }
         }
 
         /**
@@ -317,6 +392,24 @@
         }
     }
 
+    private static final class OverlayDialogGo extends AlertDialog {
+        private final String mAction;
+        private final @DialogType int mType;
+
+        OverlayDialogGo(Context context, @DialogType int type, String action) {
+            super(context);
+            mType = type;
+            mAction = action;
+        }
+
+        public String getAction() {
+            return mAction;
+        }
+        public @DialogType int getType() {
+            return mType;
+        }
+    }
+
     /**
      * Callbacks the Ui can generate. This is the only way for a Ui to call methods on the
      * controller.
diff --git a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
index aa49e08..6cad3dd 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.java
@@ -30,7 +30,6 @@
 import android.annotation.TargetApi;
 import android.os.Build;
 import android.util.FloatProperty;
-import android.util.Log;
 
 import androidx.annotation.NonNull;
 
@@ -111,8 +110,6 @@
         propertySetter.setFloat(mLauncher.getActionsView().getVisibilityAlpha(),
                 MultiValueAlpha.VALUE, overviewButtonAlpha, config.getInterpolator(
                         ANIM_OVERVIEW_ACTIONS_FADE, LINEAR));
-        Log.v("b/193125090",
-                "RecentsViewStateController - setVisibilityAlpha: " + overviewButtonAlpha);
 
         float splitPlaceholderAlpha = state.areElementsVisible(mLauncher, SPLIT_PLACHOLDER_VIEW) ?
                 0.85f : 0;
diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java
index d488dda..40c3e02 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java
@@ -54,7 +54,6 @@
 import android.animation.AnimatorListenerAdapter;
 import android.animation.ValueAnimator;
 import android.graphics.PointF;
-import android.util.Log;
 import android.view.MotionEvent;
 import android.view.animation.Interpolator;
 
@@ -228,8 +227,6 @@
         mRecentsView.setFullscreenProgress(fromState.getOverviewFullscreenProgress());
         mLauncher.getActionsView().getVisibilityAlpha().setValue(
                 (fromState.getVisibleElements(mLauncher) & OVERVIEW_ACTIONS) != 0 ? 1f : 0f);
-        Log.v("b/193125090", "NoButtonQuickSwitchTouchController - setVisibilityAlpha: "
-                + mLauncher.getActionsView().getVisibilityAlpha().getValue());
 
         float[] scaleAndOffset = toState.getOverviewScaleAndOffset(mLauncher);
         // As we drag right, animate the following properties:
diff --git a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java
index 8f8ee68..50b69dc 100644
--- a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java
+++ b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java
@@ -32,8 +32,6 @@
 import static com.android.quickstep.views.RecentsView.TASK_SECONDARY_TRANSLATION;
 import static com.android.quickstep.views.TaskView.FLAG_UPDATE_ALL;
 
-import android.util.Log;
-
 import com.android.launcher3.anim.PendingAnimation;
 import com.android.launcher3.anim.PropertySetter;
 import com.android.launcher3.statemanager.StateManager.StateHandler;
@@ -84,8 +82,6 @@
         float overviewButtonAlpha = state.hasOverviewActions() ? 1 : 0;
         setter.setFloat(mActivity.getActionsView().getVisibilityAlpha(),
                 MultiValueAlpha.VALUE, overviewButtonAlpha, LINEAR);
-        Log.v("b/193125090",
-                "FallbackRecentsStateController - setVisibilityAlpha: " + overviewButtonAlpha);
 
         float[] scaleAndOffset = state.getOverviewScaleAndOffset(mActivity);
         setter.setFloat(mRecentsView, RECENTS_SCALE_PROPERTY, scaleAndOffset[0],
diff --git a/quickstep/src/com/android/quickstep/views/OverviewActionsView.java b/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
index 65cf6ea..563bb53 100644
--- a/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
+++ b/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
@@ -23,7 +23,6 @@
 import android.content.res.Configuration;
 import android.graphics.Rect;
 import android.util.AttributeSet;
-import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.FrameLayout;
@@ -163,8 +162,6 @@
         } else {
             mHiddenFlags &= ~visibilityFlags;
         }
-        Log.v("b/193125090",
-                "updateHiddenFlags - visibilityFlags: " + visibilityFlags + ", enable: " + enable);
         boolean isHidden = mHiddenFlags != 0;
         mMultiValueAlpha.getProperty(INDEX_HIDDEN_FLAGS_ALPHA).setValue(isHidden ? 0 : 1);
     }
@@ -183,9 +180,6 @@
         } else {
             mDisabledFlags &= ~disabledFlags;
         }
-        //
-        Log.v("b/193125090",
-                "updateDisabledFlags - disabledFlags: " + disabledFlags + ", enable: " + enable);
         boolean isEnabled = (mDisabledFlags & ~DISABLED_ROTATED) == 0;
         LayoutUtils.setViewEnabled(this, isEnabled);
     }
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index ca43193..6d3f855 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -82,7 +82,6 @@
 import android.text.TextPaint;
 import android.util.AttributeSet;
 import android.util.FloatProperty;
-import android.util.Log;
 import android.util.SparseBooleanArray;
 import android.view.Gravity;
 import android.view.HapticFeedbackConstants;
@@ -1270,7 +1269,6 @@
         // Fade out the actions view quickly (0.1 range)
         mActionsView.getFullscreenAlpha().setValue(
                 mapToRange(fullscreenProgress, 0, 0.1f, 1f, 0f, LINEAR));
-        Log.v("b/193125090", "setFullscreenAlpha: " + mActionsView.getFullscreenAlpha().getValue());
     }
 
     private void updateTaskStackListenerState() {
@@ -1489,7 +1487,6 @@
             }
         }
         mActionsView.getScrollAlpha().setValue(scrollAlpha);
-        Log.v("b/193125090", "setScrollAlpha: " + scrollAlpha);
     }
 
     /**
@@ -1914,7 +1911,6 @@
     private void animateActionsViewIn() {
         ObjectAnimator anim = ObjectAnimator.ofFloat(
                 mActionsView.getVisibilityAlpha(), MultiValueAlpha.VALUE, 0, 1);
-        Log.v("b/193125090", "animateActionsViewIn - setVisibilityAlpha: " + 1);
         anim.setDuration(TaskView.SCALE_ICON_DURATION);
         anim.start();
     }
@@ -2724,7 +2720,6 @@
         mEmptyMessagePaint.setAlpha(alphaInt);
         mEmptyIcon.setAlpha(alphaInt);
         mActionsView.getContentAlpha().setValue(mContentAlpha);
-        Log.v("b/193125090", "setContentAlpha: " + mContentAlpha);
 
         if (alpha > 0) {
             setVisibility(VISIBLE);
diff --git a/res/layout/add_item_confirmation_activity.xml b/res/layout/add_item_confirmation_activity.xml
index 6fd4a85..c57b75a 100644
--- a/res/layout/add_item_confirmation_activity.xml
+++ b/res/layout/add_item_confirmation_activity.xml
@@ -62,8 +62,7 @@
                 android:text="@string/add_item_request_drag_hint"
                 android:textSize="14sp"
                 android:textColor="?android:attr/textColorSecondary"
-                android:alpha="0.7"
-                android:importantForAccessibility="no"/>
+                android:alpha="0.7"/>
 
             <ScrollView
                 android:id="@+id/widget_preview_scroll_view"
@@ -88,9 +87,11 @@
                 <Button
                     style="@style/Button.FullRounded.Colored"
                     android:layout_width="wrap_content"
-                    android:layout_height="36dp"
+                    android:layout_height="wrap_content"
                     android:paddingHorizontal="16dp"
                     android:textSize="14sp"
+                    android:maxLines="2"
+                    android:ellipsize="end"
                     android:textColor="@color/button_text"
                     android:text="@android:string/cancel"
                     android:onClick="onCancelClick"/>
@@ -102,9 +103,11 @@
                 <Button
                     style="@style/Button.FullRounded.Colored"
                     android:layout_width="wrap_content"
-                    android:layout_height="36dp"
+                    android:layout_height="wrap_content"
                     android:paddingHorizontal="16dp"
                     android:textSize="14sp"
+                    android:maxLines="2"
+                    android:ellipsize="end"
                     android:textColor="@color/button_text"
                     android:text="@string/add_to_home_screen"
                     android:onClick="onPlaceAutomaticallyClick"/>
diff --git a/res/layout/work_apps_edu.xml b/res/layout/work_apps_edu.xml
index 2a3d154..382b8fc 100644
--- a/res/layout/work_apps_edu.xml
+++ b/res/layout/work_apps_edu.xml
@@ -24,7 +24,7 @@
         android:layout_height="wrap_content"
         android:orientation="vertical"
         android:paddingHorizontal="@dimen/work_card_padding_horizontal"
-        android:paddingVertical="@dimen/work_card_padding_vertical"
+        android:paddingVertical="@dimen/work_card_padding_horizontal"
         android:background="@drawable/work_card"
         android:layout_gravity="center_horizontal"
         android:gravity="center"
@@ -36,14 +36,14 @@
             android:id="@+id/work_apps_paused_title"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_marginBottom="@dimen/work_card_padding_vertical"
+            android:layout_marginBottom="@dimen/work_card_padding_horizontal"
             android:text="@string/work_profile_edu_work_apps"
             android:textAlignment="center"
             android:textSize="20sp" />
 
         <Button
-            android:layout_width="wrap_content"
-            android:layout_height="@dimen/rounded_button_height"
+            android:layout_width="match_parent"
+            android:layout_height="52dp"
             android:id="@+id/action_btn"
             android:textColor="?attr/workProfileOverlayTextColor"
             android:text="@string/work_profile_edu_accept"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index a4a562e..c9557ef 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -122,7 +122,6 @@
     <dimen name="work_fab_height">56dp</dimen>
     <dimen name="work_fab_radius">28dp</dimen>
     <dimen name="work_card_padding_horizontal">24dp</dimen>
-    <dimen name="work_card_padding_vertical">32dp</dimen>
     <dimen name="work_fab_margin">16dp</dimen>
     <dimen name="work_profile_footer_padding">20dp</dimen>
     <dimen name="work_profile_footer_text_size">16sp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ddd838d..d1774e5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -63,6 +63,9 @@
     <string name="add_item_request_drag_hint">Touch &amp; hold the widget to move it around the Home screen</string>
     <!-- Button label to automatically add a widget to home screen [CHAR_LIMIT=50] -->
     <string name="add_to_home_screen">Add to Home screen</string>
+    <!-- Accessibility spoken message announced when a widget gets added to the home screen using a
+         button in a dialog. [CHAR_LIMIT=none] -->
+    <string name="added_to_home_screen_accessibility_text"><xliff:g id="widget_name" example="Calendar month view">%1$s</xliff:g> widget added to home screen</string>
     <!-- Label for showing the number of widgets an app has in the full widgets picker.
          [CHAR_LIMIT=25] -->
     <plurals name="widgets_count">
diff --git a/src/com/android/launcher3/dragndrop/AddItemActivity.java b/src/com/android/launcher3/dragndrop/AddItemActivity.java
index df97bfb..55be4a4 100644
--- a/src/com/android/launcher3/dragndrop/AddItemActivity.java
+++ b/src/com/android/launcher3/dragndrop/AddItemActivity.java
@@ -27,10 +27,12 @@
 import android.annotation.TargetApi;
 import android.app.ActivityOptions;
 import android.appwidget.AppWidgetManager;
+import android.appwidget.AppWidgetProviderInfo;
 import android.content.ClipData;
 import android.content.ClipDescription;
 import android.content.Intent;
 import android.content.pm.LauncherApps.PinItemRequest;
+import android.content.pm.ShortcutInfo;
 import android.content.res.Configuration;
 import android.graphics.Canvas;
 import android.graphics.Point;
@@ -39,12 +41,15 @@
 import android.os.AsyncTask;
 import android.os.Build;
 import android.os.Bundle;
+import android.text.TextUtils;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.View.DragShadowBuilder;
 import android.view.View.OnLongClickListener;
 import android.view.View.OnTouchListener;
 import android.view.WindowManager;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
 import android.widget.TextView;
 
 import com.android.launcher3.BaseActivity;
@@ -92,6 +97,7 @@
     private InvariantDeviceProfile mIdp;
     private BaseDragLayer<AddItemActivity> mDragLayer;
     private AddItemWidgetsBottomSheet mSlideInView;
+    private AccessibilityManager mAccessibilityManager;
 
     private WidgetCell mWidgetCell;
 
@@ -127,6 +133,8 @@
         mDragLayer = findViewById(R.id.add_item_drag_layer);
         mDragLayer.recreateControllers();
         mWidgetCell = findViewById(R.id.widget_cell);
+        mAccessibilityManager =
+                getApplicationContext().getSystemService(AccessibilityManager.class);
 
         if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_SHORTCUT) {
             setupShortcut();
@@ -270,7 +278,7 @@
 
             @Override
             protected void onPostExecute(WidgetItem item) {
-                mWidgetCell.setPreviewSize(item.spanX, item.spanY);
+                mWidgetCell.setPreviewSize(item);
                 mWidgetCell.applyFromCellItem(item, mApp.getWidgetCache());
                 mWidgetCell.ensurePreview();
             }
@@ -291,17 +299,25 @@
      */
     public void onPlaceAutomaticallyClick(View v) {
         if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_SHORTCUT) {
-            ItemInstallQueue.INSTANCE.get(this).queueItem(mRequest.getShortcutInfo());
+            ShortcutInfo shortcutInfo = mRequest.getShortcutInfo();
+            ItemInstallQueue.INSTANCE.get(this).queueItem(shortcutInfo);
             logCommand(LAUNCHER_ADD_EXTERNAL_ITEM_PLACED_AUTOMATICALLY);
             mRequest.accept();
+            CharSequence label = shortcutInfo.getLongLabel();
+            if (TextUtils.isEmpty(label)) {
+                label = shortcutInfo.getShortLabel();
+            }
+            sendWidgetAddedToScreenAccessibilityEvent(label.toString());
             mSlideInView.close(/* animate= */ true);
             return;
         }
 
         mPendingBindWidgetId = mAppWidgetHost.allocateAppWidgetId();
+        AppWidgetProviderInfo widgetProviderInfo = mRequest.getAppWidgetProviderInfo(this);
         boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
-                mPendingBindWidgetId, mRequest.getAppWidgetProviderInfo(this), mWidgetOptions);
+                mPendingBindWidgetId, widgetProviderInfo, mWidgetOptions);
         if (success) {
+            sendWidgetAddedToScreenAccessibilityEvent(widgetProviderInfo.label);
             acceptWidget(mPendingBindWidgetId);
             return;
         }
@@ -375,6 +391,17 @@
                 isSheetDark ? SystemUiController.FLAG_DARK_NAV : SystemUiController.FLAG_LIGHT_NAV);
     }
 
+    private void sendWidgetAddedToScreenAccessibilityEvent(String widgetName) {
+        if (mAccessibilityManager.isEnabled()) {
+            AccessibilityEvent event =
+                    AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT);
+            event.setContentDescription(
+                    getApplicationContext().getResources().getString(
+                            R.string.added_to_home_screen_accessibility_text, widgetName));
+            mAccessibilityManager.sendAccessibilityEvent(event);
+        }
+    }
+
     private void logCommand(StatsLogManager.EventEnum command) {
         getStatsLogManager().logger()
                 .withItemInfo((ItemInfo) mWidgetCell.getWidgetView().getTag())
diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java
index 6605509..5759f75 100644
--- a/src/com/android/launcher3/widget/WidgetCell.java
+++ b/src/com/android/launcher3/widget/WidgetCell.java
@@ -209,8 +209,6 @@
         mWidgetPreviewLoader = loader;
         if (item.activityInfo != null) {
             setTag(new PendingAddShortcutInfo(item.activityInfo));
-            mPreviewWidth += mShortcutPreviewPadding;
-            mPreviewHeight += mShortcutPreviewPadding;
         } else {
             setTag(new PendingAddWidgetInfo(item.widgetInfo, mSourceContainer));
         }
@@ -357,16 +355,14 @@
     }
 
     /** Sets the widget preview image size in number of cells. */
-    public Size setPreviewSize(int spanX, int spanY) {
-        return setPreviewSize(spanX, spanY, 1f);
+    public Size setPreviewSize(WidgetItem widgetItem) {
+        return setPreviewSize(widgetItem, 1f);
     }
 
     /** Sets the widget preview image size, in number of cells, and preview scale. */
-    public Size setPreviewSize(int spanX, int spanY, float previewScale) {
+    public Size setPreviewSize(WidgetItem widgetItem, float previewScale) {
         DeviceProfile deviceProfile = mActivity.getDeviceProfile();
-        Size widgetSize =
-                mItem != null ? WidgetSizes.getWidgetItemSizePx(getContext(), deviceProfile, mItem)
-                : WidgetSizes.getWidgetSizePx(deviceProfile, spanX, spanY);
+        Size widgetSize = WidgetSizes.getWidgetItemSizePx(getContext(), deviceProfile, widgetItem);
         mPreviewWidth = widgetSize.getWidth();
         mPreviewHeight = widgetSize.getHeight();
         mPreviewScale = previewScale;
diff --git a/src/com/android/launcher3/widget/WidgetsBottomSheet.java b/src/com/android/launcher3/widget/WidgetsBottomSheet.java
index 14aeaf6..406de10 100644
--- a/src/com/android/launcher3/widget/WidgetsBottomSheet.java
+++ b/src/com/android/launcher3/widget/WidgetsBottomSheet.java
@@ -202,7 +202,7 @@
             tableRow.setGravity(Gravity.TOP);
             row.forEach(widgetItem -> {
                 WidgetCell widget = addItemCell(tableRow);
-                widget.setPreviewSize(widgetItem.spanX, widgetItem.spanY);
+                widget.setPreviewSize(widgetItem);
                 widget.applyFromCellItem(widgetItem, LauncherAppState.getInstance(mActivityContext)
                         .getWidgetCache());
                 widget.ensurePreview();
diff --git a/src/com/android/launcher3/widget/picker/WidgetsListTableViewHolderBinder.java b/src/com/android/launcher3/widget/picker/WidgetsListTableViewHolderBinder.java
index 57dec14..9c06558 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsListTableViewHolderBinder.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsListTableViewHolderBinder.java
@@ -120,7 +120,7 @@
                 WidgetCell widget = (WidgetCell) row.getChildAt(j);
                 widget.clear();
                 WidgetItem widgetItem = widgetItemsPerRow.get(j);
-                Size previewSize = widget.setPreviewSize(widgetItem.spanX, widgetItem.spanY);
+                Size previewSize = widget.setPreviewSize(widgetItem);
                 widget.applyFromCellItem(widgetItem, mWidgetPreviewLoader);
                 widget.setApplyBitmapDeferred(mApplyBitmapDeferred);
                 Bitmap preview = mWidgetPreviewLoader.getPreview(widgetItem, previewSize);
diff --git a/src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java b/src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java
index 3800ede..0b8ca34 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java
@@ -115,7 +115,7 @@
 
             for (WidgetItem widgetItem : widgetItems) {
                 WidgetCell widgetCell = addItemCell(tableRow);
-                widgetCell.setPreviewSize(widgetItem.spanX, widgetItem.spanY, data.mPreviewScale);
+                widgetCell.setPreviewSize(widgetItem, data.mPreviewScale);
                 widgetCell.applyFromCellItem(widgetItem,
                         LauncherAppState.getInstance(getContext()).getWidgetCache());
                 widgetCell.ensurePreview();
diff --git a/src/com/android/launcher3/widget/util/WidgetSizes.java b/src/com/android/launcher3/widget/util/WidgetSizes.java
index e2c84b5..451ed6e 100644
--- a/src/com/android/launcher3/widget/util/WidgetSizes.java
+++ b/src/com/android/launcher3/widget/util/WidgetSizes.java
@@ -32,6 +32,7 @@
 
 import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.R;
 import com.android.launcher3.model.WidgetItem;
 
 import java.util.ArrayList;
@@ -91,7 +92,9 @@
     public static Size getWidgetItemSizePx(Context context, DeviceProfile profile,
             WidgetItem widgetItem) {
         if (widgetItem.isShortcut()) {
-            return getWidgetSizePx(profile, widgetItem.spanX, widgetItem.spanY);
+            int dimension = profile.allAppsIconSizePx + 2 * context.getResources()
+                    .getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding);
+            return new Size(dimension, dimension);
         }
         return getWidgetPaddedSizePx(context, widgetItem.componentName, profile, widgetItem.spanX,
                 widgetItem.spanY);
diff --git a/tests/src/com/android/launcher3/util/rule/ScreenRecordRule.java b/tests/src/com/android/launcher3/util/rule/ScreenRecordRule.java
index 00b1cdd..7a5cf2c 100644
--- a/tests/src/com/android/launcher3/util/rule/ScreenRecordRule.java
+++ b/tests/src/com/android/launcher3/util/rule/ScreenRecordRule.java
@@ -62,12 +62,17 @@
                 ParcelFileDescriptor output =
                         automation.executeShellCommand("screenrecord " + outputFile);
                 String screenRecordPid = device.executeShellCommand("pidof screenrecord");
+                boolean success = false;
                 try {
                     base.evaluate();
+                    success = true;
                 } finally {
                     device.executeShellCommand("kill -INT " + screenRecordPid);
                     Log.e(TAG, "Screenrecord captured at: " + outputFile);
                     output.close();
+                    if (success) {
+                        automation.executeShellCommand("rm " + outputFile);
+                    }
                 }
             }
         };
@@ -78,5 +83,6 @@
      */
     @Retention(RetentionPolicy.RUNTIME)
     @Target(ElementType.METHOD)
-    public @interface ScreenRecord { }
+    public @interface ScreenRecord {
+    }
 }