Kyunglyul Hyun | 0332e9a2 | 2019-11-20 01:39:25 +0000 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package com.android.server.media; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
| 21 | import android.content.ComponentName; |
| 22 | import android.content.Intent; |
| 23 | import android.media.MediaRoute2Info; |
| 24 | import android.media.MediaRoute2ProviderInfo; |
| 25 | |
| 26 | import java.util.Objects; |
| 27 | |
| 28 | abstract 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 | } |