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

Commit e0b281ef authored by Haofan Wang's avatar Haofan Wang
Browse files

Various bug fix for media quality framework

1. Delete skip condition in notifyHalOnPictureProfileChange since we
   we've already added strea status value as vendor parameter.
2. notify on picture profile update in onStreamStatusChange. So the
   application can get notified when stream status change with a
   previous stream status flag.
3. When getDefaultPictureProfile, it will return the default profile
   with the correct stream status. (with the STREAM_STATUS and
   PREVIOUS_STREAM_STATUS flag)

Bug: 414688986
Bug: 415898570
Bug: 415881260
Bug: 416160883
Flag: android.media.tv.flags.media_quality_fw
Test: m

Change-Id: Ie0363f605c2ab6ee4394f786243be2b8cc338164
parent 9f3ed9e1
Loading
Loading
Loading
Loading
+46 −34
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.Parcel;
import android.os.PersistableBundle;
import android.os.Process;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -109,6 +110,8 @@ public class MediaQualityService extends SystemService {
    private static final String SOUND_PROFILE_PREFERENCE = "sound_profile_preference";
    private static final String COMMA_DELIMITER = ",";
    private static final String DEFAULT_PICTURE_PROFILE_ID = "default_picture_profile_id";
    private static final String STREAM_STATUS = "stream_status";
    private static final String PREVIOUS_STREAM_STATUS = "previous_stream_status";
    private final Context mContext;
    private final MediaQualityDbHelper mMediaQualityDbHelper;
    private final BiMap<Long, String> mPictureProfileTempIdMap;
@@ -493,8 +496,14 @@ public class MediaQualityService extends SystemService {
                    -1
            );
            if (defaultPictureProfileId != -1) {
                PictureProfile currentDefaultPictureProfile =
                        mHandleToPictureProfile.get(defaultPictureProfileId);
                if (currentDefaultPictureProfile != null) {
                    return currentDefaultPictureProfile;
                } else {
                    return mMqDatabaseUtils.getPictureProfile(defaultPictureProfileId);
                }
            }
            return null;
        }

@@ -941,13 +950,6 @@ public class MediaQualityService extends SystemService {
            return incomingPackage.equalsIgnoreCase(getPackageOfUid(uid));
        }

        private boolean hasGlobalPictureQualityServicePermission(int uid, int pid) {
            return mContext.checkPermission(
                           android.Manifest.permission.MANAGE_GLOBAL_PICTURE_QUALITY_SERVICE, pid,
                           uid)
                    == PackageManager.PERMISSION_GRANTED;
        }

        private boolean hasGlobalSoundQualityServicePermission(int uid, int pid) {
            return mContext.checkPermission(
                           android.Manifest.permission.MANAGE_GLOBAL_SOUND_QUALITY_SERVICE, pid,
@@ -1691,30 +1693,26 @@ public class MediaQualityService extends SystemService {
                List<ParameterCapability> paramCaps, int uid, int pid) {
            UserState userState = getOrCreateUserState(UserHandle.USER_SYSTEM);
            int n = userState.mPictureProfileCallbacks.beginBroadcast();

            for (int i = 0; i < n; ++i) {
                try {
                    IPictureProfileCallback callback = userState.mPictureProfileCallbacks
                            .getBroadcastItem(i);
                    Pair<Integer, Integer> pidUid = userState.mPictureProfileCallbackPidUidMap
                            .get(callback);

                    if (pidUid.first == pid && pidUid.second == uid) {
                    if ((pidUid.first == pid && pidUid.second == uid)
                            || (hasGlobalPictureQualityServicePermission(
                                    pidUid.first, pidUid.second)
                            && profile.getProfileType() == PictureProfile.TYPE_SYSTEM)) {
                        if (mode == ProfileModes.ADD) {
                            userState.mPictureProfileCallbacks.getBroadcastItem(i)
                                    .onPictureProfileAdded(profileId, profile);
                            callback.onPictureProfileAdded(profileId, profile);
                        } else if (mode == ProfileModes.UPDATE) {
                            userState.mPictureProfileCallbacks.getBroadcastItem(i)
                                    .onPictureProfileUpdated(profileId, profile);
                            callback.onPictureProfileUpdated(profileId, profile);
                        } else if (mode == ProfileModes.REMOVE) {
                            userState.mPictureProfileCallbacks.getBroadcastItem(i)
                                    .onPictureProfileRemoved(profileId, profile);
                            callback.onPictureProfileRemoved(profileId, profile);
                        } else if (mode == ProfileModes.ERROR) {
                            userState.mPictureProfileCallbacks.getBroadcastItem(i)
                                    .onError(profileId, errorCode);
                            callback.onError(profileId, errorCode);
                        } else if (mode == ProfileModes.PARAMETER_CAPABILITY_CHANGED) {
                            userState.mPictureProfileCallbacks.getBroadcastItem(i)
                                    .onParameterCapabilitiesChanged(profileId, paramCaps);
                            callback.onParameterCapabilitiesChanged(profileId, paramCaps);
                        }
                    }
                } catch (RemoteException e) {
@@ -1726,9 +1724,9 @@ public class MediaQualityService extends SystemService {
                        Slog.e(TAG, "Failed to report removed picture profile to callback", e);
                    } else if (mode == ProfileModes.ERROR) {
                        Slog.e(TAG, "Failed to report picture profile error to callback", e);
                    } else if (mode == ProfileModes.PARAMETER_CAPABILITY_CHANGED) {
                        Slog.e(TAG, "Failed to report picture profile parameter capability change "
                                + "to callback", e);
                    } else {
                        Slog.e(TAG, "Failed to report picture profile parameter capability"
                                + " change to callback", e);
                    }
                }
            }
@@ -1830,11 +1828,6 @@ public class MediaQualityService extends SystemService {
        private void notifyHalOnPictureProfileChange(Long dbId, PersistableBundle params) {
            // TODO: only notify HAL when the profile is active / being used
            if (mPpChangedListener != null) {
                Long currentHandle = mCurrentPictureHandleToOriginal.getKey(dbId);
                if (currentHandle != null) {
                    // this handle maps to another current profile, skip
                    return;
                }
                try {
                    Long idForHal = dbId;
                    Long originalHandle = mCurrentPictureHandleToOriginal.getValue(dbId);
@@ -2053,13 +2046,19 @@ public class MediaQualityService extends SystemService {
                            return;
                        }
                        PictureProfile current = list.get(0);
                        PersistableBundle currentProfileParameters = current.getParameters();
                        currentProfileParameters.putString(STREAM_STATUS, newStatus);
                        // Add previous stream status information so that application can use this
                        // flag to indicate that there is a onStreamStatusChange.
                        currentProfileParameters.putString(PREVIOUS_STREAM_STATUS, profileStatus);
                        mHandleToPictureProfile.put(profileHandle, current);
                        mCurrentPictureHandleToOriginal.put(
                                current.getHandle().getId(), profileHandle);
                        mMqManagerNotifier.notifyOnPictureProfileUpdated(
                                current.getProfileId(), current, Process.INVALID_UID,
                                Process.INVALID_PID);

                        mPictureProfileForHal.add(profileHandle);
                        PersistableBundle currentProfileParameters = current.getParameters();
                        currentProfileParameters.putString("stream_status", newStatus);
                        mHalNotifier.notifyHalOnPictureProfileChange(profileHandle,
                                currentProfileParameters);
                    } else {
@@ -2090,14 +2089,20 @@ public class MediaQualityService extends SystemService {
                            return;
                        }
                        PictureProfile current = list.get(0);
                        PersistableBundle currentProfileParameters = current.getParameters();
                        currentProfileParameters.putString(
                                STREAM_STATUS, PictureProfile.STATUS_SDR);
                        // Add previous stream status information so that application can use this
                        // flag to indicate that there is a onStreamStatusChange.
                        currentProfileParameters.putString(PREVIOUS_STREAM_STATUS, profileStatus);
                        mHandleToPictureProfile.put(profileHandle, current);
                        mCurrentPictureHandleToOriginal.put(
                                current.getHandle().getId(), profileHandle);
                        mMqManagerNotifier.notifyOnPictureProfileUpdated(
                                current.getProfileId(), current, Process.INVALID_UID,
                                Process.INVALID_PID);

                        mPictureProfileForHal.add(profileHandle);
                        PersistableBundle currentProfileParameters = current.getParameters();
                        currentProfileParameters.putString(
                                "stream_status", PictureProfile.STATUS_SDR);
                        mHalNotifier.notifyHalOnPictureProfileChange(profileHandle,
                                currentProfileParameters);
                    }
@@ -2399,4 +2404,11 @@ public class MediaQualityService extends SystemService {
        return pp != null && pp.getProfileType() == PictureProfile.TYPE_SYSTEM &&
               pp.getName().equals(PictureProfile.NAME_DEFAULT);
    }

    private boolean hasGlobalPictureQualityServicePermission(int uid, int pid) {
        return mContext.checkPermission(
                android.Manifest.permission.MANAGE_GLOBAL_PICTURE_QUALITY_SERVICE, pid,
                uid)
                == PackageManager.PERMISSION_GRANTED;
    }
}