blob: 9a49c166e2b2c7c481cebf06cc28b6bf33062993 [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;
Kyunglyul Hyunf7d5e042019-11-11 13:56:28 +090025import android.os.Bundle;
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
45 public abstract void requestSelectRoute(String packageName, String routeId, int seq);
46 public abstract void unselectRoute(String packageName, String routeId);
47 public abstract void sendControlRequest(MediaRoute2Info route, Intent request);
48 public abstract void requestSetVolume(MediaRoute2Info route, int volume);
49 public abstract void requestUpdateVolume(MediaRoute2Info route, int delta);
50
51 @NonNull
52 public String getUniqueId() {
53 return mUniqueId;
54 }
55
56 @Nullable
57 public MediaRoute2ProviderInfo getProviderInfo() {
58 return mProviderInfo;
59 }
60
61 void setAndNotifyProviderInfo(MediaRoute2ProviderInfo info) {
62 //TODO: check if info is not updated
63 if (info == null) {
64 mProviderInfo = null;
65 } else {
66 mProviderInfo = new MediaRoute2ProviderInfo.Builder(info)
67 .setUniqueId(mUniqueId)
68 .build();
69 }
70 if (mCallback != null) {
71 mCallback.onProviderStateChanged(this);
72 }
73 }
74
75 public boolean hasComponentName(String packageName, String className) {
76 return mComponentName.getPackageName().equals(packageName)
77 && mComponentName.getClassName().equals(className);
78 }
79
80 public interface Callback {
Kyunglyul Hyunf7d5e042019-11-11 13:56:28 +090081 void onProviderStateChanged(@Nullable MediaRoute2Provider provider);
82 void onRouteSelected(@NonNull MediaRoute2ProviderProxy provider,
83 @NonNull String clientPackageName, @NonNull MediaRoute2Info route,
84 @Nullable Bundle controlHints, int seq);
Kyunglyul Hyun0332e9a22019-11-20 01:39:25 +000085 }
86}