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

Commit f9a50ff6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Improve debuggability of sensor listener exhaustion" into main

parents 6cdb247c 3fc9d788
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -257,15 +257,24 @@ public class SystemSensorManager extends SensorManager {
        }
        if (mSensorListeners.size() >= MAX_LISTENER_COUNT) {
            Log.e(TAG, "Too many sensor listeners! Dump:");
            Map<String, Integer> listenerCounts = new HashMap<>();
            synchronized (mSensorListeners) {
                int i = 0;
                for (SensorEventListener debugListener : mSensorListeners.keySet()) {
                    Log.e(TAG, "  " + ++i + ": " + debugListener.toString());
                }
            }
            throw new IllegalStateException("register failed, "
                + "the sensor listeners size has exceeded the maximum limit "
                + MAX_LISTENER_COUNT);
                    String listenerName = debugListener.toString();
                    Log.e(TAG, "  " + ++i + ": " + listenerName);
                    int index = listenerName.indexOf('@');
                    listenerName = index < 0 ? listenerName
                            : listenerName.substring(0, index);
                    listenerCounts.put(
                            listenerName, listenerCounts.getOrDefault(listenerName, 0) + 1);
                }
            }
            Map.Entry<String, Integer> maxEntry = listenerCounts.entrySet().stream()
                    .max(Map.Entry.comparingByValue()).get();
            throw new IllegalStateException("Too many sensor listeners (" + MAX_LISTENER_COUNT
                    + "). Most common: " + maxEntry.getKey() + " (" + maxEntry.getValue()
                    + ")");
        }

        // Invariants to preserve: