blob: 3c4b49c91cf251b64f6e44b781095210ff738f73 [file] [log] [blame]
Tomasz Wasilczykf58305d2017-12-28 14:03:15 -08001/**
2 * Copyright (C) 2017 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.broadcastradio.hal2;
18
19import android.annotation.NonNull;
20import android.hardware.broadcastradio.V2_0.ITunerCallback;
21import android.hardware.broadcastradio.V2_0.ProgramInfo;
22import android.hardware.broadcastradio.V2_0.ProgramListChunk;
23import android.hardware.broadcastradio.V2_0.ProgramSelector;
24import android.hardware.broadcastradio.V2_0.VendorKeyValue;
25import android.os.RemoteException;
26import android.util.Slog;
27
28import java.util.ArrayList;
29import java.util.Objects;
30
31class TunerCallback extends ITunerCallback.Stub {
32 private static final String TAG = "BcRadio2Srv.cb";
33
Tomasz Wasilczykca98cde2018-01-04 12:26:40 -080034 final android.hardware.radio.ITunerCallback mClientCb;
Tomasz Wasilczykf58305d2017-12-28 14:03:15 -080035
36 interface RunnableThrowingRemoteException {
37 void run() throws RemoteException;
38 }
39
40 TunerCallback(@NonNull android.hardware.radio.ITunerCallback clientCallback) {
Tomasz Wasilczykca98cde2018-01-04 12:26:40 -080041 mClientCb = Objects.requireNonNull(clientCallback);
Tomasz Wasilczykf58305d2017-12-28 14:03:15 -080042 }
43
44 static void dispatch(RunnableThrowingRemoteException func) {
45 try {
46 func.run();
47 } catch (RemoteException ex) {
48 Slog.e(TAG, "callback call failed", ex);
49 }
50 }
51
52 @Override
Tomasz Wasilczyk3b4465e2018-01-14 21:47:44 -080053 public void onTuneFailed(int result, ProgramSelector selector) {
54 dispatch(() -> mClientCb.onTuneFailed(result, Convert.programSelectorFromHal(selector)));
55 }
Tomasz Wasilczykf58305d2017-12-28 14:03:15 -080056
57 @Override
Tomasz Wasilczyk3b4465e2018-01-14 21:47:44 -080058 public void onCurrentProgramInfoChanged(ProgramInfo info) {
59 dispatch(() -> mClientCb.onCurrentProgramInfoChanged(Convert.programInfoFromHal(info)));
60 }
Tomasz Wasilczykf58305d2017-12-28 14:03:15 -080061
62 @Override
Tomasz Wasilczyk436128f2018-01-08 16:46:09 -080063 public void onProgramListUpdated(ProgramListChunk chunk) {
64 dispatch(() -> mClientCb.onProgramListUpdated(Convert.programListChunkFromHal(chunk)));
65 }
Tomasz Wasilczykf58305d2017-12-28 14:03:15 -080066
67 @Override
Tomasz Wasilczyk3b4465e2018-01-14 21:47:44 -080068 public void onAntennaStateChange(boolean connected) {
69 dispatch(() -> mClientCb.onAntennaState(connected));
70 }
Tomasz Wasilczykf58305d2017-12-28 14:03:15 -080071
72 @Override
Tomasz Wasilczyk3b4465e2018-01-14 21:47:44 -080073 public void onParametersUpdated(ArrayList<VendorKeyValue> parameters) {
74 dispatch(() -> mClientCb.onParametersUpdated(Convert.vendorInfoFromHal(parameters)));
75 }
Tomasz Wasilczykf58305d2017-12-28 14:03:15 -080076}