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

Commit f894f77d authored by Sungsoo Lim's avatar Sungsoo Lim
Browse files

Add init MediaSession2 and MediaController2

This CL only covers the connection logic between MediaSession2
and MediaController2.

Bug: 122055262
Test: build
Change-Id: I1773aa053ea1fce0cc548f334416e47d373f7f86
parent 2f16d51c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -461,11 +461,13 @@ java_defaults {
        "media/java/android/media/IAudioRoutesObserver.aidl",
        "media/java/android/media/IAudioService.aidl",
        "media/java/android/media/IAudioServerStateDispatcher.aidl",
        "media/java/android/media/IMediaController2.aidl",
        "media/java/android/media/IMediaHTTPConnection.aidl",
        "media/java/android/media/IMediaHTTPService.aidl",
        "media/java/android/media/IMediaResourceMonitor.aidl",
        "media/java/android/media/IMediaRouterClient.aidl",
        "media/java/android/media/IMediaRouterService.aidl",
        "media/java/android/media/IMediaSession2.aidl",
        "media/java/android/media/IMediaScannerListener.aidl",
        "media/java/android/media/IMediaScannerService.aidl",
        "media/java/android/media/IPlaybackConfigDispatcher.aidl",
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 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;

parcelable Controller2Link;
+133 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 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.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;

/**
 * Handles incoming commands from {@link MediaSession2} and {@link MediaLibrarySession}
 * to both {@link MediaController2} and {@link MediaBrowser2}.
 * @hide
 */
// @SystemApi
public final class Controller2Link implements Parcelable {
    private static final String TAG = "Controller2Link";
    private static final boolean DEBUG = MediaController2.DEBUG;

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

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


    private final MediaController2 mController;
    private final IMediaController2 mIController;

    public Controller2Link(MediaController2 controller) {
        mController = controller;
        mIController = new Controller2Stub();
    }

    Controller2Link(Parcel in) {
        mController = null;
        mIController = IMediaController2.Stub.asInterface(in.readStrongBinder());
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeStrongBinder(mIController.asBinder());
    }

    /** Interface method for IMediaController2.notifyConnected */
    public void notifyConnected(int seq, Bundle connectionResult) {
        try {
            mIController.notifyConnected(seq, connectionResult);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** Interface method for IMediaController2.notifyDisonnected */
    public void notifyDisconnected(int seq) {
        try {
            mIController.notifyDisconnected(seq);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** Interface method for IMediaController2.sendSessionCommand */
    public void sendSessionCommand(int seq, Session2Command command, Bundle args) {
        try {
            mIController.sendSessionCommand(seq, command, args);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** Stub implementation for IMediaController2.notifyConnected */
    public void onConnected(int seq, Bundle connectionResult) {
        if (connectionResult == null) {
            onDisconnected(seq);
            return;
        }
        mController.onConnected(seq, connectionResult);
    }

    /** Stub implementation for IMediaController2.notifyDisonnected */
    public void onDisconnected(int seq) {
        mController.onDisconnected(seq);
    }

    /** Stub implementation for IMediaController2.sendSessionCommand */
    public void onSessionCommand(int seq, Session2Command command, Bundle args) {
        mController.onSessionCommand(seq, command, args);
    }

    private class Controller2Stub extends IMediaController2.Stub {
        @Override
        public void notifyConnected(int seq, Bundle connectionResult) {
            Controller2Link.this.onConnected(seq, connectionResult);
        }

        @Override
        public void notifyDisconnected(int seq) {
            Controller2Link.this.onDisconnected(seq);
        }

        @Override
        public void sendSessionCommand(int seq, Session2Command command, Bundle args) {
            Controller2Link.this.onSessionCommand(seq, command, args);
        }
    }
}
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 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.Bundle;
import android.media.Session2Command;

/**
 * Interface from MediaSession2 to MediaController2.
 * <p>
 * Keep this interface oneway. Otherwise a malicious app may implement fake version of this,
 * and holds calls from session to make session owner(s) frozen.
 * @hide
 */
 // Code for AML only
oneway interface IMediaController2 {
    void notifyConnected(int seq, in Bundle connectionResult) = 0;
    void notifyDisconnected(int seq) = 1;
    void sendSessionCommand(int seq, in Session2Command command, in Bundle args) = 2;
}
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 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.Bundle;
import android.media.Controller2Link;
import android.media.Session2Command;

/**
 * Interface from MediaController2 to MediaSession2.
 * <p>
 * Keep this interface oneway. Otherwise a malicious app may implement fake version of this,
 * and holds calls from session to make session owner(s) frozen.
 * @hide
 */
 // Code for AML only
oneway interface IMediaSession2 {
    void connect(in Controller2Link caller, int seq, in Bundle connectionRequest) = 0;
    void disconnect(in Controller2Link caller, int seq) = 1;
    void sendSessionCommand(in Controller2Link caller, int seq, in Session2Command sessionCommand,
            in Bundle args) = 2;
    // Next Id : 3
}
Loading