Jaewan Kim | ceb6b6e | 2018-01-21 20:56:10 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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.server.media; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.media.IMediaSession2; |
| 21 | import android.media.MediaController2; |
| 22 | import android.media.SessionToken; |
| 23 | import android.media.MediaSessionService2; |
| 24 | |
| 25 | /** |
| 26 | * Records a {@link MediaSessionService2}. |
| 27 | * <p> |
| 28 | * Owner of this object should handle synchronization. |
| 29 | */ |
| 30 | class MediaSessionService2Record extends MediaSession2Record { |
| 31 | private static final boolean DEBUG = true; // TODO(jaewan): Modify |
| 32 | private static final String TAG = "SessionService2Record"; |
| 33 | |
| 34 | private final int mType; |
| 35 | private final String mServiceName; |
| 36 | private final SessionToken mToken; |
| 37 | |
| 38 | public MediaSessionService2Record(Context context, |
| 39 | SessionDestroyedListener sessionDestroyedListener, int type, |
| 40 | String packageName, String serviceName, String id) { |
| 41 | super(context, sessionDestroyedListener); |
| 42 | mType = type; |
| 43 | mServiceName = serviceName; |
| 44 | mToken = new SessionToken(mType, packageName, id, mServiceName, null); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Overriden to change behavior of |
| 49 | * {@link #createSessionToken(int, String, String, IMediaSession2)}}. |
| 50 | */ |
| 51 | @Override |
| 52 | MediaController2 onCreateMediaController( |
| 53 | String packageName, String id, IMediaSession2 sessionBinder) { |
| 54 | SessionToken token = new SessionToken(mType, packageName, id, mServiceName, sessionBinder); |
| 55 | return createMediaController(token); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @return token with no session binder information. |
| 60 | */ |
| 61 | @Override |
| 62 | public SessionToken getToken() { |
| 63 | return mToken; |
| 64 | } |
| 65 | } |