Update build tools version to fix b/237299698 am: 0d7a50767b am: a0e7aed535

Original change: https://googleplex-android-review.googlesource.com/c/platform/development/+/20764506

Change-Id: I4111dedfa654f79b5ba5f5a37a9dbb4c167bd41d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/samples/ApiDemos/AndroidManifest.xml b/samples/ApiDemos/AndroidManifest.xml
index aad0074..159437c 100644
--- a/samples/ApiDemos/AndroidManifest.xml
+++ b/samples/ApiDemos/AndroidManifest.xml
@@ -61,6 +61,7 @@
             android:icon="@drawable/app_sample_code"
             android:hardwareAccelerated="true"
             android:supportsRtl="true"
+            android:enableOnBackInvokedCallback="true"
             android:theme="@android:style/Theme.Material.Light.DarkActionBar">
 
         <!-- This is how we can request a library but still allow the app
diff --git a/samples/ApiDemos/res/layout/picture_in_picture.xml b/samples/ApiDemos/res/layout/picture_in_picture.xml
index f29bd08..3d44bcf 100644
--- a/samples/ApiDemos/res/layout/picture_in_picture.xml
+++ b/samples/ApiDemos/res/layout/picture_in_picture.xml
@@ -69,6 +69,13 @@
                 android:padding="8dp"
                 android:text="@string/activity_picture_in_picture_seamless_resize_toggle" />
 
+            <Switch
+                android:id="@+id/enter_pip_on_back"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:padding="8dp"
+                android:text="@string/activity_picture_in_picture_enter_pip_on_back_toggle" />
+
             <RadioGroup
                 android:id="@+id/current_position"
                 android:layout_width="match_parent"
@@ -95,6 +102,24 @@
 
             </RadioGroup>
 
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:padding="8dp"
+                android:orientation="horizontal">
+
+                <TextView
+                  android:layout_width="wrap_content"
+                  android:layout_height="wrap_content"
+                  android:text="@string/label_aspect_ratio" />
+
+                <Spinner
+                    android:id="@+id/aspect_ratio"
+                    android:layout_width="0dp"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1" />
+            </LinearLayout>
+
             <Button
                 android:id="@+id/enter_pip_button"
                 android:layout_width="wrap_content"
diff --git a/samples/ApiDemos/res/layout/picture_in_picture_content.xml b/samples/ApiDemos/res/layout/picture_in_picture_content.xml
index bae18db..8e948b9 100644
--- a/samples/ApiDemos/res/layout/picture_in_picture_content.xml
+++ b/samples/ApiDemos/res/layout/picture_in_picture_content.xml
@@ -14,6 +14,7 @@
   ~ See the License for the specific language governing permissions and
   ~ limitations under the License.
   -->
+<!-- Note that app:aspectRatio can be changed dynamically. -->
 <com.example.android.apis.view.FixedAspectRatioImageView
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index eccba7b..9c981ec 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -66,6 +66,7 @@
     <string name="activity_picture_in_picture_auto_pip_toggle">Enable auto PiP</string>
     <string name="activity_picture_in_picture_source_rect_hint_toggle">Enable source rect hint</string>
     <string name="activity_picture_in_picture_seamless_resize_toggle">Enable seamless resize</string>
+    <string name="activity_picture_in_picture_enter_pip_on_back_toggle">Enter PiP on back</string>
     <string name="enter_content_pip">Enter content PiP</string>
     <string name="enter_picture_in_picture">Manually enter PiP</string>
     <string name="action_custom_close">Close PiP</string>
@@ -73,6 +74,15 @@
     <string name="label_exit_position">Exit position</string>
     <string name="label_position_start">Start</string>
     <string name="label_position_end">End</string>
+    <string name="label_aspect_ratio">Aspect Ratio</string>
+    <!-- List of aspect ratio to demo, we use Rational.parseRational to parse what's inside () -->
+    <string-array name="aspect_ratio_list">
+        <item>Extreme wide (21/9)</item>
+        <item>Video (16/9)</item>
+        <item>Square (1/1)</item>
+        <item>Video call (9/16)</item>
+        <item>Extreme tall (9/21)</item>
+    </string-array>
 
     <string name="activity_keep_clear">App/Activity/Keep Clear Rects</string>
     <string name="keep_clear_property_set">
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/PictureInPicture.java b/samples/ApiDemos/src/com/example/android/apis/app/PictureInPicture.java
index 60731be..da06cf7 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/PictureInPicture.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/PictureInPicture.java
@@ -39,13 +39,18 @@
 import android.view.Gravity;
 import android.view.View;
 import android.view.WindowManager;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
 import android.widget.CompoundButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.RadioGroup;
+import android.widget.Spinner;
 import android.widget.Switch;
+import android.window.OnBackInvokedDispatcher;
 
 import com.example.android.apis.R;
+import com.example.android.apis.view.FixedAspectRatioImageView;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -54,7 +59,9 @@
     private static final String EXTRA_ENABLE_AUTO_PIP = "auto_pip";
     private static final String EXTRA_ENABLE_SOURCE_RECT_HINT = "source_rect_hint";
     private static final String EXTRA_ENABLE_SEAMLESS_RESIZE = "seamless_resize";
+    private static final String EXTRA_ENTER_PIP_ON_BACK = "enter_pip_on_back";
     private static final String EXTRA_CURRENT_POSITION = "current_position";
+    private static final String EXTRA_ASPECT_RATIO = "aspect_ratio";
 
     private static final int TABLET_BREAK_POINT_DP = 700;
 
@@ -93,12 +100,14 @@
             (v, id) -> updateContentPosition(id);
 
     private LinearLayout mContainer;
-    private ImageView mImageView;
+    private FixedAspectRatioImageView mImageView;
     private View mControlGroup;
     private Switch mAutoPipToggle;
     private Switch mSourceRectHintToggle;
     private Switch mSeamlessResizeToggle;
+    private Switch mEnterPipOnBackToggle;
     private RadioGroup mCurrentPositionGroup;
+    private Spinner mAspectRatioSpinner;
     private List<RemoteAction> mPipActions;
     private RemoteAction mCloseAction;
 
@@ -114,14 +123,47 @@
         mAutoPipToggle = findViewById(R.id.auto_pip_toggle);
         mSourceRectHintToggle = findViewById(R.id.source_rect_hint_toggle);
         mSeamlessResizeToggle = findViewById(R.id.seamless_resize_toggle);
+        mEnterPipOnBackToggle = findViewById(R.id.enter_pip_on_back);
         mCurrentPositionGroup = findViewById(R.id.current_position);
+        mAspectRatioSpinner = findViewById(R.id.aspect_ratio);
+
+        // Initiate views if applicable
+        final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
+                R.array.aspect_ratio_list, android.R.layout.simple_spinner_item);
+        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+        mAspectRatioSpinner.setAdapter(adapter);
 
         // Attach listeners
         mImageView.addOnLayoutChangeListener(mOnLayoutChangeListener);
         mAutoPipToggle.setOnCheckedChangeListener(mOnToggleChangedListener);
         mSourceRectHintToggle.setOnCheckedChangeListener(mOnToggleChangedListener);
         mSeamlessResizeToggle.setOnCheckedChangeListener(mOnToggleChangedListener);
+        mEnterPipOnBackToggle.setOnCheckedChangeListener(mOnToggleChangedListener);
+        getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
+                OnBackInvokedDispatcher.PRIORITY_DEFAULT, () -> {
+                    if (mEnterPipOnBackToggle.isChecked()) {
+                        enterPictureInPictureMode();
+                    } else {
+                        finish();
+                    }
+                });
         mCurrentPositionGroup.setOnCheckedChangeListener(mOnPositionChangedListener);
+        mAspectRatioSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+            @Override
+            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+                final String rawText = parent.getItemAtPosition(position).toString();
+                final String textToParse = rawText.substring(
+                        rawText.indexOf('(') + 1,
+                        rawText.indexOf(')'));
+                mImageView.addOnLayoutChangeListener(mOnLayoutChangeListener);
+                mImageView.setAspectRatio(Rational.parseRational(textToParse));
+            }
+
+            @Override
+            public void onNothingSelected(AdapterView<?> parent) {
+                // Do nothing.
+            }
+        });
         findViewById(R.id.enter_pip_button).setOnClickListener(v -> enterPictureInPictureMode());
         findViewById(R.id.enter_content_pip_button).setOnClickListener(v -> enterContentPip());
 
@@ -132,11 +174,14 @@
                 intent.getBooleanExtra(EXTRA_ENABLE_SOURCE_RECT_HINT, false));
         mSeamlessResizeToggle.setChecked(
                 intent.getBooleanExtra(EXTRA_ENABLE_SEAMLESS_RESIZE, false));
+        mEnterPipOnBackToggle.setChecked(
+                intent.getBooleanExtra(EXTRA_ENTER_PIP_ON_BACK, false));
         final int positionId = "end".equalsIgnoreCase(
                 intent.getStringExtra(EXTRA_CURRENT_POSITION))
                 ? R.id.radio_current_end
                 : R.id.radio_current_start;
         mCurrentPositionGroup.check(positionId);
+        mAspectRatioSpinner.setSelection(1);
 
         updateLayout(getResources().getConfiguration());
     }
diff --git a/samples/ApiDemos/src/com/example/android/apis/view/FixedAspectRatioImageView.java b/samples/ApiDemos/src/com/example/android/apis/view/FixedAspectRatioImageView.java
index f834487..b505bb3 100644
--- a/samples/ApiDemos/src/com/example/android/apis/view/FixedAspectRatioImageView.java
+++ b/samples/ApiDemos/src/com/example/android/apis/view/FixedAspectRatioImageView.java
@@ -29,7 +29,7 @@
  * one of the dimension is in exact while the other one in wrap_content size mode.
  */
 public class FixedAspectRatioImageView extends ImageView {
-    private final Rational mAspectRatio;
+    private Rational mAspectRatio;
 
     public FixedAspectRatioImageView(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -43,6 +43,13 @@
         }
     }
 
+    public void setAspectRatio(Rational aspectRatio) {
+        if (!mAspectRatio.equals(aspectRatio)) {
+            mAspectRatio = aspectRatio;
+            requestLayout();
+        }
+    }
+
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
diff --git a/tools/motion/OWNERS b/tools/motion/OWNERS
new file mode 100644
index 0000000..545b822
--- /dev/null
+++ b/tools/motion/OWNERS
@@ -0,0 +1,3 @@
+cinek@google.com
+gallmann@google.com
+michschn@google.com