OSDN Git Service

Add background scan routines and callbacks to broadcast radio HAL.
authorTomasz Wasilczyk <twasilczyk@google.com>
Mon, 13 Mar 2017 21:30:15 +0000 (14:30 -0700)
committerTomasz Wasilczyk <twasilczyk@google.com>
Thu, 23 Mar 2017 21:59:41 +0000 (14:59 -0700)
Bug: b/34054813
Test: existing VTS pass, none added.
Change-Id: I2009e73a9e5edc4752366fd84f67b5a745856441

broadcastradio/1.1/Android.bp
broadcastradio/1.1/IBroadcastRadio.hal [new file with mode: 0644]
broadcastradio/1.1/ITuner.hal
broadcastradio/1.1/ITunerCallback.hal
broadcastradio/1.1/default/BroadcastRadio.cpp
broadcastradio/1.1/default/BroadcastRadio.h
broadcastradio/1.1/default/Tuner.cpp
broadcastradio/1.1/default/Tuner.h
broadcastradio/1.1/types.hal
broadcastradio/1.1/vts/functional/VtsHalBroadcastradioV1_1TargetTest.cpp

index 570d1ae..12611dd 100644 (file)
@@ -4,6 +4,7 @@ filegroup {
     name: "android.hardware.broadcastradio@1.1_hal",
     srcs: [
         "types.hal",
+        "IBroadcastRadio.hal",
         "IBroadcastRadioFactory.hal",
         "ITuner.hal",
         "ITunerCallback.hal",
@@ -19,6 +20,7 @@ genrule {
     ],
     out: [
         "android/hardware/broadcastradio/1.1/types.cpp",
+        "android/hardware/broadcastradio/1.1/BroadcastRadioAll.cpp",
         "android/hardware/broadcastradio/1.1/BroadcastRadioFactoryAll.cpp",
         "android/hardware/broadcastradio/1.1/TunerAll.cpp",
         "android/hardware/broadcastradio/1.1/TunerCallbackAll.cpp",
@@ -34,6 +36,11 @@ genrule {
     ],
     out: [
         "android/hardware/broadcastradio/1.1/types.h",
+        "android/hardware/broadcastradio/1.1/IBroadcastRadio.h",
+        "android/hardware/broadcastradio/1.1/IHwBroadcastRadio.h",
+        "android/hardware/broadcastradio/1.1/BnHwBroadcastRadio.h",
+        "android/hardware/broadcastradio/1.1/BpHwBroadcastRadio.h",
+        "android/hardware/broadcastradio/1.1/BsBroadcastRadio.h",
         "android/hardware/broadcastradio/1.1/IBroadcastRadioFactory.h",
         "android/hardware/broadcastradio/1.1/IHwBroadcastRadioFactory.h",
         "android/hardware/broadcastradio/1.1/BnHwBroadcastRadioFactory.h",
diff --git a/broadcastradio/1.1/IBroadcastRadio.hal b/broadcastradio/1.1/IBroadcastRadio.hal
new file mode 100644 (file)
index 0000000..a6347c7
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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 android.hardware.broadcastradio@1.1;
+
+import @1.0::IBroadcastRadio;
+
+interface IBroadcastRadio extends @1.0::IBroadcastRadio {
+
+    /*
+     * Retrieve implementation properties.
+     * @return properties A Properties structure containing implementation
+     *                    description and capabilities.
+     */
+    getProperties_1_1() generates (Properties properties);
+
+};
index 4f34019..82d45c6 100644 (file)
@@ -26,7 +26,33 @@ interface ITuner extends @1.0::ITuner {
      *                NOT_INITIALIZED if another error occurs
      * @return info Current program information.
      */
-    getProgramInformation_1_1() generates(Result result, ProgramInfo info);
+    getProgramInformation_1_1() generates (Result result, ProgramInfo info);
+
+    /**
+     * Initiates a background scan to update internally cached program list.
+     *
+     * HAL client may not need to initiate the scan explicitly with this call,
+     * ie. HAL implementation MAY perform the scan on boot. It's a common
+     * practice in devices with two physical tuners with background scanning.
+     *
+     * Device must call backgroundScanComplete if the result is OK, even if the
+     * scan fails later (it must pass proper result through the callback).
+     * Otherwise, backgroundScanComplete must not be called as a result of this
+     * certain attempt. It may still be called as a response to another call to
+     * startBackgroundScan, former or latter.
+     *
+     * Device may utilize an already running (but not finished) scan for
+     * subsequent calls to startBackgroundScan, issuing a single
+     * backgroundScanComplete callback.
+     *
+     * @return result OK if the scan was properly scheduled (this does not mean
+     *                it successfully finished).
+     *                TEMPORARILY_UNAVAILABLE if the background scan is
+     *                temporarily unavailable, ie. due to ongoing foreground
+     *                playback in single-tuner device.
+     *                NOT_INITIALIZED other error, ie. HW failure.
+     */
+    startBackgroundScan() generates (ProgramListResult result);
 
     /**
      * Retrieve station list.
@@ -40,11 +66,12 @@ interface ITuner extends @1.0::ITuner {
      *               before setting this parameter to anything else.
      * @return result OK if the list was successfully retrieved.
      *                NOT_READY if the scan is in progress.
-     *                NOT_STARTED if the scan has not been started.
+     *                NOT_STARTED if the scan has not been started, client may
+     *                call startBackgroundScan to fix this.
      *                NOT_INITIALIZED if any other error occurs.
      * @return programList List of stations available for user.
      */
     getProgramList(string filter)
-            generates(ProgramListResult result, vec<ProgramInfo> programList);
+        generates (ProgramListResult result, vec<ProgramInfo> programList);
 
 };
index 4af6b1f..1ea57e9 100644 (file)
@@ -19,9 +19,10 @@ package android.hardware.broadcastradio@1.1;
 import @1.0::ITunerCallback;
 
 /**
- * Some methods of @1.1::ITunerCallback are updated versions of those from @1.0:ITunerCallback.
- * All 1.1 drivers should call both (eg. tuneComplete and tuneComplete_1_1), while 1.1 clients
- * should ignore 1.0 ones, to avoid receiving a callback twice.
+ * Some methods of @1.1::ITunerCallback are updated versions of those from
+ * @1.0:ITunerCallback. All 1.1 HAL implementations must call both
+ * (eg. tuneComplete and tuneComplete_1_1), while 1.1 clients may ignore 1.0
+ * ones, to avoid receiving a callback twice.
  */
 interface ITunerCallback extends @1.0::ITunerCallback {
     /*
@@ -37,4 +38,27 @@ interface ITunerCallback extends @1.0::ITunerCallback {
      * @param info A ProgramInfo structure describing the new tuned station.
      */
     oneway afSwitch_1_1(ProgramInfo info);
+
+    /**
+     * Called by the HAL when background scan initiated by startBackgroundScan
+     * finishes. If the list was changed, programListChanged must be called too.
+     * @param result OK if the scan succeeded, client may retrieve the actual
+     *               list with ITuner::getProgramList.
+     *               TEMPORARILY_UNAVAILABLE if the scan was interrupted due to
+     *               hardware becoming temporarily unavailable.
+     *               NOT_INITIALIZED other error, ie. HW failure.
+     */
+    oneway backgroundScanComplete(ProgramListResult result);
+
+    /**
+     * Called each time the internally cached program list changes. HAL may not
+     * call it immediately, ie. it may wait for a short time to accumulate
+     * multiple list change notifications into a single event.
+     *
+     * It may be triggered either by an explicitly issued background scan,
+     * or a scan issued by the device internally.
+     *
+     * Client may retrieve the actual list with ITuner::getProgramList.
+     */
+    oneway programListChanged();
 };
index 611267b..68c9b93 100644 (file)
@@ -94,7 +94,7 @@ int BroadcastRadio::closeHalTuner(const struct radio_tuner *halTuner)
 }
 
 
-// Methods from ::android::hardware::broadcastradio::V1_0::IBroadcastRadio follow.
+// Methods from ::android::hardware::broadcastradio::V1_1::IBroadcastRadio follow.
 Return<void> BroadcastRadio::getProperties(getProperties_cb _hidl_cb)
 {
     int rc;
@@ -115,6 +115,11 @@ exit:
     return Void();
 }
 
+Return<void> BroadcastRadio::getProperties_1_1(getProperties_1_1_cb _hidl_cb __unused)
+{
+    return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION);
+}
+
 Return<void> BroadcastRadio::openTuner(const BandConfig& config, bool audio,
     const sp<V1_0::ITunerCallback>& callback, openTuner_cb _hidl_cb)
 {
index 068979d..7de31a0 100644 (file)
@@ -16,7 +16,7 @@
 #ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_1_BROADCASTRADIO_H
 #define ANDROID_HARDWARE_BROADCASTRADIO_V1_1_BROADCASTRADIO_H
 
-#include <android/hardware/broadcastradio/1.0/IBroadcastRadio.h>
+#include <android/hardware/broadcastradio/1.1/IBroadcastRadio.h>
 #include <android/hardware/broadcastradio/1.1/types.h>
 #include <hardware/radio.h>
 
@@ -30,12 +30,13 @@ using V1_0::Class;
 using V1_0::BandConfig;
 using V1_0::Properties;
 
-struct BroadcastRadio : public V1_0::IBroadcastRadio {
+struct BroadcastRadio : public V1_1::IBroadcastRadio {
 
     BroadcastRadio(Class classId);
 
-    // Methods from ::android::hardware::broadcastradio::V1_0::IBroadcastRadio follow.
+    // Methods from ::android::hardware::broadcastradio::V1_1::IBroadcastRadio follow.
     Return<void> getProperties(getProperties_cb _hidl_cb) override;
+    Return<void> getProperties_1_1(getProperties_1_1_cb _hidl_cb) override;
     Return<void> openTuner(const BandConfig& config, bool audio,
             const sp<V1_0::ITunerCallback>& callback, openTuner_cb _hidl_cb) override;
 
index b4eb184..f280754 100644 (file)
@@ -200,6 +200,10 @@ exit:
     return Void();
 }
 
+Return<ProgramListResult> Tuner::startBackgroundScan() {
+    return ProgramListResult::NOT_INITIALIZED;
+}
+
 Return<void> Tuner::getProgramList(const hidl_string& filter __unused, getProgramList_cb _hidl_cb) {
     hidl_vec<ProgramInfo> pList;
     // TODO(b/34054813): do the actual implementation.
index fcf053a..d7b4545 100644 (file)
@@ -42,6 +42,7 @@ struct Tuner : public ITuner {
     Return<Result> cancel() override;
     Return<void> getProgramInformation(getProgramInformation_cb _hidl_cb) override;
     Return<void> getProgramInformation_1_1(getProgramInformation_1_1_cb _hidl_cb) override;
+    Return<ProgramListResult> startBackgroundScan() override;
     Return<void> getProgramList(const hidl_string& filter, getProgramList_cb _hidl_cb) override;
 
     static void callback(radio_hal_event_t *halEvent, void *cookie);
index b6f72d2..3021f2e 100644 (file)
@@ -45,6 +45,16 @@ enum ProgramInfoFlags : uint32_t {
     MUTED = 1 << 1,
 };
 
+struct Properties {
+    @1.0::Properties base;
+
+    /**
+     * The hardware supports background scanning in general. At the given time
+     * it may not be available though, see startBackgroundScan.
+     */
+    bool supportsBackgroundScanning;
+};
+
 /**
  * Radio program information. Returned by the HAL with event RADIO_EVENT_TUNED.
  * Contains information on currently tuned channel.
index a29f6dc..d3c05c4 100644 (file)
@@ -47,6 +47,7 @@ using ::android::hardware::broadcastradio::V1_1::ITuner;
 using ::android::hardware::broadcastradio::V1_1::ITunerCallback;
 using ::android::hardware::broadcastradio::V1_1::ProgramInfo;
 using ::android::hardware::broadcastradio::V1_1::Result;
+using ::android::hardware::broadcastradio::V1_1::ProgramListResult;
 
 
 // The main test class for Broadcast Radio HIDL HAL.
@@ -128,6 +129,14 @@ class BroadcastRadioHidlTest : public ::testing::VtsHalHidlTargetTestBase {
             return Void();
         }
 
+        virtual Return<void> backgroundScanComplete(ProgramListResult result __unused) {
+            return Void();
+        }
+
+        virtual Return<void> programListChanged() {
+            return Void();
+        }
+
                 MyCallback(BroadcastRadioHidlTest *parentTest) : mParentTest(parentTest) {}
 
      private: