Merge "Remove PMS snapshot lambdas" into tm-dev
diff --git a/StubLibraries.bp b/StubLibraries.bp
index 92e7dc9..726ab2a 100644
--- a/StubLibraries.bp
+++ b/StubLibraries.bp
@@ -374,6 +374,64 @@
     },
 }
 
+////////////////////////////////////////////////////////////////////////
+// api-versions.xml generation, for public and system. This API database
+// also contains the android.test.* APIs.
+////////////////////////////////////////////////////////////////////////
+
+java_library {
+    name: "android_stubs_current_with_test_libs",
+    static_libs: [
+        "android_stubs_current",
+        "android.test.base.stubs",
+        "android.test.mock.stubs",
+        "android.test.runner.stubs",
+    ],
+    defaults: ["android.jar_defaults"],
+    visibility: [
+        "//visibility:override",
+        "//visibility:private",
+    ],
+}
+
+java_library {
+    name: "android_system_stubs_current_with_test_libs",
+    static_libs: [
+        "android_system_stubs_current",
+        "android.test.base.stubs.system",
+        "android.test.mock.stubs.system",
+        "android.test.runner.stubs.system",
+    ],
+    defaults: ["android.jar_defaults"],
+    visibility: [
+        "//visibility:override",
+        "//visibility:private",
+    ],
+}
+
+droidstubs {
+    name: "api_versions_public",
+    srcs: [":android_stubs_current_with_test_libs{.jar}"],
+    generate_stubs: false,
+    api_levels_annotations_enabled: true,
+    api_levels_annotations_dirs: [
+        "sdk-dir",
+        "api-versions-jars-dir",
+    ],
+}
+
+droidstubs {
+    name: "api_versions_system",
+    srcs: [":android_system_stubs_current_with_test_libs{.jar}"],
+    generate_stubs: false,
+    api_levels_annotations_enabled: true,
+    api_levels_annotations_dirs: [
+        "sdk-dir",
+        "api-versions-jars-dir",
+    ],
+    api_levels_sdk_type: "system",
+}
+
 /////////////////////////////////////////////////////////////////////
 // hwbinder.stubs provides APIs required for building HIDL Java
 // libraries.
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 904aa7b..ed7fc66 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -11749,8 +11749,6 @@
 
   public class TraceReportService extends android.app.Service {
     ctor public TraceReportService();
-    method @Nullable public android.os.IBinder onBind(@NonNull android.content.Intent);
-    method public boolean onMessage(@NonNull android.os.Message);
     method public void onReportTrace(@NonNull android.service.tracing.TraceReportService.TraceParams);
   }
 
diff --git a/core/java/android/service/tracing/TraceReportService.java b/core/java/android/service/tracing/TraceReportService.java
index 3d16a3d..6fdc8e8 100644
--- a/core/java/android/service/tracing/TraceReportService.java
+++ b/core/java/android/service/tracing/TraceReportService.java
@@ -112,7 +112,6 @@
         }
     }
 
-    // Methods to override.
     /**
      * Called when a trace is reported and sent to this class.
      *
@@ -123,15 +122,10 @@
     public void onReportTrace(@NonNull TraceParams args) {
     }
 
-    // Optional methods to override.
-    // Realistically, these methods are internal implementation details but since this class is
-    // a SystemApi, it's better to err on the side of flexibility just in-case we need to override
-    // these methods down the line.
-
     /**
      * Handles binder calls from system_server.
      */
-    public boolean onMessage(@NonNull Message msg) {
+    private boolean onMessage(@NonNull Message msg) {
         if (msg.what == MSG_REPORT_TRACE) {
             if (!(msg.obj instanceof TraceReportParams)) {
                 Log.e(TAG, "Received invalid type for report trace message.");
@@ -153,10 +147,12 @@
 
     /**
      * Returns an IBinder for handling binder calls from system_server.
+     *
+     * @hide
      */
     @Nullable
     @Override
-    public IBinder onBind(@NonNull Intent intent) {
+    public final IBinder onBind(@NonNull Intent intent) {
         if (mMessenger == null) {
             mMessenger = new Messenger(new Handler(Looper.getMainLooper(), this::onMessage));
         }
diff --git a/core/java/android/speech/IRecognitionListener.aidl b/core/java/android/speech/IRecognitionListener.aidl
index 986a41c..f7e459e 100644
--- a/core/java/android/speech/IRecognitionListener.aidl
+++ b/core/java/android/speech/IRecognitionListener.aidl
@@ -79,7 +79,7 @@
 
     /**
      * Called for each ready segment of a recognition request. To request segmented speech results
-     * use {@link RecognizerIntent#EXTRA_SEGMENT_SESSION}. The callback might be called
+     * use {@link RecognizerIntent#EXTRA_SEGMENTED_SESSION}. The callback might be called
      * any number of times between {@link #onBeginningOfSpeech()} and
      * {@link #onEndOfSegmentedSession()}.
      *
@@ -91,7 +91,7 @@
 
     /**
      * Called at the end of a segmented recognition request. To request segmented speech results
-     * use {@link RecognizerIntent#EXTRA_SEGMENT_SESSION}.
+     * use {@link RecognizerIntent#EXTRA_SEGMENTED_SESSION}.
      */
     void onEndOfSegmentedSession();
 
diff --git a/core/java/android/speech/RecognitionListener.java b/core/java/android/speech/RecognitionListener.java
index 64fd09f..ee4a7d0 100644
--- a/core/java/android/speech/RecognitionListener.java
+++ b/core/java/android/speech/RecognitionListener.java
@@ -74,7 +74,7 @@
      * <p>
      *     Called with the results for the full speech since {@link #onReadyForSpeech(Bundle)}.
      *     To get recognition results in segments rather than for the full session see
-     *     {@link RecognizerIntent#EXTRA_SEGMENT_SESSION}.
+     *     {@link RecognizerIntent#EXTRA_SEGMENTED_SESSION}.
      * </p>
      *
      * @param results the recognition results. To retrieve the results in {@code
@@ -100,7 +100,7 @@
 
     /**
      * Called for each ready segment of a recognition request. To request segmented speech results
-     * use {@link RecognizerIntent#EXTRA_SEGMENT_SESSION}. The callback might be called
+     * use {@link RecognizerIntent#EXTRA_SEGMENTED_SESSION}. The callback might be called
      * any number of times between {@link #onReadyForSpeech(Bundle)} and
      * {@link #onEndOfSegmentedSession()}.
      *
@@ -112,7 +112,7 @@
 
     /**
      * Called at the end of a segmented recognition request. To request segmented speech results
-     * use {@link RecognizerIntent#EXTRA_SEGMENT_SESSION}.
+     * use {@link RecognizerIntent#EXTRA_SEGMENTED_SESSION}.
      */
     default void onEndOfSegmentedSession() {}
 
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 4dc1fca..286b502 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -21142,6 +21142,10 @@
         }
 
         notifyEnterOrExitForAutoFillIfNeeded(false);
+
+        if (info != null && !collectPreferKeepClearRects().isEmpty()) {
+            info.mViewRootImpl.updateKeepClearRectsForView(this);
+        }
     }
 
     /**
diff --git a/media/jni/android_media_tv_Tuner.cpp b/media/jni/android_media_tv_Tuner.cpp
index 9ed1ac0..d0acc53 100644
--- a/media/jni/android_media_tv_Tuner.cpp
+++ b/media/jni/android_media_tv_Tuner.cpp
@@ -4592,7 +4592,8 @@
         ALOGD("Failed to GetByteArrayElements");
         return -1;
     }
-    long realSize = dvrClient->readFromBuffer(reinterpret_cast<signed char *>(src) + offset, size);
+    int64_t realSize =
+            dvrClient->readFromBuffer(reinterpret_cast<signed char *>(src) + offset, size);
     env->ReleaseByteArrayElements(buffer, src, 0);
     return (jlong)realSize;
 }
@@ -4624,7 +4625,8 @@
         return -1;
     }
 
-    long realSize = dvrClient->writeToBuffer(reinterpret_cast<signed char *>(dst) + offset, size);
+    int64_t realSize =
+            dvrClient->writeToBuffer(reinterpret_cast<signed char *>(dst) + offset, size);
     env->ReleaseByteArrayElements(buffer, dst, 0);
     return (jlong)realSize;
 }
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt b/packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt
index 1d1a230..7b85050 100644
--- a/packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt
@@ -531,7 +531,8 @@
         foregroundExecutor.execute {
             onMediaDataLoaded(packageName, null, MediaData(userId, true, bgColor, appName,
                     null, desc.subtitle, desc.title, artworkIcon, listOf(mediaAction), listOf(0),
-                    null, packageName, token, appIntent, device = null, active = false,
+                    MediaButton(playOrPause = mediaAction), packageName, token, appIntent,
+                    device = null, active = false,
                     resumeAction = resumeAction, resumption = true, notificationKey = packageName,
                     hasCheckedForResume = true, lastActive = lastActive))
         }
@@ -951,6 +952,7 @@
             // Move to resume key (aka package name) if that key doesn't already exist.
             val resumeAction = getResumeMediaAction(removed.resumeAction!!)
             val updated = removed.copy(token = null, actions = listOf(resumeAction),
+                    semanticActions = MediaButton(playOrPause = resumeAction),
                     actionsToShowInCompact = listOf(0), active = false, resumption = true,
                     isPlaying = false, isClearable = true)
             val pkg = removed.packageName
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java
index 6ea7aec..80a7a4ae 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java
@@ -274,11 +274,21 @@
             };
 
     private final OnComputeInternalInsetsListener mOnComputeInternalInsetsListener = info -> {
-        // When the nav bar is in 2-button or 3-button mode, or when IME is visible in fully
-        // gestural mode, the entire nav bar should be touchable.
+        // When the nav bar is in 2-button or 3-button mode, or when the back button is force-shown
+        // while in gesture nav in SUW, the entire nav bar should be touchable.
         if (!mEdgeBackGestureHandler.isHandlingGestures()) {
-            info.setTouchableInsets(InternalInsetsInfo.TOUCHABLE_INSETS_FRAME);
-            return;
+            // We're in 2/3 button mode OR back button force-shown in SUW
+            if (!mImeVisible) {
+                // IME not showing, take all touches
+                info.setTouchableInsets(InternalInsetsInfo.TOUCHABLE_INSETS_FRAME);
+                return;
+            }
+  
+            if (!isImeRenderingNavButtons()) {
+                // IME showing but not drawing any buttons, take all touches
+                info.setTouchableInsets(InternalInsetsInfo.TOUCHABLE_INSETS_FRAME);
+                return;     
+            }
         }
 
         // When in gestural and the IME is showing, don't use the nearest region since it will take
@@ -775,14 +785,10 @@
 
         updateRecentsIcon();
 
-        boolean isImeRenderingNavButtons = mImeDrawsImeNavBar
-                && mImeCanRenderGesturalNavButtons
-                && (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) != 0;
-
         // Update IME button visibility, a11y and rotate button always overrides the appearance
         boolean disableImeSwitcher =
                 (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SWITCHER_SHOWN) == 0
-                || isImeRenderingNavButtons;
+                || isImeRenderingNavButtons();
         mContextualButtonGroup.setButtonVisibility(R.id.ime_switcher, !disableImeSwitcher);
 
         mBarTransitions.reapplyDarkIntensity();
@@ -799,7 +805,7 @@
 
         boolean disableBack = !useAltBack && (mEdgeBackGestureHandler.isHandlingGestures()
                 || ((mDisabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0))
-                || isImeRenderingNavButtons;
+                || isImeRenderingNavButtons();
 
         // When screen pinning, don't hide back and home when connected service or back and
         // recents buttons when disconnected from launcher service in screen pinning mode,
@@ -832,6 +838,15 @@
         notifyActiveTouchRegions();
     }
 
+    /**
+     * Returns whether the IME is currently visible and drawing the nav buttons.
+     */
+    private boolean isImeRenderingNavButtons() {
+        return mImeDrawsImeNavBar
+                && mImeCanRenderGesturalNavButtons
+                && (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) != 0;
+    }
+
     @VisibleForTesting
     boolean isRecentsButtonDisabled() {
         return mUseCarModeUi || !isOverviewEnabled()
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/MediaDataManagerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/MediaDataManagerTest.kt
index f4fa921..021f70e 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/MediaDataManagerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/MediaDataManagerTest.kt
@@ -370,6 +370,7 @@
         assertThat(data.song).isEqualTo(SESSION_TITLE)
         assertThat(data.app).isEqualTo(APP_NAME)
         assertThat(data.actions).hasSize(1)
+        assertThat(data.semanticActions!!.playOrPause).isNotNull()
         assertThat(data.lastActive).isAtLeast(currentTime)
     }
 
diff --git a/telephony/java/android/telephony/PhysicalChannelConfig.java b/telephony/java/android/telephony/PhysicalChannelConfig.java
index 95448c7..d91134e 100644
--- a/telephony/java/android/telephony/PhysicalChannelConfig.java
+++ b/telephony/java/android/telephony/PhysicalChannelConfig.java
@@ -23,12 +23,15 @@
 import android.os.Parcelable;
 import android.telephony.Annotation.NetworkType;
 
+import com.android.telephony.Rlog;
+
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.util.Arrays;
 import java.util.Objects;
 
 public final class PhysicalChannelConfig implements Parcelable {
+    static final String TAG = "PhysicalChannelConfig";
 
     // TODO(b/72993578) consolidate these enums in a central location.
     /** @hide */
@@ -568,19 +571,21 @@
 
         public @NonNull Builder setNetworkType(@NetworkType int networkType) {
             if (!TelephonyManager.isNetworkTypeValid(networkType)) {
-                throw new IllegalArgumentException("Network type: " + networkType + " is invalid.");
+                Rlog.e(TAG, "Builder.setNetworkType: Network type " + networkType + " is invalid.");
+            } else {
+                mNetworkType = networkType;
             }
-            mNetworkType = networkType;
             return this;
         }
 
         public @NonNull Builder setFrequencyRange(int frequencyRange) {
             if (!ServiceState.isFrequencyRangeValid(frequencyRange)
                     && frequencyRange != ServiceState.FREQUENCY_RANGE_UNKNOWN) {
-                throw new IllegalArgumentException("Frequency range: " + frequencyRange +
-                        " is invalid.");
+                Rlog.e(TAG, "Builder.setFrequencyRange: Frequency range " + frequencyRange
+                        + " is invalid.");
+            } else {
+                mFrequencyRange = frequencyRange;
             }
-            mFrequencyRange = frequencyRange;
             return this;
         }
 
@@ -596,19 +601,21 @@
 
         public @NonNull Builder setCellBandwidthDownlinkKhz(int cellBandwidthDownlinkKhz) {
             if (cellBandwidthDownlinkKhz < CELL_BANDWIDTH_UNKNOWN) {
-                throw new IllegalArgumentException("Cell downlink bandwidth(kHz): " +
-                        cellBandwidthDownlinkKhz + " is invalid.");
+                Rlog.e(TAG, "Builder.setCellBandwidthDownlinkKhz: Cell downlink bandwidth(kHz) "
+                        + cellBandwidthDownlinkKhz + " is invalid.");
+            } else {
+                mCellBandwidthDownlinkKhz = cellBandwidthDownlinkKhz;
             }
-            mCellBandwidthDownlinkKhz = cellBandwidthDownlinkKhz;
             return this;
         }
 
         public @NonNull Builder setCellBandwidthUplinkKhz(int cellBandwidthUplinkKhz) {
             if (cellBandwidthUplinkKhz < CELL_BANDWIDTH_UNKNOWN) {
-                throw new IllegalArgumentException("Cell uplink bandwidth(kHz): "+
-                        cellBandwidthUplinkKhz +" is invalid.");
+                Rlog.e(TAG, "Builder.setCellBandwidthUplinkKhz: Cell uplink bandwidth(kHz) "
+                        + cellBandwidthUplinkKhz + " is invalid.");
+            } else {
+                mCellBandwidthUplinkKhz = cellBandwidthUplinkKhz;
             }
-            mCellBandwidthUplinkKhz = cellBandwidthUplinkKhz;
             return this;
         }
 
@@ -625,19 +632,20 @@
 
         public @NonNull Builder setPhysicalCellId(int physicalCellId) {
             if (physicalCellId > PHYSICAL_CELL_ID_MAXIMUM_VALUE) {
-                throw new IllegalArgumentException("Physical cell Id: " + physicalCellId +
-                        " is over limit.");
+                Rlog.e(TAG, "Builder.setPhysicalCellId: Physical cell ID " + physicalCellId
+                        + " is over limit.");
+            } else {
+                mPhysicalCellId = physicalCellId;
             }
-            mPhysicalCellId = physicalCellId;
             return this;
         }
 
         public @NonNull Builder setBand(int band) {
             if (band <= BAND_UNKNOWN) {
-                throw new IllegalArgumentException("Band: " + band +
-                        " is invalid.");
+                Rlog.e(TAG, "Builder.setBand: Band " + band + " is invalid.");
+            } else {
+                mBand = band;
             }
-            mBand = band;
             return this;
         }
     }