Merge "Implement Gnss::start() and Gnss::stop()" into pi-dev
diff --git a/automotive/audiocontrol/1.0/IAudioControl.hal b/automotive/audiocontrol/1.0/IAudioControl.hal
index c029499..3c8b086 100644
--- a/automotive/audiocontrol/1.0/IAudioControl.hal
+++ b/automotive/audiocontrol/1.0/IAudioControl.hal
@@ -29,10 +29,8 @@
      *
      * For every context, a valid bus number (0 - num busses-1) must be returned. If an
      * unrecognized contextNumber is encountered, then -1 shall be returned.
-     *
-     * Any context for which an invalid busNumber is returned must be routed to bus 0.
      */
-    getBusForContext(uint32_t contextNumber)
+    getBusForContext(ContextNumber contextNumber)
         generates (int32_t busNumber);
 
 
diff --git a/automotive/audiocontrol/1.0/default/AudioControl.cpp b/automotive/audiocontrol/1.0/default/AudioControl.cpp
index b40f2ae..c96580e 100644
--- a/automotive/audiocontrol/1.0/default/AudioControl.cpp
+++ b/automotive/audiocontrol/1.0/default/AudioControl.cpp
@@ -36,7 +36,8 @@
 };
 
 
-Return<int32_t> AudioControl::getBusForContext(uint32_t contextNumber) {
+Return<int32_t> AudioControl::getBusForContext(ContextNumber ctxt) {
+    unsigned contextNumber = static_cast<unsigned>(ctxt);
     if (contextNumber > sContextNumberMax) {
         ALOGE("Unexpected context number %d (max expected is %d)", contextNumber, sContextCount);
         return -1;
diff --git a/automotive/audiocontrol/1.0/default/AudioControl.h b/automotive/audiocontrol/1.0/default/AudioControl.h
index 89e41f9..37f43c6 100644
--- a/automotive/audiocontrol/1.0/default/AudioControl.h
+++ b/automotive/audiocontrol/1.0/default/AudioControl.h
@@ -23,7 +23,7 @@
 struct AudioControl : public IAudioControl {
 public:
     // Methods from ::android::hardware::automotive::audiocontrol::V1_0::IAudioControl follow.
-    Return<int32_t> getBusForContext(uint32_t contextNumber) override;
+    Return<int32_t> getBusForContext(ContextNumber contextNumber) override;
     Return<void> setBalanceTowardRight(float value) override;
     Return<void> setFadeTowardFront(float value) override;
 
diff --git a/automotive/audiocontrol/1.0/vts/functional/Android.bp b/automotive/audiocontrol/1.0/vts/functional/Android.bp
new file mode 100644
index 0000000..c6e0d8e
--- /dev/null
+++ b/automotive/audiocontrol/1.0/vts/functional/Android.bp
@@ -0,0 +1,31 @@
+//
+// Copyright (C) 2016 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.
+//
+
+cc_test {
+    name: "VtsHalAudioControlV1_0TargetTest",
+
+    srcs: [
+        "VtsHalAudioControlV1_0TargetTest.cpp",
+    ],
+
+    defaults: [
+        "VtsHalTargetTestDefaults",
+    ],
+
+    static_libs: [
+        "android.hardware.automotive.audiocontrol@1.0",
+    ],
+}
diff --git a/automotive/audiocontrol/1.0/vts/functional/VtsHalAudioControlV1_0TargetTest.cpp b/automotive/audiocontrol/1.0/vts/functional/VtsHalAudioControlV1_0TargetTest.cpp
new file mode 100644
index 0000000..68ed778
--- /dev/null
+++ b/automotive/audiocontrol/1.0/vts/functional/VtsHalAudioControlV1_0TargetTest.cpp
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#define LOG_TAG "VtsHalAudioControlTest"
+
+#include <stdio.h>
+#include <string.h>
+
+#include <hidl/HidlTransportSupport.h>
+#include <hwbinder/ProcessState.h>
+#include <log/log.h>
+#include <utils/Errors.h>
+#include <utils/StrongPointer.h>
+
+#include <android/hardware/automotive/audiocontrol/1.0/types.h>
+#include <android/hardware/automotive/audiocontrol/1.0/IAudioControl.h>
+#include <android/log.h>
+
+#include <VtsHalHidlTargetTestBase.h>
+
+using namespace ::android::hardware::automotive::audiocontrol::V1_0;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_enum_iterator;
+using ::android::hardware::hidl_handle;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::sp;
+
+
+// Boiler plate for test harness
+class CarAudioControlHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static CarAudioControlHidlEnvironment* Instance() {
+        static CarAudioControlHidlEnvironment* instance = new CarAudioControlHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<IAudioControl>(); }
+   private:
+    CarAudioControlHidlEnvironment() {}
+};
+
+
+// The main test class for the automotive AudioControl HAL
+class CarAudioControlHidlTest : public ::testing::VtsHalHidlTargetTestBase {
+public:
+    virtual void SetUp() override {
+        // Make sure we can connect to the driver
+        pAudioControl = ::testing::VtsHalHidlTargetTestBase::getService<IAudioControl>(
+                                    CarAudioControlHidlEnvironment::Instance()->
+                                    getServiceName<IAudioControl>());
+        ASSERT_NE(pAudioControl.get(), nullptr);
+    }
+
+    virtual void TearDown() override {}
+
+   protected:
+    sp<IAudioControl> pAudioControl;  // Every test needs access to the service
+};
+
+//
+// Tests start here...
+//
+
+/*
+ * Fader exercise test.  Note that only a subjective observer could determine if the
+ * fader actually works.  The only thing we can do is exercise the HAL and if the HAL crashes,
+ * we _might_ get a test failure if that breaks the connection to the driver.
+ */
+TEST_F(CarAudioControlHidlTest, FaderExercise) {
+    ALOGI("Fader exercise test (silent)");
+
+    // Set the fader all the way to the back
+    pAudioControl->setFadeTowardFront(-1.0f);
+
+    // Set the fader all the way to the front
+    pAudioControl->setFadeTowardFront(1.0f);
+
+    // Set the fader part way toward the back
+    pAudioControl->setFadeTowardFront(-0.333f);
+
+    // Set the fader to a out of bounds value (driver should clamp)
+    pAudioControl->setFadeTowardFront(99999.9f);
+
+    // Set the fader back to the middle
+    pAudioControl->setFadeTowardFront(0.0f);
+}
+
+/*
+ * Balance exercise test.
+ */
+TEST_F(CarAudioControlHidlTest, BalanceExercise) {
+    ALOGI("Balance exercise test (silent)");
+
+    // Set the balance all the way to the left
+    pAudioControl->setBalanceTowardRight(-1.0f);
+
+    // Set the balance all the way to the right
+    pAudioControl->setBalanceTowardRight(1.0f);
+
+    // Set the balance part way toward the left
+    pAudioControl->setBalanceTowardRight(-0.333f);
+
+    // Set the balance to a out of bounds value (driver should clamp)
+    pAudioControl->setBalanceTowardRight(99999.9f);
+
+    // Set the balance back to the middle
+    pAudioControl->setBalanceTowardRight(0.0f);
+}
+
+/*
+ * Context mapping test.
+ */
+TEST_F(CarAudioControlHidlTest, ContextMapping) {
+    ALOGI("Context mapping test");
+
+    int bus = -1;
+
+    // For each defined context, query the driver for the BUS on which it should be delivered
+    for (const auto& ctxt : hidl_enum_iterator<ContextNumber>()) {
+         bus = pAudioControl->getBusForContext(ctxt);
+
+         if (ctxt == ContextNumber::INVALID) {
+             // Invalid context should never be mapped to a bus
+             EXPECT_EQ(bus, -1);
+         } else {
+             EXPECT_GE(bus, 0);
+             // TODO:  Consider enumerating the devices on the actual audio hal to validate the
+             // bus IDs.  This would introduce an dependency on the audio HAL, however.  Would that
+             // even work while Android is up and running?
+         }
+    }
+
+    // Try asking about an invalid context one beyond the last defined to see that it gets back a -1
+    int contextRange = std::distance(hidl_enum_iterator<ContextNumber>().begin(),
+                                     hidl_enum_iterator<ContextNumber>().end());
+    bus = pAudioControl->getBusForContext((ContextNumber)contextRange);
+    EXPECT_EQ(bus, -1);
+
+    // Try asking about an invalid context WAY out of range to see that it gets back a -1
+    bus = pAudioControl->getBusForContext((ContextNumber)~0);
+    EXPECT_EQ(bus, -1);
+}
diff --git a/camera/device/3.2/default/CameraDeviceSession.cpp b/camera/device/3.2/default/CameraDeviceSession.cpp
index 975fb01..5f89cde 100644
--- a/camera/device/3.2/default/CameraDeviceSession.cpp
+++ b/camera/device/3.2/default/CameraDeviceSession.cpp
@@ -1198,7 +1198,7 @@
     return Void();
 }
 
-void CameraDeviceSession::constructCaptureResult(CaptureResult& result,
+status_t CameraDeviceSession::constructCaptureResult(CaptureResult& result,
                                                  const camera3_capture_result *hal_result) {
     uint32_t frameNumber = hal_result->frame_number;
     bool hasInputBuf = (hal_result->input_buffer != nullptr);
@@ -1213,7 +1213,7 @@
             if (mInflightBuffers.count(key) != 1) {
                 ALOGE("%s: input buffer for stream %d frame %d is not inflight!",
                         __FUNCTION__, streamId, frameNumber);
-                return;
+                return -EINVAL;
             }
         }
 
@@ -1224,7 +1224,7 @@
             if (mInflightBuffers.count(key) != 1) {
                 ALOGE("%s: output buffer for stream %d frame %d is not inflight!",
                         __FUNCTION__, streamId, frameNumber);
-                return;
+                return -EINVAL;
             }
         }
     }
@@ -1344,7 +1344,7 @@
             ALOGV("%s: inflight buffer queue is now empty!", __FUNCTION__);
         }
     }
-
+    return OK;
 }
 
 /**
@@ -1356,10 +1356,11 @@
     CameraDeviceSession *d =
             const_cast<CameraDeviceSession*>(static_cast<const CameraDeviceSession*>(cb));
 
-    CaptureResult result;
-    d->constructCaptureResult(result, hal_result);
-
-    d->mResultBatcher.processCaptureResult(result);
+    CaptureResult result = {};
+    status_t ret = d->constructCaptureResult(result, hal_result);
+    if (ret == OK) {
+        d->mResultBatcher.processCaptureResult(result);
+    }
 }
 
 void CameraDeviceSession::sNotify(
diff --git a/camera/device/3.2/default/CameraDeviceSession.h b/camera/device/3.2/default/CameraDeviceSession.h
index 61db671..269cc06 100644
--- a/camera/device/3.2/default/CameraDeviceSession.h
+++ b/camera/device/3.2/default/CameraDeviceSession.h
@@ -327,7 +327,7 @@
     static callbacks_process_capture_result_t sProcessCaptureResult;
     static callbacks_notify_t sNotify;
 
-    void constructCaptureResult(CaptureResult& result,
+    status_t constructCaptureResult(CaptureResult& result,
                                 const camera3_capture_result *hal_result);
 private:
 
diff --git a/camera/device/3.4/default/CameraDeviceSession.cpp b/camera/device/3.4/default/CameraDeviceSession.cpp
index b032357..ad7f6f5 100644
--- a/camera/device/3.4/default/CameraDeviceSession.cpp
+++ b/camera/device/3.4/default/CameraDeviceSession.cpp
@@ -450,8 +450,12 @@
     CameraDeviceSession *d =
             const_cast<CameraDeviceSession*>(static_cast<const CameraDeviceSession*>(cb));
 
-    CaptureResult result;
-    d->constructCaptureResult(result.v3_2, hal_result);
+    CaptureResult result = {};
+    status_t ret = d->constructCaptureResult(result.v3_2, hal_result);
+    if (ret != OK) {
+        return;
+    }
+
     result.physicalCameraMetadata.resize(hal_result->num_physcam_metadata);
     for (uint32_t i = 0; i < hal_result->num_physcam_metadata; i++) {
         std::string physicalId = hal_result->physcam_ids[i];
diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml
index 930c763..dd8d92d 100644
--- a/compatibility_matrices/compatibility_matrix.current.xml
+++ b/compatibility_matrices/compatibility_matrix.current.xml
@@ -1,7 +1,6 @@
 <compatibility-matrix version="1.0" type="framework" level="3">
     <hal format="hidl" optional="false">
         <name>android.hardware.audio</name>
-        <version>2.0</version>
         <version>4.0</version>
         <interface>
             <name>IDevicesFactory</name>
@@ -10,7 +9,6 @@
     </hal>
     <hal format="hidl" optional="false">
         <name>android.hardware.audio.effect</name>
-        <version>2.0</version>
         <version>4.0</version>
         <interface>
             <name>IEffectsFactory</name>
diff --git a/graphics/composer/2.1/default/android.hardware.graphics.composer@2.1-service.rc b/graphics/composer/2.1/default/android.hardware.graphics.composer@2.1-service.rc
index 3b6710b..5a5b51e 100644
--- a/graphics/composer/2.1/default/android.hardware.graphics.composer@2.1-service.rc
+++ b/graphics/composer/2.1/default/android.hardware.graphics.composer@2.1-service.rc
@@ -4,3 +4,4 @@
     group graphics drmrpc
     capabilities SYS_NICE
     onrestart restart surfaceflinger
+    writepid /dev/cpuset/system-background/tasks
diff --git a/nfc/1.1/Android.bp b/nfc/1.1/Android.bp
index 73dc70a..9a1392e 100644
--- a/nfc/1.1/Android.bp
+++ b/nfc/1.1/Android.bp
@@ -16,7 +16,11 @@
         "android.hidl.base@1.0",
     ],
     types: [
+        "Constant",
+        "NfcConfig",
         "NfcEvent",
+        "PresenceCheckAlgorithm",
+        "ProtocolDiscoveryConfig",
     ],
     gen_java: true,
 }
diff --git a/nfc/1.1/INfc.hal b/nfc/1.1/INfc.hal
index ea6a571..b629d8c 100644
--- a/nfc/1.1/INfc.hal
+++ b/nfc/1.1/INfc.hal
@@ -49,4 +49,11 @@
      *                NfcStatus::SUCCESS otherwise.
      */
     open_1_1(INfcClientCallback clientCallback) generates (NfcStatus status);
+
+    /**
+     * Fetches vendor specific configurations.
+     * @return config indicates support for certain features and
+     *     populates the vendor specific configs
+     */
+    getConfig() generates (NfcConfig config);
 };
diff --git a/nfc/1.1/types.hal b/nfc/1.1/types.hal
index 2f5ec7f..469e878 100644
--- a/nfc/1.1/types.hal
+++ b/nfc/1.1/types.hal
@@ -21,3 +21,78 @@
     /** In case of an error, HCI network needs to be re-initialized */
     HCI_NETWORK_RESET = 7
 };
+
+enum Constant : uint8_t {
+    UNSUPPORTED_CONFIG = 0xFF,
+};
+
+/**
+ * Vendor Specific Proprietary Protocol & Discovery Configuration.
+ * Set to UNSUPPORTED_CONFIG if not supported.
+ * discovery* fields map to "RF Technology and Mode" in NCI Spec
+ * protocol* fields map to "RF protocols" in NCI Spec
+ */
+struct ProtocolDiscoveryConfig {
+    uint8_t protocol18092Active;
+    uint8_t protocolBPrime;
+    uint8_t protocolDual;
+    uint8_t protocol15693;
+    uint8_t protocolKovio;
+    uint8_t protocolMifare;
+    uint8_t discoveryPollKovio;
+    uint8_t discoveryPollBPrime;
+    uint8_t discoveryListenBPrime;
+};
+
+/* Presence Check Algorithm as per ISO/IEC 14443-4 */
+enum PresenceCheckAlgorithm : uint8_t {
+    /** Lets the stack select an algorithm */
+    DEFAULT = 0,
+    /** ISO-DEP protocol's empty I-block */
+    I_BLOCK = 1,
+    /**
+     * Type - 4 tag protocol iso-dep nak presence check command is sent waiting for
+     * response and notification.
+     */
+    ISO_DEP_NAK = 2
+};
+
+struct NfcConfig {
+    /** If true, NFCC is using bail out mode for either Type A or Type B poll. */
+    bool nfaPollBailOutMode;
+
+    PresenceCheckAlgorithm presenceCheckAlgorithm;
+
+    ProtocolDiscoveryConfig nfaProprietaryCfg;
+
+    /** Default off-host route. 0x00 if there aren't any. Refer to NCI spec. */
+    uint8_t defaultOffHostRoute;
+
+    /**
+     * Default off-host route for Felica. 0x00 if there aren't any. Refer to
+     * NCI spec.
+     */
+    uint8_t defaultOffHostRouteFelica;
+
+    /** Default system code route. 0x00 if there aren't any. Refer NCI spec */
+    uint8_t defaultSystemCodeRoute;
+
+    /**
+     * Default route for all remaining protocols and technology which haven't
+     * been configured.
+     * Device Host(0x00) is the default. Refer to NCI spec.
+     * */
+    uint8_t defaultRoute;
+
+    /** Pipe ID for eSE. 0x00 if there aren't any. */
+    uint8_t offHostESEPipeId;
+
+    /** Pipe ID for UICC. 0x00 if there aren't any. */
+    uint8_t offHostSIMPipeId;
+
+    /** Extended APDU length for ISO_DEP. If not supported default length is 261 */
+    uint32_t maxIsoDepTransceiveLength;
+
+    /** list of white listed host ids, as per ETSI TS 102 622 */
+    vec<uint8_t> hostWhitelist;
+};
diff --git a/nfc/1.1/vts/functional/VtsHalNfcV1_1TargetTest.cpp b/nfc/1.1/vts/functional/VtsHalNfcV1_1TargetTest.cpp
index bef412b..0b7c88b 100644
--- a/nfc/1.1/vts/functional/VtsHalNfcV1_1TargetTest.cpp
+++ b/nfc/1.1/vts/functional/VtsHalNfcV1_1TargetTest.cpp
@@ -30,6 +30,7 @@
 using ::android::hardware::nfc::V1_1::INfc;
 using ::android::hardware::nfc::V1_1::INfcClientCallback;
 using ::android::hardware::nfc::V1_1::NfcEvent;
+using ::android::hardware::nfc::V1_1::NfcConfig;
 using ::android::hardware::nfc::V1_0::NfcStatus;
 using ::android::hardware::nfc::V1_0::NfcData;
 using ::android::hardware::Return;
@@ -37,6 +38,9 @@
 using ::android::hardware::hidl_vec;
 using ::android::sp;
 
+// 261 bytes is the default and minimum transceive length
+constexpr unsigned int MIN_ISO_DEP_TRANSCEIVE_LENGTH = 261;
+
 constexpr char kCallbackNameSendEvent[] = "sendEvent";
 constexpr char kCallbackNameSendData[] = "sendData";
 
@@ -209,6 +213,17 @@
     EXPECT_EQ(NfcStatus::OK, res.args->last_status_);
 }
 
+/*
+ * getConfig:
+ * Calls getConfig()
+ * checks if fields in NfcConfig are populated correctly
+ */
+TEST_F(NfcHidlTest, GetConfig) {
+    nfc_->getConfig([](NfcConfig config) {
+        EXPECT_GE(config.maxIsoDepTransceiveLength, MIN_ISO_DEP_TRANSCEIVE_LENGTH);
+    });
+}
+
 int main(int argc, char** argv) {
     ::testing::AddGlobalTestEnvironment(NfcHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
diff --git a/wifi/1.2/default/hidl_struct_util.cpp b/wifi/1.2/default/hidl_struct_util.cpp
index 33450ab..39ac544 100644
--- a/wifi/1.2/default/hidl_struct_util.cpp
+++ b/wifi/1.2/default/hidl_struct_util.cpp
@@ -2342,6 +2342,10 @@
             return RttStatus::NO_WIFI;
         case legacy_hal::RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE:
             return RttStatus::FAIL_FTM_PARAM_OVERRIDE;
+        case legacy_hal::RTT_STATUS_NAN_RANGING_PROTOCOL_FAILURE:
+            return RttStatus::FAILURE;  // TODO: add HIDL enumeration
+        case legacy_hal::RTT_STATUS_NAN_RANGING_CONCURRENCY_NOT_SUPPORTED:
+            return RttStatus::FAILURE;  // TODO: add HIDL enumeration
     };
     CHECK(false) << "Unknown legacy status: " << status;
 }