TunerAdapter.java revision 9fa0287c1802df074d4039489dcfad712c19bcba
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 17package android.hardware.radio; 18 19import android.annotation.NonNull; 20import android.annotation.Nullable; 21import android.os.RemoteException; 22import android.util.Log; 23 24import java.util.List; 25 26/** 27 * Implements the RadioTuner interface by forwarding calls to radio service. 28 */ 29class TunerAdapter extends RadioTuner { 30 private static final String TAG = "radio.TunerAdapter"; 31 32 @NonNull private final ITuner mTuner; 33 private boolean mIsClosed = false; 34 35 TunerAdapter(ITuner tuner) { 36 if (tuner == null) { 37 throw new NullPointerException(); 38 } 39 mTuner = tuner; 40 } 41 42 @Override 43 public void close() { 44 synchronized (mTuner) { 45 if (mIsClosed) { 46 Log.d(TAG, "Tuner is already closed"); 47 return; 48 } 49 mIsClosed = true; 50 } 51 try { 52 mTuner.close(); 53 } catch (RemoteException e) { 54 Log.e(TAG, "Exception trying to close tuner", e); 55 } 56 } 57 58 @Override 59 public int setConfiguration(RadioManager.BandConfig config) { 60 try { 61 mTuner.setConfiguration(config); 62 return RadioManager.STATUS_OK; 63 } catch (IllegalArgumentException e) { 64 Log.e(TAG, "Can't set configuration", e); 65 return RadioManager.STATUS_BAD_VALUE; 66 } catch (RemoteException e) { 67 Log.e(TAG, "service died", e); 68 return RadioManager.STATUS_DEAD_OBJECT; 69 } 70 } 71 72 @Override 73 public int getConfiguration(RadioManager.BandConfig[] config) { 74 if (config == null || config.length != 1) { 75 throw new IllegalArgumentException("The argument must be an array of length 1"); 76 } 77 try { 78 config[0] = mTuner.getConfiguration(); 79 return RadioManager.STATUS_OK; 80 } catch (RemoteException e) { 81 Log.e(TAG, "service died", e); 82 return RadioManager.STATUS_DEAD_OBJECT; 83 } 84 } 85 86 @Override 87 public int setMute(boolean mute) { 88 try { 89 mTuner.setMuted(mute); 90 } catch (IllegalStateException e) { 91 Log.e(TAG, "Can't set muted", e); 92 return RadioManager.STATUS_ERROR; 93 } catch (RemoteException e) { 94 Log.e(TAG, "service died", e); 95 return RadioManager.STATUS_DEAD_OBJECT; 96 } 97 return RadioManager.STATUS_OK; 98 } 99 100 @Override 101 public boolean getMute() { 102 try { 103 return mTuner.isMuted(); 104 } catch (RemoteException e) { 105 Log.e(TAG, "service died", e); 106 return true; 107 } 108 } 109 110 @Override 111 public int step(int direction, boolean skipSubChannel) { 112 // TODO(b/36863239): forward to mTuner 113 throw new RuntimeException("Not implemented"); 114 } 115 116 @Override 117 public int scan(int direction, boolean skipSubChannel) { 118 // TODO(b/36863239): forward to mTuner 119 throw new RuntimeException("Not implemented"); 120 } 121 122 @Override 123 public int tune(int channel, int subChannel) { 124 // TODO(b/36863239): forward to mTuner 125 throw new RuntimeException("Not implemented"); 126 } 127 128 @Override 129 public int cancel() { 130 // TODO(b/36863239): forward to mTuner 131 throw new RuntimeException("Not implemented"); 132 } 133 134 @Override 135 public int getProgramInformation(RadioManager.ProgramInfo[] info) { 136 if (info == null || info.length != 1) { 137 throw new IllegalArgumentException("The argument must be an array of length 1"); 138 } 139 try { 140 return mTuner.getProgramInformation(info); 141 } catch (RemoteException e) { 142 Log.e(TAG, "service died", e); 143 return RadioManager.STATUS_DEAD_OBJECT; 144 } 145 } 146 147 @Override 148 public boolean startBackgroundScan() { 149 // TODO(b/36863239): forward to mTuner 150 throw new RuntimeException("Not implemented"); 151 } 152 153 @Override 154 public @NonNull List<RadioManager.ProgramInfo> getProgramList(@Nullable String filter) { 155 // TODO(b/36863239): forward to mTuner 156 throw new RuntimeException("Not implemented"); 157 } 158 159 @Override 160 public boolean isAnalogForced() { 161 // TODO(b/36863239): forward to mTuner 162 throw new RuntimeException("Not implemented"); 163 } 164 165 @Override 166 public void setAnalogForced(boolean isForced) { 167 // TODO(b/36863239): forward to mTuner 168 throw new RuntimeException("Not implemented"); 169 } 170 171 @Override 172 public boolean isAntennaConnected() { 173 // TODO(b/36863239): forward to mTuner 174 throw new RuntimeException("Not implemented"); 175 } 176 177 @Override 178 public boolean hasControl() { 179 // TODO(b/36863239): forward to mTuner 180 throw new RuntimeException("Not implemented"); 181 } 182} 183