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

Commit 256ba236 authored by Shubang Lu's avatar Shubang Lu
Browse files

[MQ] Set picture profile for TV input

Test: CTS
Bug: 405276566
Flag: android.media.tv.flags.media_quality_fw

Change-Id: Id04e419d9417ad9d794750853a81755f22f562f0
parent d7c15565
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -377,6 +377,18 @@ public final class MediaQualityManager {
        }
    }

    /**
     * Gets picture profile handle for TV input.
     * @hide
     */
    public long getPictureProfileForTvInput(String inputId) {
        try {
            return mService.getPictureProfileForTvInput(inputId, mUserHandle.getIdentifier());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Gets sound profile handle by profile ID.
     * @hide
+6 −3
Original line number Diff line number Diff line
@@ -73,6 +73,12 @@ public final class PictureProfile implements Parcelable {
     */
    public static final int TYPE_APPLICATION = 2;

    /**
     * Default profile name
     * @hide
     */
    public static final String NAME_DEFAULT = "default";

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @StringDef(prefix = "NAME_", value = {
@@ -80,9 +86,6 @@ public final class PictureProfile implements Parcelable {
    })
    public @interface ProfileName {}

    /** @hide */
    public static final String NAME_DEFAULT = "default";

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(flag = false, prefix = "ERROR_", value = {
+3 −0
Original line number Diff line number Diff line
@@ -46,10 +46,13 @@ interface IMediaQualityManager {
    List<String> getPictureProfileAllowList(int userId);
    void setPictureProfileAllowList(in List<String> packages, int userId);
    List<PictureProfileHandle> getPictureProfileHandle(in String[] id, int userId);

    long getPictureProfileHandleValue(in String id, int userId);
    long getDefaultPictureProfileHandleValue(int userId);
    void notifyPictureProfileHandleSelection(in long handle, int userId);

    long getPictureProfileForTvInput(in String inputId, int userId);

    void createSoundProfile(in SoundProfile pp, int userId);
    void updateSoundProfile(in String id, in SoundProfile pp, int userId);
    void removeSoundProfile(in String id, int userId);
+37 −0
Original line number Diff line number Diff line
@@ -419,6 +419,7 @@ public class MediaQualityService extends SystemService {
                if (mMediaQuality != null) {
                    PictureParameters pp = new PictureParameters();
                    // put ID in params for profile update in HAL
                    // TODO: update HAL API for this case
                    params.putLong(BaseParameters.PARAMETER_ID, longId);
                    PictureParameter[] pictureParameters = MediaQualityUtils
                            .convertPersistableBundleToPictureParameterList(params);
@@ -505,6 +506,41 @@ public class MediaQualityService extends SystemService {
            }
        }

        public long getPictureProfileForTvInput(String inputId, int userId) {
            // TODO: cache profiles
            if (!hasGlobalPictureQualityServicePermission()) {
                mMqManagerNotifier.notifyOnPictureProfileError(null,
                        PictureProfile.ERROR_NO_PERMISSION,
                        Binder.getCallingUid(), Binder.getCallingPid());
            }
            String[] columns = {BaseParameters.PARAMETER_ID};
            String selection = BaseParameters.PARAMETER_TYPE + " = ? AND "
                    + BaseParameters.PARAMETER_NAME + " = ? AND "
                    + BaseParameters.PARAMETER_INPUT_ID + " = ?";
            String[] selectionArguments = {
                    Integer.toString(PictureProfile.TYPE_SYSTEM),
                    PictureProfile.NAME_DEFAULT,
                    inputId
            };
            synchronized (mPictureProfileLock) {
                try (Cursor cursor = mMqDatabaseUtils.getCursorAfterQuerying(
                        mMediaQualityDbHelper.PICTURE_QUALITY_TABLE_NAME,
                        columns, selection, selectionArguments)) {
                    int count = cursor.getCount();
                    if (count == 0) {
                        return -1;
                    }
                    long handle = -1;
                    cursor.moveToFirst();
                    int colIndex = cursor.getColumnIndex(BaseParameters.PARAMETER_ID);
                    if (colIndex != -1) {
                        handle = cursor.getLong(colIndex);
                    }
                    return handle;
                }
            }
        }

        @GuardedBy("mSoundProfileLock")
        @Override
        public List<SoundProfileHandle> getSoundProfileHandle(String[] ids, int userId) {
@@ -713,6 +749,7 @@ public class MediaQualityService extends SystemService {
                if (mMediaQuality != null) {
                    SoundParameters sp = new SoundParameters();
                    // put ID in params for profile update in HAL
                    // TODO: update HAL API for this case
                    params.putLong(BaseParameters.PARAMETER_ID, longId);
                    SoundParameter[] soundParameters =
                            MediaQualityUtils.convertPersistableBundleToSoundParameterList(params);
+19 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ final class TvInputHal implements Handler.Callback {
    private static native void nativeClose(long ptr);
    private static native int nativeSetTvMessageEnabled(long ptr, int deviceId, int streamId,
            int type, boolean enabled);

    private static native int nativeSetPictureProfile(
            long ptr, int deviceId, int streamId, long profileHandle);

@@ -124,6 +125,24 @@ final class TvInputHal implements Handler.Callback {
        }
    }

    public int setPictureProfile(int deviceId, TvStreamConfig streamConfig, long profileHandle) {
        synchronized (mLock) {
            if (mPtr == 0) {
                return ERROR_NO_INIT;
            }
            int generation = mStreamConfigGenerations.get(deviceId, 0);
            if (generation != streamConfig.getGeneration()) {
                return ERROR_STALE_CONFIG;
            }
            if (nativeSetPictureProfile(mPtr, deviceId, streamConfig.getStreamId(), profileHandle)
                    == 0) {
                return SUCCESS;
            } else {
                return ERROR_UNKNOWN;
            }
        }
    }

    public int removeStream(int deviceId, TvStreamConfig streamConfig) {
        synchronized (mLock) {
            if (mPtr == 0) {
Loading