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

Commit 8a3b1b18 authored by Zhou Song's avatar Zhou Song Committed by Gerrit - the friendly Code Review server
Browse files

Avoid duplicated calling to isRestricted to improve performance

isRestricted() is called every time in Play and setVolume API.
Then it introduces some latency here, the perfromance can be bad
especially when the APIs called multiple times.

Initialize the permission check result in constructor to avoid
calling to isRestricted.

CRs-Fixed: 812386

Change-Id: I1ce81d1723a6b29adf4117ac0ccb7a98850ef2dd
parent feba6ba3
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -522,6 +522,7 @@ public class SoundPool {
        private final Object mLock;
        private final AudioAttributes mAttributes;
        private final IAppOpsService mAppOps;
        private final boolean mIsRestricted;

        // SoundPool messages
        //
@@ -539,6 +540,7 @@ public class SoundPool {
            mAttributes = attr;
            IBinder b = ServiceManager.getService(Context.APP_OPS_SERVICE);
            mAppOps = IAppOpsService.Stub.asInterface(b);
            mIsRestricted = isRestricted();
        }

        public int load(String path, int priority)
@@ -600,7 +602,7 @@ public class SoundPool {

        public final int play(int soundID, float leftVolume, float rightVolume,
                int priority, int loop, float rate) {
            if (isRestricted()) {
            if (mIsRestricted) {
                leftVolume = rightVolume = 0;
            }
            return _play(soundID, leftVolume, rightVolume, priority, loop, rate);
@@ -631,7 +633,7 @@ public class SoundPool {
        public native final void stop(int streamID);

        public final void setVolume(int streamID, float leftVolume, float rightVolume) {
            if (isRestricted()) {
            if (mIsRestricted) {
                return;
            }
            _setVolume(streamID, leftVolume, rightVolume);