diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index ecbc9b1d52c2cd3429a7cc2eecce0cd83a148b8b..9a19d8edf8a818cf99080c83f88106be113affa5 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -8638,8 +8638,8 @@ public class AppOpsManager {
                 }
             }
 
-            SyncNotedAppOp syncOp = mService.noteProxyOperation(op, attributionSource.asState(),
-                    collectionMode == COLLECT_ASYNC, message,
+            SyncNotedAppOp syncOp = mService.noteProxyOperationWithState(op,
+                    attributionSource.asState(), collectionMode == COLLECT_ASYNC, message,
                     shouldCollectMessage, skipProxyOperation);
 
             if (syncOp.getOpMode() == MODE_ALLOWED) {
@@ -9110,7 +9110,7 @@ public class AppOpsManager {
                 }
             }
 
-            SyncNotedAppOp syncOp = mService.startProxyOperation(clientId, op,
+            SyncNotedAppOp syncOp = mService.startProxyOperationWithState(clientId, op,
                     attributionSource.asState(), false, collectionMode == COLLECT_ASYNC, message,
                     shouldCollectMessage, skipProxyOperation, proxyAttributionFlags,
                     proxiedAttributionFlags, attributionChainId);
@@ -9229,8 +9229,8 @@ public class AppOpsManager {
     public void finishProxyOp(@NonNull IBinder clientId, @NonNull String op,
             @NonNull AttributionSource attributionSource, boolean skipProxyOperation) {
         try {
-            mService.finishProxyOperation(clientId, strOpToOp(op), attributionSource.asState(),
-                    skipProxyOperation);
+            mService.finishProxyOperationWithState(
+                    clientId, strOpToOp(op), attributionSource.asState(), skipProxyOperation);
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
diff --git a/core/java/com/android/internal/app/IAppOpsService.aidl b/core/java/com/android/internal/app/IAppOpsService.aidl
index 584dd806361ce93a18b7edb4a0cdb0aba3cac851..492e2ac7cc288f3f10e9f4a37b56a2be954f59e0 100644
--- a/core/java/com/android/internal/app/IAppOpsService.aidl
+++ b/core/java/com/android/internal/app/IAppOpsService.aidl
@@ -20,6 +20,7 @@ import android.app.AppOpsManager;
 import android.app.AsyncNotedAppOp;
 import android.app.SyncNotedAppOp;
 import android.app.RuntimeAppOpAccessMessage;
+import android.content.AttributionSource;
 import android.content.AttributionSourceState;
 import android.content.pm.ParceledListSlice;
 import android.os.Bundle;
@@ -32,10 +33,17 @@ import com.android.internal.app.IAppOpsNotedCallback;
 import com.android.internal.app.IAppOpsStartedCallback;
 import com.android.internal.app.MessageSamplingConfig;
 
+// AppOpsService AIDL interface.
+// PLEASE READ BEFORE MODIFYING THIS FILE.
+// Some methods in this interface or their transaction codes are mentioned in
+// frameworks/base/boot/hiddenapi/hiddenapi-unsupported.txt, meaning that we cannot change their
+// signature or ordering as they may be used by 3p apps.
+// Also, some methods are mentioned in native code, meaning that the numbering in
+// frameworks/native/libs/permission/include/binder/IAppOpsService.h must match the order here.
+// Please be careful to respect both these issues when modifying this file.
 interface IAppOpsService {
-    // These methods are also called by native code, so must
-    // be kept in sync with frameworks/native/libs/permission/include/binder/IAppOpsService.h
-    // and not be reordered
+    // These methods are also called by native code, so please be careful that the number in
+    // frameworks/native/libs/permission/include/binder/IAppOpsService.h matches the ordering here.
     int checkOperation(int code, int uid, String packageName);
     SyncNotedAppOp noteOperation(int code, int uid, String packageName, @nullable String attributionTag,
             boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage);
@@ -54,21 +62,21 @@ interface IAppOpsService {
     void setCameraAudioRestriction(int mode);
     void startWatchingModeWithFlags(int op, String packageName, int flags,
             IAppOpsCallback callback);
-    // End of methods also called by native code.
-    // Any new method exposed to native must be added after the last one, do not reorder
-
-    SyncNotedAppOp noteProxyOperation(int code, in AttributionSourceState attributionSourceState,
+    // End of methods also called by native code (there may be more blocks like this of native
+    // methods later in this file).
+    // Deprecated, use noteProxyOperationWithState instead.
+    SyncNotedAppOp noteProxyOperation(int code, in AttributionSource attributionSource,
             boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
             boolean skipProxyOperation);
+    // Deprecated, use startProxyOperationWithState instead.
     SyncNotedAppOp startProxyOperation(IBinder clientId, int code,
-            in AttributionSourceState attributionSourceState, boolean startIfModeDefault,
+            in AttributionSource attributionSource, boolean startIfModeDefault,
             boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
             boolean skipProxyOperation, int proxyAttributionFlags, int proxiedAttributionFlags,
             int attributionChainId);
-    void finishProxyOperation(IBinder clientId, int code,
-            in AttributionSourceState attributionSourceState, boolean skipProxyOperation);
-
-    // Remaining methods are only used in Java.
+    // Deprecated, use finishProxyOperationWithState instead.
+    void finishProxyOperation(IBinder clientId, int code, in AttributionSource attributionSource,
+            boolean skipProxyOperation);
     int checkPackage(int uid, String packageName);
     RuntimeAppOpAccessMessage collectRuntimeAppOpAccessMessage();
     MessageSamplingConfig reportRuntimeAppOpAccessMessageAndGetConfig(String packageName,
@@ -127,8 +135,19 @@ interface IAppOpsService {
     List<AsyncNotedAppOp> extractAsyncOps(String packageName);
 
     int checkOperationRaw(int code, int uid, String packageName, @nullable String attributionTag);
-
     void reloadNonHistoricalState();
 
     void collectNoteOpCallsForValidation(String stackTrace, int op, String packageName, long version);
+
+    SyncNotedAppOp noteProxyOperationWithState(int code,
+                in AttributionSourceState attributionSourceStateState,
+                boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
+                boolean skipProxyOperation);
+    SyncNotedAppOp startProxyOperationWithState(IBinder clientId, int code,
+                in AttributionSourceState attributionSourceStateState, boolean startIfModeDefault,
+                boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
+                boolean skipProxyOperation, int proxyAttributionFlags, int proxiedAttributionFlags,
+                int attributionChainId);
+    void finishProxyOperationWithState(IBinder clientId, int code,
+                in AttributionSourceState attributionSourceStateState, boolean skipProxyOperation);
 }
diff --git a/core/jni/android_view_VelocityTracker.cpp b/core/jni/android_view_VelocityTracker.cpp
index 03e9a6a9d139ec817170ad9f6ce77f8dad5b7aad..1b24efa163db2ab4d6ab988c6f666cad9a36a925 100644
--- a/core/jni/android_view_VelocityTracker.cpp
+++ b/core/jni/android_view_VelocityTracker.cpp
@@ -39,7 +39,7 @@ public:
     explicit VelocityTrackerState(const VelocityTracker::Strategy strategy);
 
     void clear();
-    void addMovement(const MotionEvent* event);
+    void addMovement(const MotionEvent& event);
     // TODO(b/32830165): consider supporting an overload that supports computing velocity only for
     // a subset of the supported axes.
     void computeCurrentVelocity(int32_t units, float maxVelocity);
@@ -57,7 +57,7 @@ void VelocityTrackerState::clear() {
     mVelocityTracker.clear();
 }
 
-void VelocityTrackerState::addMovement(const MotionEvent* event) {
+void VelocityTrackerState::addMovement(const MotionEvent& event) {
     mVelocityTracker.addMovement(event);
 }
 
@@ -102,13 +102,13 @@ static void android_view_VelocityTracker_nativeClear(JNIEnv* env, jclass clazz,
 static void android_view_VelocityTracker_nativeAddMovement(JNIEnv* env, jclass clazz, jlong ptr,
         jobject eventObj) {
     const MotionEvent* event = android_view_MotionEvent_getNativePtr(env, eventObj);
-    if (!event) {
+    if (event == nullptr) {
         LOG(WARNING) << "nativeAddMovement failed because MotionEvent was finalized.";
         return;
     }
 
     VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
-    state->addMovement(event);
+    state->addMovement(*event);
 }
 
 static void android_view_VelocityTracker_nativeComputeCurrentVelocity(JNIEnv* env, jclass clazz,
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index 516293b6fa2e30cd2aecd74639dc87562e1bad26..052b0c2078d1c8d8050de6f4553f2410c3fc7f9d 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -2680,8 +2680,17 @@ public class AppOpsService extends IAppOpsService.Stub {
                 .filterAppAccess(packageName, callingUid, userId);
     }
 
+    /** @deprecated Use {@link #noteProxyOperationWithState} instead. */
     @Override
     public SyncNotedAppOp noteProxyOperation(int code,
+            AttributionSource attributionSource, boolean shouldCollectAsyncNotedOp,
+            String message, boolean shouldCollectMessage, boolean skipProxyOperation) {
+        return mCheckOpsDelegateDispatcher.noteProxyOperation(code, attributionSource,
+                shouldCollectAsyncNotedOp, message, shouldCollectMessage, skipProxyOperation);
+    }
+
+    @Override
+    public SyncNotedAppOp noteProxyOperationWithState(int code,
             AttributionSourceState attributionSourceState, boolean shouldCollectAsyncNotedOp,
             String message, boolean shouldCollectMessage, boolean skipProxyOperation) {
         AttributionSource attributionSource = new AttributionSource(attributionSourceState);
@@ -3212,8 +3221,21 @@ public class AppOpsService extends IAppOpsService.Stub {
                 attributionChainId);
     }
 
+    /** @deprecated Use {@link #startProxyOperationWithState} instead. */
     @Override
     public SyncNotedAppOp startProxyOperation(@NonNull IBinder clientId, int code,
+            @NonNull AttributionSource attributionSource, boolean startIfModeDefault,
+            boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
+            boolean skipProxyOperation, @AttributionFlags int proxyAttributionFlags,
+            @AttributionFlags int proxiedAttributionFlags, int attributionChainId) {
+        return mCheckOpsDelegateDispatcher.startProxyOperation(clientId, code, attributionSource,
+                startIfModeDefault, shouldCollectAsyncNotedOp, message, shouldCollectMessage,
+                skipProxyOperation, proxyAttributionFlags, proxiedAttributionFlags,
+                attributionChainId);
+    }
+
+    @Override
+    public SyncNotedAppOp startProxyOperationWithState(@NonNull IBinder clientId, int code,
             @NonNull AttributionSourceState attributionSourceState, boolean startIfModeDefault,
             boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
             boolean skipProxyOperation, @AttributionFlags int proxyAttributionFlags,
@@ -3513,8 +3535,16 @@ public class AppOpsService extends IAppOpsService.Stub {
         finishOperationUnchecked(clientId, code, uid, resolvedPackageName, attributionTag);
     }
 
+    /** @deprecated Use {@link #finishProxyOperationWithState} instead. */
     @Override
     public void finishProxyOperation(@NonNull IBinder clientId, int code,
+            @NonNull AttributionSource attributionSource, boolean skipProxyOperation) {
+        mCheckOpsDelegateDispatcher.finishProxyOperation(clientId, code, attributionSource,
+                skipProxyOperation);
+    }
+
+    @Override
+    public void finishProxyOperationWithState(@NonNull IBinder clientId, int code,
             @NonNull AttributionSourceState attributionSourceState, boolean skipProxyOperation) {
         AttributionSource attributionSource = new AttributionSource(attributionSourceState);
         mCheckOpsDelegateDispatcher.finishProxyOperation(clientId, code, attributionSource,