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

Commit ee44c3b6 authored by Haofan Wang's avatar Haofan Wang Committed by Android (Google) Code Review
Browse files

Merge "[MQ] Should return when the APK don't have permission for sound APIs" into main

parents cbd4919a a77e74d0
Loading
Loading
Loading
Loading
+57 −1
Original line number Diff line number Diff line
@@ -727,9 +727,23 @@ public class MediaQualityService extends SystemService {
        @GuardedBy("mPictureProfileLock")
        @Override
        public long getPictureProfileHandleValue(String id, int userId) {
            if (DEBUG) {
                Slog.d(TAG, "getPictureProfileHandleValue with id = " + id);
            }
            synchronized (mPictureProfileLock) {
                Long value = mPictureProfileTempIdMap.getKey(id);
                if (DEBUG) {
                    Collection<String> values = mPictureProfileTempIdMap.getValues();
                    for (String val: values) {
                        Slog.d(TAG, "key: " + mPictureProfileTempIdMap.getKey(val)
                                + " value: " + val);
                    }
                }
                if (value != null) {
                    if (DEBUG) {
                        Slog.d(TAG, "the value from the mPictureProfileTempIdMap is: "
                                + value);
                    }
                    mPictureProfileForHal.add(value);
                    mHalNotifier.notifyHalOnPictureProfileChange(value, null);
                }
@@ -740,11 +754,19 @@ public class MediaQualityService extends SystemService {
        @GuardedBy("mPictureProfileLock")
        @Override
        public long getDefaultPictureProfileHandleValue(int userId) {
            if (DEBUG) {
                Slog.d(TAG, "getDefaultPictureProfileHandleValue");
            }
            int callingUid = Binder.getCallingUid();
            synchronized (mPictureProfileLock) {
                String packageName = getPackageOfUid(callingUid);

                Long value = null;
                if (packageName != null) {
                    if (DEBUG) {
                        Slog.d(TAG, "getDefaultPictureProfileHandleValue: "
                                + "the package name is " + packageName);
                    }
                    value = mPackageDefaultPictureProfileHandleMap.get(packageName);

                    if (value == null) {
@@ -753,15 +775,22 @@ public class MediaQualityService extends SystemService {
                        if (defaultPictureProfileId != -1) {
                          Log.v(TAG,
                                  "Default picture profile handle value for " + packageName
                                  + " not found. Fallback to return global default.");
                                  + " not found. Fallback to return global default: "
                                          + defaultPictureProfileId);
                          value = defaultPictureProfileId;
                        }
                    }

                    if (value != null) {
                        if (DEBUG) {
                            Slog.d(TAG, "the value got from the map is " + value);
                        }
                        mPictureProfileForHal.add(value);
                        mHalNotifier.notifyHalOnPictureProfileChange(value, null);
                    }
                } else {
                    Slog.e(TAG, "The packageName of callingUid: " + callingUid + " is null");
                    return -1;
                }
                return value != null ? value : -1;
            }
@@ -770,8 +799,15 @@ public class MediaQualityService extends SystemService {
        @GuardedBy("mPictureProfileLock")
        @Override
        public void notifyPictureProfileHandleSelection(long handle, int userId) {
            if (DEBUG) {
                Slog.d(TAG, "notifyPictureProfileHandleSelection with handle " + handle);
            }
            PictureProfile profile = mMqDatabaseUtils.getPictureProfile(handle, true);
            if (profile != null) {
                if (DEBUG) {
                    Slog.d(TAG, "the picture profile got from this handle is "
                            + profile.getName());
                }
                mPictureProfileForHal.add(handle);
                mHalNotifier.notifyHalOnPictureProfileChange(handle, profile.getParameters());
            }
@@ -994,6 +1030,7 @@ public class MediaQualityService extends SystemService {
                                id, SoundProfile.ERROR_NO_PERMISSION, callingUid, callingPid);
                        Slog.e(TAG, "removeSoundProfile: "
                                + "no permission to remove sound profile");
                        return;
                    }
                    if (dbId != null) {
                        SQLiteDatabase db = mMediaQualityDbHelper.getWritableDatabase();
@@ -1083,6 +1120,7 @@ public class MediaQualityService extends SystemService {
                        null, SoundProfile.ERROR_NO_PERMISSION, uid, pid);
                Slog.e(TAG, "getSoundProfilesByPackage: no permission to get sound profile "
                        + "by package");
                return new ArrayList<>();
            }

            synchronized (mSoundProfileLock) {
@@ -1124,6 +1162,7 @@ public class MediaQualityService extends SystemService {
                        profileId, SoundProfile.ERROR_NO_PERMISSION, callingUid, callingPid);
                Slog.e(TAG, "setDefaultSoundProfile: "
                        + "no permission to set default sound profile");
                return false;
            }

            Long longId = mSoundProfileTempIdMap.getKey(profileId);
@@ -1169,6 +1208,7 @@ public class MediaQualityService extends SystemService {
                mMqManagerNotifier.notifyOnSoundProfileError(
                        null, SoundProfile.ERROR_NO_PERMISSION, callingUid, callingPid);
                Slog.e(TAG, "no permission to get sound profile package names");
                return new ArrayList<>();
            }
            String [] column = {BaseParameters.PARAMETER_NAME};

@@ -1641,6 +1681,9 @@ public class MediaQualityService extends SystemService {
                if (!hasGlobalSoundQualityServicePermission(callingUid, callingPid)) {
                    mMqManagerNotifier.notifyOnSoundProfileError(
                            null, SoundProfile.ERROR_NO_PERMISSION, callingUid, callingPid);
                    Slog.e(TAG, "setAutoSoundQualityEnabled: "
                            + "no permission to set auto sound quality enabled");
                    return;
                }

                synchronized (mSoundProfileLock) {
@@ -2853,8 +2896,21 @@ public class MediaQualityService extends SystemService {
    }

    private void putCurrentPictureProfile(Long originalHandle, Long currentHandle) {
        if (DEBUG) {
            Slog.d(TAG, "putCurrentPictureProfile: put originalHandle: " + originalHandle
                    + " currentHandle: " + currentHandle + " into mOriginalToCurrent " + " remove "
                    + "originalHandle from mCurrentPictureHandleToOriginal and put "
                    + "current and original handle in mCurrentPictureHandleToOriginal");
        }
        mOriginalToCurrent.put(originalHandle, currentHandle);
        mCurrentPictureHandleToOriginal.removeValue(originalHandle);
        mCurrentPictureHandleToOriginal.put(currentHandle, originalHandle);
        if (DEBUG) {
            Collection<Long> values = mCurrentPictureHandleToOriginal.getValues();
            for (Long value: values) {
                Slog.d(TAG, "putCurrentPictureProfile: key: "
                        + mCurrentPictureHandleToOriginal.getKey(value) + " value: " + value);
            }
        }
    }
}