blob: 91c9253269a378bb18f47b4138c535bcfa22944d [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;
25
26import java.util.Objects;
27
28abstract class MediaRoute2Provider {
29 final ComponentName mComponentName;
30 final String mUniqueId;
31
32 private Callback mCallback;
33 private MediaRoute2ProviderInfo mProviderInfo;
34
35 MediaRoute2Provider(@NonNull ComponentName componentName) {
36 mComponentName = Objects.requireNonNull(componentName, "Component name must not be null.");
37 mUniqueId = componentName.flattenToShortString();
38 }
39
40 public void setCallback(MediaRoute2ProviderProxy.Callback callback) {
41 mCallback = callback;
42 }
43
44 public abstract void requestSelectRoute(String packageName, String routeId, int seq);
45 public abstract void unselectRoute(String packageName, String routeId);
46 public abstract void sendControlRequest(MediaRoute2Info route, Intent request);
47 public abstract void requestSetVolume(MediaRoute2Info route, int volume);
48 public abstract void requestUpdateVolume(MediaRoute2Info route, int delta);
49
50 @NonNull
51 public String getUniqueId() {
52 return mUniqueId;
53 }
54
55 @Nullable
56 public MediaRoute2ProviderInfo getProviderInfo() {
57 return mProviderInfo;
58 }
59
60 void setAndNotifyProviderInfo(MediaRoute2ProviderInfo info) {
61 //TODO: check if info is not updated
62 if (info == null) {
63 mProviderInfo = null;
64 } else {
65 mProviderInfo = new MediaRoute2ProviderInfo.Builder(info)
66 .setUniqueId(mUniqueId)
67 .build();
68 }
69 if (mCallback != null) {
70 mCallback.onProviderStateChanged(this);
71 }
72 }
73
74 public boolean hasComponentName(String packageName, String className) {
75 return mComponentName.getPackageName().equals(packageName)
76 && mComponentName.getClassName().equals(className);
77 }
78
79 public interface Callback {
80 void onProviderStateChanged(MediaRoute2Provider provider);
81 }
82}