Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d949809 authored by Atneya Nair's avatar Atneya Nair
Browse files

Fix onOpChanged null package regression

Fix an issue in Id0857e2aa1eb9906478135bffe483191b1452674 where we no
longer pass a null packageName to onOpChanged(String, String) in the
case of global restrictions.

That change was not backwards compatible because Java AIDL backend
permits nulls across non-null interfaces (for backwards compat), and
there is no client-side checking. So, despite annotations, nulls were
actually propagating to callers of the API, who could rely on it to
listen for global restriction changes for an op.

Fix this on the client-side by re-translating an empty package name
(which is the new service behavior) to null specifically for the legacy
param method, since the new, multi-param is explicitly marked non-null.
Update the docs for that method as well.

Bug: 434993506
Flag: EXEMPT bugfix, requires soak/backport
Test: manual logging in SystemAppOpsHelper
Change-Id: I6a6a696490993c077b7a86dfdd031a072e7460a2
parent 1a81a01d
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -7925,6 +7925,17 @@ public class AppOpsManager {
         * @hide
         */
        default void onOpChanged(@NonNull String op, @NonNull String packageName,  int userId) {
            // Backwards compat handling for the original {@link onOpChanged(String, String)}
            // interface, which wasn't documented non-null. In 25Q2, we changed the
            // service side implementation to pass empty strings to fix issues with
            // dropped updates for native callers due to the AIDL interface being
            // non-null. However, Java callers could still rely on the original,
            // Java-specific nullity behavior, where a change with a null package name
            // would be dispatched in the case of a global op state update (such as a
            // restriction).
            if ("".equals(packageName)) {
                packageName = null;
            }
            onOpChanged(op, packageName);
        }

@@ -7940,7 +7951,9 @@ public class AppOpsManager {
         * automatically.
         *
         * @param op The Op that changed.
         * @param packageName Package of the app whose Op changed.
         * @param packageName Package of the app whose Op changed. Can be empty in the case of a
         * change which is not package specific (such as global restrictions) which may imply
         * a change to the op or package being listened to.
         * @param userId User id of the app whose Op changed.
         * @param persistentDeviceId persistent device id whose Op changed.
         */