• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.hal1;
18 
19 import android.annotation.NonNull;
20 import android.Manifest;
21 import android.content.Context;
22 import android.content.pm.PackageManager;
23 import android.hardware.radio.IRadioService;
24 import android.hardware.radio.ITuner;
25 import android.hardware.radio.ITunerCallback;
26 import android.hardware.radio.RadioManager;
27 import android.os.ParcelableException;
28 
29 import com.android.server.SystemService;
30 
31 import java.util.List;
32 import java.util.Objects;
33 
34 public class BroadcastRadioService {
35     /**
36      * This field is used by native code, do not access or modify.
37      */
38     private final long mNativeContext = nativeInit();
39 
40     private final Object mLock = new Object();
41 
42     @Override
finalize()43     protected void finalize() throws Throwable {
44         nativeFinalize(mNativeContext);
45         super.finalize();
46     }
47 
nativeInit()48     private native long nativeInit();
nativeFinalize(long nativeContext)49     private native void nativeFinalize(long nativeContext);
nativeLoadModules(long nativeContext)50     private native List<RadioManager.ModuleProperties> nativeLoadModules(long nativeContext);
nativeOpenTuner(long nativeContext, int moduleId, RadioManager.BandConfig config, boolean withAudio, ITunerCallback callback)51     private native Tuner nativeOpenTuner(long nativeContext, int moduleId,
52             RadioManager.BandConfig config, boolean withAudio, ITunerCallback callback);
53 
loadModules()54     public @NonNull List<RadioManager.ModuleProperties> loadModules() {
55         synchronized (mLock) {
56             return Objects.requireNonNull(nativeLoadModules(mNativeContext));
57         }
58     }
59 
openTuner(int moduleId, RadioManager.BandConfig bandConfig, boolean withAudio, @NonNull ITunerCallback callback)60     public ITuner openTuner(int moduleId, RadioManager.BandConfig bandConfig,
61             boolean withAudio, @NonNull ITunerCallback callback) {
62         synchronized (mLock) {
63             return nativeOpenTuner(mNativeContext, moduleId, bandConfig, withAudio, callback);
64         }
65     }
66 }
67