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 com.android.server.broadcastradio.hal1;
18
19import android.annotation.NonNull;
20import android.Manifest;
21import android.content.Context;
22import android.content.pm.PackageManager;
23import android.hardware.radio.IRadioService;
24import android.hardware.radio.ITuner;
25import android.hardware.radio.ITunerCallback;
26import android.hardware.radio.RadioManager;
27import android.os.ParcelableException;
28
29import com.android.server.SystemService;
30
31import java.util.List;
32import java.util.Objects;
33
34public 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
43    protected void finalize() throws Throwable {
44        nativeFinalize(mNativeContext);
45        super.finalize();
46    }
47
48    private native long nativeInit();
49    private native void nativeFinalize(long nativeContext);
50    private native List<RadioManager.ModuleProperties> nativeLoadModules(long nativeContext);
51    private native Tuner nativeOpenTuner(long nativeContext, int moduleId,
52            RadioManager.BandConfig config, boolean withAudio, ITunerCallback callback);
53
54    public @NonNull List<RadioManager.ModuleProperties> loadModules() {
55        synchronized (mLock) {
56            return Objects.requireNonNull(nativeLoadModules(mNativeContext));
57        }
58    }
59
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