blob: 85509f7d1ee0028f28b9825627a5b8953b7e13b9 [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 Hyunf7d5e042019-11-11 13:56:28 +090026import android.os.Bundle;
Kyunglyul Hyun0332e9a22019-11-20 01:39:25 +000027
28import java.util.Objects;
29
30abstract class MediaRoute2Provider {
31 final ComponentName mComponentName;
32 final String mUniqueId;
33
Kyunglyul Hyunf7d5e042019-11-11 13:56:28 +090034 Callback mCallback;
Kyunglyul Hyun0332e9a22019-11-20 01:39:25 +000035 private MediaRoute2ProviderInfo mProviderInfo;
36
37 MediaRoute2Provider(@NonNull ComponentName componentName) {
38 mComponentName = Objects.requireNonNull(componentName, "Component name must not be null.");
39 mUniqueId = componentName.flattenToShortString();
40 }
41
42 public void setCallback(MediaRoute2ProviderProxy.Callback callback) {
43 mCallback = callback;
44 }
45
Hyundo Moon63a05402019-12-19 20:13:56 +090046 public abstract void requestCreateSession(String packageName, String routeId,
47 String controlCategory, int requestId);
Kyunglyul Hyun0332e9a22019-11-20 01:39:25 +000048 public abstract void requestSelectRoute(String packageName, String routeId, int seq);
49 public abstract void unselectRoute(String packageName, String routeId);
50 public abstract void sendControlRequest(MediaRoute2Info route, Intent request);
51 public abstract void requestSetVolume(MediaRoute2Info route, int volume);
52 public abstract void requestUpdateVolume(MediaRoute2Info route, int delta);
53
54 @NonNull
55 public String getUniqueId() {
56 return mUniqueId;
57 }
58
59 @Nullable
60 public MediaRoute2ProviderInfo getProviderInfo() {
61 return mProviderInfo;
62 }
63
64 void setAndNotifyProviderInfo(MediaRoute2ProviderInfo info) {
65 //TODO: check if info is not updated
66 if (info == null) {
67 mProviderInfo = null;
68 } else {
69 mProviderInfo = new MediaRoute2ProviderInfo.Builder(info)
70 .setUniqueId(mUniqueId)
71 .build();
72 }
73 if (mCallback != null) {
74 mCallback.onProviderStateChanged(this);
75 }
76 }
77
78 public boolean hasComponentName(String packageName, String className) {
79 return mComponentName.getPackageName().equals(packageName)
80 && mComponentName.getClassName().equals(className);
81 }
82
83 public interface Callback {
Kyunglyul Hyunf7d5e042019-11-11 13:56:28 +090084 void onProviderStateChanged(@Nullable MediaRoute2Provider provider);
85 void onRouteSelected(@NonNull MediaRoute2ProviderProxy provider,
86 @NonNull String clientPackageName, @NonNull MediaRoute2Info route,
87 @Nullable Bundle controlHints, int seq);
Hyundo Moon63a05402019-12-19 20:13:56 +090088 void onSessionCreated(@NonNull MediaRoute2Provider provider,
89 @Nullable RouteSessionInfo sessionInfo, @Nullable Bundle controlHints,
90 int requestId);
Kyunglyul Hyun0332e9a22019-11-20 01:39:25 +000091 }
92}