1 /** 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 17 package com.android.server.broadcastradio.hal2; 18 19 import android.annotation.NonNull; 20 import android.hardware.broadcastradio.V2_0.ITunerCallback; 21 import android.hardware.broadcastradio.V2_0.ProgramInfo; 22 import android.hardware.broadcastradio.V2_0.ProgramListChunk; 23 import android.hardware.broadcastradio.V2_0.ProgramSelector; 24 import android.hardware.broadcastradio.V2_0.VendorKeyValue; 25 import android.os.RemoteException; 26 import android.util.Slog; 27 28 import java.util.ArrayList; 29 import java.util.Objects; 30 31 class TunerCallback extends ITunerCallback.Stub { 32 private static final String TAG = "BcRadio2Srv.cb"; 33 34 final android.hardware.radio.ITunerCallback mClientCb; 35 36 interface RunnableThrowingRemoteException { 37 void run() throws RemoteException; 38 } 39 40 TunerCallback(@NonNull android.hardware.radio.ITunerCallback clientCallback) { 41 mClientCb = Objects.requireNonNull(clientCallback); 42 } 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 53 public void onTuneFailed(int result, ProgramSelector selector) { 54 dispatch(() -> mClientCb.onTuneFailed(result, Convert.programSelectorFromHal(selector))); 55 } 56 57 @Override 58 public void onCurrentProgramInfoChanged(ProgramInfo info) { 59 dispatch(() -> mClientCb.onCurrentProgramInfoChanged(Convert.programInfoFromHal(info))); 60 } 61 62 @Override 63 public void onProgramListUpdated(ProgramListChunk chunk) { 64 dispatch(() -> mClientCb.onProgramListUpdated(Convert.programListChunkFromHal(chunk))); 65 } 66 67 @Override 68 public void onAntennaStateChange(boolean connected) { 69 dispatch(() -> mClientCb.onAntennaState(connected)); 70 } 71 72 @Override 73 public void onParametersUpdated(ArrayList<VendorKeyValue> parameters) { 74 dispatch(() -> mClientCb.onParametersUpdated(Convert.vendorInfoFromHal(parameters))); 75 } 76 } 77