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

Commit db772d81 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

rework SystemSensorManager.java

- it doesn't need a dedicated thread to pull events out
- events are now sent directly to the proper looper by
  the sensorservice

this simplifies things a lot.

Change-Id: Ifa32fed3eff9007a2ee03aaaa837412cb4c15e52
parent 58395e71
Loading
Loading
Loading
Loading
+0 −52
Original line number Diff line number Diff line
@@ -1314,56 +1314,4 @@ public abstract class SensorManager {
            return mLegacySensorManager;
        }
    }

    /**
     * Sensor event pool implementation.
     * @hide
     */
    protected static final class SensorEventPool {
        private final int mPoolSize;
        private final SensorEvent mPool[];
        private int mNumItemsInPool;

        private SensorEvent createSensorEvent() {
            // maximal size for all legacy events is 3
            return new SensorEvent(3);
        }

        SensorEventPool(int poolSize) {
            mPoolSize = poolSize;
            mNumItemsInPool = poolSize;
            mPool = new SensorEvent[poolSize];
        }

        SensorEvent getFromPool() {
            SensorEvent t = null;
            synchronized (this) {
                if (mNumItemsInPool > 0) {
                    // remove the "top" item from the pool
                    final int index = mPoolSize - mNumItemsInPool;
                    t = mPool[index];
                    mPool[index] = null;
                    mNumItemsInPool--;
                }
            }
            if (t == null) {
                // the pool was empty or this item was removed from the pool for
                // the first time. In any case, we need to create a new item.
                t = createSensorEvent();
            }
            return t;
        }

        void returnToPool(SensorEvent t) {
            synchronized (this) {
                // is there space left in the pool?
                if (mNumItemsInPool < mPoolSize) {
                    // if so, return the item to the pool
                    mNumItemsInPool++;
                    final int index = mPoolSize - mNumItemsInPool;
                    mPool[index] = t;
                }
            }
        }
    }
}