• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2018 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.car.radio.utils;
18 
19 import android.annotation.NonNull;
20 import android.hardware.radio.ProgramSelector;
21 import android.hardware.radio.RadioManager;
22 
23 import com.android.car.broadcastradio.support.platform.ProgramSelectorExt;
24 import com.android.car.radio.storage.RadioStorage;
25 
26 /**
27  * Helper methods for android.hardware.radio.ProgramSelector.
28  *
29  * Most probably, this code will end up refactored out, less likely pushed to the platform.
30  */
31 public class ProgramSelectorUtils {
32     /**
33      * Returns AM/FM band for a given ProgramSelector.
34      *
35      * @param sel ProgramSelector to check.
36      * @return {@link RadioManager#BAND_FM} if sel is FM program,
37      *         {@link RadioManager#BAND_AM} if sel is AM program,
38      *         {@link RadioStorage#INVALID_RADIO_BAND} otherwise.
39      */
getRadioBand(@onNull ProgramSelector sel)40     public static int getRadioBand(@NonNull ProgramSelector sel) {
41         if (!ProgramSelectorExt.isAmFmProgram(sel)) return RadioStorage.INVALID_RADIO_BAND;
42         if (!ProgramSelectorExt.hasId(sel, ProgramSelector.IDENTIFIER_TYPE_AMFM_FREQUENCY)) {
43             return RadioStorage.INVALID_RADIO_BAND;
44         }
45 
46         long freq = sel.getFirstId(ProgramSelector.IDENTIFIER_TYPE_AMFM_FREQUENCY);
47         if (ProgramSelectorExt.isAmFrequency(freq)) return RadioManager.BAND_AM;
48         if (ProgramSelectorExt.isFmFrequency(freq)) return RadioManager.BAND_FM;
49 
50         return RadioStorage.INVALID_RADIO_BAND;
51     }
52 }
53