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

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

Merge "[Media Quality] Implement UpdateProfilePicture, UpdateSoundProfile,...

Merge "[Media Quality] Implement UpdateProfilePicture, UpdateSoundProfile, GetAvailablePictureProfiles, GetAvailableSoundProfiles" into main
parents 664d05c1 34fdad99
Loading
Loading
Loading
Loading
+83 −21
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.media.quality.PictureProfile;
import android.media.quality.PictureProfileHandle;
import android.media.quality.SoundProfile;
import android.media.quality.SoundProfileHandle;
import android.os.Binder;
import android.os.PersistableBundle;
import android.os.UserHandle;
import android.util.Log;
@@ -58,6 +59,7 @@ public class MediaQualityService extends SystemService {

    private static final boolean DEBUG = false;
    private static final String TAG = "MediaQualityService";
    private static final int MAX_UUID_GENERATION_ATTEMPTS = 10;
    private final Context mContext;
    private final MediaQualityDbHelper mMediaQualityDbHelper;
    private final BiMap<Long, String> mPictureProfileTempIdMap;
@@ -85,12 +87,12 @@ public class MediaQualityService extends SystemService {
        public PictureProfile createPictureProfile(PictureProfile pp, UserHandle user) {
            SQLiteDatabase db = mMediaQualityDbHelper.getWritableDatabase();

            ContentValues values = new ContentValues();
            values.put(BaseParameters.PARAMETER_TYPE, pp.getProfileType());
            values.put(BaseParameters.PARAMETER_NAME, pp.getName());
            values.put(BaseParameters.PARAMETER_PACKAGE, pp.getPackageName());
            values.put(BaseParameters.PARAMETER_INPUT_ID, pp.getInputId());
            values.put(mMediaQualityDbHelper.SETTINGS, persistableBundleToJson(pp.getParameters()));
            ContentValues values = getContentValues(null,
                    pp.getProfileType(),
                    pp.getName(),
                    pp.getPackageName(),
                    pp.getInputId(),
                    pp.getParameters());

            // id is auto-generated by SQLite upon successful insertion of row
            Long id = db.insert(mMediaQualityDbHelper.PICTURE_QUALITY_TABLE_NAME,
@@ -102,7 +104,18 @@ public class MediaQualityService extends SystemService {

        @Override
        public void updatePictureProfile(String id, PictureProfile pp, UserHandle user) {
            // TODO: implement
            Long intId = mPictureProfileTempIdMap.inverse().get(id);

            ContentValues values = getContentValues(intId,
                    pp.getProfileType(),
                    pp.getName(),
                    pp.getPackageName(),
                    pp.getInputId(),
                    pp.getParameters());

            SQLiteDatabase db = mMediaQualityDbHelper.getWritableDatabase();
            db.replace(mMediaQualityDbHelper.PICTURE_QUALITY_TABLE_NAME,
                    null, values);
        }

        @Override
@@ -157,6 +170,11 @@ public class MediaQualityService extends SystemService {
        @Override
        public List<PictureProfile> getAvailablePictureProfiles(
                boolean includeParams, UserHandle user) {
            String[] packageNames = mContext.getPackageManager().getPackagesForUid(
                    Binder.getCallingUid());
            if (packageNames != null && packageNames.length == 1 && !packageNames[0].isEmpty()) {
                return getPictureProfilesByPackage(packageNames[0], includeParams, user);
            }
            return new ArrayList<>();
        }

@@ -191,12 +209,12 @@ public class MediaQualityService extends SystemService {
        public SoundProfile createSoundProfile(SoundProfile sp, UserHandle user) {
            SQLiteDatabase db = mMediaQualityDbHelper.getWritableDatabase();

            ContentValues values = new ContentValues();
            values.put(BaseParameters.PARAMETER_TYPE, sp.getProfileType());
            values.put(BaseParameters.PARAMETER_NAME, sp.getName());
            values.put(BaseParameters.PARAMETER_PACKAGE, sp.getPackageName());
            values.put(BaseParameters.PARAMETER_INPUT_ID, sp.getInputId());
            values.put(mMediaQualityDbHelper.SETTINGS, persistableBundleToJson(sp.getParameters()));
            ContentValues values = getContentValues(null,
                    sp.getProfileType(),
                    sp.getName(),
                    sp.getPackageName(),
                    sp.getInputId(),
                    sp.getParameters());

            // id is auto-generated by SQLite upon successful insertion of row
            Long id = db.insert(mMediaQualityDbHelper.SOUND_QUALITY_TABLE_NAME,
@@ -207,8 +225,18 @@ public class MediaQualityService extends SystemService {
        }

        @Override
        public void updateSoundProfile(String id, SoundProfile pp, UserHandle user) {
            // TODO: implement
        public void updateSoundProfile(String id, SoundProfile sp, UserHandle user) {
            Long intId = mSoundProfileTempIdMap.inverse().get(id);

            ContentValues values = getContentValues(intId,
                    sp.getProfileType(),
                    sp.getName(),
                    sp.getPackageName(),
                    sp.getInputId(),
                    sp.getParameters());

            SQLiteDatabase db = mMediaQualityDbHelper.getWritableDatabase();
            db.replace(mMediaQualityDbHelper.SOUND_QUALITY_TABLE_NAME, null, values);
        }

        @Override
@@ -263,6 +291,11 @@ public class MediaQualityService extends SystemService {
        @Override
        public List<SoundProfile> getAvailableSoundProfiles(
                boolean includeParams, UserHandle user) {
            String[] packageNames = mContext.getPackageManager().getPackagesForUid(
                    Binder.getCallingUid());
            if (packageNames != null && packageNames.length == 1 && !packageNames[0].isEmpty()) {
                return getSoundProfilesByPackage(packageNames[0], includeParams, user);
            }
            return new ArrayList<>();
        }

@@ -285,11 +318,16 @@ public class MediaQualityService extends SystemService {

        private void populateTempIdMap(BiMap<Long, String> map, Long id) {
            if (id != null && map.get(id) == null) {
                String uuid = UUID.randomUUID().toString();
                while (map.inverse().containsKey(uuid)) {
                String uuid;
                int attempts = 0;
                while (attempts < MAX_UUID_GENERATION_ATTEMPTS) {
                    uuid = UUID.randomUUID().toString();
                }
                    if (!map.inverse().containsKey(uuid)) {
                        map.put(id, uuid);
                        return;
                    }
                    attempts++;
                }
            }
        }

@@ -316,7 +354,7 @@ public class MediaQualityService extends SystemService {
            return json.toString();
        }

        private PersistableBundle jsonToBundle(String jsonString) {
        private PersistableBundle jsonToPersistableBundle(String jsonString) {
            PersistableBundle bundle = new PersistableBundle();
            if (jsonString != null) {
                JSONObject jsonObject = null;
@@ -347,6 +385,30 @@ public class MediaQualityService extends SystemService {
            return bundle;
        }

        private ContentValues getContentValues(Long dbId, Integer profileType, String name,
                String packageName, String inputId, PersistableBundle params) {
            ContentValues values = new ContentValues();
            if (dbId != null) {
                values.put(BaseParameters.PARAMETER_ID, dbId);
            }
            if (profileType != null) {
                values.put(BaseParameters.PARAMETER_TYPE, profileType);
            }
            if (name != null) {
                values.put(BaseParameters.PARAMETER_NAME, name);
            }
            if (packageName != null) {
                values.put(BaseParameters.PARAMETER_PACKAGE, packageName);
            }
            if (inputId != null) {
                values.put(BaseParameters.PARAMETER_INPUT_ID, inputId);
            }
            if (params != null) {
                values.put(mMediaQualityDbHelper.SETTINGS, persistableBundleToJson(params));
            }
            return values;
        }

        private String[] getAllMediaProfileColumns() {
            return new String[]{
                    BaseParameters.PARAMETER_ID,
@@ -365,7 +427,7 @@ public class MediaQualityService extends SystemService {
                    getName(cursor),
                    getInputId(cursor),
                    getPackageName(cursor),
                    jsonToBundle(getSettingsString(cursor)),
                    jsonToPersistableBundle(getSettingsString(cursor)),
                    PictureProfileHandle.NONE
            );
        }
@@ -377,7 +439,7 @@ public class MediaQualityService extends SystemService {
                    getName(cursor),
                    getInputId(cursor),
                    getPackageName(cursor),
                    jsonToBundle(getSettingsString(cursor)),
                    jsonToPersistableBundle(getSettingsString(cursor)),
                    SoundProfileHandle.NONE
            );
        }
+2 −1
Original line number Diff line number Diff line
shubang@google.com
haofanw@google.com
pkandhalu@google.com
 No newline at end of file