Merge "graphics: restart HWC when SurfaceFlinger stops" into pi-dev
diff --git a/audio/common/all-versions/default/service/Android.mk b/audio/common/all-versions/default/service/Android.mk
index f502dfd..43d7fe1 100644
--- a/audio/common/all-versions/default/service/Android.mk
+++ b/audio/common/all-versions/default/service/Android.mk
@@ -43,6 +43,7 @@
     android.hardware.audio.common@4.0 \
     android.hardware.audio.effect@2.0 \
     android.hardware.audio.effect@4.0 \
+    android.hardware.bluetooth.a2dp@1.0 \
     android.hardware.soundtrigger@2.0 \
     android.hardware.soundtrigger@2.1
 
diff --git a/audio/common/all-versions/default/service/service.cpp b/audio/common/all-versions/default/service/service.cpp
index f6e4353..c7ce638 100644
--- a/audio/common/all-versions/default/service/service.cpp
+++ b/audio/common/all-versions/default/service/service.cpp
@@ -20,6 +20,7 @@
 #include <android/hardware/audio/4.0/IDevicesFactory.h>
 #include <android/hardware/audio/effect/2.0/IEffectsFactory.h>
 #include <android/hardware/audio/effect/4.0/IEffectsFactory.h>
+#include <android/hardware/bluetooth/a2dp/1.0/IBluetoothAudioOffload.h>
 #include <android/hardware/soundtrigger/2.0/ISoundTriggerHw.h>
 #include <android/hardware/soundtrigger/2.1/ISoundTriggerHw.h>
 #include <binder/ProcessState.h>
@@ -47,5 +48,10 @@
            registerPassthroughServiceImplementation<soundtrigger::V2_0::ISoundTriggerHw>() != OK,
     ALOGW_IF(fail, "Could not register soundtrigger API 2.0 nor 2.1");
 
+    fail =
+        registerPassthroughServiceImplementation<bluetooth::a2dp::V1_0::IBluetoothAudioOffload>() !=
+        OK;
+    ALOGW_IF(fail, "Could not register Bluetooth audio offload 1.0");
+
     joinRpcThreadpool();
 }
diff --git a/bluetooth/a2dp/1.0/Android.bp b/bluetooth/a2dp/1.0/Android.bp
new file mode 100644
index 0000000..5e85290
--- /dev/null
+++ b/bluetooth/a2dp/1.0/Android.bp
@@ -0,0 +1,27 @@
+// This file is autogenerated by hidl-gen -Landroidbp.
+
+hidl_interface {
+    name: "android.hardware.bluetooth.a2dp@1.0",
+    root: "android.hardware",
+    vndk: {
+        enabled: true,
+    },
+    srcs: [
+        "types.hal",
+        "IBluetoothAudioHost.hal",
+        "IBluetoothAudioOffload.hal",
+    ],
+    interfaces: [
+        "android.hidl.base@1.0",
+    ],
+    types: [
+        "BitsPerSample",
+        "ChannelMode",
+        "CodecConfiguration",
+        "CodecType",
+        "SampleRate",
+        "Status",
+    ],
+    gen_java: false,
+}
+
diff --git a/bluetooth/a2dp/1.0/IBluetoothAudioHost.hal b/bluetooth/a2dp/1.0/IBluetoothAudioHost.hal
new file mode 100644
index 0000000..666419d
--- /dev/null
+++ b/bluetooth/a2dp/1.0/IBluetoothAudioHost.hal
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+package android.hardware.bluetooth.a2dp@1.0;
+
+/**
+ * HAL interface for Bluetooth A2DP Offload functionality where
+ * the encoding of the A2DP data packets is offloaded to platform
+ * specific encoders. The A2DP control path is maintained in the
+ * Bluetooth stack.
+ *
+ * This interface is from HAL server to HAL client.
+ *
+ * The HAL server must call into the IBluetoothAudioHost to initiate
+ * the start, suspend and stop of the streaming operation. These
+ * calls return immediately and the results, if any, are send over
+ * the IBluetoothAudioOffload interface.
+ */
+
+interface IBluetoothAudioHost {
+    /**
+     * Invoked when the start stream is requested from HAL server
+     * to HAL client. This indicates that the HAL server
+     * has initialized the platform for streaming use case, and the
+     * HAL client can proceed with the streaming procedure. The
+     * result of the operation must be provided by the HAL
+     * client using the IBluetoothAudioOffload interface.
+     */
+    oneway startStream();
+
+    /**
+     * Invoked when the suspend stream is requested from HAL server
+     * to HAL client. This indicates that the HAL server
+     * wants to suspend the streaming procedure. The result of the
+     * operation must be provided by the HAL client using the
+     * IBluetoothAudioOffload interface.
+     */
+    oneway suspendStream();
+
+    /**
+     * Invoked when the stop stream is requested from HAL server
+     * to HAL client. This indicates that the HAL server wants to
+     * stop and reset the streaming procedure. There is no result
+     * provided by the HAL client for this call.
+     */
+    oneway stopStream();
+
+};
diff --git a/bluetooth/a2dp/1.0/IBluetoothAudioOffload.hal b/bluetooth/a2dp/1.0/IBluetoothAudioOffload.hal
new file mode 100644
index 0000000..52a580f
--- /dev/null
+++ b/bluetooth/a2dp/1.0/IBluetoothAudioOffload.hal
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+
+package android.hardware.bluetooth.a2dp@1.0;
+
+import IBluetoothAudioHost;
+
+/**
+ * HAL interface for Bluetooth A2DP Offload functionality where
+ * the encoding of the A2DP data packets is offloaded to platform
+ * specific encoders. The A2DP control path is maintained in the
+ * Bluetooth stack.
+ *
+ * This interface is from HAL client to HAL server.
+ *
+ * The HAL client must provide the handle of IBluetoothAudioHost as well
+ * as codec configuration to the HAL server, when its connected to an
+ * active A2DP Sink device. HAL Server, based on the feedback from the Audio
+ * framework must call into the commands provided by the IBluetoothAudioHost.
+ * HAL client must call into IBluetoothAudioOffload to provide the status of
+ * these commands. Once the device becomes inactive, the HAL client must
+ * call the endSession to terminate the session with the HAL server.
+ */
+interface IBluetoothAudioOffload {
+
+    /**
+     * Indicates that the HAL client is connected to an A2DP Sink device
+     * and is ready to stream audio. This function is also used to register
+     * the BluetoothAudioHost interface and the provide the current negotiated
+     * codec.
+     *
+     * |endSession| must be called to unregister the interface.
+     *
+     * @param hostIf interface used to request stream control
+     * @param codecConfig Codec configuration as negotiated with the A2DP Sink
+     *    device
+     * @return status one of the following
+     *    SUCCESS if HAL server successfully initializes the platform with the
+     *        given codec configuration
+     *    UNSUPPORTED_CODEC_CONFIGURATION if HAL server cannot initialize the
+     *        platform with the given codec configuration
+     *    FAILURE if HAL server cannot initialize the platform for any other
+     *        reason
+     */
+    startSession(IBluetoothAudioHost hostIf, CodecConfiguration codecConfig) generates (Status status);
+
+    /**
+     * Updates status for start stream request. The HAL client may need
+     * to communicate to Bluetooth Controller and remote Sink device, in which
+     * case it must update with PENDING status. Once the operation is
+     * completed, it must return with either SUCCESS or FAILURE.
+     *
+     * @param status SUCCESS, FAILURE or PENDING
+     */
+    oneway streamStarted(Status status);
+
+    /**
+     * Updates status for suspend stream request. The HAL client may need
+     * to communicate to Bluetooth Controller and remote device, in which case
+     * it must update with PENDING status. Once the operation is completed, it
+     * must return with either SUCCESS or FAILURE.
+     *
+     * @param status SUCCESS, FAILURE or PENDING
+     */
+    oneway streamSuspended(Status status);
+
+    /**
+     * Ends the current A2DP offload session and unregisters the
+     * BluetoothAudioHost interface.
+     */
+    oneway endSession();
+};
diff --git a/bluetooth/a2dp/1.0/default/Android.bp b/bluetooth/a2dp/1.0/default/Android.bp
new file mode 100644
index 0000000..8e6f32d
--- /dev/null
+++ b/bluetooth/a2dp/1.0/default/Android.bp
@@ -0,0 +1,14 @@
+cc_library_shared {
+    name: "android.hardware.bluetooth.a2dp@1.0-impl",
+    relative_install_path: "hw",
+    vendor: true,
+    srcs: [
+        "BluetoothAudioOffload.cpp",
+    ],
+    shared_libs: [
+        "libhidlbase",
+        "libhidltransport",
+        "libutils",
+        "android.hardware.bluetooth.a2dp@1.0",
+    ],
+}
diff --git a/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.cpp b/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.cpp
new file mode 100644
index 0000000..2a66abe
--- /dev/null
+++ b/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.cpp
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+#include "BluetoothAudioOffload.h"
+
+namespace android {
+namespace hardware {
+namespace bluetooth {
+namespace a2dp {
+namespace V1_0 {
+namespace implementation {
+
+IBluetoothAudioOffload* HIDL_FETCH_IBluetoothAudioOffload(const char* /* name */) {
+    return new BluetoothAudioOffload();
+}
+
+// Methods from ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload follow.
+Return<::android::hardware::bluetooth::a2dp::V1_0::Status> BluetoothAudioOffload::startSession(
+    const sp<::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost>& hostIf __unused,
+    const ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration& codecConfig __unused) {
+    /**
+     * Initialize the audio platform if codecConfiguration is supported.
+     * Save the the IBluetoothAudioHost interface, so that it can be used
+     * later to send stream control commands to the HAL client, based on
+     * interaction with Audio framework.
+     */
+    return ::android::hardware::bluetooth::a2dp::V1_0::Status::FAILURE;
+}
+
+Return<void> BluetoothAudioOffload::streamStarted(
+    ::android::hardware::bluetooth::a2dp::V1_0::Status status __unused) {
+    /**
+     * Streaming on control path has started,
+     * HAL server should start the streaming on data path.
+     */
+    return Void();
+}
+
+Return<void> BluetoothAudioOffload::streamSuspended(
+    ::android::hardware::bluetooth::a2dp::V1_0::Status status __unused) {
+    /**
+     * Streaming on control path has suspend,
+     * HAL server should suspend the streaming on data path.
+     */
+    return Void();
+}
+
+Return<void> BluetoothAudioOffload::endSession() {
+    /**
+     * Cleanup the audio platform as remote A2DP Sink device is no
+     * longer active
+     */
+    return Void();
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace a2dp
+}  // namespace bluetooth
+}  // namespace hardware
+}  // namespace android
diff --git a/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.h b/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.h
new file mode 100644
index 0000000..5d07b5b
--- /dev/null
+++ b/bluetooth/a2dp/1.0/default/BluetoothAudioOffload.h
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+#ifndef ANDROID_HARDWARE_BLUETOOTH_A2DP_V1_0_BLUETOOTHAUDIOOFFLOAD_H
+#define ANDROID_HARDWARE_BLUETOOTH_A2DP_V1_0_BLUETOOTHAUDIOOFFLOAD_H
+
+#include <android/hardware/bluetooth/a2dp/1.0/IBluetoothAudioOffload.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace bluetooth {
+namespace a2dp {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+struct BluetoothAudioOffload : public IBluetoothAudioOffload {
+    BluetoothAudioOffload() {}
+    // Methods from ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload follow.
+    Return<::android::hardware::bluetooth::a2dp::V1_0::Status> startSession(
+        const sp<::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost>& hostIf,
+        const ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration& codecConfig) override;
+    Return<void> streamStarted(::android::hardware::bluetooth::a2dp::V1_0::Status status) override;
+    Return<void> streamSuspended(
+        ::android::hardware::bluetooth::a2dp::V1_0::Status status) override;
+    Return<void> endSession() override;
+};
+
+extern "C" IBluetoothAudioOffload* HIDL_FETCH_IBluetoothAudioOffload(const char* name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace a2dp
+}  // namespace bluetooth
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_BLUETOOTH_A2DP_V1_0_BLUETOOTHAUDIOOFFLOAD_H
diff --git a/bluetooth/a2dp/1.0/types.hal b/bluetooth/a2dp/1.0/types.hal
new file mode 100644
index 0000000..6a430f0
--- /dev/null
+++ b/bluetooth/a2dp/1.0/types.hal
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+
+package android.hardware.bluetooth.a2dp@1.0;
+
+enum Status : uint8_t {
+    SUCCESS,
+    FAILURE,
+    /** codec configuration not supported by the audio platform */
+    UNSUPPORTED_CODEC_CONFIGURATION ,
+    /** operation is pending */
+    PENDING,
+};
+
+enum CodecType : uint32_t {
+    UNKNOWN = 0x00,
+    SBC = 0x01,
+    AAC = 0x02,
+    APTX = 0x04,
+    APTX_HD = 0x08,
+    LDAC = 0x10,
+};
+enum SampleRate : uint32_t {
+    RATE_UNKNOWN = 0x00,
+    RATE_44100 = 0x01,
+    RATE_48000 = 0x02,
+    RATE_88200 = 0x04,
+    RATE_96000 = 0x08,
+    RATE_176400 = 0x10,
+    RATE_192000 = 0x20,
+};
+enum BitsPerSample : uint8_t {
+    BITS_UNKNOWN = 0x00,
+    BITS_16 = 0x01,
+    BITS_24 = 0x02,
+    BITS_32 = 0x04,
+};
+enum ChannelMode : uint8_t {
+    UNKNOWN = 0x00,
+    MONO = 0x01,
+    STEREO = 0x02,
+};
+struct CodecConfiguration {
+    /** Bluetooth A2DP codec */
+    CodecType codecType;
+    /** Sampling rate for encoder */
+    SampleRate sampleRate;
+    /** Bits per sample for encoder */
+    BitsPerSample bitsPerSample;
+    /** Channel mode for encoder */
+    ChannelMode channelMode;
+    /**
+     * The encoded audio bitrate in bits / second.
+     * 0x00000000 - The audio bitrate is not specified / unused
+     * 0x00000001 - 0x00FFFFFF - Encoded audio bitrate in bits/second
+     * 0x01000000 - 0xFFFFFFFF - Reserved
+     */
+    uint32_t encodedAudioBitrate;
+    /** Peer MTU (in octets) */
+    uint16_t peerMtu;
+    union CodecSpecific {
+        /**
+         * SBC Codec specific information
+         * Refer to SBC Codec specific information elements in A2DP v1.3
+         * Profile Specification.
+         */
+        struct SbcData {
+            /** Block length: 4 bits | Subbands: 2 bits | Allocation Method: 2 bits */
+            uint8_t codecParameters;
+            /** Minimum bitpool value */
+            uint8_t minBitpool;
+            /** Maximum bitpool value */
+            uint8_t maxBitpool;
+        } sbcData;
+        struct LdacData {
+            /**
+             * LDAC bitrate index value:
+             * 0x00 - High
+             * 0x01 - Mid
+             * 0x02 - Low
+             * 0x7F - ABR (Adaptive Bit Rate)
+             */
+            uint8_t bitrateIndex;
+        } ldacData;
+    } codecSpecific;
+};
diff --git a/camera/provider/2.4/default/ExternalCameraProvider.cpp b/camera/provider/2.4/default/ExternalCameraProvider.cpp
index faa4e3a..285e96b 100644
--- a/camera/provider/2.4/default/ExternalCameraProvider.cpp
+++ b/camera/provider/2.4/default/ExternalCameraProvider.cpp
@@ -75,6 +75,9 @@
         Mutex::Autolock _l(mLock);
         mCallbacks = callback;
     }
+    if (mCallbacks == nullptr) {
+        return Status::OK;
+    }
     // Send a callback for all devices to initialize
     {
         for (const auto& pair : mCameraStatusMap) {
diff --git a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp
index abd875a..5feec87 100644
--- a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp
+++ b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp
@@ -16,6 +16,7 @@
 
 #define LOG_TAG "camera_hidl_hal_test"
 
+#include <algorithm>
 #include <chrono>
 #include <mutex>
 #include <regex>
@@ -65,6 +66,7 @@
 using ::android::BufferItemConsumer;
 using ::android::Surface;
 using ::android::hardware::graphics::common::V1_0::BufferUsage;
+using ::android::hardware::graphics::common::V1_0::Dataspace;
 using ::android::hardware::graphics::common::V1_0::PixelFormat;
 using ::android::hardware::camera::common::V1_0::Status;
 using ::android::hardware::camera::common::V1_0::CameraDeviceStatus;
@@ -1084,7 +1086,7 @@
 }
 
 hidl_vec<hidl_string> CameraHidlTest::getCameraDeviceNames(sp<ICameraProvider> provider) {
-    hidl_vec<hidl_string> cameraDeviceNames;
+    std::vector<std::string> cameraDeviceNames;
     Return<void> ret;
     ret = provider->getCameraIdList(
         [&](auto status, const auto& idList) {
@@ -1093,12 +1095,50 @@
                 ALOGI("Camera Id[%zu] is %s", i, idList[i].c_str());
             }
             ASSERT_EQ(Status::OK, status);
-            cameraDeviceNames = idList;
+            for (const auto& id : idList) {
+                cameraDeviceNames.push_back(id);
+            }
         });
     if (!ret.isOk()) {
         ADD_FAILURE();
     }
-    return cameraDeviceNames;
+
+    // External camera devices are reported through cameraDeviceStatusChange
+    struct ProviderCb : public ICameraProviderCallback {
+        virtual Return<void> cameraDeviceStatusChange(
+                const hidl_string& devName,
+                CameraDeviceStatus newStatus) override {
+            ALOGI("camera device status callback name %s, status %d",
+                    devName.c_str(), (int) newStatus);
+            if (newStatus == CameraDeviceStatus::PRESENT) {
+                externalCameraDeviceNames.push_back(devName);
+
+            }
+            return Void();
+        }
+
+        virtual Return<void> torchModeStatusChange(
+                const hidl_string&, TorchModeStatus) override {
+            return Void();
+        }
+
+        std::vector<std::string> externalCameraDeviceNames;
+    };
+    sp<ProviderCb> cb = new ProviderCb;
+    auto status = mProvider->setCallback(cb);
+
+    for (const auto& devName : cb->externalCameraDeviceNames) {
+        if (cameraDeviceNames.end() == std::find(
+                cameraDeviceNames.begin(), cameraDeviceNames.end(), devName)) {
+            cameraDeviceNames.push_back(devName);
+        }
+    }
+
+    hidl_vec<hidl_string> retList(cameraDeviceNames.size());
+    for (size_t i = 0; i < cameraDeviceNames.size(); i++) {
+        retList[i] = cameraDeviceNames[i];
+    }
+    return retList;
 }
 
 // Test devices with first_api_level >= P does not advertise device@1.0
@@ -2010,7 +2050,8 @@
                         ASSERT_TRUE(
                                 hardwareLevel == ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED ||
                                 hardwareLevel == ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_FULL ||
-                                hardwareLevel == ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_3);
+                                hardwareLevel == ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_3 ||
+                                hardwareLevel == ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL);
                     } else {
                         ADD_FAILURE() << "Get camera hardware level failed!";
                     }
@@ -2440,13 +2481,14 @@
         int32_t streamId = 0;
         for (auto& it : outputStreams) {
             V3_2::Stream stream3_2;
+            bool isJpeg = static_cast<PixelFormat>(it.format) == PixelFormat::BLOB;
             stream3_2 = {streamId,
                              StreamType::OUTPUT,
                              static_cast<uint32_t>(it.width),
                              static_cast<uint32_t>(it.height),
                              static_cast<PixelFormat>(it.format),
                              GRALLOC1_CONSUMER_USAGE_HWCOMPOSER,
-                             0,
+                             (isJpeg) ? static_cast<V3_2::DataspaceFlags>(Dataspace::V0_JFIF) : 0,
                              StreamRotation::ROTATION_0};
             ::android::hardware::hidl_vec<V3_2::Stream> streams3_2 = {stream3_2};
             ::android::hardware::camera::device::V3_4::StreamConfiguration config3_4;
@@ -2897,7 +2939,7 @@
                                      static_cast<uint32_t>(blobIter.height),
                                      static_cast<PixelFormat>(blobIter.format),
                                      GRALLOC1_CONSUMER_USAGE_CPU_READ,
-                                     0,
+                                     static_cast<V3_2::DataspaceFlags>(Dataspace::V0_JFIF),
                                      StreamRotation::ROTATION_0};
                 ::android::hardware::hidl_vec<V3_2::Stream> streams = {previewStream,
                                                                  blobStream};
@@ -3162,7 +3204,7 @@
                                      static_cast<uint32_t>(blobIter.height),
                                      static_cast<PixelFormat>(blobIter.format),
                                      GRALLOC1_CONSUMER_USAGE_CPU_READ,
-                                     0,
+                                     static_cast<V3_2::DataspaceFlags>(Dataspace::V0_JFIF),
                                      StreamRotation::ROTATION_0};
                 ::android::hardware::hidl_vec<V3_2::Stream> streams = {videoStream, blobStream};
                 ::android::hardware::camera::device::V3_4::StreamConfiguration config3_4;
@@ -3603,8 +3645,9 @@
 
         camera_metadata_entry_t hwLevel = staticMeta.find(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL);
         ASSERT_TRUE(0 < hwLevel.count);
-        if (ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED == hwLevel.data.u8[0]) {
-            //Limited devices can skip this test
+        if (ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED == hwLevel.data.u8[0] ||
+                ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL == hwLevel.data.u8[0]) {
+            //Limited/External devices can skip this test
             ret = session->close();
             ASSERT_TRUE(ret.isOk());
             continue;