1 /*
2  * Copyright (C) 2017 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 package com.android.media.update;
18 
19 import android.app.Notification;
20 import android.content.Context;
21 import android.content.pm.ApplicationInfo;
22 import android.media.MediaBrowser2;
23 import android.media.MediaBrowser2.BrowserCallback;
24 import android.media.MediaController2;
25 import android.media.MediaController2.ControllerCallback;
26 import android.media.MediaItem2;
27 import android.media.MediaLibraryService2;
28 import android.media.MediaLibraryService2.LibraryRoot;
29 import android.media.MediaLibraryService2.MediaLibrarySession;
30 import android.media.MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback;
31 import android.media.MediaMetadata2;
32 import android.media.MediaPlaylistAgent;
33 import android.media.MediaSession2;
34 import android.media.SessionCommand2;
35 import android.media.SessionCommandGroup2;
36 import android.media.MediaSession2.ControllerInfo;
37 import android.media.MediaSession2.SessionCallback;
38 import android.media.MediaSessionService2;
39 import android.media.MediaSessionService2.MediaNotification;
40 import android.media.Rating2;
41 import android.media.SessionToken2;
42 import android.media.VolumeProvider2;
43 import android.media.update.MediaBrowser2Provider;
44 import android.media.update.MediaControlView2Provider;
45 import android.media.update.MediaController2Provider;
46 import android.media.update.MediaItem2Provider;
47 import android.media.update.MediaLibraryService2Provider.LibraryRootProvider;
48 import android.media.update.MediaMetadata2Provider;
49 import android.media.update.MediaPlaylistAgentProvider;
50 import android.media.update.MediaSession2Provider;
51 import android.media.update.MediaSession2Provider.BuilderBaseProvider;
52 import android.media.update.MediaSession2Provider.CommandButtonProvider.BuilderProvider;
53 import android.media.update.MediaSessionService2Provider;
54 import android.media.update.MediaSessionService2Provider.MediaNotificationProvider;
55 import android.media.update.SessionToken2Provider;
56 import android.media.update.StaticProvider;
57 import android.media.update.VideoView2Provider;
58 import android.media.update.ViewGroupProvider;
59 import android.media.update.VolumeProvider2Provider;
60 import android.os.Bundle;
61 import android.os.IInterface;
62 import android.support.annotation.Nullable;
63 import android.util.AttributeSet;
64 import android.widget.MediaControlView2;
65 import android.widget.VideoView2;
66 
67 import com.android.media.IMediaController2;
68 import com.android.media.MediaBrowser2Impl;
69 import com.android.media.MediaController2Impl;
70 import com.android.media.MediaItem2Impl;
71 import com.android.media.MediaLibraryService2Impl;
72 import com.android.media.MediaLibraryService2Impl.LibraryRootImpl;
73 import com.android.media.MediaMetadata2Impl;
74 import com.android.media.MediaPlaylistAgentImpl;
75 import com.android.media.MediaSession2Impl;
76 import com.android.media.MediaSessionService2Impl;
77 import com.android.media.Rating2Impl;
78 import com.android.media.SessionToken2Impl;
79 import com.android.media.VolumeProvider2Impl;
80 import com.android.widget.MediaControlView2Impl;
81 import com.android.widget.VideoView2Impl;
82 
83 import java.util.concurrent.Executor;
84 
85 public final class ApiFactory implements StaticProvider {
ApiFactory()86     private ApiFactory() { }
87 
initialize(ApplicationInfo updatableInfo)88     public static StaticProvider initialize(ApplicationInfo updatableInfo) {
89         ApiHelper.initialize(updatableInfo);
90         return new ApiFactory();
91     }
92 
93     @Override
createMediaController2( Context context, MediaController2 instance, SessionToken2 token, Executor executor, ControllerCallback callback)94     public MediaController2Provider createMediaController2(
95             Context context, MediaController2 instance, SessionToken2 token,
96             Executor executor, ControllerCallback callback) {
97         return new MediaController2Impl(context, instance, token, executor, callback);
98     }
99 
100     @Override
createMediaBrowser2(Context context, MediaBrowser2 instance, SessionToken2 token, Executor executor, BrowserCallback callback)101     public MediaBrowser2Provider createMediaBrowser2(Context context, MediaBrowser2 instance,
102             SessionToken2 token, Executor executor, BrowserCallback callback) {
103         return new MediaBrowser2Impl(context, instance, token, executor, callback);
104     }
105 
106     @Override
createMediaSession2Command( SessionCommand2 instance, int commandCode, String action, Bundle extra)107     public MediaSession2Provider.CommandProvider createMediaSession2Command(
108             SessionCommand2 instance, int commandCode, String action, Bundle extra) {
109         if (action == null && extra == null) {
110             return new MediaSession2Impl.CommandImpl(instance, commandCode);
111         }
112         return new MediaSession2Impl.CommandImpl(instance, action, extra);
113     }
114 
115     @Override
fromBundle_MediaSession2Command(Bundle command)116     public SessionCommand2 fromBundle_MediaSession2Command(Bundle command) {
117         return MediaSession2Impl.CommandImpl.fromBundle_impl(command);
118     }
119 
120     @Override
createMediaSession2CommandGroup( SessionCommandGroup2 instance, SessionCommandGroup2 other)121     public MediaSession2Provider.CommandGroupProvider createMediaSession2CommandGroup(
122             SessionCommandGroup2 instance, SessionCommandGroup2 other) {
123         return new MediaSession2Impl.CommandGroupImpl(instance,
124                 (other == null) ? null : other.getProvider());
125     }
126 
127     @Override
fromBundle_MediaSession2CommandGroup(Bundle commands)128     public SessionCommandGroup2 fromBundle_MediaSession2CommandGroup(Bundle commands) {
129         return MediaSession2Impl.CommandGroupImpl.fromBundle_impl(commands);
130     }
131 
132     @Override
createMediaSession2ControllerInfo( Context context, ControllerInfo instance, int uid, int pid, String packageName, IInterface callback)133     public MediaSession2Provider.ControllerInfoProvider createMediaSession2ControllerInfo(
134             Context context, ControllerInfo instance, int uid, int pid, String packageName,
135             IInterface callback) {
136         return new MediaSession2Impl.ControllerInfoImpl(context,
137                 instance, uid, pid, packageName, (IMediaController2) callback);
138     }
139 
140     @Override
createMediaSession2CommandButtonBuilder( MediaSession2.CommandButton.Builder instance)141     public BuilderProvider createMediaSession2CommandButtonBuilder(
142             MediaSession2.CommandButton.Builder instance) {
143         return new MediaSession2Impl.CommandButtonImpl.BuilderImpl(instance);
144     }
145 
createMediaSession2Builder( Context context, MediaSession2.Builder instance)146     public BuilderBaseProvider<MediaSession2, SessionCallback> createMediaSession2Builder(
147             Context context, MediaSession2.Builder instance) {
148         return new MediaSession2Impl.BuilderImpl(context, instance);
149     }
150 
151     @Override
createMediaSessionService2(MediaSessionService2 instance)152     public MediaSessionService2Provider createMediaSessionService2(MediaSessionService2 instance) {
153         return new MediaSessionService2Impl(instance);
154     }
155 
156     @Override
createMediaSessionService2MediaNotification( MediaNotification instance, int notificationId, Notification notification)157     public MediaNotificationProvider createMediaSessionService2MediaNotification(
158             MediaNotification instance, int notificationId, Notification notification) {
159         return new MediaSessionService2Impl.MediaNotificationImpl(
160                 instance, notificationId, notification);
161     }
162 
163     @Override
createMediaLibraryService2(MediaLibraryService2 instance)164     public MediaSessionService2Provider createMediaLibraryService2(MediaLibraryService2 instance) {
165         return new MediaLibraryService2Impl(instance);
166     }
167 
168     @Override
169     public BuilderBaseProvider<MediaLibrarySession, MediaLibrarySessionCallback>
createMediaLibraryService2Builder(MediaLibraryService2 service, MediaLibrarySession.Builder instance, Executor callbackExecutor, MediaLibrarySessionCallback callback)170         createMediaLibraryService2Builder(MediaLibraryService2 service,
171             MediaLibrarySession.Builder instance, Executor callbackExecutor,
172             MediaLibrarySessionCallback callback) {
173         return new MediaLibraryService2Impl.BuilderImpl(service, instance, callbackExecutor,
174                 callback);
175     }
176 
177     @Override
createMediaLibraryService2LibraryRoot( LibraryRoot instance, String rootId, Bundle extras)178     public LibraryRootProvider createMediaLibraryService2LibraryRoot(
179             LibraryRoot instance, String rootId, Bundle extras) {
180         return new LibraryRootImpl(instance, rootId, extras);
181     }
182 
183     @Override
createMediaControlView2(MediaControlView2 instance, ViewGroupProvider superProvider, ViewGroupProvider privateProvider, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes)184     public MediaControlView2Provider createMediaControlView2(MediaControlView2 instance,
185             ViewGroupProvider superProvider, ViewGroupProvider privateProvider,
186             @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
187         return new MediaControlView2Impl(instance, superProvider, privateProvider);
188     }
189 
190     @Override
createVideoView2( VideoView2 instance, ViewGroupProvider superProvider, ViewGroupProvider privateProvider, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes)191     public VideoView2Provider createVideoView2(
192             VideoView2 instance, ViewGroupProvider superProvider, ViewGroupProvider privateProvider,
193             @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
194         return new VideoView2Impl(instance, superProvider, privateProvider);
195     }
196 
197     @Override
createSessionToken2(Context context, SessionToken2 instance, String packageName, String serviceName, int uid)198     public SessionToken2Provider createSessionToken2(Context context, SessionToken2 instance,
199             String packageName, String serviceName, int uid) {
200         return new SessionToken2Impl(context, instance, packageName, serviceName, uid);
201     }
202 
203     @Override
fromBundle_SessionToken2(Bundle bundle)204     public SessionToken2 fromBundle_SessionToken2(Bundle bundle) {
205         return SessionToken2Impl.fromBundle_impl(bundle);
206     }
207 
208     @Override
createMediaItem2Builder(MediaItem2.Builder instance, int flags)209     public MediaItem2Provider.BuilderProvider createMediaItem2Builder(MediaItem2.Builder instance,
210             int flags) {
211         return new MediaItem2Impl.BuilderImpl(instance, flags);
212     }
213 
214     @Override
fromBundle_MediaItem2(Bundle bundle)215     public MediaItem2 fromBundle_MediaItem2(Bundle bundle) {
216         return MediaItem2Impl.fromBundle_impl(bundle);
217     }
218 
219     @Override
createVolumeProvider2(VolumeProvider2 instance, int controlType, int maxVolume, int currentVolume)220     public VolumeProvider2Provider createVolumeProvider2(VolumeProvider2 instance, int controlType,
221             int maxVolume, int currentVolume) {
222         return new VolumeProvider2Impl(instance, controlType, maxVolume, currentVolume);
223     }
224 
225     @Override
fromBundle_MediaMetadata2(Bundle bundle)226     public MediaMetadata2 fromBundle_MediaMetadata2(Bundle bundle) {
227         return MediaMetadata2Impl.fromBundle_impl(bundle);
228     }
229 
230     @Override
createMediaMetadata2Builder( MediaMetadata2.Builder instance)231     public MediaMetadata2Provider.BuilderProvider createMediaMetadata2Builder(
232             MediaMetadata2.Builder instance) {
233         return new MediaMetadata2Impl.BuilderImpl(instance);
234     }
235 
236     @Override
createMediaMetadata2Builder( MediaMetadata2.Builder instance, MediaMetadata2 source)237     public MediaMetadata2Provider.BuilderProvider createMediaMetadata2Builder(
238             MediaMetadata2.Builder instance, MediaMetadata2 source) {
239         return new MediaMetadata2Impl.BuilderImpl(instance, source);
240     }
241 
242     @Override
fromBundle_Rating2(Bundle bundle)243     public Rating2 fromBundle_Rating2(Bundle bundle) {
244         return Rating2Impl.fromBundle_impl(bundle);
245     }
246 
247     @Override
newUnratedRating_Rating2(int ratingStyle)248     public Rating2 newUnratedRating_Rating2(int ratingStyle) {
249         return Rating2Impl.newUnratedRating_impl(ratingStyle);
250     }
251 
252     @Override
newHeartRating_Rating2(boolean hasHeart)253     public Rating2 newHeartRating_Rating2(boolean hasHeart) {
254         return Rating2Impl.newHeartRating_impl(hasHeart);
255     }
256 
257     @Override
newThumbRating_Rating2(boolean thumbIsUp)258     public Rating2 newThumbRating_Rating2(boolean thumbIsUp) {
259         return Rating2Impl.newThumbRating_impl(thumbIsUp);
260     }
261 
262     @Override
newStarRating_Rating2(int starRatingStyle, float starRating)263     public Rating2 newStarRating_Rating2(int starRatingStyle, float starRating) {
264         return Rating2Impl.newStarRating_impl(starRatingStyle, starRating);
265     }
266 
267     @Override
newPercentageRating_Rating2(float percent)268     public Rating2 newPercentageRating_Rating2(float percent) {
269         return Rating2Impl.newPercentageRating_impl(percent);
270     }
271 
272     @Override
createMediaPlaylistAgent(MediaPlaylistAgent instance)273     public MediaPlaylistAgentProvider createMediaPlaylistAgent(MediaPlaylistAgent instance) {
274         return new MediaPlaylistAgentImpl(instance);
275     }
276 }
277