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

Commit de64f012 authored by Preethi Kandhalu's avatar Preethi Kandhalu
Browse files

[MediaQuality] Add Picture Profile, Ambient Backlight and Sound Profile Lock

Test: m
Fix: 388542145
Fix: 388542560
Flag: android.media.tv.flags.media_quality_fw

Change-Id: I9e96b6462e89a1f3963f414de34746f63e105f78
parent 582a607e
Loading
Loading
Loading
Loading
+286 −196
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;

import com.android.internal.annotations.GuardedBy;
import com.android.server.SystemService;
import com.android.server.utils.Slogf;

@@ -122,6 +123,13 @@ public class MediaQualityService extends SystemService {
    private SharedPreferences mPictureProfileSharedPreference;
    private SharedPreferences mSoundProfileSharedPreference;

    // A global lock for picture profile objects.
    private final Object mPictureProfileLock = new Object();
    // A global lock for sound profile objects.
    private final Object mSoundProfileLock = new Object();
    // A global lock for ambient backlight objects.
    private final Object mAmbientBacklightLock = new Object();

    public MediaQualityService(Context context) {
        super(context);
        mContext = context;
@@ -254,6 +262,7 @@ public class MediaQualityService extends SystemService {
    // TODO: Add additional APIs. b/373951081
    private final class BinderService extends IMediaQualityManager.Stub {

        @GuardedBy("mPictureProfileLock")
        @Override
        public PictureProfile createPictureProfile(PictureProfile pp, UserHandle user) {
            if ((pp.getPackageName() != null && !pp.getPackageName().isEmpty()
@@ -263,6 +272,7 @@ public class MediaQualityService extends SystemService {
                        Binder.getCallingUid(), Binder.getCallingPid());
            }

            synchronized (mPictureProfileLock) {
                SQLiteDatabase db = mMediaQualityDbHelper.getWritableDatabase();

                ContentValues values = getContentValues(null,
@@ -279,9 +289,11 @@ public class MediaQualityService extends SystemService {
                populateTempIdMap(mPictureProfileTempIdMap, id);
                String value = mPictureProfileTempIdMap.getValue(id);
                pp.setProfileId(value);
            notifyOnPictureProfileAdded(value, pp, Binder.getCallingUid(), Binder.getCallingPid());
                notifyOnPictureProfileAdded(value, pp, Binder.getCallingUid(),
                        Binder.getCallingPid());
                return pp;
            }
        }

        private void notifyHalOnPictureProfileChange(Long dbId, PersistableBundle params) {
            // TODO: only notify HAL when the profile is active / being used
@@ -307,6 +319,7 @@ public class MediaQualityService extends SystemService {
            return toReturn;
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public void updatePictureProfile(String id, PictureProfile pp, UserHandle user) {
            Long dbId = mPictureProfileTempIdMap.getKey(id);
@@ -315,6 +328,7 @@ public class MediaQualityService extends SystemService {
                        Binder.getCallingUid(), Binder.getCallingPid());
            }

            synchronized (mPictureProfileLock) {
                ContentValues values = getContentValues(dbId,
                        pp.getProfileType(),
                        pp.getName(),
@@ -329,6 +343,7 @@ public class MediaQualityService extends SystemService {
                    getPictureProfile(dbId), Binder.getCallingUid(), Binder.getCallingPid());
            notifyHalOnPictureProfileChange(dbId, pp.getParameters());
            }
        }

        private boolean hasPermissionToUpdatePictureProfile(Long dbId, PictureProfile toUpdate) {
            PictureProfile fromDb = getPictureProfile(dbId);
@@ -338,8 +353,10 @@ public class MediaQualityService extends SystemService {
                    && fromDb.getName().equals(getPackageOfCallingUid());
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public void removePictureProfile(String id, UserHandle user) {
            synchronized (mPictureProfileLock) {
                Long dbId = mPictureProfileTempIdMap.getKey(id);

                PictureProfile toDelete = getPictureProfile(dbId);
@@ -352,8 +369,8 @@ public class MediaQualityService extends SystemService {
                    SQLiteDatabase db = mMediaQualityDbHelper.getWritableDatabase();
                    String selection = BaseParameters.PARAMETER_ID + " = ?";
                    String[] selectionArgs = {Long.toString(dbId)};
                int result = db.delete(mMediaQualityDbHelper.PICTURE_QUALITY_TABLE_NAME, selection,
                        selectionArgs);
                    int result = db.delete(mMediaQualityDbHelper.PICTURE_QUALITY_TABLE_NAME,
                            selection, selectionArgs);
                    if (result == 0) {
                        notifyOnPictureProfileError(id, PictureProfile.ERROR_INVALID_ARGUMENT,
                                Binder.getCallingUid(), Binder.getCallingPid());
@@ -364,6 +381,7 @@ public class MediaQualityService extends SystemService {
                    notifyHalOnPictureProfileChange(dbId, null);
                }
            }
        }

        private boolean hasPermissionToRemovePictureProfile(PictureProfile toDelete) {
            if (toDelete != null) {
@@ -372,6 +390,7 @@ public class MediaQualityService extends SystemService {
            return false;
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public PictureProfile getPictureProfile(int type, String name, Bundle options,
                UserHandle user) {
@@ -382,18 +401,21 @@ public class MediaQualityService extends SystemService {
                    + BaseParameters.PARAMETER_PACKAGE + " = ?";
            String[] selectionArguments = {Integer.toString(type), name, getPackageOfCallingUid()};

            synchronized (mPictureProfileLock) {
                try (
                        Cursor cursor = getCursorAfterQuerying(
                                mMediaQualityDbHelper.PICTURE_QUALITY_TABLE_NAME,
                            getMediaProfileColumns(includeParams), selection, selectionArguments)
                                getMediaProfileColumns(includeParams), selection,
                                selectionArguments)
                ) {
                    int count = cursor.getCount();
                    if (count == 0) {
                        return null;
                    }
                    if (count > 1) {
                    Log.wtf(TAG, String.format(Locale.US, "%d entries found for type=%d and name=%s"
                                    + " in %s. Should only ever be 0 or 1.", count, type, name,
                        Log.wtf(TAG, TextUtils.formatSimple(String.valueOf(Locale.US), "%d "
                                        + "entries found for type=%d and name=%s in %s. Should"
                                        + " only ever be 0 or 1.", count, type, name,
                                mMediaQualityDbHelper.PICTURE_QUALITY_TABLE_NAME));
                        return null;
                    }
@@ -401,6 +423,7 @@ public class MediaQualityService extends SystemService {
                    return convertCursorToPictureProfileWithTempId(cursor);
                }
            }
        }

        private PictureProfile getPictureProfile(Long dbId) {
            String selection = BaseParameters.PARAMETER_ID + " = ?";
@@ -416,9 +439,9 @@ public class MediaQualityService extends SystemService {
                    return null;
                }
                if (count > 1) {
                    Log.wtf(TAG, String.format(Locale.US, "%d entries found for id=%d"
                                    + " in %s. Should only ever be 0 or 1.", count, dbId,
                            mMediaQualityDbHelper.PICTURE_QUALITY_TABLE_NAME));
                    Log.wtf(TAG, TextUtils.formatSimple(String.valueOf(Locale.US), "%d entries "
                                    + "found for id=%d in %s. Should only ever be 0 or 1.",
                            count, dbId, mMediaQualityDbHelper.PICTURE_QUALITY_TABLE_NAME));
                    return null;
                }
                cursor.moveToFirst();
@@ -426,6 +449,7 @@ public class MediaQualityService extends SystemService {
            }
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public List<PictureProfile> getPictureProfilesByPackage(
                String packageName, Bundle options, UserHandle user) {
@@ -434,6 +458,7 @@ public class MediaQualityService extends SystemService {
                        Binder.getCallingUid(), Binder.getCallingPid());
            }

            synchronized (mPictureProfileLock) {
                boolean includeParams =
                        options.getBoolean(MediaQualityManager.OPTION_INCLUDE_PARAMETERS, false);
                String selection = BaseParameters.PARAMETER_PACKAGE + " = ?";
@@ -441,7 +466,9 @@ public class MediaQualityService extends SystemService {
                return getPictureProfilesBasedOnConditions(getMediaProfileColumns(includeParams),
                        selection, selectionArguments);
            }
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public List<PictureProfile> getAvailablePictureProfiles(Bundle options, UserHandle user) {
            String packageName = getPackageOfCallingUid();
@@ -451,6 +478,7 @@ public class MediaQualityService extends SystemService {
            return new ArrayList<>();
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public boolean setDefaultPictureProfile(String profileId, UserHandle user) {
            if (!hasGlobalPictureQualityServicePermission()) {
@@ -810,6 +838,7 @@ public class MediaQualityService extends SystemService {
            return  (PictureParameter[]) pictureParams.toArray();
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public List<String> getPictureProfilePackageNames(UserHandle user) {
            if (!hasGlobalPictureQualityServicePermission()) {
@@ -817,6 +846,7 @@ public class MediaQualityService extends SystemService {
                        Binder.getCallingUid(), Binder.getCallingPid());
            }
            String [] column = {BaseParameters.PARAMETER_PACKAGE};
            synchronized (mPictureProfileLock) {
                List<PictureProfile> pictureProfiles = getPictureProfilesBasedOnConditions(column,
                        null, null);
                return pictureProfiles.stream()
@@ -824,10 +854,13 @@ public class MediaQualityService extends SystemService {
                        .distinct()
                        .collect(Collectors.toList());
            }
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public List<PictureProfileHandle> getPictureProfileHandle(String[] ids, UserHandle user) {
            List<PictureProfileHandle> toReturn = new ArrayList<>();
            synchronized (mPictureProfileLock) {
                for (String id : ids) {
                    Long key = mPictureProfileTempIdMap.getKey(id);
                    if (key != null) {
@@ -836,12 +869,15 @@ public class MediaQualityService extends SystemService {
                        toReturn.add(null);
                    }
                }
            }
            return toReturn;
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public List<SoundProfileHandle> getSoundProfileHandle(String[] ids, UserHandle user) {
            List<SoundProfileHandle> toReturn = new ArrayList<>();
            synchronized (mSoundProfileLock) {
                for (String id : ids) {
                    Long key = mSoundProfileTempIdMap.getKey(id);
                    if (key != null) {
@@ -850,9 +886,11 @@ public class MediaQualityService extends SystemService {
                        toReturn.add(null);
                    }
                }
            }
            return toReturn;
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public SoundProfile createSoundProfile(SoundProfile sp, UserHandle user) {
            if ((sp.getPackageName() != null && !sp.getPackageName().isEmpty()
@@ -861,6 +899,8 @@ public class MediaQualityService extends SystemService {
                notifyOnSoundProfileError(null, SoundProfile.ERROR_NO_PERMISSION,
                        Binder.getCallingUid(), Binder.getCallingPid());
            }

            synchronized (mSoundProfileLock) {
                SQLiteDatabase db = mMediaQualityDbHelper.getWritableDatabase();

                ContentValues values = getContentValues(null,
@@ -877,9 +917,11 @@ public class MediaQualityService extends SystemService {
                populateTempIdMap(mSoundProfileTempIdMap, id);
                String value = mSoundProfileTempIdMap.getValue(id);
                sp.setProfileId(value);
            notifyOnSoundProfileAdded(value, sp, Binder.getCallingUid(), Binder.getCallingPid());
                notifyOnSoundProfileAdded(value, sp, Binder.getCallingUid(),
                        Binder.getCallingPid());
                return sp;
            }
        }

        private void notifyHalOnSoundProfileChange(Long dbId, PersistableBundle params) {
            // TODO: only notify HAL when the profile is active / being used
@@ -903,6 +945,7 @@ public class MediaQualityService extends SystemService {
            return toReturn;
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public void updateSoundProfile(String id, SoundProfile sp, UserHandle user) {
            Long dbId = mSoundProfileTempIdMap.getKey(id);
@@ -911,6 +954,7 @@ public class MediaQualityService extends SystemService {
                        Binder.getCallingUid(), Binder.getCallingPid());
            }

            synchronized (mSoundProfileLock) {
                ContentValues values = getContentValues(dbId,
                        sp.getProfileType(),
                        sp.getName(),
@@ -924,6 +968,7 @@ public class MediaQualityService extends SystemService {
                    getSoundProfile(dbId), Binder.getCallingUid(), Binder.getCallingPid());
            notifyHalOnSoundProfileChange(dbId, sp.getParameters());
            }
        }

        private boolean hasPermissionToUpdateSoundProfile(Long dbId, SoundProfile sp) {
            SoundProfile fromDb = getSoundProfile(dbId);
@@ -933,20 +978,22 @@ public class MediaQualityService extends SystemService {
                    && fromDb.getName().equals(getPackageOfCallingUid());
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public void removeSoundProfile(String id, UserHandle user) {
            synchronized (mSoundProfileLock) {
                Long dbId = mSoundProfileTempIdMap.getKey(id);
                SoundProfile toDelete = getSoundProfile(dbId);
                if (!hasPermissionToRemoveSoundProfile(toDelete)) {
                    notifyOnSoundProfileError(id, SoundProfile.ERROR_NO_PERMISSION,
                            Binder.getCallingUid(), Binder.getCallingPid());
                }

                if (dbId != null) {
                    SQLiteDatabase db = mMediaQualityDbHelper.getWritableDatabase();
                    String selection = BaseParameters.PARAMETER_ID + " = ?";
                    String[] selectionArgs = {Long.toString(dbId)};
                int result = db.delete(mMediaQualityDbHelper.SOUND_QUALITY_TABLE_NAME, selection,
                    int result = db.delete(mMediaQualityDbHelper.SOUND_QUALITY_TABLE_NAME,
                            selection,
                            selectionArgs);
                    if (result == 0) {
                        notifyOnSoundProfileError(id, SoundProfile.ERROR_INVALID_ARGUMENT,
@@ -958,6 +1005,7 @@ public class MediaQualityService extends SystemService {
                    notifyHalOnSoundProfileChange(dbId, null);
                }
            }
        }

        private boolean hasPermissionToRemoveSoundProfile(SoundProfile toDelete) {
            if (toDelete != null) {
@@ -966,6 +1014,7 @@ public class MediaQualityService extends SystemService {
            return false;
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public SoundProfile getSoundProfile(int type, String name, Bundle options,
                UserHandle user) {
@@ -976,18 +1025,21 @@ public class MediaQualityService extends SystemService {
                    + BaseParameters.PARAMETER_PACKAGE + " = ?";
            String[] selectionArguments = {String.valueOf(type), name, getPackageOfCallingUid()};

            synchronized (mSoundProfileLock) {
                try (
                        Cursor cursor = getCursorAfterQuerying(
                                mMediaQualityDbHelper.SOUND_QUALITY_TABLE_NAME,
                            getMediaProfileColumns(includeParams), selection, selectionArguments)
                                getMediaProfileColumns(includeParams), selection,
                                selectionArguments)
                ) {
                    int count = cursor.getCount();
                    if (count == 0) {
                        return null;
                    }
                    if (count > 1) {
                    Log.wtf(TAG, String.format(Locale.US, "%d entries found for name=%s"
                                    + " in %s. Should only ever be 0 or 1.", count, name,
                        Log.wtf(TAG, TextUtils.formatSimple(String.valueOf(Locale.US), "%d "
                                        + "entries found for name=%s in %s. Should only ever "
                                        + "be 0 or 1.", String.valueOf(count), name,
                                mMediaQualityDbHelper.SOUND_QUALITY_TABLE_NAME));
                        return null;
                    }
@@ -995,6 +1047,7 @@ public class MediaQualityService extends SystemService {
                    return convertCursorToSoundProfileWithTempId(cursor);
                }
            }
        }

        private SoundProfile getSoundProfile(Long dbId) {
            String selection = BaseParameters.PARAMETER_ID + " = ?";
@@ -1010,9 +1063,9 @@ public class MediaQualityService extends SystemService {
                    return null;
                }
                if (count > 1) {
                    Log.wtf(TAG, String.format(Locale.US, "%d entries found for id=%s "
                                    + "in %s. Should only ever be 0 or 1.", count, dbId,
                            mMediaQualityDbHelper.SOUND_QUALITY_TABLE_NAME));
                    Log.wtf(TAG, TextUtils.formatSimple(String.valueOf(Locale.US), "%d entries "
                                    + "found for id=%s in %s. Should only ever be 0 or 1.", count,
                            dbId, mMediaQualityDbHelper.SOUND_QUALITY_TABLE_NAME));
                    return null;
                }
                cursor.moveToFirst();
@@ -1020,6 +1073,7 @@ public class MediaQualityService extends SystemService {
            }
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public List<SoundProfile> getSoundProfilesByPackage(
                String packageName, Bundle options, UserHandle user) {
@@ -1028,6 +1082,7 @@ public class MediaQualityService extends SystemService {
                        Binder.getCallingUid(), Binder.getCallingPid());
            }

            synchronized (mSoundProfileLock) {
                boolean includeParams =
                        options.getBoolean(MediaQualityManager.OPTION_INCLUDE_PARAMETERS, false);
                String selection = BaseParameters.PARAMETER_PACKAGE + " = ?";
@@ -1035,7 +1090,9 @@ public class MediaQualityService extends SystemService {
                return getSoundProfilesBasedOnConditions(getMediaProfileColumns(includeParams),
                        selection, selectionArguments);
            }
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public List<SoundProfile> getAvailableSoundProfiles(Bundle options, UserHandle user) {
            String packageName = getPackageOfCallingUid();
@@ -1045,6 +1102,7 @@ public class MediaQualityService extends SystemService {
            return new ArrayList<>();
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public boolean setDefaultSoundProfile(String profileId, UserHandle user) {
            if (!hasGlobalSoundQualityServicePermission()) {
@@ -1161,6 +1219,7 @@ public class MediaQualityService extends SystemService {
            return  (SoundParameter[]) soundParams.toArray();
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public List<String> getSoundProfilePackageNames(UserHandle user) {
            if (!hasGlobalSoundQualityServicePermission()) {
@@ -1168,6 +1227,8 @@ public class MediaQualityService extends SystemService {
                        Binder.getCallingUid(), Binder.getCallingPid());
            }
            String [] column = {BaseParameters.PARAMETER_NAME};

            synchronized (mSoundProfileLock) {
                List<SoundProfile> soundProfiles = getSoundProfilesBasedOnConditions(column,
                        null, null);
                return soundProfiles.stream()
@@ -1175,6 +1236,7 @@ public class MediaQualityService extends SystemService {
                        .distinct()
                        .collect(Collectors.toList());
            }
        }

        private String getPackageOfCallingUid() {
            String[] packageNames = mPackageManager.getPackagesForUid(
@@ -1539,6 +1601,7 @@ public class MediaQualityService extends SystemService {
            userState.mSoundProfileCallbacks.finishBroadcast();
        }

        //TODO: need lock here?
        @Override
        public void registerPictureProfileCallback(final IPictureProfileCallback callback) {
            int callingPid = Binder.getCallingPid();
@@ -1549,6 +1612,7 @@ public class MediaQualityService extends SystemService {
                    Pair.create(callingPid, callingUid));
        }

        //TODO: need lock here?
        @Override
        public void registerSoundProfileCallback(final ISoundProfileCallback callback) {
            int callingPid = Binder.getCallingPid();
@@ -1586,6 +1650,7 @@ public class MediaQualityService extends SystemService {
            }
        }

        @GuardedBy("mAmbientBacklightLock")
        @Override
        public void setAmbientBacklightSettings(
                AmbientBacklightSettings settings, UserHandle user) {
@@ -1624,6 +1689,7 @@ public class MediaQualityService extends SystemService {
            }
        }

        @GuardedBy("mAmbientBacklightLock")
        @Override
        public void setAmbientBacklightEnabled(boolean enabled, UserHandle user) {
            if (DEBUG) {
@@ -1643,12 +1709,14 @@ public class MediaQualityService extends SystemService {
            }
        }

        //TODO: do I need a lock here?
        @Override
        public List<ParameterCapability> getParameterCapabilities(
                List<String> names, UserHandle user) {
            return new ArrayList<>();
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public List<String> getPictureProfileAllowList(UserHandle user) {
            if (!hasGlobalPictureQualityServicePermission()) {
@@ -1663,6 +1731,7 @@ public class MediaQualityService extends SystemService {
            return new ArrayList<>();
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public void setPictureProfileAllowList(List<String> packages, UserHandle user) {
            if (!hasGlobalPictureQualityServicePermission()) {
@@ -1674,6 +1743,7 @@ public class MediaQualityService extends SystemService {
            editor.commit();
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public List<String> getSoundProfileAllowList(UserHandle user) {
            if (!hasGlobalSoundQualityServicePermission()) {
@@ -1688,6 +1758,7 @@ public class MediaQualityService extends SystemService {
            return new ArrayList<>();
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public void setSoundProfileAllowList(List<String> packages, UserHandle user) {
            if (!hasGlobalSoundQualityServicePermission()) {
@@ -1704,13 +1775,14 @@ public class MediaQualityService extends SystemService {
            return false;
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public void setAutoPictureQualityEnabled(boolean enabled, UserHandle user) {
            if (!hasGlobalPictureQualityServicePermission()) {
                notifyOnPictureProfileError(null, PictureProfile.ERROR_NO_PERMISSION,
                        Binder.getCallingUid(), Binder.getCallingPid());
            }

            synchronized (mPictureProfileLock) {
                try {
                    if (mMediaQuality != null) {
                        if (mMediaQuality.isAutoPqSupported()) {
@@ -1721,9 +1793,12 @@ public class MediaQualityService extends SystemService {
                    Slog.e(TAG, "Failed to set auto picture quality", e);
                }
            }
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public boolean isAutoPictureQualityEnabled(UserHandle user) {
            synchronized (mPictureProfileLock) {
                try {
                    if (mMediaQuality != null) {
                        if (mMediaQuality.isAutoPqSupported()) {
@@ -1735,14 +1810,16 @@ public class MediaQualityService extends SystemService {
                }
                return false;
            }
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public void setSuperResolutionEnabled(boolean enabled, UserHandle user) {
            if (!hasGlobalPictureQualityServicePermission()) {
                notifyOnPictureProfileError(null, PictureProfile.ERROR_NO_PERMISSION,
                        Binder.getCallingUid(), Binder.getCallingPid());
            }

            synchronized (mPictureProfileLock) {
                try {
                    if (mMediaQuality != null) {
                        if (mMediaQuality.isAutoSrSupported()) {
@@ -1753,9 +1830,12 @@ public class MediaQualityService extends SystemService {
                    Slog.e(TAG, "Failed to set super resolution", e);
                }
            }
        }

        @GuardedBy("mPictureProfileLock")
        @Override
        public boolean isSuperResolutionEnabled(UserHandle user) {
            synchronized (mPictureProfileLock) {
                try {
                    if (mMediaQuality != null) {
                        if (mMediaQuality.isAutoSrSupported()) {
@@ -1767,7 +1847,9 @@ public class MediaQualityService extends SystemService {
                }
                return false;
            }
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public void setAutoSoundQualityEnabled(boolean enabled, UserHandle user) {
            if (!hasGlobalSoundQualityServicePermission()) {
@@ -1775,6 +1857,7 @@ public class MediaQualityService extends SystemService {
                        Binder.getCallingUid(), Binder.getCallingPid());
            }

            synchronized (mSoundProfileLock) {
                try {
                    if (mMediaQuality != null) {
                        if (mMediaQuality.isAutoAqSupported()) {
@@ -1785,9 +1868,12 @@ public class MediaQualityService extends SystemService {
                    Slog.e(TAG, "Failed to set auto sound quality", e);
                }
            }
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public boolean isAutoSoundQualityEnabled(UserHandle user) {
            synchronized (mSoundProfileLock) {
                try {
                    if (mMediaQuality != null) {
                        if (mMediaQuality.isAutoAqSupported()) {
@@ -1799,7 +1885,9 @@ public class MediaQualityService extends SystemService {
                }
                return false;
            }
        }

        @GuardedBy("mAmbientBacklightLock")
        @Override
        public boolean isAmbientBacklightEnabled(UserHandle user) {
            return false;
@@ -1853,6 +1941,7 @@ public class MediaQualityService extends SystemService {
        }
    }

    //TODO: used by both picture and sound. can i add both locks?
    private UserState getOrCreateUserStateLocked(int userId) {
        UserState userState = getUserStateLocked(userId);
        if (userState == null) {
@@ -1862,6 +1951,7 @@ public class MediaQualityService extends SystemService {
        return userState;
    }

    //TODO: used by both picture and sound. can i add both locks?
    private UserState getUserStateLocked(int userId) {
        return mUserStates.get(userId);
    }