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

Commit 3e8c1c9d authored by Hyundo Moon's avatar Hyundo Moon
Browse files

AML: Apply changes under frameworks/av to frameworks/base

This CL copies the AML-related changes under frameworks/av to
frameworks/base. This CL includes changes in following merged commits:

a003298 AML: Replace ParceledListSlice
b82512b AML: Remove use of Bundle#setDefusable
70b92a4 AML: Use config_mediaMetadataBitmapMaxSize which is @SystemApi
b4dbc2d Replace hidden Parcel.(read|write)CharSequence usages

Bug:122711373, Bug:122432476
Test: atest CtsMediaTestCases:android.media.cts.MediaSessionTest;
      atest CtsMediaTestCases:android.media.cts.MediaControllerTest;
      atest CtsMediaTestCases:android.media.cts.MediaBrowserTest;
      atest CtsMediaTestCases:android.media.cts.MediaBrowserServiceTest;
      atest CtsMediaTestCases:android.media.cts.MediaBrowserServiceTest;
Change-Id: I1a13e0ae71097caa90f677bc19b7864929dbc20f
parent ebc2af2c
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -1419,11 +1419,6 @@ Landroid/service/euicc/IGetEuiccProfileInfoListCallback;->onComplete(Landroid/se
Landroid/service/euicc/IRetainSubscriptionsForFactoryResetCallback;->onComplete(I)V
Landroid/service/euicc/ISwitchToSubscriptionCallback;->onComplete(I)V
Landroid/service/euicc/IUpdateSubscriptionNicknameCallback;->onComplete(I)V
Landroid/service/media/IMediaBrowserServiceCallbacks$Stub;->asInterface(Landroid/os/IBinder;)Landroid/service/media/IMediaBrowserServiceCallbacks;
Landroid/service/media/IMediaBrowserServiceCallbacks;->onConnect(Ljava/lang/String;Landroid/media/session/MediaSession$Token;Landroid/os/Bundle;)V
Landroid/service/media/IMediaBrowserServiceCallbacks;->onConnectFailed()V
Landroid/service/media/IMediaBrowserServiceCallbacks;->onLoadChildren(Ljava/lang/String;Landroid/content/pm/ParceledListSlice;)V
Landroid/service/media/IMediaBrowserServiceCallbacks;->onLoadChildrenWithOptions(Ljava/lang/String;Landroid/content/pm/ParceledListSlice;Landroid/os/Bundle;)V
Landroid/service/notification/INotificationListener$Stub;-><init>()V
Landroid/service/persistentdata/IPersistentDataBlockService$Stub;->asInterface(Landroid/os/IBinder;)Landroid/service/persistentdata/IPersistentDataBlockService;
Landroid/service/vr/IVrManager$Stub;->asInterface(Landroid/os/IBinder;)Landroid/service/vr/IVrManager;
+7 −6
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

/**
 * A simple set of metadata for a media item suitable for display. This can be
@@ -122,9 +123,9 @@ public class MediaDescription implements Parcelable {

    private MediaDescription(Parcel in) {
        mMediaId = in.readString();
        mTitle = in.readCharSequence();
        mSubtitle = in.readCharSequence();
        mDescription = in.readCharSequence();
        mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mSubtitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mIcon = in.readParcelable(null);
        mIconUri = in.readParcelable(null);
        mExtras = in.readBundle();
@@ -210,9 +211,9 @@ public class MediaDescription implements Parcelable {
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mMediaId);
        dest.writeCharSequence(mTitle);
        dest.writeCharSequence(mSubtitle);
        dest.writeCharSequence(mDescription);
        TextUtils.writeToParcel(mTitle, dest, 0);
        TextUtils.writeToParcel(mSubtitle, dest, 0);
        TextUtils.writeToParcel(mDescription, dest, 0);
        dest.writeParcelable(mIcon, flags);
        dest.writeParcelable(mIconUri, flags);
        dest.writeBundle(mExtras);
+2 −2
Original line number Diff line number Diff line
@@ -34,8 +34,8 @@ import android.util.SparseArray;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Set;
import java.util.Objects;
import java.util.Set;

/**
 * Contains metadata about an item, such as the title, artist, etc.
@@ -422,7 +422,7 @@ public final class MediaMetadata implements Parcelable {
    }

    private MediaMetadata(Parcel in) {
        mBundle = Bundle.setDefusable(in.readBundle(), true);
        mBundle = in.readBundle();
    }

    /**
+20 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 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;

/** @hide */
parcelable MediaParceledListSlice;
+200 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 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;

import android.os.Binder;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * Transfer a large list of objects across an IPC. Splits into multiple transactions if needed.
 * Note: Only use classes declared final in order to avoid subclasses overriding reading/writing
 * parcel logic.
 *
 * TODO: Add test for sending large data
 * @param <T> A Parcelable class which will be sent over the binder calls.
 * @hide
 */
public class MediaParceledListSlice<T extends Parcelable> implements Parcelable {
    private static final String TAG = "MediaParceledListSlice";
    private static final boolean DEBUG = false;

    private static final int MAX_IPC_SIZE = 64 * 1024; // IBinder.MAX_IPC_SIZE

    final List<T> mList;

    public MediaParceledListSlice(List<T> list) {
        if (list == null) {
            throw new IllegalArgumentException("list shouldn't be null");
        }
        mList = list;
    }

    MediaParceledListSlice(Parcel p) {
        final int itemCount = p.readInt();
        mList = new ArrayList<>(itemCount);
        if (DEBUG) {
            Log.d(TAG, "Retrieving " + itemCount + " items");
        }
        if (itemCount <= 0) {
            return;
        }

        int i = 0;
        while (i < itemCount) {
            if (p.readInt() == 0) {
                break;
            }

            final T parcelable = p.readParcelable(null);
            mList.add(parcelable);

            if (DEBUG) {
                Log.d(TAG, "Read inline #" + i + ": " + mList.get(mList.size() - 1));
            }
            i++;
        }
        if (i >= itemCount) {
            return;
        }
        final IBinder retriever = p.readStrongBinder();
        while (i < itemCount) {
            if (DEBUG) {
                Log.d(TAG, "Reading more @" + i + " of " + itemCount + ": retriever=" + retriever);
            }
            Parcel data = Parcel.obtain();
            Parcel reply = Parcel.obtain();
            data.writeInt(i);
            try {
                retriever.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
            } catch (RemoteException e) {
                Log.w(TAG, "Failure retrieving array; only received " + i + " of " + itemCount, e);
                return;
            }
            while (i < itemCount && reply.readInt() != 0) {
                final T parcelable = reply.readParcelable(null);
                mList.add(parcelable);

                if (DEBUG) {
                    Log.d(TAG, "Read extra #" + i + ": " + mList.get(mList.size() - 1));
                }
                i++;
            }
            reply.recycle();
            data.recycle();
        }
    }

    public List<T> getList() {
        return mList;
    }

    /**
     * Write this to another Parcel. Note that this discards the internal Parcel
     * and should not be used anymore. This is so we can pass this to a Binder
     * where we won't have a chance to call recycle on this.
     */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        final int itemCount = mList.size();
        dest.writeInt(itemCount);
        if (DEBUG) {
            Log.d(TAG, "Writing " + itemCount + " items");
        }
        if (itemCount > 0) {
            int i = 0;
            while (i < itemCount && dest.dataSize() < MAX_IPC_SIZE) {
                dest.writeInt(1);

                final T parcelable = mList.get(i);
                dest.writeParcelable(parcelable, flags);

                if (DEBUG) {
                    Log.d(TAG, "Wrote inline #" + i + ": " + mList.get(i));
                }
                i++;
            }
            if (i < itemCount) {
                dest.writeInt(0);
                Binder retriever = new Binder() {
                    @Override
                    protected boolean onTransact(int code, Parcel data, Parcel reply, int flags)
                            throws RemoteException {
                        if (code != FIRST_CALL_TRANSACTION) {
                            return super.onTransact(code, data, reply, flags);
                        }
                        int i = data.readInt();
                        if (DEBUG) {
                            Log.d(TAG, "Writing more @" + i + " of " + itemCount);
                        }
                        while (i < itemCount && reply.dataSize() < MAX_IPC_SIZE) {
                            reply.writeInt(1);

                            final T parcelable = mList.get(i);
                            reply.writeParcelable(parcelable, flags);

                            if (DEBUG) {
                                Log.d(TAG, "Wrote extra #" + i + ": " + mList.get(i));
                            }
                            i++;
                        }
                        if (i < itemCount) {
                            if (DEBUG) {
                                Log.d(TAG, "Breaking @" + i + " of " + itemCount);
                            }
                            reply.writeInt(0);
                        }
                        return true;
                    }
                };
                if (DEBUG) {
                    Log.d(TAG, "Breaking @" + i + " of " + itemCount + ": retriever=" + retriever);
                }
                dest.writeStrongBinder(retriever);
            }
        }
    }

    @Override
    public int describeContents() {
        int contents = 0;
        final List<T> list = getList();
        for (int i = 0; i < list.size(); i++) {
            contents |= list.get(i).describeContents();
        }
        return contents;
    }

    public static final Parcelable.Creator<MediaParceledListSlice> CREATOR =
            new Parcelable.Creator<MediaParceledListSlice>() {
        @Override
        public MediaParceledListSlice createFromParcel(Parcel in) {
            return new MediaParceledListSlice(in);
        }

        @Override
        public MediaParceledListSlice[] newArray(int size) {
            return new MediaParceledListSlice[size];
        }
    };
}
Loading