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

Commit d9179546 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[MQ] Add media profiles, callback and contract" into main

parents 22f8bd16 64ea1667
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -16,9 +16,16 @@

package android.media.quality;

import android.media.quality.PictureProfile;

/**
 * Interface for Media Quality Manager
 * @hide
 */
interface IMediaQualityManager {
    PictureProfile createPictureProfile(in PictureProfile pp);
    PictureProfile getPictureProfileById(in long id);
    List<PictureProfile> getPictureProfilesByPackage(in String packageName);
    List<PictureProfile> getAvailablePictureProfiles();
    List<PictureProfile> getAvailableAllPictureProfiles();
}
 No newline at end of file
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package android.media.quality;

import android.media.quality.PictureProfile;

/**
 * Interface to receive callbacks from IMediaQuality.
 * @hide
 */
oneway interface IPictureProfileCallback {
    void onPictureProfileAdded(in long id, in PictureProfile p);
    void onPictureProfileUpdated(in long id, in PictureProfile p);
}
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.media.quality;


import android.annotation.FlaggedApi;
import android.media.tv.flags.Flags;

/**
 * @hide
 */
@FlaggedApi(Flags.FLAG_MEDIA_QUALITY_FW)
public class MediaQualityContract {

    public interface BaseParameters {
        String PARAMETER_ID = "_id";
        String PARAMETER_NAME = "_name";
        String PARAMETER_PACKAGE = "_package";
        String PARAMETER_INPUT_ID = "_input_id";

    }
    public static final class PictureQuality implements BaseParameters {
        public static final String PARAMETER_BRIGHTNESS = "brightness";
        public static final String PARAMETER_CONTRAST = "contrast";
        public static final String PARAMETER_SHARPNESS = "sharpness";
        public static final String PARAMETER_SATURATION = "saturation";
    }

    public static final class SoundQuality implements BaseParameters {
        public static final String PARAMETER_BALANCE = "balance";
        public static final String PARAMETER_BASS = "bass";
        public static final String PARAMETER_TREBLE = "treble";
    }

    private MediaQualityContract() {
    }
}
+175 −0
Original line number Diff line number Diff line
@@ -16,10 +16,22 @@

package android.media.quality;

import android.annotation.CallbackExecutor;
import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.SystemService;
import android.content.Context;
import android.media.tv.flags.Flags;
import android.os.RemoteException;

import androidx.annotation.RequiresPermission;

import com.android.internal.util.Preconditions;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Executor;

/**
 * Expose TV setting APIs for the application to use
@@ -33,6 +45,9 @@ public class MediaQualityManager {

    private final IMediaQualityManager mService;
    private final Context mContext;
    private final Object mLock = new Object();
    // @GuardedBy("mLock")
    private final List<PictureProfileCallbackRecord> mPpCallbackRecords = new ArrayList<>();

    /**
     * @hide
@@ -40,5 +55,165 @@ public class MediaQualityManager {
    public MediaQualityManager(Context context, IMediaQualityManager service) {
        mContext = context;
        mService = service;
        IPictureProfileCallback mqCallback = new IPictureProfileCallback.Stub() {
            @Override
            public void onPictureProfileAdded(long profileId, PictureProfile profile) {
                synchronized (mLock) {
                    for (PictureProfileCallbackRecord record : mPpCallbackRecords) {
                        // TODO: filter callback record
                        record.postPictureProfileAdded(profileId, profile);
                    }
                }
            }
            @Override
            public void onPictureProfileUpdated(long profileId, PictureProfile profile) {
                synchronized (mLock) {
                    for (PictureProfileCallbackRecord record : mPpCallbackRecords) {
                        // TODO: filter callback record
                        record.postPictureProfileUpdated(profileId, profile);
                    }
                }
            }
        };
    }

    /**
     * Registers a {@link PictureProfileCallback}.
     * @hide
     */
    public void registerCallback(
            @NonNull @CallbackExecutor Executor executor,
            @NonNull PictureProfileCallback callback) {
        Preconditions.checkNotNull(callback);
        Preconditions.checkNotNull(executor);
        synchronized (mLock) {
            mPpCallbackRecords.add(new PictureProfileCallbackRecord(callback, executor));
        }
    }

    /**
     * Unregisters the existing {@link PictureProfileCallback}.
     * @hide
     */
    public void unregisterCallback(@NonNull final PictureProfileCallback callback) {
        Preconditions.checkNotNull(callback);
        synchronized (mLock) {
            for (Iterator<PictureProfileCallbackRecord> it = mPpCallbackRecords.iterator();
                    it.hasNext(); ) {
                PictureProfileCallbackRecord record = it.next();
                if (record.getCallback() == callback) {
                    it.remove();
                    break;
                }
            }
        }
    }


    /**
     * Gets picture profile by given profile ID.
     * @return the corresponding picture profile if available; {@code null} if the ID doesn't
     *         exist or the profile is not accessible to the caller.
     */
    public PictureProfile getPictureProfileById(long profileId) {
        try {
            return mService.getPictureProfileById(profileId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }


    /** @SystemApi gets profiles that available to the given package */
    @RequiresPermission(android.Manifest.permission.MANAGE_GLOBAL_PICTURE_QUALITY_SERVICE)
    public List<PictureProfile> getPictureProfilesByPackage(String packageName) {
        try {
            return mService.getPictureProfilesByPackage(packageName);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** Gets profiles that available to the caller package */
    public List<PictureProfile> getAvailablePictureProfiles() {
        try {
            return mService.getAvailablePictureProfiles();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** @SystemApi all stored picture profiles */
    @RequiresPermission(android.Manifest.permission.MANAGE_GLOBAL_PICTURE_QUALITY_SERVICE)
    public List<PictureProfile> getAvailableAllPictureProfiles() {
        try {
            return mService.getAvailableAllPictureProfiles();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }


    /**
     * Creates a picture profile and store it in the system.
     *
     * @return the stored profile with an assigned profile ID.
     */
    public PictureProfile createPictureProfile(PictureProfile pp) {
        try {
            return mService.createPictureProfile(pp);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    private static final class PictureProfileCallbackRecord {
        private final PictureProfileCallback mCallback;
        private final Executor mExecutor;

        PictureProfileCallbackRecord(PictureProfileCallback callback, Executor executor) {
            mCallback = callback;
            mExecutor = executor;
        }

        public PictureProfileCallback getCallback() {
            return mCallback;
        }

        public void postPictureProfileAdded(final long id, PictureProfile profile) {

            mExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    mCallback.onPictureProfileAdded(id, profile);
                }
            });
        }

        public void postPictureProfileUpdated(final long id, PictureProfile profile) {
            mExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    mCallback.onPictureProfileUpdated(id, profile);
                }
            });
        }
    }

    /**
     * Callback used to monitor status of picture profiles.
     * @hide
     */
    public abstract static class PictureProfileCallback {
        /**
         * @hide
         */
        public void onPictureProfileAdded(long id, PictureProfile profile) {
        }
        /**
         * @hide
         */
        public void onPictureProfileUpdated(long id, PictureProfile profile) {
        }
    }
}
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.media.quality;

parcelable PictureProfile;
Loading