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

Commit 16c05430 authored by Haofan Wang's avatar Haofan Wang
Browse files

Fix MediaQuality bug for profile and callback handing

Fix addresses four key issues:
    1. Avoid null cases when retrieving profiles from the database to prevent update issues.
    2. Handle profile and non-profile callbacks separately when calling back to MediaQualityManager.
    3. System_UID apps no longer require MANAGE_GLOBAL_PICTURE_QUALITY_SERVICE permission, preventing MediaQualityHAL callback blockage.
    4. Use a switch-case to correctly retrieve all PictureParameter contents.

Bug: 437838660
Flag: EXEMPT BUGFIX
Test: Manual
No-Typo-Check: truSurroundX is a sound parameter
BYPASS_LARGE_CHANGE_WARNING: most lines are change from if statement to switch-case.
(cherry picked from https://tv-keystone-review.googlesource.com/q/commit:63450f8146e0a8b75f50818a5617e49ea14d8343)

Change-Id: Iea87d0b345ca79bea5b26b8398f442b72b37bc28
parent f0f7b0fc
Loading
Loading
Loading
Loading
+56 −42
Original line number Diff line number Diff line
@@ -424,6 +424,10 @@ public class MediaQualityService extends SystemService {
        private boolean hasPermissionToUpdatePictureProfile(
                Long dbId, PictureProfile toUpdate, int uid, int pid) {
            PictureProfile fromDb = mMqDatabaseUtils.getPictureProfile(dbId);
            if (fromDb == null) {
                Slog.e(TAG, "Failed to get picture profile from db");
                return false;
            }
            boolean isPackageOwner = fromDb.getPackageName().equals(getPackageOfUid(uid));
            boolean isSystemAppWithPermission =
                hasGlobalPictureQualityServicePermission(uid, pid)
@@ -1031,6 +1035,10 @@ public class MediaQualityService extends SystemService {
        private boolean hasPermissionToUpdateSoundProfile(
                Long dbId, SoundProfile toUpdate, int uid, int pid) {
            SoundProfile fromDb = mMqDatabaseUtils.getSoundProfile(dbId);
            if (fromDb == null) {
                Slog.e(TAG, "Failed to get sound profile from db");
                return false;
            }
            boolean isPackageOwner = fromDb.getPackageName().equals(getPackageOfUid(uid));
            boolean isSystemAppWithPermission = hasGlobalSoundQualityServicePermission(uid, pid)
                    && fromDb.getProfileType() == PictureProfile.TYPE_SYSTEM;
@@ -1264,7 +1272,7 @@ public class MediaQualityService extends SystemService {

        private boolean hasReadColorZonesPermission(int uid, int pid) {
            return mContext.checkPermission(android.Manifest.permission.READ_COLOR_ZONES, pid, uid)
                    == PackageManager.PERMISSION_GRANTED;
                    == PackageManager.PERMISSION_GRANTED || uid == Process.SYSTEM_UID;
        }

        @Override
@@ -1750,11 +1758,12 @@ public class MediaQualityService extends SystemService {
    public void updatePictureProfileFromHal(Long dbId, PersistableBundle bundle) {
        int callingUid = Binder.getCallingUid();
        int callingPid = Binder.getCallingPid();
        PictureProfile pp = mMqDatabaseUtils.getPictureProfile(dbId);
        ContentValues values = MediaQualityUtils.getContentValues(dbId,
                null,
                null,
                null,
                null,
                pp.getProfileType(),
                pp.getName(),
                pp.getPackageName(),
                pp.getInputId(),
                bundle);

        updateDatabaseOnPictureProfileAndNotifyManager(
@@ -1777,11 +1786,12 @@ public class MediaQualityService extends SystemService {
    public void updateSoundProfileFromHal(Long dbId, PersistableBundle bundle) {
        int callingUid = Binder.getCallingUid();
        int callingPid = Binder.getCallingPid();
        SoundProfile sp = mMqDatabaseUtils.getSoundProfile(dbId);
        ContentValues values = MediaQualityUtils.getContentValues(dbId,
                null,
                null,
                null,
                null,
                sp.getProfileType(),
                sp.getName(),
                sp.getPackageName(),
                sp.getInputId(),
                bundle);

        updateDatabaseOnSoundProfileAndNotifyManager(values, bundle, callingUid,
@@ -2046,21 +2056,25 @@ public class MediaQualityService extends SystemService {
                            .get(callback);
                    if ((pidUid.first == pid && pidUid.second == uid)
                            || (hasGlobalPictureQualityServicePermission(
                                    pidUid.second, pidUid.first)
                            && profile != null
                            && profile.getProfileType() == PictureProfile.TYPE_SYSTEM)) {
                        if (mode == ProfileModes.ADD) {
                                    pidUid.second, pidUid.first))) {
                        if (profile != null
                                && profile.getProfileType() == PictureProfile.TYPE_SYSTEM) {
                            switch (mode) {
                                case ProfileModes.ADD ->
                                        callback.onPictureProfileAdded(profileId, profile);
                        } else if (mode == ProfileModes.UPDATE) {
                                case ProfileModes.UPDATE ->
                                        callback.onPictureProfileUpdated(profileId, profile);
                        } else if (mode == ProfileModes.REMOVE) {
                                case ProfileModes.REMOVE ->
                                        callback.onPictureProfileRemoved(profileId, profile);
                        } else if (mode == ProfileModes.ERROR) {
                            callback.onError(profileId, errorCode);
                        } else if (mode == ProfileModes.PARAMETER_CAPABILITY_CHANGED) {
                            }
                        } else {
                            switch (mode) {
                                case ProfileModes.ERROR -> callback.onError(profileId, errorCode);
                                case ProfileModes.PARAMETER_CAPABILITY_CHANGED ->
                                    callback.onParameterCapabilitiesChanged(profileId, paramCaps);
                            }
                        }
                    }
                } catch (RemoteException e) {
                    if (mode == ProfileModes.ADD) {
                        Slog.e(TAG, "Failed to report added picture profile to callback", e);
@@ -2130,24 +2144,24 @@ public class MediaQualityService extends SystemService {
                            .get(callback);

                    if ((pidUid.first == pid && pidUid.second == uid)
                            || (hasGlobalSoundQualityServicePermission(pidUid.second, pidUid.first)
                                    && profile != null
                                    && profile.getProfileType() == PictureProfile.TYPE_SYSTEM)) {
                        if (mode == ProfileModes.ADD) {
                            userState.mSoundProfileCallbacks.getBroadcastItem(i)
                                    .onSoundProfileAdded(profileId, profile);
                        } else if (mode == ProfileModes.UPDATE) {
                            userState.mSoundProfileCallbacks.getBroadcastItem(i)
                                    .onSoundProfileUpdated(profileId, profile);
                        } else if (mode == ProfileModes.REMOVE) {
                            userState.mSoundProfileCallbacks.getBroadcastItem(i)
                                    .onSoundProfileRemoved(profileId, profile);
                        } else if (mode == ProfileModes.ERROR) {
                            userState.mSoundProfileCallbacks.getBroadcastItem(i)
                                    .onError(profileId, errorCode);
                        } else if (mode == ProfileModes.PARAMETER_CAPABILITY_CHANGED) {
                            userState.mSoundProfileCallbacks.getBroadcastItem(i)
                                    .onParameterCapabilitiesChanged(profileId, paramCaps);
                            || (hasGlobalSoundQualityServicePermission(
                            pidUid.second, pidUid.first))) {
                        if (profile != null
                                && profile.getProfileType() == SoundProfile.TYPE_SYSTEM) {
                            switch (mode) {
                                case ProfileModes.ADD ->
                                        callback.onSoundProfileAdded(profileId, profile);
                                case ProfileModes.UPDATE ->
                                        callback.onSoundProfileUpdated(profileId, profile);
                                case ProfileModes.REMOVE ->
                                        callback.onSoundProfileRemoved(profileId, profile);
                            }
                        } else {
                            switch (mode) {
                                case ProfileModes.ERROR -> callback.onError(profileId, errorCode);
                                case ProfileModes.PARAMETER_CAPABILITY_CHANGED ->
                                    callback.onParameterCapabilitiesChanged(profileId, paramCaps);
                            }
                        }
                    }
                } catch (RemoteException e) {
@@ -2892,13 +2906,13 @@ public class MediaQualityService extends SystemService {
        return mContext.checkPermission(
                android.Manifest.permission.MANAGE_GLOBAL_PICTURE_QUALITY_SERVICE, pid,
                uid)
                == PackageManager.PERMISSION_GRANTED;
                == PackageManager.PERMISSION_GRANTED || uid == Process.SYSTEM_UID;
    }

    private boolean hasGlobalSoundQualityServicePermission(int uid, int pid) {
        return mContext.checkPermission(
                       android.Manifest.permission.MANAGE_GLOBAL_SOUND_QUALITY_SERVICE, pid, uid)
                == PackageManager.PERMISSION_GRANTED;
                == PackageManager.PERMISSION_GRANTED || uid == Process.SYSTEM_UID;
    }

    private PictureProfile getSdrPictureProfile(String profileName, PictureProfile previous) {
+630 −366

File changed.

Preview size limit exceeded, changes collapsed.