blob: a30dd98987c1fcf10166b883dcdfd345edaa3c78 [file] [log] [blame]
Kyunglyul Hyun0332e9a22019-11-20 01:39:25 +00001/*
2 * Copyright 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
17package com.android.server.media;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.content.ComponentName;
22import android.content.Intent;
23import android.media.MediaRoute2Info;
24import android.media.MediaRoute2ProviderInfo;
Hyundo Moon63a05402019-12-19 20:13:56 +090025import android.media.RouteSessionInfo;
Kyunglyul Hyun0332e9a22019-11-20 01:39:25 +000026
27import java.util.Objects;
28
29abstract class MediaRoute2Provider {
30 final ComponentName mComponentName;
31 final String mUniqueId;
32
Kyunglyul Hyunf7d5e042019-11-11 13:56:28 +090033 Callback mCallback;
Kyunglyul Hyun0332e9a22019-11-20 01:39:25 +000034 private MediaRoute2ProviderInfo mProviderInfo;
35
36 MediaRoute2Provider(@NonNull ComponentName componentName) {
37 mComponentName = Objects.requireNonNull(componentName, "Component name must not be null.");
38 mUniqueId = componentName.flattenToShortString();
39 }
40
41 public void setCallback(MediaRoute2ProviderProxy.Callback callback) {
42 mCallback = callback;
43 }
44
Hyundo Moon63a05402019-12-19 20:13:56 +090045 public abstract void requestCreateSession(String packageName, String routeId,
Kyunglyul Hyunc7847242019-12-30 17:46:04 +090046 String controlCategory, long requestId);
Kyunglyul Hyuncb8894d2019-12-27 14:24:46 +090047 public abstract void releaseSession(int sessionId);
48
Hyundo Moon9be35482019-12-30 17:33:13 +090049 public abstract void selectRoute(int sessionId, MediaRoute2Info route);
50 public abstract void deselectRoute(int sessionId, MediaRoute2Info route);
Kyunglyul Hyuncb8894d2019-12-27 14:24:46 +090051 public abstract void transferRoute(int sessionId, MediaRoute2Info route);
52
Kyunglyul Hyun0332e9a22019-11-20 01:39:25 +000053 public abstract void sendControlRequest(MediaRoute2Info route, Intent request);
54 public abstract void requestSetVolume(MediaRoute2Info route, int volume);
55 public abstract void requestUpdateVolume(MediaRoute2Info route, int delta);
56
57 @NonNull
58 public String getUniqueId() {
59 return mUniqueId;
60 }
61
62 @Nullable
63 public MediaRoute2ProviderInfo getProviderInfo() {
64 return mProviderInfo;
65 }
66
67 void setAndNotifyProviderInfo(MediaRoute2ProviderInfo info) {
68 //TODO: check if info is not updated
69 if (info == null) {
70 mProviderInfo = null;
71 } else {
72 mProviderInfo = new MediaRoute2ProviderInfo.Builder(info)
73 .setUniqueId(mUniqueId)
74 .build();
75 }
76 if (mCallback != null) {
77 mCallback.onProviderStateChanged(this);
78 }
79 }
80
81 public boolean hasComponentName(String packageName, String className) {
82 return mComponentName.getPackageName().equals(packageName)
83 && mComponentName.getClassName().equals(className);
84 }
85
86 public interface Callback {
Kyunglyul Hyunf7d5e042019-11-11 13:56:28 +090087 void onProviderStateChanged(@Nullable MediaRoute2Provider provider);
Hyundo Moon63a05402019-12-19 20:13:56 +090088 void onSessionCreated(@NonNull MediaRoute2Provider provider,
Kyunglyul Hyunc7847242019-12-30 17:46:04 +090089 @Nullable RouteSessionInfo sessionInfo, long requestId);
Kyunglyul Hyun0332e9a22019-11-20 01:39:25 +000090 }
91}