1  /*
2   * Copyright (C) 2015 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 android.hardware.radio;
18  
19  import android.Manifest;
20  import android.annotation.IntDef;
21  import android.annotation.NonNull;
22  import android.annotation.Nullable;
23  import android.annotation.RequiresPermission;
24  import android.annotation.SystemApi;
25  import android.graphics.Bitmap;
26  import android.os.Handler;
27  
28  import java.lang.annotation.Retention;
29  import java.lang.annotation.RetentionPolicy;
30  import java.util.List;
31  import java.util.Map;
32  import java.util.concurrent.Executor;
33  
34  /**
35   * RadioTuner interface provides methods to control a radio tuner on the device: selecting and
36   * configuring the active band, muting/unmuting, scanning and tuning, etc...
37   *
38   * Obtain a RadioTuner interface by calling {@link RadioManager#openTuner(int,
39   * RadioManager.BandConfig, boolean, RadioTuner.Callback, Handler)}.
40   * @hide
41   */
42  @SystemApi
43  public abstract class RadioTuner {
44  
45      /** Scanning direction UP for {@link #step(int, boolean)}, {@link #scan(int, boolean)} */
46      public static final int DIRECTION_UP      = 0;
47  
48      /** Scanning directions DOWN for {@link #step(int, boolean)}, {@link #scan(int, boolean)} */
49      public static final int DIRECTION_DOWN    = 1;
50  
51      /**
52       * Close the tuner interface.
53       *
54       * <p>The {@link Callback} callback will not be called anymore and associated resources will be
55       * released. Must be called when the tuner is not needed to make hardware resources available
56       * to others.
57       * */
58      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
close()59      public abstract void close();
60  
61      /**
62       * Set the active band configuration for this module.
63       *
64       * <p>Must be a valid configuration obtained via buildConfig() from a valid BandDescriptor
65       * listed in the ModuleProperties of the module with the specified ID.
66       *
67       * @param config The desired band configuration (FmBandConfig or AmBandConfig).
68       * @return
69       * <ul>
70       *  <li>{@link RadioManager#STATUS_OK} in case of success, </li>
71       *  <li>{@link RadioManager#STATUS_ERROR} in case of unspecified error, </li>
72       *  <li>{@link RadioManager#STATUS_NO_INIT} if the native service cannot be reached, </li>
73       *  <li>{@link RadioManager#STATUS_BAD_VALUE} if parameters are invalid, </li>
74       *  <li>{@link RadioManager#STATUS_INVALID_OPERATION} if the call is out of sequence, </li>
75       *  <li>{@link RadioManager#STATUS_DEAD_OBJECT} if the binder transaction to the native
76       *  service fails, </li>
77       * </ul>
78       * @deprecated Only applicable for HAL 1.x.
79       */
80      @Deprecated
81      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
82      @RadioManager.RadioStatusType
setConfiguration(RadioManager.BandConfig config)83      public abstract int setConfiguration(RadioManager.BandConfig config);
84  
85      /**
86       * Get current configuration.
87       *
88       * @param config a BandConfig array of lengh 1 where the configuration is returned.
89       * @return
90       * <ul>
91       *  <li>{@link RadioManager#STATUS_OK} in case of success, </li>
92       *  <li>{@link RadioManager#STATUS_ERROR} in case of unspecified error, </li>
93       *  <li>{@link RadioManager#STATUS_NO_INIT} if the native service cannot be reached, </li>
94       *  <li>{@link RadioManager#STATUS_BAD_VALUE} if parameters are invalid, </li>
95       *  <li>{@link RadioManager#STATUS_INVALID_OPERATION} if the call is out of sequence, </li>
96       *  <li>{@link RadioManager#STATUS_DEAD_OBJECT} if the binder transaction to the native
97       *  service fails, </li>
98       * </ul>
99       *
100       * @deprecated Only applicable for HAL 1.x.
101       */
102      @Deprecated
103      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
104      @RadioManager.RadioStatusType
getConfiguration(RadioManager.BandConfig[] config)105      public abstract int getConfiguration(RadioManager.BandConfig[] config);
106  
107  
108      /**
109       * Set mute state.
110       *
111       * <p>When muted, the radio tuner audio source is not available for playback on
112       * any audio device. when unmuted, the radio tuner audio source is output as a media source
113       * and renderd over the audio device selected for media use case.
114       * The radio tuner audio source is muted by default when the tuner is first attached.
115       * Only effective if the tuner is attached with audio enabled.
116       *
117       * @param mute the requested mute state.
118       * @return
119       * <ul>
120       *  <li>{@link RadioManager#STATUS_OK} in case of success, </li>
121       *  <li>{@link RadioManager#STATUS_ERROR} in case of unspecified error, </li>
122       *  <li>{@link RadioManager#STATUS_NO_INIT} if the native service cannot be reached, </li>
123       *  <li>{@link RadioManager#STATUS_INVALID_OPERATION} if the call is out of sequence, </li>
124       *  <li>{@link RadioManager#STATUS_DEAD_OBJECT} if the binder transaction to the native
125       *  service fails, </li>
126       * </ul>
127       */
128      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
129      @RadioManager.RadioStatusType
setMute(boolean mute)130      public abstract int setMute(boolean mute);
131  
132      /**
133       * Get mute state.
134       *
135       * @return {@code true} if the radio tuner audio source is muted or a problem occured
136       * retrieving the mute state, {@code false} otherwise.
137       */
138      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
getMute()139      public abstract boolean getMute();
140  
141      /**
142       * Step up or down by one channel spacing.
143       *
144       * <p>The operation is asynchronous and {@link Callback#onProgramInfoChanged}
145       * will be called when step completes or {@link Callback#onTuneFailed}
146       * when timeout or canceled.
147       *
148       * <p>When this operation is called by users other than current user or system user, it is
149       * ignored silently.
150       *
151       * @param direction {@link #DIRECTION_UP} or {@link #DIRECTION_DOWN}.
152       * @param skipSubChannel indicates to skip sub channels when the configuration currently
153       * selected supports sub channel (e.g HD Radio). N/A otherwise.
154       * @return
155       * <ul>
156       *  <li>{@link RadioManager#STATUS_OK} in case of success, </li>
157       *  <li>{@link RadioManager#STATUS_ERROR} in case of unspecified error, </li>
158       *  <li>{@link RadioManager#STATUS_NO_INIT} if the native service cannot be reached, </li>
159       *  <li>{@link RadioManager#STATUS_BAD_VALUE} if parameters are invalid, </li>
160       *  <li>{@link RadioManager#STATUS_INVALID_OPERATION} if the call is out of sequence, </li>
161       *  <li>{@link RadioManager#STATUS_DEAD_OBJECT} if the binder transaction to the native
162       *  service fails, </li>
163       * </ul>
164       */
165      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
166      @RadioManager.RadioStatusType
step(int direction, boolean skipSubChannel)167      public abstract int step(int direction, boolean skipSubChannel);
168  
169      /**
170       * Scan up or down to next valid station.
171       *
172       * <p>The operation is asynchronous and {@link Callback#onProgramInfoChanged}
173       * will be called when scan completes or {@link Callback#onTuneFailed}
174       * when timeout or canceled.
175       *
176       * <p>When this operation is called by users other than current user or system user, it is
177       * ignored silently.
178       *
179       * @param direction {@link #DIRECTION_UP} or {@link #DIRECTION_DOWN}.
180       * @param skipSubChannel indicates to skip sub channels when the configuration currently
181       * selected supports sub channel (e.g HD Radio). N/A otherwise.
182       * @return
183       * <ul>
184       *  <li>{@link RadioManager#STATUS_OK} in case of success, </li>
185       *  <li>{@link RadioManager#STATUS_ERROR} in case of unspecified error, </li>
186       *  <li>{@link RadioManager#STATUS_NO_INIT} if the native service cannot be reached, </li>
187       *  <li>{@link RadioManager#STATUS_BAD_VALUE} if parameters are invalid, </li>
188       *  <li>{@link RadioManager#STATUS_INVALID_OPERATION} if the call is out of sequence, </li>
189       *  <li>{@link RadioManager#STATUS_DEAD_OBJECT} if the binder transaction to the native
190       *  service fails, </li>
191       * </ul>
192       * @deprecated Use {@link #seek(int, boolean)} instead.
193       */
194      @Deprecated
195      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
196      @RadioManager.RadioStatusType
scan(int direction, boolean skipSubChannel)197      public abstract int scan(int direction, boolean skipSubChannel);
198  
199      /**
200       * Seek up or down to next valid station.
201       *
202       * <p>The operation is asynchronous and {@link Callback#onProgramInfoChanged}
203       * will be called when seek completes or {@link Callback#onTuneFailed}
204       * when timeout or canceled.
205       *
206       * <p>When this operation is called by users other than current user or system user, it is
207       * ignore silently.
208       *
209       * @param direction {@link #DIRECTION_UP} or {@link #DIRECTION_DOWN}.
210       * @param skipSubChannel indicates to skip sub channels when the configuration currently
211       * selected supports sub channel (e.g HD Radio). N/A otherwise.
212       * @return
213       * <ul>
214       *  <li>{@link RadioManager#STATUS_OK} in case of success, </li>
215       *  <li>{@link RadioManager#STATUS_ERROR} in case of unspecified error, </li>
216       *  <li>{@link RadioManager#STATUS_NO_INIT} if the native service cannot be reached, </li>
217       *  <li>{@link RadioManager#STATUS_BAD_VALUE} if parameters are invalid, </li>
218       *  <li>{@link RadioManager#STATUS_INVALID_OPERATION} if the call is out of sequence, </li>
219       *  <li>{@link RadioManager#STATUS_DEAD_OBJECT} if the binder transaction to the native
220       *  service fails, </li>
221       * </ul>
222       */
223      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
224      @RadioManager.RadioStatusType
seek(int direction, boolean skipSubChannel)225      public int seek(int direction, boolean skipSubChannel) {
226          throw new UnsupportedOperationException("Seeking is not supported");
227      }
228  
229      /**
230       * Tune to a specific frequency.
231       *
232       * <p>The operation is asynchronous and {@link Callback#onProgramInfoChanged}
233       * will be called when tune completes or {@link Callback#onTuneFailed}
234       * when timeout or canceled.
235       *
236       * <p>When this operation is called by users other than current user or system user, it is
237       * ignored silently.
238       *
239       * @param channel the specific channel or frequency to tune to.
240       * @param subChannel the specific sub-channel to tune to. N/A if the selected configuration
241       * does not support cub channels.
242       * @return
243       * <ul>
244       *  <li>{@link RadioManager#STATUS_OK} in case of success, </li>
245       *  <li>{@link RadioManager#STATUS_ERROR} in case of unspecified error, </li>
246       *  <li>{@link RadioManager#STATUS_NO_INIT} if the native service cannot be reached, </li>
247       *  <li>{@link RadioManager#STATUS_BAD_VALUE} if parameters are invalid, </li>
248       *  <li>{@link RadioManager#STATUS_INVALID_OPERATION} if the call is out of sequence, </li>
249       *  <li>{@link RadioManager#STATUS_DEAD_OBJECT} if the binder transaction to the native
250       *  service fails, </li>
251       * </ul>
252       * @deprecated Use {@link #tune(ProgramSelector)} instead.
253       */
254      @Deprecated
255      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
256      @RadioManager.RadioStatusType
tune(int channel, int subChannel)257      public abstract int tune(int channel, int subChannel);
258  
259      /**
260       * Tune to a program.
261       *
262       * <p>The operation is asynchronous and {@link Callback#onProgramInfoChanged}
263       * will be called when tune completes or {@link Callback#onTuneFailed}
264       * when timeout or canceled.
265       *
266       * <p>When this operation is called by users other than current user or system user, it is
267       * ignored silently.
268       *
269       * @throws IllegalArgumentException if the provided selector is invalid
270       */
271      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
tune(@onNull ProgramSelector selector)272      public abstract void tune(@NonNull ProgramSelector selector);
273  
274      /**
275       * Cancel a pending scan or tune operation.
276       *
277       * <p>If an operation is pending, {@link Callback#onTuneFailed} will be called with
278       * {@link #ERROR_CANCELLED}.
279       *
280       * <p>When this operation is called by users other than current user or system
281       * user, it is ignored silently.
282       *
283       * @return
284       * <ul>
285       *  <li>{@link RadioManager#STATUS_OK} in case of success, </li>
286       *  <li>{@link RadioManager#STATUS_ERROR} in case of unspecified error, </li>
287       *  <li>{@link RadioManager#STATUS_NO_INIT} if the native service cannot be reached, </li>
288       *  <li>{@link RadioManager#STATUS_BAD_VALUE} if parameters are invalid, </li>
289       *  <li>{@link RadioManager#STATUS_INVALID_OPERATION} if the call is out of sequence, </li>
290       *  <li>{@link RadioManager#STATUS_DEAD_OBJECT} if the binder transaction to the native
291       *  service fails, </li>
292       * </ul>
293       */
294      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
295      @RadioManager.RadioStatusType
cancel()296      public abstract int cancel();
297  
298      /**
299       * Cancels traffic or emergency announcement.
300       *
301       * <p>If there was no announcement to cancel, no action is taken.
302       *
303       * <p>There is a race condition between calling cancelAnnouncement and the actual announcement
304       * being finished, so onTrafficAnnouncement / onEmergencyAnnouncement callback should be
305       * tracked with proper locking.
306       * @deprecated Only applicable for HAL 1.x.
307       */
308      @Deprecated
309      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
cancelAnnouncement()310      public abstract void cancelAnnouncement();
311  
312      /**
313       * Get current station information.
314       *
315       * @param info a ProgramInfo array of lengh 1 where the information is returned.
316       * @return
317       * <ul>
318       *  <li>{@link RadioManager#STATUS_OK} in case of success, </li>
319       *  <li>{@link RadioManager#STATUS_ERROR} in case of unspecified error, </li>
320       *  <li>{@link RadioManager#STATUS_NO_INIT} if the native service cannot be reached, </li>
321       *  <li>{@link RadioManager#STATUS_BAD_VALUE} if parameters are invalid, </li>
322       *  <li>{@link RadioManager#STATUS_INVALID_OPERATION} if the call is out of sequence, </li>
323       *  <li>{@link RadioManager#STATUS_DEAD_OBJECT} if the binder transaction to the native
324       *  service fails, </li>
325       * </ul>
326       * @deprecated Use {@link Callback#onProgramInfoChanged(RadioManager.ProgramInfo)} callback
327       * instead.
328       */
329      @Deprecated
330      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
331      @RadioManager.RadioStatusType
getProgramInformation(RadioManager.ProgramInfo[] info)332      public abstract int getProgramInformation(RadioManager.ProgramInfo[] info);
333  
334      /**
335       * Retrieves a {@link Bitmap} for the given image ID or null,
336       * if the image was missing from the tuner.
337       *
338       * <p>This involves doing a call to the tuner, so the bitmap should be cached
339       * on the application side.
340       *
341       * <p>If the method returns null for non-zero ID, it means the image was
342       * updated on the tuner side. There is a race conditon between fetching
343       * image for an old ID and tuner updating the image (and cleaning up the
344       * old image). In such case, a new ProgramInfo with updated image id will
345       * be sent with a {@link Callback#onProgramInfoChanged(RadioManager.ProgramInfo)}
346       * callback.
347       *
348       * @param id The image identifier, retrieved with
349       *           {@link RadioMetadata#getBitmapId(String)}.
350       * @return A {@link Bitmap} or null.
351       * @throws IllegalArgumentException if id==0
352       * @hide This API is not thoroughly elaborated yet
353       */
354      @SuppressWarnings("HiddenAbstractMethod")
355      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
getMetadataImage(int id)356      public abstract @Nullable Bitmap getMetadataImage(int id);
357  
358      /**
359       * Initiates a background scan to update internally cached program list.
360       *
361       * <p>It may not be necessary to initiate the scan explicitly - the scan MAY be performed on
362       * boot.
363       *
364       * <p>The operation is asynchronous and {@link Callback} backgroundScanComplete or onError will
365       * be called if the return value of this call was {@code true}. As result of this call
366       * programListChanged may be triggered (if the scanned list differs).
367       *
368       * @return {@code true} if the scan was properly scheduled, {@code false} if the scan feature
369       * is unavailable; ie. temporarily due to ongoing foreground playback in single-tuner device
370       * or permanently if the feature is not supported
371       * (see ModuleProperties#isBackgroundScanningSupported()).
372       * @deprecated Only applicable for HAL 1.x.
373       */
374      @Deprecated
375      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
startBackgroundScan()376      public abstract boolean startBackgroundScan();
377  
378      /**
379       * Get the list of discovered radio stations.
380       *
381       * <p>To get the full list, set filter to null or empty map.
382       * Keys must be prefixed with unique vendor Java-style namespace,
383       * eg. 'com.somecompany.parameter1'.
384       *
385       * @param vendorFilter vendor-specific selector for radio stations.
386       * @return a list of radio stations.
387       * @throws IllegalStateException if the scan is in progress or has not been started,
388       *         startBackgroundScan() call may fix it.
389       * @throws IllegalArgumentException if the vendorFilter argument is not valid.
390       * @deprecated Use {@link #getDynamicProgramList(ProgramList.Filter)} instead.
391       */
392      @Deprecated
393      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
394      public abstract @NonNull List<RadioManager.ProgramInfo>
getProgramList(@ullable Map<String, String> vendorFilter)395              getProgramList(@Nullable Map<String, String> vendorFilter);
396  
397      /**
398       * Get the dynamic list of discovered radio stations.
399       *
400       * <p>The list object is updated asynchronously; to get the updates register
401       * with {@link ProgramList#registerListCallback(ProgramList.ListCallback)}
402       * or {@link ProgramList#registerListCallback(Executor, ProgramList.ListCallback)}.
403       *
404       * <p>When the returned object is no longer used, it must be closed.
405       *
406       * @param filter filter for the list, or null to get the full list.
407       * @return the dynamic program list object, close it after use
408       *         or {@code null} if program list is not supported by the tuner
409       */
410      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
getDynamicProgramList(@ullable ProgramList.Filter filter)411      public @Nullable ProgramList getDynamicProgramList(@Nullable ProgramList.Filter filter) {
412          return null;
413      }
414  
415      /**
416       * Checks, if the analog playback is forced, see setAnalogForced.
417       *
418       * @throws IllegalStateException if the switch is not supported at current
419       *         configuration.
420       * @return {@code true} if analog is forced, {@code false} otherwise.
421       * @deprecated Use {@link #isConfigFlagSet(int)} instead.
422       */
423      @Deprecated
424      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
isAnalogForced()425      public abstract boolean isAnalogForced();
426  
427      /**
428       * Forces the analog playback for the supporting radio technology.
429       *
430       * <p>User may disable digital playback for FM HD Radio or hybrid FM/DAB with
431       * this option. This is purely user choice, ie. does not reflect digital-
432       * analog handover managed from the HAL implementation side.
433       *
434       * <p>Some radio technologies may not support this, ie. DAB.
435       *
436       * @param isForced {@code true} to force analog, {@code false} for a default behaviour.
437       * @throws IllegalStateException if the switch is not supported at current
438       *         configuration.
439       * @deprecated Use {@link #setConfigFlag(int, boolean)}  instead.
440       */
441      @Deprecated
442      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
setAnalogForced(boolean isForced)443      public abstract void setAnalogForced(boolean isForced);
444  
445      /**
446       * Checks, if a given config flag is supported
447       *
448       * @param flag Flag to check.
449       * @return True, if the flag is supported.
450       */
451      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
isConfigFlagSupported(@adioManager.ConfigFlag int flag)452      public boolean isConfigFlagSupported(@RadioManager.ConfigFlag int flag) {
453          return false;
454      }
455  
456      /**
457       * Fetches the current setting of a given config flag.
458       *
459       * <p>The success/failure result is consistent with isConfigFlagSupported.
460       *
461       * @param flag Flag to fetch.
462       * @return The current value of the flag.
463       * @throws IllegalStateException if the flag is not applicable right now.
464       * @throws UnsupportedOperationException if the flag is not supported at all.
465       */
466      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
isConfigFlagSet(@adioManager.ConfigFlag int flag)467      public boolean isConfigFlagSet(@RadioManager.ConfigFlag int flag) {
468          throw new UnsupportedOperationException("isConfigFlagSet is not supported");
469      }
470  
471      /**
472       * Sets the config flag.
473       *
474       * <p>The success/failure result is consistent with isConfigFlagSupported.
475       *
476       * <p>When this operation is called by users other than current user or system user,
477       * it is ignored silently.
478       *
479       * @param flag Flag to set.
480       * @param value The new value of a given flag.
481       * @throws IllegalStateException if the flag is not applicable right now.
482       * @throws UnsupportedOperationException if the flag is not supported at all.
483       */
484      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
setConfigFlag(@adioManager.ConfigFlag int flag, boolean value)485      public void setConfigFlag(@RadioManager.ConfigFlag int flag, boolean value) {
486          throw new UnsupportedOperationException("Setting config flag is not supported");
487      }
488  
489      /**
490       * Generic method for setting vendor-specific parameter values.
491       * The framework does not interpret the parameters, they are passed
492       * in an opaque manner between a vendor application and HAL.
493       *
494       * <p>Framework does not make any assumptions on the keys or values, other than
495       * ones stated in VendorKeyValue documentation (a requirement of key
496       * prefixes).
497       * See VendorKeyValue at hardware/interfaces/broadcastradio/2.0/types.hal for
498       * HIDL 2.0 HAL or
499       * hardware/interfaces/broadcastradio/aidl/android/hardware/broadcastradio/VendorKeyValue.aidl
500       * for AIDL HAL.
501       *
502       * <p>For each pair in the result map, the key will be one of the keys
503       * contained in the input (possibly with wildcards expanded), and the value
504       * will be a vendor-specific result status (such as "OK" or an error code).
505       * The implementation may choose to return an empty map, or only return
506       * a status for a subset of the provided inputs, at its discretion.
507       *
508       * <p>Application and HAL must not use keys with unknown prefix. In particular,
509       * it must not place a key-value pair in results vector for unknown key from
510       * parameters vector - instead, an unknown key should simply be ignored.
511       * In other words, results vector may contain a subset of parameter keys
512       * (however, the framework doesn't enforce a strict subset - the only
513       * formal requirement is vendor domain prefix for keys).
514       *
515       * <p>When this operation is called by users other than current user or system user,
516       * it is ignored silently.
517       *
518       * @param parameters Vendor-specific key-value pairs.
519       * @return Operation completion status for parameters being set.
520       */
521      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
522      public @NonNull Map<String, String>
setParameters(@onNull Map<String, String> parameters)523              setParameters(@NonNull Map<String, String> parameters) {
524          throw new UnsupportedOperationException("Setting parameters is not supported");
525      }
526  
527      /**
528       * Generic method for retrieving vendor-specific parameter values.
529       * The framework does not interpret the parameters, they are passed
530       * in an opaque manner between a vendor application and HAL.
531       *
532       * <p>Framework does not cache set/get requests, so it's possible for
533       * getParameter to return a different value than previous setParameter call.
534       *
535       * <p>The syntax and semantics of keys are up to the vendor (as long as prefix
536       * rules are obeyed). For instance, vendors may include some form of
537       * wildcard support. In such case, result vector may be of different size
538       * than requested keys vector. However, wildcards are not recognized by
539       * framework and they are passed as-is to the HAL implementation.
540       *
541       * <p>Unknown keys must be ignored and not placed into results vector.
542       *
543       * @param keys Parameter keys to fetch.
544       * @return Vendor-specific key-value pairs.
545       */
546      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
547      public @NonNull Map<String, String>
getParameters(@onNull List<String> keys)548              getParameters(@NonNull List<String> keys) {
549          throw new UnsupportedOperationException("Getting parameters is not supported");
550      }
551  
552      /**
553       * Get current antenna connection state for current configuration.
554       * Only valid if a configuration has been applied.
555       * @return {@code true} if the antenna is connected, {@code false} otherwise.
556       *
557       * @deprecated Use {@link Callback#onAntennaState(boolean)} callback instead
558       */
559      @Deprecated
560      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
isAntennaConnected()561      public abstract boolean isAntennaConnected();
562  
563      /**
564       * Indicates if this client actually controls the tuner.
565       *
566       * <p>Control is always granted after
567       * {@link RadioManager#openTuner(int,
568       * RadioManager.BandConfig, boolean, Callback, Handler)}
569       * returns a non null tuner interface.
570       * Control is lost when another client opens an interface on the same tuner.
571       * When this happens, {@link Callback#onControlChanged(boolean)} is received.
572       * The client can either wait for control to be returned (which is indicated by the same
573       * callback) or close and reopen the tuner interface.
574       *
575       * @return {@code true} if this interface controls the tuner,
576       * {@code false} otherwise or if a problem occured retrieving the state.
577       */
578      @RequiresPermission(Manifest.permission.ACCESS_BROADCAST_RADIO)
hasControl()579      public abstract boolean hasControl();
580  
581      /** Indicates a failure of radio IC or driver.
582       *
583       * <p>The application must close and re open the tuner
584       *
585       * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
586       */
587      @Deprecated
588      public static final int ERROR_HARDWARE_FAILURE = 0;
589      /** Indicates a failure of the radio service.
590       *
591       * <p>The application must close and re open the tuner
592       * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
593       */
594      @Deprecated
595      public static final  int ERROR_SERVER_DIED = 1;
596      /** A pending seek or tune operation was cancelled
597       * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
598       */
599      @Deprecated
600      public static final  int ERROR_CANCELLED = 2;
601      /** A pending seek or tune operation timed out
602       * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
603       */
604      @Deprecated
605      public static final  int ERROR_SCAN_TIMEOUT = 3;
606      /** The requested configuration could not be applied
607       * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
608       */
609      @Deprecated
610      public static final  int ERROR_CONFIG = 4;
611      /** Background scan was interrupted due to hardware becoming temporarily unavailable.
612       * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
613       */
614      @Deprecated
615      public static final int ERROR_BACKGROUND_SCAN_UNAVAILABLE = 5;
616      /** Background scan failed due to other error, ie. HW failure.
617       * @deprecated See {@link RadioTuner.Callback#onError(int)} callback.
618       */
619      @Deprecated
620      public static final int ERROR_BACKGROUND_SCAN_FAILED = 6;
621      /** Result when a tune, seek, or step operation runs without error.
622       */
623      public static final int TUNER_RESULT_OK = 0;
624      /** Result when internal error occurs in HAL.
625       * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
626       */
627      public static final int TUNER_RESULT_INTERNAL_ERROR = 1;
628      /** Result used when the input argument for the method is invalid.
629       * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
630       */
631      public static final int TUNER_RESULT_INVALID_ARGUMENTS = 2;
632      /** Result when HAL is of invalid state.
633       * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
634       */
635      public static final int TUNER_RESULT_INVALID_STATE = 3;
636      /** Result when the operation is not supported.
637       * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
638       */
639      public static final int TUNER_RESULT_NOT_SUPPORTED = 4;
640      /** Result when a tune, seek, or step operation is timeout
641       * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
642       */
643      public static final int TUNER_RESULT_TIMEOUT = 5;
644      /** Result when a tune, seek, or step operation is canceled before processed.
645       * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
646       */
647      public static final int TUNER_RESULT_CANCELED = 6;
648      /** Result when a tune, seek, or step operation fails due to unknown error.
649       * See {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} callback.
650       */
651      public static final int TUNER_RESULT_UNKNOWN_ERROR = 7;
652  
653      /**
654       *  Tuning operation result types
655       *
656       * @hide
657       */
658      @IntDef(prefix = { "TUNER_RESULT_" }, value = {
659              TUNER_RESULT_OK,
660              TUNER_RESULT_INTERNAL_ERROR,
661              TUNER_RESULT_INVALID_ARGUMENTS,
662              TUNER_RESULT_INVALID_STATE,
663              TUNER_RESULT_NOT_SUPPORTED,
664              TUNER_RESULT_TIMEOUT,
665              TUNER_RESULT_CANCELED,
666              TUNER_RESULT_UNKNOWN_ERROR,
667      })
668      @Retention(RetentionPolicy.SOURCE)
669      public @interface TunerResultType{}
670  
671      /**
672       * Callback provided by the client application when opening a {@link RadioTuner}
673       * to receive asynchronous operation results, updates and error notifications.
674       */
675      public static abstract class Callback {
676          /**
677           * onError() is called when an error occured while performing an asynchronous
678           * operation of when the hardware or system service experiences a problem.
679           * status is one of {@link #ERROR_HARDWARE_FAILURE}, {@link #ERROR_SERVER_DIED},
680           * {@link #ERROR_CANCELLED}, {@link #ERROR_SCAN_TIMEOUT},
681           * {@link #ERROR_CONFIG}
682           *
683           * @deprecated Use {@link RadioTuner.Callback#onTuneFailed(int, ProgramSelector)} for
684           *             tune, scan and step; other use cases (configuration, background scan)
685           *             are already deprecated.
686           */
onError(int status)687          public void onError(int status) {}
688  
689          /**
690           * Called when tune, scan or step operation fails.
691           *
692           * @param result cause of the failure
693           * @param selector ProgramSelector argument of tune that failed;
694           *                 null for scan and step.
695           */
onTuneFailed(@unerResultType int result, @Nullable ProgramSelector selector)696          public void onTuneFailed(@TunerResultType int result, @Nullable ProgramSelector selector) {}
697  
698          /**
699           * onConfigurationChanged() is called upon successful completion of
700           * {@link RadioManager#openTuner(int, RadioManager.BandConfig, boolean, Callback, Handler)}
701           * or {@link RadioTuner#setConfiguration(RadioManager.BandConfig)}
702           *
703           * @deprecated Only applicable for HAL 1.x.
704           */
705          @Deprecated
onConfigurationChanged(RadioManager.BandConfig config)706          public void onConfigurationChanged(RadioManager.BandConfig config) {}
707  
708          /**
709           * Called when program info (including metadata) for the current program has changed.
710           *
711           * <p>It happens either upon successful completion of {@link RadioTuner#step(int, boolean)},
712           * {@link RadioTuner#scan(int, boolean)}, {@link RadioTuner#tune(int, int)}; when
713           * a switching to alternate frequency occurs; or when metadata is updated.
714           */
onProgramInfoChanged(RadioManager.ProgramInfo info)715          public void onProgramInfoChanged(RadioManager.ProgramInfo info) {}
716  
717          /**
718           * Called when metadata is updated for the current program.
719           *
720           * @deprecated Use {@link #onProgramInfoChanged(RadioManager.ProgramInfo)} instead.
721           */
722          @Deprecated
onMetadataChanged(RadioMetadata metadata)723          public void onMetadataChanged(RadioMetadata metadata) {}
724  
725          /**
726           * onTrafficAnnouncement() is called when a traffic announcement starts and stops.
727           */
onTrafficAnnouncement(boolean active)728          public void onTrafficAnnouncement(boolean active) {}
729          /**
730           * onEmergencyAnnouncement() is called when an emergency annoucement starts and stops.
731           */
onEmergencyAnnouncement(boolean active)732          public void onEmergencyAnnouncement(boolean active) {}
733          /**
734           * onAntennaState() is called when the antenna is connected or disconnected.
735           */
onAntennaState(boolean connected)736          public void onAntennaState(boolean connected) {}
737          /**
738           * onControlChanged() is called when the client loses or gains control of the radio tuner.
739           * The control is always granted after a successful call to
740           * {@link RadioManager#openTuner(int, RadioManager.BandConfig, boolean, Callback, Handler)}.
741           * If another client opens the same tuner, onControlChanged() will be called with
742           * control set to {@code false} to indicate loss of control.
743           * At this point, RadioTuner APIs other than getters will return
744           * {@link RadioManager#STATUS_INVALID_OPERATION}.
745           * When the other client releases the tuner, onControlChanged() will be called
746           * with control set to {@code true}.
747           */
onControlChanged(boolean control)748          public void onControlChanged(boolean control) {}
749  
750          /**
751           * onBackgroundScanAvailabilityChange() is called when background scan
752           * feature becomes available or not.
753           *
754           * @param isAvailable true, if the tuner turned temporarily background-
755           *                    capable, false in the other case.
756           */
onBackgroundScanAvailabilityChange(boolean isAvailable)757          public void onBackgroundScanAvailabilityChange(boolean isAvailable) {}
758  
759          /**
760           * Called when a background scan completes successfully.
761           */
onBackgroundScanComplete()762          public void onBackgroundScanComplete() {}
763  
764          /**
765           * Called when available program list changed.
766           *
767           * Use {@link RadioTuner#getProgramList(Map)} to get an actual list.
768           */
onProgramListChanged()769          public void onProgramListChanged() {}
770  
771          /**
772           * Called when config flags are updated asynchronously due to internal events
773           * in broadcast radio HAL.
774           *
775           * {@link RadioTuner#setConfigFlag(int, boolean)} must not trigger this
776           * callback.
777           *
778           * @param flag Config flag updated
779           * @param value Value of the updated config flag
780           */
onConfigFlagUpdated(@adioManager.ConfigFlag int flag, boolean value)781          public void onConfigFlagUpdated(@RadioManager.ConfigFlag int flag, boolean value) {}
782  
783          /**
784           * Generic callback for passing updates to vendor-specific parameter values.
785           *
786           * <p>The framework does not interpret the parameters, they are passed
787           * in an opaque manner between a vendor application and HAL.
788           *
789           * <p>It's up to the HAL implementation if and how to implement this callback,
790           * as long as it obeys the prefix rule. In particular, only selected keys
791           * may be notified this way. However, setParameters must not trigger
792           * this callback, while an internal event can change parameters
793           * asynchronously.
794           *
795           * @param parameters Vendor-specific key-value pairs.
796           */
onParametersUpdated(@onNull Map<String, String> parameters)797          public void onParametersUpdated(@NonNull Map<String, String> parameters) {}
798      }
799  
800  }
801  
802