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

Commit 3b3d4148 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Add an overload of IntentFilter#countActions() to avoid NPE.

Since IntentFilter.mActions could be null, calling countActions()
could result in a NPE. Add an overload of that method that takes
into account the fact that mActions could be null.

Bug: 336385821
Test: manual
Flag: com.android.server.am.trace_receiver_registration
Change-Id: I73c4238f037f1a6931a610cc5d207f30a59392ba
parent 1baf5540
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -822,6 +822,16 @@ public class IntentFilter implements Parcelable {
        return mActions.size();
    }

    /**
     * Returns the number of actions in the filter, or {@code 0} if there are no actions.
     * <p> This method provides a safe alternative to {@link #countActions()}, which
     * may throw an exception if there are no actions.
     * @hide
     */
    public final int safeCountActions() {
        return mActions == null ? 0 : mActions.size();
    }

    /**
     * Return an action in the filter.
     */
+1 −1
Original line number Diff line number Diff line
@@ -14677,7 +14677,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            final StringBuilder sb = new StringBuilder("registerReceiver: ");
            sb.append(Binder.getCallingUid()); sb.append('/');
            sb.append(receiverId == null ? "null" : receiverId); sb.append('/');
            final int actionsCount = filter.countActions();
            final int actionsCount = filter.safeCountActions();
            if (actionsCount > 0) {
                for (int i = 0; i < actionsCount; ++i) {
                    sb.append(filter.getAction(i));