Loading core/java/android/hardware/radio/RadioManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -161,7 +161,8 @@ public class RadioManager { private final Set<Integer> mSupportedIdentifierTypes; @NonNull private final Map<String, String> mVendorInfo; ModuleProperties(int id, String serviceName, int classId, String implementor, /** @hide */ public ModuleProperties(int id, String serviceName, int classId, String implementor, String product, String version, String serial, int numTuners, int numAudioSources, boolean isCaptureSupported, BandDescriptor[] bands, boolean isBgScanSupported, @ProgramSelector.ProgramType int[] supportedProgramTypes, Loading services/core/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ java_library_static { static_libs: [ "time_zone_distro", "time_zone_distro_installer", "android.hardware.broadcastradio-V2.0-java", "android.hardware.health-V1.0-java", "android.hardware.health-V2.0-java", "android.hardware.weaver-V1.0-java", Loading services/core/java/com/android/server/broadcastradio/BroadcastRadioService.java +22 −22 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.broadcastradio; import android.annotation.NonNull; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; Loading @@ -28,14 +29,16 @@ import android.os.ParcelableException; import com.android.server.SystemService; import java.util.List; import java.util.Objects; import java.util.OptionalInt; public class BroadcastRadioService extends SystemService { private final ServiceImpl mServiceImpl = new ServiceImpl(); /** * This field is used by native code, do not access or modify. */ private final long mNativeContext = nativeInit(); private final com.android.server.broadcastradio.hal1.BroadcastRadioService mHal1 = new com.android.server.broadcastradio.hal1.BroadcastRadioService(); private final com.android.server.broadcastradio.hal2.BroadcastRadioService mHal2 = new com.android.server.broadcastradio.hal2.BroadcastRadioService(); private final Object mLock = new Object(); private List<RadioManager.ModuleProperties> mModules = null; Loading @@ -44,23 +47,19 @@ public class BroadcastRadioService extends SystemService { super(context); } @Override protected void finalize() throws Throwable { nativeFinalize(mNativeContext); super.finalize(); } private native long nativeInit(); private native void nativeFinalize(long nativeContext); private native List<RadioManager.ModuleProperties> nativeLoadModules(long nativeContext); private native Tuner nativeOpenTuner(long nativeContext, int moduleId, RadioManager.BandConfig config, boolean withAudio, ITunerCallback callback); @Override public void onStart() { publishBinderService(Context.RADIO_SERVICE, mServiceImpl); } /** * Finds next available index for newly loaded modules. */ private static int getNextId(@NonNull List<RadioManager.ModuleProperties> modules) { OptionalInt max = modules.stream().mapToInt(RadioManager.ModuleProperties::getId).max(); return max.isPresent() ? max.getAsInt() + 1 : 0; } private class ServiceImpl extends IRadioService.Stub { private void enforcePolicyAccess() { if (PackageManager.PERMISSION_GRANTED != getContext().checkCallingPermission( Loading @@ -75,11 +74,8 @@ public class BroadcastRadioService extends SystemService { synchronized (mLock) { if (mModules != null) return mModules; mModules = nativeLoadModules(mNativeContext); if (mModules == null) { throw new ParcelableException(new NullPointerException( "couldn't load radio modules")); } mModules = mHal1.loadModules(); mModules.addAll(mHal2.loadModules(getNextId(mModules))); return mModules; } Loading @@ -93,7 +89,11 @@ public class BroadcastRadioService extends SystemService { throw new IllegalArgumentException("Callback must not be empty"); } synchronized (mLock) { return nativeOpenTuner(mNativeContext, moduleId, bandConfig, withAudio, callback); if (mHal2.hasModule(moduleId)) { throw new RuntimeException("Not implemented"); } else { return mHal1.openTuner(moduleId, bandConfig, withAudio, callback); } } } } Loading services/core/java/com/android/server/broadcastradio/hal1/BroadcastRadioService.java 0 → 100644 +66 −0 Original line number Diff line number Diff line /** * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.broadcastradio.hal1; import android.annotation.NonNull; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.hardware.radio.IRadioService; import android.hardware.radio.ITuner; import android.hardware.radio.ITunerCallback; import android.hardware.radio.RadioManager; import android.os.ParcelableException; import com.android.server.SystemService; import java.util.List; import java.util.Objects; public class BroadcastRadioService { /** * This field is used by native code, do not access or modify. */ private final long mNativeContext = nativeInit(); private final Object mLock = new Object(); @Override protected void finalize() throws Throwable { nativeFinalize(mNativeContext); super.finalize(); } private native long nativeInit(); private native void nativeFinalize(long nativeContext); private native List<RadioManager.ModuleProperties> nativeLoadModules(long nativeContext); private native Tuner nativeOpenTuner(long nativeContext, int moduleId, RadioManager.BandConfig config, boolean withAudio, ITunerCallback callback); public @NonNull List<RadioManager.ModuleProperties> loadModules() { synchronized (mLock) { return Objects.requireNonNull(nativeLoadModules(mNativeContext)); } } public ITuner openTuner(int moduleId, RadioManager.BandConfig bandConfig, boolean withAudio, @NonNull ITunerCallback callback) { synchronized (mLock) { return nativeOpenTuner(mNativeContext, moduleId, bandConfig, withAudio, callback); } } } services/core/java/com/android/server/broadcastradio/Convert.java→services/core/java/com/android/server/broadcastradio/hal1/Convert.java +1 −1 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.server.broadcastradio; package com.android.server.broadcastradio.hal1; import android.annotation.NonNull; import android.annotation.Nullable; Loading Loading
core/java/android/hardware/radio/RadioManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -161,7 +161,8 @@ public class RadioManager { private final Set<Integer> mSupportedIdentifierTypes; @NonNull private final Map<String, String> mVendorInfo; ModuleProperties(int id, String serviceName, int classId, String implementor, /** @hide */ public ModuleProperties(int id, String serviceName, int classId, String implementor, String product, String version, String serial, int numTuners, int numAudioSources, boolean isCaptureSupported, BandDescriptor[] bands, boolean isBgScanSupported, @ProgramSelector.ProgramType int[] supportedProgramTypes, Loading
services/core/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ java_library_static { static_libs: [ "time_zone_distro", "time_zone_distro_installer", "android.hardware.broadcastradio-V2.0-java", "android.hardware.health-V1.0-java", "android.hardware.health-V2.0-java", "android.hardware.weaver-V1.0-java", Loading
services/core/java/com/android/server/broadcastradio/BroadcastRadioService.java +22 −22 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.broadcastradio; import android.annotation.NonNull; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; Loading @@ -28,14 +29,16 @@ import android.os.ParcelableException; import com.android.server.SystemService; import java.util.List; import java.util.Objects; import java.util.OptionalInt; public class BroadcastRadioService extends SystemService { private final ServiceImpl mServiceImpl = new ServiceImpl(); /** * This field is used by native code, do not access or modify. */ private final long mNativeContext = nativeInit(); private final com.android.server.broadcastradio.hal1.BroadcastRadioService mHal1 = new com.android.server.broadcastradio.hal1.BroadcastRadioService(); private final com.android.server.broadcastradio.hal2.BroadcastRadioService mHal2 = new com.android.server.broadcastradio.hal2.BroadcastRadioService(); private final Object mLock = new Object(); private List<RadioManager.ModuleProperties> mModules = null; Loading @@ -44,23 +47,19 @@ public class BroadcastRadioService extends SystemService { super(context); } @Override protected void finalize() throws Throwable { nativeFinalize(mNativeContext); super.finalize(); } private native long nativeInit(); private native void nativeFinalize(long nativeContext); private native List<RadioManager.ModuleProperties> nativeLoadModules(long nativeContext); private native Tuner nativeOpenTuner(long nativeContext, int moduleId, RadioManager.BandConfig config, boolean withAudio, ITunerCallback callback); @Override public void onStart() { publishBinderService(Context.RADIO_SERVICE, mServiceImpl); } /** * Finds next available index for newly loaded modules. */ private static int getNextId(@NonNull List<RadioManager.ModuleProperties> modules) { OptionalInt max = modules.stream().mapToInt(RadioManager.ModuleProperties::getId).max(); return max.isPresent() ? max.getAsInt() + 1 : 0; } private class ServiceImpl extends IRadioService.Stub { private void enforcePolicyAccess() { if (PackageManager.PERMISSION_GRANTED != getContext().checkCallingPermission( Loading @@ -75,11 +74,8 @@ public class BroadcastRadioService extends SystemService { synchronized (mLock) { if (mModules != null) return mModules; mModules = nativeLoadModules(mNativeContext); if (mModules == null) { throw new ParcelableException(new NullPointerException( "couldn't load radio modules")); } mModules = mHal1.loadModules(); mModules.addAll(mHal2.loadModules(getNextId(mModules))); return mModules; } Loading @@ -93,7 +89,11 @@ public class BroadcastRadioService extends SystemService { throw new IllegalArgumentException("Callback must not be empty"); } synchronized (mLock) { return nativeOpenTuner(mNativeContext, moduleId, bandConfig, withAudio, callback); if (mHal2.hasModule(moduleId)) { throw new RuntimeException("Not implemented"); } else { return mHal1.openTuner(moduleId, bandConfig, withAudio, callback); } } } } Loading
services/core/java/com/android/server/broadcastradio/hal1/BroadcastRadioService.java 0 → 100644 +66 −0 Original line number Diff line number Diff line /** * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.broadcastradio.hal1; import android.annotation.NonNull; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.hardware.radio.IRadioService; import android.hardware.radio.ITuner; import android.hardware.radio.ITunerCallback; import android.hardware.radio.RadioManager; import android.os.ParcelableException; import com.android.server.SystemService; import java.util.List; import java.util.Objects; public class BroadcastRadioService { /** * This field is used by native code, do not access or modify. */ private final long mNativeContext = nativeInit(); private final Object mLock = new Object(); @Override protected void finalize() throws Throwable { nativeFinalize(mNativeContext); super.finalize(); } private native long nativeInit(); private native void nativeFinalize(long nativeContext); private native List<RadioManager.ModuleProperties> nativeLoadModules(long nativeContext); private native Tuner nativeOpenTuner(long nativeContext, int moduleId, RadioManager.BandConfig config, boolean withAudio, ITunerCallback callback); public @NonNull List<RadioManager.ModuleProperties> loadModules() { synchronized (mLock) { return Objects.requireNonNull(nativeLoadModules(mNativeContext)); } } public ITuner openTuner(int moduleId, RadioManager.BandConfig bandConfig, boolean withAudio, @NonNull ITunerCallback callback) { synchronized (mLock) { return nativeOpenTuner(mNativeContext, moduleId, bandConfig, withAudio, callback); } } }
services/core/java/com/android/server/broadcastradio/Convert.java→services/core/java/com/android/server/broadcastradio/hal1/Convert.java +1 −1 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.server.broadcastradio; package com.android.server.broadcastradio.hal1; import android.annotation.NonNull; import android.annotation.Nullable; Loading