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

Commit ef4351cc authored by Eugene Susla's avatar Eugene Susla
Browse files

Dont dispatch a11y events that have no subscribers

This allows to avoid A11yManager -> A11yManagerService IPC, when there's no
subscribers to a given event

Test: steps:
  - Enable A11yManager.DEBUG
  - Navigate through a few random activities
  - In logcat, ensure log messages are present, notifying that certain events
  won't be dispatched
Change-Id: Ia019fb66053f10095b3651407d09de8e89cdd227
parent ca6d48f3
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package android.os;

import android.util.ArrayMap;

import java.util.function.Consumer;

/**
 * Takes care of the grunt work of maintaining a list of remote interfaces,
 * typically for the use of performing callbacks from a
@@ -307,6 +309,23 @@ public class RemoteCallbackList<E extends IInterface> {
        }
    }

    /**
     * Performs {@code action} on each callback, calling
     * {@link #beginBroadcast()}/{@link #finishBroadcast()} before/after looping
     *
     * @hide
     */
    public void broadcast(Consumer<E> action) {
        int itemCount = beginBroadcast();
        try {
            for (int i = 0; i < itemCount; i++) {
                action.accept(getBroadcastItem(i));
            }
        } finally {
            finishBroadcast();
        }
    }

    /**
     * Returns the number of registered callbacks. Note that the number of registered
     * callbacks may differ from the value returned by {@link #beginBroadcast()} since
+20 −2
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ import android.util.Log;
import android.view.IWindow;
import android.view.View;

import com.android.internal.util.IntPair;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -109,6 +111,8 @@ public final class AccessibilityManager {

    boolean mIsEnabled;

    int mRelevantEventTypes = AccessibilityEvent.TYPES_ALL_MASK;

    boolean mIsTouchExplorationEnabled;

    boolean mIsHighTextContrastEnabled;
@@ -203,6 +207,11 @@ public final class AccessibilityManager {
        public void notifyServicesStateChanged() {
            mHandler.obtainMessage(MyHandler.MSG_NOTIFY_SERVICES_STATE_CHANGED).sendToTarget();
        }

        @Override
        public void setRelevantEventTypes(int eventTypes) {
            mRelevantEventTypes = eventTypes;
        }
    };

    /**
@@ -362,6 +371,14 @@ public final class AccessibilityManager {
                    return;
                }
            }
            if ((event.getEventType() & mRelevantEventTypes) == 0) {
                if (DEBUG) {
                    Log.i(LOG_TAG, "Not dispatching irrelevant event: " + event
                            + " that is not among "
                            + AccessibilityEvent.eventTypeToString(mRelevantEventTypes));
                }
                return;
            }
            userId = mUserId;
        }
        try {
@@ -865,8 +882,9 @@ public final class AccessibilityManager {
        }

        try {
            final int stateFlags = service.addClient(mClient, mUserId);
            setStateLocked(stateFlags);
            final long userStateAndRelevantEvents = service.addClient(mClient, mUserId);
            setStateLocked(IntPair.first(userStateAndRelevantEvents));
            mRelevantEventTypes = IntPair.second(userStateAndRelevantEvents);
            mService = service;
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "AccessibilityManagerService is dead", re);
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ interface IAccessibilityManager {

    oneway void sendAccessibilityEvent(in AccessibilityEvent uiEvent, int userId);

    int addClient(IAccessibilityManagerClient client, int userId);
    long addClient(IAccessibilityManagerClient client, int userId);

    List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList(int userId);

+3 −0
Original line number Diff line number Diff line
@@ -25,5 +25,8 @@ package android.view.accessibility;
oneway interface IAccessibilityManagerClient {

    void setState(int stateFlags);

    void notifyServicesStateChanged();

    void setRelevantEventTypes(int eventTypes);
}
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.util;

/**
 * Utilities for treating a {@code long} as a pair of {@code int}s
 *
 * @hide
 */
public class IntPair {
    private IntPair() {}

    public static long of(int first, int second) {
        return (((long)first) << 32) | ((long)second & 0xffffffffL);
    }

    public static int first(long intPair) {
        return (int)(intPair >> 32);
    }

    public static int second(long intPair) {
        return (int)intPair;
    }
}
Loading