Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 27926edc authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Indicate whether BandConfig initialization is required or not.

The broadcastradio HAL 1.x requires waiting for onConfigChanged callback
to indicate the initialization is done, while HAL 2.0 does not have the
config setting (at the tuner session level) at all.

This change makes it possible to cleanly workaround race condition in the
radio app retaining support for both HAL revisions. Future versions of the
RadioManager will provide a method to open a session without taking care
about these nuances.

Bug: 74353024
Test: manual
Change-Id: I5de2d5e5c33626fcf0cfbbaf121d0b13e53d0bae
parent f45b3a11
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2103,6 +2103,7 @@ package android.hardware.radio {
    method public java.lang.String getVersion();
    method public boolean isBackgroundScanningSupported();
    method public boolean isCaptureSupported();
    method public boolean isInitializationRequired();
    method public boolean isProgramIdentifierSupported(int);
    method public boolean isProgramTypeSupported(int);
    method public void writeToParcel(android.os.Parcel, int);
+22 −3
Original line number Diff line number Diff line
@@ -211,6 +211,7 @@ public class RadioManager {
        private final String mSerial;
        private final int mNumTuners;
        private final int mNumAudioSources;
        private final boolean mIsInitializationRequired;
        private final boolean mIsCaptureSupported;
        private final BandDescriptor[] mBands;
        private final boolean mIsBgScanSupported;
@@ -222,7 +223,8 @@ public class RadioManager {
        /** @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,
                boolean isInitializationRequired, boolean isCaptureSupported,
                BandDescriptor[] bands, boolean isBgScanSupported,
                @ProgramSelector.ProgramType int[] supportedProgramTypes,
                @ProgramSelector.IdentifierType int[] supportedIdentifierTypes,
                @Nullable Map<String, Integer> dabFrequencyTable,
@@ -236,6 +238,7 @@ public class RadioManager {
            mSerial = serial;
            mNumTuners = numTuners;
            mNumAudioSources = numAudioSources;
            mIsInitializationRequired = isInitializationRequired;
            mIsCaptureSupported = isCaptureSupported;
            mBands = bands;
            mIsBgScanSupported = isBgScanSupported;
@@ -329,6 +332,18 @@ public class RadioManager {
            return mNumAudioSources;
        }

        /**
         * Checks, if BandConfig initialization (after {@link RadioManager#openTuner})
         * is required to be done before other operations or not.
         *
         * If it is, the client has to wait for {@link RadioTuner.Callback#onConfigurationChanged}
         * callback before executing any other operations. Otherwise, such operation will fail
         * returning {@link RadioManager#STATUS_INVALID_OPERATION} error code.
         */
        public boolean isInitializationRequired() {
            return mIsInitializationRequired;
        }

        /** {@code true} if audio capture is possible from radio tuner output.
         * This indicates if routing to audio devices not connected to the same HAL as the FM radio
         * is possible (e.g. to USB) or DAR (Digital Audio Recorder) feature can be implemented.
@@ -419,6 +434,7 @@ public class RadioManager {
            mSerial = in.readString();
            mNumTuners = in.readInt();
            mNumAudioSources = in.readInt();
            mIsInitializationRequired = in.readInt() == 1;
            mIsCaptureSupported = in.readInt() == 1;
            Parcelable[] tmp = in.readParcelableArray(BandDescriptor.class.getClassLoader());
            mBands = new BandDescriptor[tmp.length];
@@ -454,6 +470,7 @@ public class RadioManager {
            dest.writeString(mSerial);
            dest.writeInt(mNumTuners);
            dest.writeInt(mNumAudioSources);
            dest.writeInt(mIsInitializationRequired ? 1 : 0);
            dest.writeInt(mIsCaptureSupported ? 1 : 0);
            dest.writeParcelableArray(mBands, flags);
            dest.writeInt(mIsBgScanSupported ? 1 : 0);
@@ -476,6 +493,7 @@ public class RadioManager {
                    + ", mVersion=" + mVersion + ", mSerial=" + mSerial
                    + ", mNumTuners=" + mNumTuners
                    + ", mNumAudioSources=" + mNumAudioSources
                    + ", mIsInitializationRequired=" + mIsInitializationRequired
                    + ", mIsCaptureSupported=" + mIsCaptureSupported
                    + ", mIsBgScanSupported=" + mIsBgScanSupported
                    + ", mBands=" + Arrays.toString(mBands) + "]";
@@ -484,8 +502,8 @@ public class RadioManager {
        @Override
        public int hashCode() {
            return Objects.hash(mId, mServiceName, mClassId, mImplementor, mProduct, mVersion,
                mSerial, mNumTuners, mNumAudioSources, mIsCaptureSupported, mBands,
                mIsBgScanSupported, mDabFrequencyTable, mVendorInfo);
                mSerial, mNumTuners, mNumAudioSources, mIsInitializationRequired,
                mIsCaptureSupported, mBands, mIsBgScanSupported, mDabFrequencyTable, mVendorInfo);
        }

        @Override
@@ -503,6 +521,7 @@ public class RadioManager {
            if (!Objects.equals(mSerial, other.mSerial)) return false;
            if (mNumTuners != other.mNumTuners) return false;
            if (mNumAudioSources != other.mNumAudioSources) return false;
            if (mIsInitializationRequired != other.mIsInitializationRequired) return false;
            if (mIsCaptureSupported != other.mIsCaptureSupported) return false;
            if (!Objects.equals(mBands, other.mBands)) return false;
            if (mIsBgScanSupported != other.mIsBgScanSupported) return false;
+1 −0
Original line number Diff line number Diff line
@@ -232,6 +232,7 @@ class Convert {
                 * HAL implementation instance. */
                1,      // numTuners
                1,      // numAudioSources
                false,  // isInitializationRequired
                false,  // isCaptureSupported

                amfmConfigToBands(amfmConfig),
+5 −4
Original line number Diff line number Diff line
@@ -380,6 +380,7 @@ static JavaRef<jobject> ModulePropertiesFromHal(JNIEnv *env, const V1_0::Propert
    auto jProduct = make_javastr(env, prop10.product);
    auto jVersion = make_javastr(env, prop10.version);
    auto jSerial = make_javastr(env, prop10.serial);
    constexpr bool isInitializationRequired = true;
    bool isBgScanSupported = prop11 ? prop11->supportsBackgroundScanning : false;
    auto jVendorInfo = prop11 ? VendorInfoFromHal(env, prop11->vendorInfo) : nullptr;

@@ -394,9 +395,9 @@ static JavaRef<jobject> ModulePropertiesFromHal(JNIEnv *env, const V1_0::Propert
    return make_javaref(env, env->NewObject(gjni.ModuleProperties.clazz,
            gjni.ModuleProperties.cstor, moduleId, jServiceName.get(), prop10.classId,
            jImplementor.get(), jProduct.get(), jVersion.get(), jSerial.get(), prop10.numTuners,
            prop10.numAudioSources, prop10.supportsCapture, jBands.get(), isBgScanSupported,
            jSupportedProgramTypes.get(), jSupportedIdentifierTypes.get(), nullptr,
            jVendorInfo.get()));
            prop10.numAudioSources, isInitializationRequired, prop10.supportsCapture, jBands.get(),
            isBgScanSupported, jSupportedProgramTypes.get(), jSupportedIdentifierTypes.get(),
            nullptr, jVendorInfo.get()));
}

JavaRef<jobject> ModulePropertiesFromHal(JNIEnv *env, const V1_0::Properties &properties,
@@ -712,7 +713,7 @@ void register_android_server_broadcastradio_convert(JNIEnv *env) {
    gjni.ModuleProperties.clazz = MakeGlobalRefOrDie(env, modulePropertiesClass);
    gjni.ModuleProperties.cstor = GetMethodIDOrDie(env, modulePropertiesClass, "<init>",
            "(ILjava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;"
            "Ljava/lang/String;IIZ[Landroid/hardware/radio/RadioManager$BandDescriptor;Z"
            "Ljava/lang/String;IIZZ[Landroid/hardware/radio/RadioManager$BandDescriptor;Z"
            "[I[ILjava/util/Map;Ljava/util/Map;)V");

    auto programInfoClass = FindClassOrDie(env, "android/hardware/radio/RadioManager$ProgramInfo");