Camera: Switch camera2 to auto-gen C++ binder interfaces

 - Move camera service AIDL files to frameworks/av
 - Build C++ interface stubs with AIDL tools
 - Add necessary native-side parcelables and update existing ones
 - Remove manually-written stubs, rearrange remaining manual stubs
 - Adjust implementations to work with auto-generated stubs
   - Adjust method signatures for auto-gen differences
   - Add rich error messages using binder::Status

Bug: 25091611
Change-Id: I6f69f34b9d1a3f8d1fb7db87357363f8fa8483ff
diff --git a/camera/Android.mk b/camera/Android.mk
index de23953..b0df7c4 100644
--- a/camera/Android.mk
+++ b/camera/Android.mk
@@ -18,7 +18,24 @@
 
 LOCAL_PATH := $(CAMERA_CLIENT_LOCAL_PATH)
 
-LOCAL_SRC_FILES:= \
+LOCAL_AIDL_INCLUDES := \
+    frameworks/av/camera/aidl \
+    frameworks/base/core/java \
+    frameworks/native/aidl/gui
+
+# AIDL files for camera interfaces
+# The headers for these interfaces will be available to any modules that
+# include libcamera_client, at the path "aidl/package/path/BnFoo.h"
+
+LOCAL_SRC_FILES := \
+    aidl/android/hardware/ICameraService.aidl \
+    aidl/android/hardware/ICameraServiceListener.aidl \
+    aidl/android/hardware/camera2/ICameraDeviceCallbacks.aidl \
+    aidl/android/hardware/camera2/ICameraDeviceUser.aidl
+
+# Source for camera interface parcelables, and manually-written interfaces
+
+LOCAL_SRC_FILES += \
 	Camera.cpp \
 	CameraMetadata.cpp \
 	CameraParameters.cpp \
@@ -26,15 +43,12 @@
 	CameraParameters2.cpp \
 	ICamera.cpp \
 	ICameraClient.cpp \
-	ICameraService.cpp \
-	ICameraServiceListener.cpp \
 	ICameraServiceProxy.cpp \
 	ICameraRecordingProxy.cpp \
 	ICameraRecordingProxyListener.cpp \
-	camera2/ICameraDeviceUser.cpp \
-	camera2/ICameraDeviceCallbacks.cpp \
 	camera2/CaptureRequest.cpp \
 	camera2/OutputConfiguration.cpp \
+	camera2/SubmitInfo.cpp \
 	CameraBase.cpp \
 	CameraUtils.cpp \
 	VendorTagDescriptor.cpp
@@ -53,6 +67,11 @@
 	system/media/camera/include \
 	system/media/private/camera/include \
 	frameworks/native/include/media/openmax \
+	frameworks/av/include/camera
+
+LOCAL_EXPORT_C_INCLUDE_DIRS := \
+	system/media/camera/include \
+	frameworks/av/include/camera
 
 LOCAL_MODULE:= libcamera_client
 
diff --git a/camera/Camera.cpp b/camera/Camera.cpp
index 1289348..8d7a107 100644
--- a/camera/Camera.cpp
+++ b/camera/Camera.cpp
@@ -24,10 +24,10 @@
 #include <binder/IServiceManager.h>
 #include <binder/IMemory.h>
 
-#include <camera/Camera.h>
-#include <camera/ICameraRecordingProxyListener.h>
-#include <camera/ICameraService.h>
-#include <camera/ICamera.h>
+#include <Camera.h>
+#include <ICameraRecordingProxyListener.h>
+#include <android/hardware/ICameraService.h>
+#include <android/hardware/ICamera.h>
 
 #include <gui/IGraphicBufferProducer.h>
 #include <gui/Surface.h>
@@ -40,10 +40,10 @@
 }
 
 CameraTraits<Camera>::TCamConnectService CameraTraits<Camera>::fnConnectService =
-        &ICameraService::connect;
+        &::android::hardware::ICameraService::connect;
 
 // construct a camera client from an existing camera remote
-sp<Camera> Camera::create(const sp<ICamera>& camera)
+sp<Camera> Camera::create(const sp<::android::hardware::ICamera>& camera)
 {
      ALOGV("create");
      if (camera == 0) {
@@ -84,21 +84,23 @@
 {
     ALOGV("%s: connect legacy camera device", __FUNCTION__);
     sp<Camera> c = new Camera(cameraId);
-    sp<ICameraClient> cl = c;
+    sp<::android::hardware::ICameraClient> cl = c;
     status_t status = NO_ERROR;
-    const sp<ICameraService>& cs = CameraBaseT::getCameraService();
+    const sp<::android::hardware::ICameraService>& cs = CameraBaseT::getCameraService();
 
-    if (cs != 0) {
-        status = cs.get()->connectLegacy(cl, cameraId, halVersion, clientPackageName,
-                                        clientUid, /*out*/c->mCamera);
+    binder::Status ret;
+    if (cs != nullptr) {
+        ret = cs.get()->connectLegacy(cl, cameraId, halVersion, clientPackageName,
+                clientUid, /*out*/&(c->mCamera));
     }
-    if (status == OK && c->mCamera != 0) {
+    if (ret.isOk() && c->mCamera != nullptr) {
         IInterface::asBinder(c->mCamera)->linkToDeath(c);
         c->mStatus = NO_ERROR;
         camera = c;
     } else {
-        ALOGW("An error occurred while connecting to camera %d: %d (%s)",
-                cameraId, status, strerror(-status));
+        ALOGW("An error occurred while connecting to camera %d: %s", cameraId,
+                (cs != nullptr) ? "Service not available" : ret.toString8().string());
+        status = -EINVAL;
         c.clear();
     }
     return status;
@@ -107,21 +109,21 @@
 status_t Camera::reconnect()
 {
     ALOGV("reconnect");
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     return c->connect(this);
 }
 
 status_t Camera::lock()
 {
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     return c->lock();
 }
 
 status_t Camera::unlock()
 {
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     return c->unlock();
 }
@@ -130,7 +132,7 @@
 status_t Camera::setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)
 {
     ALOGV("setPreviewTarget(%p)", bufferProducer.get());
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     ALOGD_IF(bufferProducer == 0, "app passed NULL surface");
     return c->setPreviewTarget(bufferProducer);
@@ -139,7 +141,7 @@
 status_t Camera::setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer)
 {
     ALOGV("setVideoTarget(%p)", bufferProducer.get());
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     ALOGD_IF(bufferProducer == 0, "app passed NULL video surface");
     return c->setVideoTarget(bufferProducer);
@@ -149,7 +151,7 @@
 status_t Camera::startPreview()
 {
     ALOGV("startPreview");
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     return c->startPreview();
 }
@@ -157,7 +159,7 @@
 status_t Camera::setVideoBufferMode(int32_t videoBufferMode)
 {
     ALOGV("setVideoBufferMode: %d", videoBufferMode);
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     return c->setVideoBufferMode(videoBufferMode);
 }
@@ -166,7 +168,7 @@
 status_t Camera::startRecording()
 {
     ALOGV("startRecording");
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     return c->startRecording();
 }
@@ -175,7 +177,7 @@
 void Camera::stopPreview()
 {
     ALOGV("stopPreview");
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return;
     c->stopPreview();
 }
@@ -188,7 +190,7 @@
         Mutex::Autolock _l(mLock);
         mRecordingProxyListener.clear();
     }
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return;
     c->stopRecording();
 }
@@ -197,7 +199,7 @@
 void Camera::releaseRecordingFrame(const sp<IMemory>& mem)
 {
     ALOGV("releaseRecordingFrame");
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return;
     c->releaseRecordingFrame(mem);
 }
@@ -206,7 +208,7 @@
 bool Camera::previewEnabled()
 {
     ALOGV("previewEnabled");
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return false;
     return c->previewEnabled();
 }
@@ -215,7 +217,7 @@
 bool Camera::recordingEnabled()
 {
     ALOGV("recordingEnabled");
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return false;
     return c->recordingEnabled();
 }
@@ -223,7 +225,7 @@
 status_t Camera::autoFocus()
 {
     ALOGV("autoFocus");
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     return c->autoFocus();
 }
@@ -231,7 +233,7 @@
 status_t Camera::cancelAutoFocus()
 {
     ALOGV("cancelAutoFocus");
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     return c->cancelAutoFocus();
 }
@@ -240,7 +242,7 @@
 status_t Camera::takePicture(int msgType)
 {
     ALOGV("takePicture: 0x%x", msgType);
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     return c->takePicture(msgType);
 }
@@ -249,7 +251,7 @@
 status_t Camera::setParameters(const String8& params)
 {
     ALOGV("setParameters");
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     return c->setParameters(params);
 }
@@ -259,7 +261,7 @@
 {
     ALOGV("getParameters");
     String8 params;
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c != 0) params = mCamera->getParameters();
     return params;
 }
@@ -268,7 +270,7 @@
 status_t Camera::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
 {
     ALOGV("sendCommand");
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     return c->sendCommand(cmd, arg1, arg2);
 }
@@ -288,7 +290,7 @@
 void Camera::setPreviewCallbackFlags(int flag)
 {
     ALOGV("setPreviewCallbackFlags");
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return;
     mCamera->setPreviewCallbackFlag(flag);
 }
@@ -296,7 +298,7 @@
 status_t Camera::setPreviewCallbackTarget(
         const sp<IGraphicBufferProducer>& callbackProducer)
 {
-    sp <ICamera> c = mCamera;
+    sp <::android::hardware::ICamera> c = mCamera;
     if (c == 0) return NO_INIT;
     return c->setPreviewCallbackTarget(callbackProducer);
 }
diff --git a/camera/CameraBase.cpp b/camera/CameraBase.cpp
index 9ee7ae5..9aa0b4e 100644
--- a/camera/CameraBase.cpp
+++ b/camera/CameraBase.cpp
@@ -21,12 +21,13 @@
 #include <utils/threads.h>
 #include <utils/Mutex.h>
 
+#include <android/hardware/ICameraService.h>
+
 #include <binder/IPCThreadState.h>
 #include <binder/IServiceManager.h>
 #include <binder/IMemory.h>
 
 #include <camera/CameraBase.h>
-#include <camera/ICameraService.h>
 
 // needed to instantiate
 #include <camera/Camera.h>
@@ -35,8 +36,28 @@
 
 namespace android {
 
+namespace hardware {
+
+status_t CameraInfo::writeToParcel(Parcel* parcel) const {
+    status_t res;
+    res = parcel->writeInt32(facing);
+    if (res != OK) return res;
+    res = parcel->writeInt32(orientation);
+    return res;
+}
+
+status_t CameraInfo::readFromParcel(const Parcel* parcel) {
+    status_t res;
+    res = parcel->readInt32(&facing);
+    if (res != OK) return res;
+    res = parcel->readInt32(&orientation);
+    return res;
+}
+
+}
+
 namespace {
-    sp<ICameraService>        gCameraService;
+    sp<::android::hardware::ICameraService> gCameraService;
     const int                 kCameraServicePollDelay = 500000; // 0.5s
     const char*               kCameraServiceName      = "media.camera";
 
@@ -65,7 +86,7 @@
 
 // establish binder interface to camera service
 template <typename TCam, typename TCamTraits>
-const sp<ICameraService>& CameraBase<TCam, TCamTraits>::getCameraService()
+const sp<::android::hardware::ICameraService>& CameraBase<TCam, TCamTraits>::getCameraService()
 {
     Mutex::Autolock _l(gLock);
     if (gCameraService.get() == 0) {
@@ -83,7 +104,7 @@
             gDeathNotifier = new DeathNotifier();
         }
         binder->linkToDeath(gDeathNotifier);
-        gCameraService = interface_cast<ICameraService>(binder);
+        gCameraService = interface_cast<::android::hardware::ICameraService>(binder);
     }
     ALOGE_IF(gCameraService == 0, "no CameraService!?");
     return gCameraService;
@@ -98,18 +119,20 @@
     sp<TCam> c = new TCam(cameraId);
     sp<TCamCallbacks> cl = c;
     status_t status = NO_ERROR;
-    const sp<ICameraService>& cs = getCameraService();
+    const sp<::android::hardware::ICameraService>& cs = getCameraService();
 
-    if (cs != 0) {
+    binder::Status ret;
+    if (cs != nullptr) {
         TCamConnectService fnConnectService = TCamTraits::fnConnectService;
-        status = (cs.get()->*fnConnectService)(cl, cameraId, clientPackageName, clientUid,
-                                               clientPid, /*out*/ c->mCamera);
+        ret = (cs.get()->*fnConnectService)(cl, cameraId, clientPackageName, clientUid,
+                                               clientPid, /*out*/ &c->mCamera);
     }
-    if (status == OK && c->mCamera != 0) {
+    if (ret.isOk() && c->mCamera != nullptr) {
         IInterface::asBinder(c->mCamera)->linkToDeath(c);
         c->mStatus = NO_ERROR;
     } else {
-        ALOGW("An error occurred while connecting to camera: %d", cameraId);
+        ALOGW("An error occurred while connecting to camera %d: %s", cameraId,
+                (cs != nullptr) ? "Service not available" : ret.toString8().string());
         c.clear();
     }
     return c;
@@ -182,38 +205,50 @@
 
 template <typename TCam, typename TCamTraits>
 int CameraBase<TCam, TCamTraits>::getNumberOfCameras() {
-    const sp<ICameraService> cs = getCameraService();
+    const sp<::android::hardware::ICameraService> cs = getCameraService();
 
     if (!cs.get()) {
         // as required by the public Java APIs
         return 0;
     }
-    return cs->getNumberOfCameras();
+    int32_t count;
+    binder::Status res = cs->getNumberOfCameras(
+            ::android::hardware::ICameraService::CAMERA_TYPE_BACKWARD_COMPATIBLE,
+            &count);
+    if (!res.isOk()) {
+        ALOGE("Error reading number of cameras: %s",
+                res.toString8().string());
+        count = 0;
+    }
+    return count;
 }
 
 // this can be in BaseCamera but it should be an instance method
 template <typename TCam, typename TCamTraits>
 status_t CameraBase<TCam, TCamTraits>::getCameraInfo(int cameraId,
-                               struct CameraInfo* cameraInfo) {
-    const sp<ICameraService>& cs = getCameraService();
+        struct hardware::CameraInfo* cameraInfo) {
+    const sp<::android::hardware::ICameraService>& cs = getCameraService();
     if (cs == 0) return UNKNOWN_ERROR;
-    return cs->getCameraInfo(cameraId, cameraInfo);
+    binder::Status res = cs->getCameraInfo(cameraId, cameraInfo);
+    return res.isOk() ? OK : res.serviceSpecificErrorCode();
 }
 
 template <typename TCam, typename TCamTraits>
 status_t CameraBase<TCam, TCamTraits>::addServiceListener(
-                            const sp<ICameraServiceListener>& listener) {
-    const sp<ICameraService>& cs = getCameraService();
+        const sp<::android::hardware::ICameraServiceListener>& listener) {
+    const sp<::android::hardware::ICameraService>& cs = getCameraService();
     if (cs == 0) return UNKNOWN_ERROR;
-    return cs->addListener(listener);
+    binder::Status res = cs->addListener(listener);
+    return res.isOk() ? OK : res.serviceSpecificErrorCode();
 }
 
 template <typename TCam, typename TCamTraits>
 status_t CameraBase<TCam, TCamTraits>::removeServiceListener(
-                            const sp<ICameraServiceListener>& listener) {
-    const sp<ICameraService>& cs = getCameraService();
+        const sp<::android::hardware::ICameraServiceListener>& listener) {
+    const sp<::android::hardware::ICameraService>& cs = getCameraService();
     if (cs == 0) return UNKNOWN_ERROR;
-    return cs->removeListener(listener);
+    binder::Status res = cs->removeListener(listener);
+    return res.isOk() ? OK : res.serviceSpecificErrorCode();
 }
 
 template class CameraBase<Camera>;
diff --git a/camera/CameraMetadata.cpp b/camera/CameraMetadata.cpp
index 46bcc1d..fad57ba 100644
--- a/camera/CameraMetadata.cpp
+++ b/camera/CameraMetadata.cpp
@@ -621,7 +621,7 @@
     return res;
 }
 
-status_t CameraMetadata::readFromParcel(Parcel *parcel) {
+status_t CameraMetadata::readFromParcel(const Parcel *parcel) {
 
     ALOGV("%s: parcel = %p", __FUNCTION__, parcel);
 
diff --git a/camera/CaptureResult.cpp b/camera/CaptureResult.cpp
index 4e36160..58d9b43 100644
--- a/camera/CaptureResult.cpp
+++ b/camera/CaptureResult.cpp
@@ -26,7 +26,7 @@
     return requestId >= 0;
 }
 
-status_t CaptureResultExtras::readFromParcel(Parcel *parcel) {
+status_t CaptureResultExtras::readFromParcel(const Parcel *parcel) {
     if (parcel == NULL) {
         ALOGE("%s: Null parcel", __FUNCTION__);
         return BAD_VALUE;
diff --git a/camera/ICamera.cpp b/camera/ICamera.cpp
index 1dd8912..37b0a10 100644
--- a/camera/ICamera.cpp
+++ b/camera/ICamera.cpp
@@ -22,12 +22,14 @@
 #include <sys/types.h>
 #include <binder/Parcel.h>
 #include <camera/CameraUtils.h>
-#include <camera/ICamera.h>
+#include <android/hardware/ICamera.h>
+#include <android/hardware/ICameraClient.h>
 #include <gui/IGraphicBufferProducer.h>
 #include <gui/Surface.h>
 #include <media/hardware/HardwareAPI.h>
 
 namespace android {
+namespace hardware {
 
 enum {
     DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
@@ -63,13 +65,14 @@
     }
 
     // disconnect from camera service
-    void disconnect()
+    binder::Status disconnect()
     {
         ALOGV("disconnect");
         Parcel data, reply;
         data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
         remote()->transact(DISCONNECT, data, &reply);
         reply.readExceptionCode();
+        return binder::Status::ok();
     }
 
     // pass the buffered IGraphicBufferProducer to the camera service
@@ -467,4 +470,5 @@
 
 // ----------------------------------------------------------------------------
 
-}; // namespace android
+} // namespace hardware
+} // namespace android
diff --git a/camera/ICameraClient.cpp b/camera/ICameraClient.cpp
index 4282f9a..d058138 100644
--- a/camera/ICameraClient.cpp
+++ b/camera/ICameraClient.cpp
@@ -21,10 +21,11 @@
 #include <stdint.h>
 #include <sys/types.h>
 #include <camera/CameraUtils.h>
-#include <camera/ICameraClient.h>
+#include <android/hardware/ICameraClient.h>
 #include <media/hardware/HardwareAPI.h>
 
 namespace android {
+namespace hardware {
 
 enum {
     NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
@@ -150,5 +151,5 @@
 
 // ----------------------------------------------------------------------------
 
-}; // namespace android
-
+} // namespace hardware
+} // namespace android
diff --git a/camera/ICameraService.cpp b/camera/ICameraService.cpp
deleted file mode 100644
index 4a042a6..0000000
--- a/camera/ICameraService.cpp
+++ /dev/null
@@ -1,536 +0,0 @@
-/*
-**
-** Copyright 2008, 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 "BpCameraService"
-#include <utils/Log.h>
-#include <utils/Errors.h>
-#include <utils/String16.h>
-
-#include <inttypes.h>
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <binder/Parcel.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
-
-#include <camera/ICameraService.h>
-#include <camera/ICameraServiceListener.h>
-#include <camera/ICamera.h>
-#include <camera/ICameraClient.h>
-#include <camera/camera2/ICameraDeviceUser.h>
-#include <camera/camera2/ICameraDeviceCallbacks.h>
-#include <camera/CameraMetadata.h>
-#include <camera/VendorTagDescriptor.h>
-
-namespace android {
-
-namespace {
-
-enum {
-    EX_SECURITY = -1,
-    EX_BAD_PARCELABLE = -2,
-    EX_ILLEGAL_ARGUMENT = -3,
-    EX_NULL_POINTER = -4,
-    EX_ILLEGAL_STATE = -5,
-    EX_HAS_REPLY_HEADER = -128,  // special; see below
-};
-
-static bool readExceptionCode(Parcel& reply) {
-    int32_t exceptionCode = reply.readExceptionCode();
-
-    if (exceptionCode != 0) {
-        const char* errorMsg;
-        switch(exceptionCode) {
-            case EX_SECURITY:
-                errorMsg = "Security";
-                break;
-            case EX_BAD_PARCELABLE:
-                errorMsg = "BadParcelable";
-                break;
-            case EX_NULL_POINTER:
-                errorMsg = "NullPointer";
-                break;
-            case EX_ILLEGAL_STATE:
-                errorMsg = "IllegalState";
-                break;
-            // Binder should be handling this code inside Parcel::readException
-            // but lets have a to-string here anyway just in case.
-            case EX_HAS_REPLY_HEADER:
-                errorMsg = "HasReplyHeader";
-                break;
-            default:
-                errorMsg = "Unknown";
-        }
-
-        ALOGE("Binder transmission error %s (%d)", errorMsg, exceptionCode);
-        return true;
-    }
-
-    return false;
-}
-
-};
-
-class BpCameraService: public BpInterface<ICameraService>
-{
-public:
-    BpCameraService(const sp<IBinder>& impl)
-        : BpInterface<ICameraService>(impl)
-    {
-    }
-
-    // get number of cameras available that support standard camera operations
-    virtual int32_t getNumberOfCameras()
-    {
-        return getNumberOfCameras(CAMERA_TYPE_BACKWARD_COMPATIBLE);
-    }
-
-    // get number of cameras available of a given type
-    virtual int32_t getNumberOfCameras(int type)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeInt32(type);
-        remote()->transact(BnCameraService::GET_NUMBER_OF_CAMERAS, data, &reply);
-
-        if (readExceptionCode(reply)) return 0;
-        return reply.readInt32();
-    }
-
-    // get information about a camera
-    virtual status_t getCameraInfo(int cameraId,
-                                   struct CameraInfo* cameraInfo) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeInt32(cameraId);
-        remote()->transact(BnCameraService::GET_CAMERA_INFO, data, &reply);
-
-        if (readExceptionCode(reply)) return -EPROTO;
-        status_t result = reply.readInt32();
-        if (reply.readInt32() != 0) {
-            cameraInfo->facing = reply.readInt32();
-            cameraInfo->orientation = reply.readInt32();
-        }
-        return result;
-    }
-
-    // get camera characteristics (static metadata)
-    virtual status_t getCameraCharacteristics(int cameraId,
-                                              CameraMetadata* cameraInfo) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeInt32(cameraId);
-        remote()->transact(BnCameraService::GET_CAMERA_CHARACTERISTICS, data, &reply);
-
-        if (readExceptionCode(reply)) return -EPROTO;
-        status_t result = reply.readInt32();
-
-        CameraMetadata out;
-        if (reply.readInt32() != 0) {
-            out.readFromParcel(&reply);
-        }
-
-        if (cameraInfo != NULL) {
-            cameraInfo->swap(out);
-        }
-
-        return result;
-    }
-
-    // Get enumeration and description of vendor tags for camera
-    virtual status_t getCameraVendorTagDescriptor(/*out*/sp<VendorTagDescriptor>& desc) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        remote()->transact(BnCameraService::GET_CAMERA_VENDOR_TAG_DESCRIPTOR, data, &reply);
-
-        if (readExceptionCode(reply)) return -EPROTO;
-        status_t result = reply.readInt32();
-
-        if (reply.readInt32() != 0) {
-            sp<VendorTagDescriptor> d;
-            if (VendorTagDescriptor::createFromParcel(&reply, /*out*/d) == OK) {
-                desc = d;
-            }
-        }
-        return result;
-    }
-
-    // connect to camera service (android.hardware.Camera)
-    virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId,
-                             const String16 &clientPackageName, int clientUid, int clientPid,
-                             /*out*/
-                             sp<ICamera>& device)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeStrongBinder(IInterface::asBinder(cameraClient));
-        data.writeInt32(cameraId);
-        data.writeString16(clientPackageName);
-        data.writeInt32(clientUid);
-        data.writeInt32(clientPid);
-
-        status_t status;
-        status = remote()->transact(BnCameraService::CONNECT, data, &reply);
-        if (status != OK) return status;
-
-        if (readExceptionCode(reply)) return -EPROTO;
-        status = reply.readInt32();
-        if (reply.readInt32() != 0) {
-            device = interface_cast<ICamera>(reply.readStrongBinder());
-        }
-        return status;
-    }
-
-    // connect to camera service (android.hardware.Camera)
-    virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient, int cameraId,
-                             int halVersion,
-                             const String16 &clientPackageName, int clientUid,
-                             /*out*/sp<ICamera>& device)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeStrongBinder(IInterface::asBinder(cameraClient));
-        data.writeInt32(cameraId);
-        data.writeInt32(halVersion);
-        data.writeString16(clientPackageName);
-        data.writeInt32(clientUid);
-
-        status_t status;
-        status = remote()->transact(BnCameraService::CONNECT_LEGACY, data, &reply);
-        if (status != OK) return status;
-
-        if (readExceptionCode(reply)) return -EPROTO;
-        status = reply.readInt32();
-        if (reply.readInt32() != 0) {
-            device = interface_cast<ICamera>(reply.readStrongBinder());
-        }
-        return status;
-    }
-
-    virtual status_t setTorchMode(const String16& cameraId, bool enabled,
-            const sp<IBinder>& clientBinder)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeString16(cameraId);
-        data.writeInt32(enabled ? 1 : 0);
-        data.writeStrongBinder(clientBinder);
-        remote()->transact(BnCameraService::SET_TORCH_MODE, data, &reply);
-
-        if (readExceptionCode(reply)) return -EPROTO;
-        return reply.readInt32();
-    }
-
-    // connect to camera service (android.hardware.camera2.CameraDevice)
-    virtual status_t connectDevice(
-            const sp<ICameraDeviceCallbacks>& cameraCb,
-            int cameraId,
-            const String16& clientPackageName,
-            int clientUid,
-            /*out*/
-            sp<ICameraDeviceUser>& device)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeStrongBinder(IInterface::asBinder(cameraCb));
-        data.writeInt32(cameraId);
-        data.writeString16(clientPackageName);
-        data.writeInt32(clientUid);
-
-        status_t status;
-        status = remote()->transact(BnCameraService::CONNECT_DEVICE, data, &reply);
-        if (status != OK) return status;
-
-        if (readExceptionCode(reply)) return -EPROTO;
-        status = reply.readInt32();
-        if (reply.readInt32() != 0) {
-            device = interface_cast<ICameraDeviceUser>(reply.readStrongBinder());
-        }
-        return status;
-    }
-
-    virtual status_t addListener(const sp<ICameraServiceListener>& listener)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeStrongBinder(IInterface::asBinder(listener));
-        remote()->transact(BnCameraService::ADD_LISTENER, data, &reply);
-
-        if (readExceptionCode(reply)) return -EPROTO;
-        return reply.readInt32();
-    }
-
-    virtual status_t removeListener(const sp<ICameraServiceListener>& listener)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeStrongBinder(IInterface::asBinder(listener));
-        remote()->transact(BnCameraService::REMOVE_LISTENER, data, &reply);
-
-        if (readExceptionCode(reply)) return -EPROTO;
-        return reply.readInt32();
-    }
-
-    virtual status_t getLegacyParameters(int cameraId, String16* parameters) {
-        if (parameters == NULL) {
-            ALOGE("%s: parameters must not be null", __FUNCTION__);
-            return BAD_VALUE;
-        }
-
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-
-        data.writeInt32(cameraId);
-        remote()->transact(BnCameraService::GET_LEGACY_PARAMETERS, data, &reply);
-        if (readExceptionCode(reply)) return -EPROTO;
-
-        status_t res = data.readInt32();
-        int32_t length = data.readInt32(); // -1 means null
-        if (length > 0) {
-            *parameters = data.readString16();
-        } else {
-            *parameters = String16();
-        }
-
-        return res;
-    }
-
-    virtual status_t supportsCameraApi(int cameraId, int apiVersion) {
-        Parcel data, reply;
-
-        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeInt32(cameraId);
-        data.writeInt32(apiVersion);
-        remote()->transact(BnCameraService::SUPPORTS_CAMERA_API, data, &reply);
-        if (readExceptionCode(reply)) return -EPROTO;
-
-        status_t res = data.readInt32();
-        return res;
-    }
-
-    virtual void notifySystemEvent(int32_t eventId, const int32_t* args, size_t len) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeInt32(eventId);
-        data.writeInt32Array(len, args);
-        remote()->transact(BnCameraService::NOTIFY_SYSTEM_EVENT, data, &reply,
-                IBinder::FLAG_ONEWAY);
-    }
-
-};
-
-IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService");
-
-// ----------------------------------------------------------------------
-
-status_t BnCameraService::onTransact(
-    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
-    switch(code) {
-        case GET_NUMBER_OF_CAMERAS: {
-            CHECK_INTERFACE(ICameraService, data, reply);
-            reply->writeNoException();
-            reply->writeInt32(getNumberOfCameras(data.readInt32()));
-            return NO_ERROR;
-        } break;
-        case GET_CAMERA_INFO: {
-            CHECK_INTERFACE(ICameraService, data, reply);
-            CameraInfo cameraInfo = CameraInfo();
-            memset(&cameraInfo, 0, sizeof(cameraInfo));
-            status_t result = getCameraInfo(data.readInt32(), &cameraInfo);
-            reply->writeNoException();
-            reply->writeInt32(result);
-
-            // Fake a parcelable object here
-            reply->writeInt32(1); // means the parcelable is included
-            reply->writeInt32(cameraInfo.facing);
-            reply->writeInt32(cameraInfo.orientation);
-            return NO_ERROR;
-        } break;
-        case GET_CAMERA_CHARACTERISTICS: {
-            CHECK_INTERFACE(ICameraService, data, reply);
-            CameraMetadata info;
-            status_t result = getCameraCharacteristics(data.readInt32(), &info);
-            reply->writeNoException();
-            reply->writeInt32(result);
-
-            // out-variables are after exception and return value
-            reply->writeInt32(1); // means the parcelable is included
-            info.writeToParcel(reply);
-            return NO_ERROR;
-        } break;
-        case GET_CAMERA_VENDOR_TAG_DESCRIPTOR: {
-            CHECK_INTERFACE(ICameraService, data, reply);
-            sp<VendorTagDescriptor> d;
-            status_t result = getCameraVendorTagDescriptor(d);
-            reply->writeNoException();
-            reply->writeInt32(result);
-
-            // out-variables are after exception and return value
-            if (d == NULL) {
-                reply->writeInt32(0);
-            } else {
-                reply->writeInt32(1); // means the parcelable is included
-                d->writeToParcel(reply);
-            }
-            return NO_ERROR;
-        } break;
-        case CONNECT: {
-            CHECK_INTERFACE(ICameraService, data, reply);
-            sp<ICameraClient> cameraClient =
-                    interface_cast<ICameraClient>(data.readStrongBinder());
-            int32_t cameraId = data.readInt32();
-            const String16 clientName = data.readString16();
-            int32_t clientUid = data.readInt32();
-            int32_t clientPid = data.readInt32();
-            sp<ICamera> camera;
-            status_t status = connect(cameraClient, cameraId,
-                    clientName, clientUid, clientPid, /*out*/camera);
-            reply->writeNoException();
-            reply->writeInt32(status);
-            if (camera != NULL) {
-                reply->writeInt32(1);
-                reply->writeStrongBinder(IInterface::asBinder(camera));
-            } else {
-                reply->writeInt32(0);
-            }
-            return NO_ERROR;
-        } break;
-        case CONNECT_DEVICE: {
-            CHECK_INTERFACE(ICameraService, data, reply);
-            sp<ICameraDeviceCallbacks> cameraClient =
-                interface_cast<ICameraDeviceCallbacks>(data.readStrongBinder());
-            int32_t cameraId = data.readInt32();
-            const String16 clientName = data.readString16();
-            int32_t clientUid = data.readInt32();
-            sp<ICameraDeviceUser> camera;
-            status_t status = connectDevice(cameraClient, cameraId,
-                    clientName, clientUid, /*out*/camera);
-            reply->writeNoException();
-            reply->writeInt32(status);
-            if (camera != NULL) {
-                reply->writeInt32(1);
-                reply->writeStrongBinder(IInterface::asBinder(camera));
-            } else {
-                reply->writeInt32(0);
-            }
-            return NO_ERROR;
-        } break;
-        case ADD_LISTENER: {
-            CHECK_INTERFACE(ICameraService, data, reply);
-            sp<ICameraServiceListener> listener =
-                interface_cast<ICameraServiceListener>(data.readStrongBinder());
-            reply->writeNoException();
-            reply->writeInt32(addListener(listener));
-            return NO_ERROR;
-        } break;
-        case REMOVE_LISTENER: {
-            CHECK_INTERFACE(ICameraService, data, reply);
-            sp<ICameraServiceListener> listener =
-                interface_cast<ICameraServiceListener>(data.readStrongBinder());
-            reply->writeNoException();
-            reply->writeInt32(removeListener(listener));
-            return NO_ERROR;
-        } break;
-        case GET_LEGACY_PARAMETERS: {
-            CHECK_INTERFACE(ICameraService, data, reply);
-            int cameraId = data.readInt32();
-            String16 parameters;
-
-            reply->writeNoException();
-            // return value
-            reply->writeInt32(getLegacyParameters(cameraId, &parameters));
-            // out parameters
-            reply->writeInt32(1); // parameters is always available
-            reply->writeString16(parameters);
-            return NO_ERROR;
-        } break;
-        case SUPPORTS_CAMERA_API: {
-            CHECK_INTERFACE(ICameraService, data, reply);
-            int cameraId = data.readInt32();
-            int apiVersion = data.readInt32();
-
-            reply->writeNoException();
-            // return value
-            reply->writeInt32(supportsCameraApi(cameraId, apiVersion));
-            return NO_ERROR;
-        } break;
-        case CONNECT_LEGACY: {
-            CHECK_INTERFACE(ICameraService, data, reply);
-            sp<ICameraClient> cameraClient =
-                    interface_cast<ICameraClient>(data.readStrongBinder());
-            int32_t cameraId = data.readInt32();
-            int32_t halVersion = data.readInt32();
-            const String16 clientName = data.readString16();
-            int32_t clientUid = data.readInt32();
-            sp<ICamera> camera;
-            status_t status = connectLegacy(cameraClient, cameraId, halVersion,
-                    clientName, clientUid, /*out*/camera);
-            reply->writeNoException();
-            reply->writeInt32(status);
-            if (camera != NULL) {
-                reply->writeInt32(1);
-                reply->writeStrongBinder(IInterface::asBinder(camera));
-            } else {
-                reply->writeInt32(0);
-            }
-            return NO_ERROR;
-        } break;
-        case SET_TORCH_MODE: {
-            CHECK_INTERFACE(ICameraService, data, reply);
-            String16 cameraId = data.readString16();
-            bool enabled = data.readInt32() != 0 ? true : false;
-            const sp<IBinder> clientBinder = data.readStrongBinder();
-            status_t status = setTorchMode(cameraId, enabled, clientBinder);
-            reply->writeNoException();
-            reply->writeInt32(status);
-            return NO_ERROR;
-        } break;
-        case NOTIFY_SYSTEM_EVENT: {
-            CHECK_INTERFACE(ICameraService, data, reply);
-            int32_t eventId = data.readInt32();
-            int32_t len = data.readInt32();
-            if (len < 0) {
-                ALOGE("%s: Received poorly formatted length in binder request: notifySystemEvent.",
-                        __FUNCTION__);
-                return FAILED_TRANSACTION;
-            }
-            if (len > 512) {
-                ALOGE("%s: Length %" PRIi32 " too long in binder request: notifySystemEvent.",
-                        __FUNCTION__, len);
-                return FAILED_TRANSACTION;
-            }
-            int32_t events[len];
-            memset(events, 0, sizeof(int32_t) * len);
-            status_t status = data.read(events, sizeof(int32_t) * len);
-            if (status != NO_ERROR) {
-                ALOGE("%s: Received poorly formatted binder request: notifySystemEvent.",
-                        __FUNCTION__);
-                return FAILED_TRANSACTION;
-            }
-            notifySystemEvent(eventId, events, len);
-            return NO_ERROR;
-        } break;
-        default:
-            return BBinder::onTransact(code, data, reply, flags);
-    }
-}
-
-// ----------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/camera/ICameraServiceListener.cpp b/camera/ICameraServiceListener.cpp
deleted file mode 100644
index 0010325..0000000
--- a/camera/ICameraServiceListener.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
-**
-** Copyright 2013, 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 <stdint.h>
-#include <sys/types.h>
-
-#include <binder/Parcel.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
-
-#include <camera/ICameraServiceListener.h>
-
-namespace android {
-
-namespace {
-    enum {
-        STATUS_CHANGED = IBinder::FIRST_CALL_TRANSACTION,
-        TORCH_STATUS_CHANGED,
-    };
-}; // namespace anonymous
-
-class BpCameraServiceListener: public BpInterface<ICameraServiceListener>
-{
-
-public:
-    BpCameraServiceListener(const sp<IBinder>& impl)
-        : BpInterface<ICameraServiceListener>(impl)
-    {
-    }
-
-    virtual void onStatusChanged(Status status, int32_t cameraId)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraServiceListener::getInterfaceDescriptor());
-
-        data.writeInt32(static_cast<int32_t>(status));
-        data.writeInt32(cameraId);
-
-        remote()->transact(STATUS_CHANGED,
-                           data,
-                           &reply,
-                           IBinder::FLAG_ONEWAY);
-    }
-
-    virtual void onTorchStatusChanged(TorchStatus status, const String16 &cameraId)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraServiceListener::getInterfaceDescriptor());
-
-        data.writeInt32(static_cast<int32_t>(status));
-        data.writeString16(cameraId);
-
-        remote()->transact(TORCH_STATUS_CHANGED,
-                           data,
-                           &reply,
-                           IBinder::FLAG_ONEWAY);
-    }
-};
-
-IMPLEMENT_META_INTERFACE(CameraServiceListener, "android.hardware.ICameraServiceListener");
-
-// ----------------------------------------------------------------------
-
-status_t BnCameraServiceListener::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
-        uint32_t flags) {
-    switch(code) {
-        case STATUS_CHANGED: {
-            CHECK_INTERFACE(ICameraServiceListener, data, reply);
-
-            Status status = static_cast<Status>(data.readInt32());
-            int32_t cameraId = data.readInt32();
-
-            onStatusChanged(status, cameraId);
-
-            return NO_ERROR;
-        } break;
-        case TORCH_STATUS_CHANGED: {
-            CHECK_INTERFACE(ICameraServiceListener, data, reply);
-
-            TorchStatus status = static_cast<TorchStatus>(data.readInt32());
-            String16 cameraId = data.readString16();
-
-            onTorchStatusChanged(status, cameraId);
-
-            return NO_ERROR;
-        } break;
-        default:
-            return BBinder::onTransact(code, data, reply, flags);
-    }
-}
-
-// ----------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/camera/VendorTagDescriptor.cpp b/camera/VendorTagDescriptor.cpp
index dce313a..de69a5b 100644
--- a/camera/VendorTagDescriptor.cpp
+++ b/camera/VendorTagDescriptor.cpp
@@ -46,7 +46,9 @@
 static Mutex sLock;
 static sp<VendorTagDescriptor> sGlobalVendorTagDescriptor;
 
-VendorTagDescriptor::VendorTagDescriptor() {}
+namespace hardware {
+namespace camera2 {
+namespace params {
 
 VendorTagDescriptor::~VendorTagDescriptor() {
     size_t len = mReverseMapping.size();
@@ -55,90 +57,46 @@
     }
 }
 
-status_t VendorTagDescriptor::createDescriptorFromOps(const vendor_tag_ops_t* vOps,
-            /*out*/
-            sp<VendorTagDescriptor>& descriptor) {
-    if (vOps == NULL) {
-        ALOGE("%s: vendor_tag_ops argument was NULL.", __FUNCTION__);
-        return BAD_VALUE;
-    }
-
-    int tagCount = vOps->get_tag_count(vOps);
-    if (tagCount < 0 || tagCount > INT32_MAX) {
-        ALOGE("%s: tag count %d from vendor ops is invalid.", __FUNCTION__, tagCount);
-        return BAD_VALUE;
-    }
-
-    Vector<uint32_t> tagArray;
-    LOG_ALWAYS_FATAL_IF(tagArray.resize(tagCount) != tagCount,
-            "%s: too many (%u) vendor tags defined.", __FUNCTION__, tagCount);
-
-    vOps->get_all_tags(vOps, /*out*/tagArray.editArray());
-
-    sp<VendorTagDescriptor> desc = new VendorTagDescriptor();
-    desc->mTagCount = tagCount;
-
-    SortedVector<String8> sections;
-    KeyedVector<uint32_t, String8> tagToSectionMap;
-
-    for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) {
-        uint32_t tag = tagArray[i];
-        if (tag < CAMERA_METADATA_VENDOR_TAG_BOUNDARY) {
-            ALOGE("%s: vendor tag %d not in vendor tag section.", __FUNCTION__, tag);
-            return BAD_VALUE;
-        }
-        const char *tagName = vOps->get_tag_name(vOps, tag);
-        if (tagName == NULL) {
-            ALOGE("%s: no tag name defined for vendor tag %d.", __FUNCTION__, tag);
-            return BAD_VALUE;
-        }
-        desc->mTagToNameMap.add(tag, String8(tagName));
-        const char *sectionName = vOps->get_section_name(vOps, tag);
-        if (sectionName == NULL) {
-            ALOGE("%s: no section name defined for vendor tag %d.", __FUNCTION__, tag);
-            return BAD_VALUE;
-        }
-
-        String8 sectionString(sectionName);
-
-        sections.add(sectionString);
-        tagToSectionMap.add(tag, sectionString);
-
-        int tagType = vOps->get_tag_type(vOps, tag);
-        if (tagType < 0 || tagType >= NUM_TYPES) {
-            ALOGE("%s: tag type %d from vendor ops does not exist.", __FUNCTION__, tagType);
-            return BAD_VALUE;
-        }
-        desc->mTagToTypeMap.add(tag, tagType);
-    }
-
-    desc->mSections = sections;
-
-    for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) {
-        uint32_t tag = tagArray[i];
-        String8 sectionString = tagToSectionMap.valueFor(tag);
-
-        // Set up tag to section index map
-        ssize_t index = sections.indexOf(sectionString);
-        LOG_ALWAYS_FATAL_IF(index < 0, "index %zd must be non-negative", index);
-        desc->mTagToSectionMap.add(tag, static_cast<uint32_t>(index));
-
-        // Set up reverse mapping
-        ssize_t reverseIndex = -1;
-        if ((reverseIndex = desc->mReverseMapping.indexOfKey(sectionString)) < 0) {
-            KeyedVector<String8, uint32_t>* nameMapper = new KeyedVector<String8, uint32_t>();
-            reverseIndex = desc->mReverseMapping.add(sectionString, nameMapper);
-        }
-        desc->mReverseMapping[reverseIndex]->add(desc->mTagToNameMap.valueFor(tag), tag);
-    }
-
-    descriptor = desc;
-    return OK;
+VendorTagDescriptor::VendorTagDescriptor() :
+        mTagCount(0),
+        mVendorOps({nullptr}) {
 }
 
-status_t VendorTagDescriptor::createFromParcel(const Parcel* parcel,
-            /*out*/
-            sp<VendorTagDescriptor>& descriptor) {
+VendorTagDescriptor::VendorTagDescriptor(const VendorTagDescriptor& src) {
+    copyFrom(src);
+}
+
+VendorTagDescriptor& VendorTagDescriptor::operator=(const VendorTagDescriptor& rhs) {
+    copyFrom(rhs);
+    return *this;
+}
+
+void VendorTagDescriptor::copyFrom(const VendorTagDescriptor& src) {
+    if (this == &src) return;
+
+    size_t len = mReverseMapping.size();
+    for (size_t i = 0; i < len; ++i) {
+        delete mReverseMapping[i];
+    }
+    mReverseMapping.clear();
+
+    len = src.mReverseMapping.size();
+    // Have to copy KeyedVectors inside mReverseMapping
+    for (size_t i = 0; i < len; ++i) {
+        KeyedVector<String8, uint32_t>* nameMapper = new KeyedVector<String8, uint32_t>();
+        *nameMapper = *(src.mReverseMapping.valueAt(i));
+        mReverseMapping.add(src.mReverseMapping.keyAt(i), nameMapper);
+    }
+    // Everything else is simple
+    mTagToNameMap = src.mTagToNameMap;
+    mTagToSectionMap = src.mTagToSectionMap;
+    mTagToTypeMap = src.mTagToTypeMap;
+    mSections = src.mSections;
+    mTagCount = src.mTagCount;
+    mVendorOps = src.mVendorOps;
+}
+
+status_t VendorTagDescriptor::readFromParcel(const Parcel* parcel) {
     status_t res = OK;
     if (parcel == NULL) {
         ALOGE("%s: parcel argument was NULL.", __FUNCTION__);
@@ -156,8 +114,7 @@
         return BAD_VALUE;
     }
 
-    sp<VendorTagDescriptor> desc = new VendorTagDescriptor();
-    desc->mTagCount = tagCount;
+    mTagCount = tagCount;
 
     uint32_t tag, sectionIndex;
     uint32_t maxSectionIndex = 0;
@@ -197,9 +154,9 @@
         maxSectionIndex = (maxSectionIndex >= sectionIndex) ? maxSectionIndex : sectionIndex;
 
         allTags.add(tag);
-        desc->mTagToNameMap.add(tag, tagName);
-        desc->mTagToSectionMap.add(tag, sectionIndex);
-        desc->mTagToTypeMap.add(tag, tagType);
+        mTagToNameMap.add(tag, tagName);
+        mTagToSectionMap.add(tag, sectionIndex);
+        mTagToTypeMap.add(tag, tagType);
     }
 
     if (res != OK) {
@@ -217,7 +174,7 @@
                     __FUNCTION__, sectionCount, (maxSectionIndex + 1));
             return BAD_VALUE;
         }
-        LOG_ALWAYS_FATAL_IF(desc->mSections.setCapacity(sectionCount) <= 0,
+        LOG_ALWAYS_FATAL_IF(mSections.setCapacity(sectionCount) <= 0,
                 "Vector capacity must be positive");
         for (size_t i = 0; i < sectionCount; ++i) {
             String8 sectionName = parcel->readString8();
@@ -226,7 +183,7 @@
                       __FUNCTION__, i);
                 return NOT_ENOUGH_DATA;
             }
-            desc->mSections.add(sectionName);
+            mSections.add(sectionName);
         }
     }
 
@@ -235,17 +192,16 @@
     // Set up reverse mapping
     for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) {
         uint32_t tag = allTags[i];
-        String8 sectionString = desc->mSections[desc->mTagToSectionMap.valueFor(tag)];
+        String8 sectionString = mSections[mTagToSectionMap.valueFor(tag)];
 
         ssize_t reverseIndex = -1;
-        if ((reverseIndex = desc->mReverseMapping.indexOfKey(sectionString)) < 0) {
+        if ((reverseIndex = mReverseMapping.indexOfKey(sectionString)) < 0) {
             KeyedVector<String8, uint32_t>* nameMapper = new KeyedVector<String8, uint32_t>();
-            reverseIndex = desc->mReverseMapping.add(sectionString, nameMapper);
+            reverseIndex = mReverseMapping.add(sectionString, nameMapper);
         }
-        desc->mReverseMapping[reverseIndex]->add(desc->mTagToNameMap.valueFor(tag), tag);
+        mReverseMapping[reverseIndex]->add(mTagToNameMap.valueFor(tag), tag);
     }
 
-    descriptor = desc;
     return res;
 }
 
@@ -377,6 +333,92 @@
 
 }
 
+} // namespace params
+} // namespace camera2
+} // namespace hardware
+
+
+status_t VendorTagDescriptor::createDescriptorFromOps(const vendor_tag_ops_t* vOps,
+            /*out*/
+            sp<VendorTagDescriptor>& descriptor) {
+    if (vOps == NULL) {
+        ALOGE("%s: vendor_tag_ops argument was NULL.", __FUNCTION__);
+        return BAD_VALUE;
+    }
+
+    int tagCount = vOps->get_tag_count(vOps);
+    if (tagCount < 0 || tagCount > INT32_MAX) {
+        ALOGE("%s: tag count %d from vendor ops is invalid.", __FUNCTION__, tagCount);
+        return BAD_VALUE;
+    }
+
+    Vector<uint32_t> tagArray;
+    LOG_ALWAYS_FATAL_IF(tagArray.resize(tagCount) != tagCount,
+            "%s: too many (%u) vendor tags defined.", __FUNCTION__, tagCount);
+
+    vOps->get_all_tags(vOps, /*out*/tagArray.editArray());
+
+    sp<VendorTagDescriptor> desc = new VendorTagDescriptor();
+    desc->mTagCount = tagCount;
+
+    SortedVector<String8> sections;
+    KeyedVector<uint32_t, String8> tagToSectionMap;
+
+    for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) {
+        uint32_t tag = tagArray[i];
+        if (tag < CAMERA_METADATA_VENDOR_TAG_BOUNDARY) {
+            ALOGE("%s: vendor tag %d not in vendor tag section.", __FUNCTION__, tag);
+            return BAD_VALUE;
+        }
+        const char *tagName = vOps->get_tag_name(vOps, tag);
+        if (tagName == NULL) {
+            ALOGE("%s: no tag name defined for vendor tag %d.", __FUNCTION__, tag);
+            return BAD_VALUE;
+        }
+        desc->mTagToNameMap.add(tag, String8(tagName));
+        const char *sectionName = vOps->get_section_name(vOps, tag);
+        if (sectionName == NULL) {
+            ALOGE("%s: no section name defined for vendor tag %d.", __FUNCTION__, tag);
+            return BAD_VALUE;
+        }
+
+        String8 sectionString(sectionName);
+
+        sections.add(sectionString);
+        tagToSectionMap.add(tag, sectionString);
+
+        int tagType = vOps->get_tag_type(vOps, tag);
+        if (tagType < 0 || tagType >= NUM_TYPES) {
+            ALOGE("%s: tag type %d from vendor ops does not exist.", __FUNCTION__, tagType);
+            return BAD_VALUE;
+        }
+        desc->mTagToTypeMap.add(tag, tagType);
+    }
+
+    desc->mSections = sections;
+
+    for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) {
+        uint32_t tag = tagArray[i];
+        String8 sectionString = tagToSectionMap.valueFor(tag);
+
+        // Set up tag to section index map
+        ssize_t index = sections.indexOf(sectionString);
+        LOG_ALWAYS_FATAL_IF(index < 0, "index %zd must be non-negative", index);
+        desc->mTagToSectionMap.add(tag, static_cast<uint32_t>(index));
+
+        // Set up reverse mapping
+        ssize_t reverseIndex = -1;
+        if ((reverseIndex = desc->mReverseMapping.indexOfKey(sectionString)) < 0) {
+            KeyedVector<String8, uint32_t>* nameMapper = new KeyedVector<String8, uint32_t>();
+            reverseIndex = desc->mReverseMapping.add(sectionString, nameMapper);
+        }
+        desc->mReverseMapping[reverseIndex]->add(desc->mTagToNameMap.valueFor(tag), tag);
+    }
+
+    descriptor = desc;
+    return OK;
+}
+
 status_t VendorTagDescriptor::setAsGlobalVendorTagDescriptor(const sp<VendorTagDescriptor>& desc) {
     status_t res = OK;
     Mutex::Autolock al(sLock);
diff --git a/camera/aidl/android/hardware/CameraInfo.aidl b/camera/aidl/android/hardware/CameraInfo.aidl
new file mode 100644
index 0000000..c6a3a61
--- /dev/null
+++ b/camera/aidl/android/hardware/CameraInfo.aidl
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2013 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;
+
+/** @hide */
+parcelable CameraInfo cpp_header "camera/CameraBase.h";
diff --git a/camera/aidl/android/hardware/ICamera.aidl b/camera/aidl/android/hardware/ICamera.aidl
new file mode 100644
index 0000000..f9db842
--- /dev/null
+++ b/camera/aidl/android/hardware/ICamera.aidl
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2013 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;
+
+/** @hide */
+interface ICamera
+{
+    /**
+     * Only one call exposed, for ICameraService testing purposes
+     *
+     * Keep up-to-date with frameworks/av/include/camera/ICamera.h
+     */
+    void disconnect();
+}
diff --git a/camera/aidl/android/hardware/ICameraClient.aidl b/camera/aidl/android/hardware/ICameraClient.aidl
new file mode 100644
index 0000000..808edee
--- /dev/null
+++ b/camera/aidl/android/hardware/ICameraClient.aidl
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2013 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;
+
+/** @hide */
+interface ICameraClient
+{
+    // For now, empty because there is a manual implementation
+}
diff --git a/camera/aidl/android/hardware/ICameraService.aidl b/camera/aidl/android/hardware/ICameraService.aidl
new file mode 100644
index 0000000..e94fd0c
--- /dev/null
+++ b/camera/aidl/android/hardware/ICameraService.aidl
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2013 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;
+
+import android.hardware.ICamera;
+import android.hardware.ICameraClient;
+import android.hardware.camera2.ICameraDeviceUser;
+import android.hardware.camera2.ICameraDeviceCallbacks;
+import android.hardware.camera2.params.VendorTagDescriptor;
+import android.hardware.camera2.impl.CameraMetadataNative;
+import android.hardware.ICameraServiceListener;
+import android.hardware.CameraInfo;
+
+/**
+ * Binder interface for the native camera service running in mediaserver.
+ *
+ * @hide
+ */
+interface ICameraService
+{
+    /**
+     * All camera service and device Binder calls may return a
+     * ServiceSpecificException with the following error codes
+     */
+    const int ERROR_PERMISSION_DENIED = 1;
+    const int ERROR_ALREADY_EXISTS = 2;
+    const int ERROR_ILLEGAL_ARGUMENT = 3;
+    const int ERROR_DISCONNECTED = 4;
+    const int ERROR_TIMED_OUT = 5;
+    const int ERROR_DISABLED = 6;
+    const int ERROR_CAMERA_IN_USE = 7;
+    const int ERROR_MAX_CAMERAS_IN_USE = 8;
+    const int ERROR_DEPRECATED_HAL = 9;
+    const int ERROR_INVALID_OPERATION = 10;
+
+    /**
+     * Types for getNumberOfCameras
+     */
+    const int CAMERA_TYPE_BACKWARD_COMPATIBLE = 0;
+    const int CAMERA_TYPE_ALL = 1;
+
+    /**
+     * Return the number of camera devices available in the system
+     */
+    int getNumberOfCameras(int type);
+
+    /**
+     * Fetch basic camera information for a camera device
+     */
+    CameraInfo getCameraInfo(int cameraId);
+
+    /**
+     * Default UID/PID values for non-privileged callers of
+     * connect(), connectDevice(), and connectLegacy()
+     */
+    const int USE_CALLING_UID = -1;
+    const int USE_CALLING_PID = -1;
+
+    /**
+     * Open a camera device through the old camera API
+     */
+    ICamera connect(ICameraClient client,
+            int cameraId,
+            String opPackageName,
+            int clientUid, int clientPid);
+
+    /**
+     * Open a camera device through the new camera API
+     * Only supported for device HAL versions >= 3.2
+     */
+    ICameraDeviceUser connectDevice(ICameraDeviceCallbacks callbacks,
+            int cameraId,
+            String opPackageName,
+            int clientUid);
+
+    /**
+     * halVersion constant for connectLegacy
+     */
+    const int CAMERA_HAL_API_VERSION_UNSPECIFIED = -1;
+
+    /**
+     * Open a camera device in legacy mode, if supported by the camera module HAL.
+     */
+    ICamera connectLegacy(ICameraClient client,
+            int cameraId,
+            int halVersion,
+            String opPackageName,
+            int clientUid);
+
+    /**
+     * Add/remove listeners for changes to camera device and flashlight state
+     */
+    void addListener(ICameraServiceListener listener);
+    void removeListener(ICameraServiceListener listener);
+
+    /**
+     * Read the static camera metadata for a camera device.
+     * Only supported for device HAL versions >= 3.2
+     */
+    CameraMetadataNative getCameraCharacteristics(int cameraId);
+
+    /**
+     * Read in the vendor tag descriptors from the camera module HAL.
+     * Intended to be used by the native code of CameraMetadataNative to correctly
+     * interpret camera metadata with vendor tags.
+     */
+    VendorTagDescriptor getCameraVendorTagDescriptor();
+
+    /**
+     * Read the legacy camera1 parameters into a String
+     */
+    String getLegacyParameters(int cameraId);
+
+    /**
+     * apiVersion constants for supportsCameraApi
+     */
+    const int API_VERSION_1 = 1;
+    const int API_VERSION_2 = 2;
+
+    // Determines if a particular API version is supported directly
+    boolean supportsCameraApi(int cameraId, int apiVersion);
+
+    void setTorchMode(String CameraId, boolean enabled, IBinder clientBinder);
+
+    /**
+     * Notify the camera service of a system event.  Should only be called from system_server.
+     *
+     * Callers require the android.permission.CAMERA_SEND_SYSTEM_EVENTS permission.
+     */
+    const int EVENT_NONE = 0;
+    const int EVENT_USER_SWITCHED = 1;
+    oneway void notifySystemEvent(int eventId, in int[] args);
+}
diff --git a/camera/aidl/android/hardware/ICameraServiceListener.aidl b/camera/aidl/android/hardware/ICameraServiceListener.aidl
new file mode 100644
index 0000000..4e2a8c7
--- /dev/null
+++ b/camera/aidl/android/hardware/ICameraServiceListener.aidl
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2013 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;
+
+/** @hide */
+interface ICameraServiceListener
+{
+
+    /**
+     * Initial status will be transmitted with onStatusChange immediately
+     * after this listener is added to the service listener list.
+     *
+     * Allowed transitions:
+     *
+     *     (Any)               -> NOT_PRESENT
+     *     NOT_PRESENT         -> PRESENT
+     *     NOT_PRESENT         -> ENUMERATING
+     *     ENUMERATING         -> PRESENT
+     *     PRESENT             -> NOT_AVAILABLE
+     *     NOT_AVAILABLE       -> PRESENT
+     *
+     * A state will never immediately transition back to itself.
+     *
+     * The enums must match the values in
+     * include/hardware/camera_common.h when applicable
+     */
+    // Device physically unplugged
+    const int STATUS_NOT_PRESENT      = 0;
+    // Device physically has been plugged in and the camera can be used exlusively
+    const int STATUS_PRESENT          = 1;
+    // Device physically has been plugged in but it will not be connect-able until enumeration is
+    // complete
+    const int STATUS_ENUMERATING      = 2;
+    // Camera is in use by another app and cannot be used exclusively
+    const int STATUS_NOT_AVAILABLE    = -2;
+
+    // Use to initialize variables only
+    const int STATUS_UNKNOWN          = -1;
+
+    oneway void onStatusChanged(int status, int cameraId);
+
+    /**
+     * The torch mode status of a camera.
+     *
+     * Initial status will be transmitted with onTorchStatusChanged immediately
+     * after this listener is added to the service listener list.
+     *
+     * The enums must match the values in
+     * include/hardware/camera_common.h
+     */
+    // The camera's torch mode has become not available to use via
+    // setTorchMode().
+    const int TORCH_STATUS_NOT_AVAILABLE = 0;
+    // The camera's torch mode is off and available to be turned on via
+    // setTorchMode().
+    const int TORCH_STATUS_AVAILABLE_OFF = 1;
+    // The camera's torch mode is on and available to be turned off via
+    // setTorchMode().
+    const int TORCH_STATUS_AVAILABLE_ON  = 2;
+
+    // Use to initialize variables only
+    const int TORCH_STATUS_UNKNOWN = -1;
+
+    oneway void onTorchStatusChanged(int status, String cameraId);
+}
diff --git a/camera/aidl/android/hardware/ICameraServiceProxy.aidl b/camera/aidl/android/hardware/ICameraServiceProxy.aidl
new file mode 100644
index 0000000..0e654d5
--- /dev/null
+++ b/camera/aidl/android/hardware/ICameraServiceProxy.aidl
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2015 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;
+
+/**
+ * Binder interface for the camera service proxy running in system_server.
+ *
+ * Keep in sync with frameworks/av/include/camera/ICameraServiceProxy.h
+ *
+ * @hide
+ */
+interface ICameraServiceProxy
+{
+    /**
+     * Ping the service proxy to update the valid users for the camera service.
+     */
+    oneway void pingForUserUpdate();
+
+    /**
+     * Update the status of a camera device
+     */
+     oneway void notifyCameraState(String cameraId, int newCameraState);
+}
diff --git a/camera/aidl/android/hardware/camera2/CaptureRequest.aidl b/camera/aidl/android/hardware/camera2/CaptureRequest.aidl
new file mode 100644
index 0000000..9931fc7
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/CaptureRequest.aidl
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2013 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.camera2;
+
+/** @hide */
+parcelable CaptureRequest cpp_header "camera/camera2/CaptureRequest.h";
diff --git a/camera/aidl/android/hardware/camera2/ICameraDeviceCallbacks.aidl b/camera/aidl/android/hardware/camera2/ICameraDeviceCallbacks.aidl
new file mode 100644
index 0000000..ab57db5
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/ICameraDeviceCallbacks.aidl
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2015 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.camera2;
+
+import android.hardware.camera2.impl.CameraMetadataNative;
+import android.hardware.camera2.impl.CaptureResultExtras;
+
+/** @hide */
+interface ICameraDeviceCallbacks
+{
+    // Error codes for onDeviceError
+    const int ERROR_CAMERA_INVALID_ERROR = -1; // To indicate all invalid error codes
+    const int ERROR_CAMERA_DISCONNECTED = 0;
+    const int ERROR_CAMERA_DEVICE = 1;
+    const int ERROR_CAMERA_SERVICE = 2;
+    const int ERROR_CAMERA_REQUEST = 3;
+    const int ERROR_CAMERA_RESULT = 4;
+    const int ERROR_CAMERA_BUFFER = 5;
+
+    oneway void onDeviceError(int errorCode, in CaptureResultExtras resultExtras);
+    oneway void onDeviceIdle();
+    oneway void onCaptureStarted(in CaptureResultExtras resultExtras, long timestamp);
+    oneway void onResultReceived(in CameraMetadataNative result,
+                                 in CaptureResultExtras resultExtras);
+    oneway void onPrepared(int streamId);
+}
diff --git a/camera/aidl/android/hardware/camera2/ICameraDeviceUser.aidl b/camera/aidl/android/hardware/camera2/ICameraDeviceUser.aidl
new file mode 100644
index 0000000..250f15e
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/ICameraDeviceUser.aidl
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2013 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.camera2;
+
+import android.hardware.camera2.CaptureRequest;
+import android.hardware.camera2.impl.CameraMetadataNative;
+import android.hardware.camera2.params.OutputConfiguration;
+import android.hardware.camera2.utils.SubmitInfo;
+import android.view.Surface;
+
+/** @hide */
+interface ICameraDeviceUser
+{
+    void disconnect();
+
+    const int NO_IN_FLIGHT_REPEATING_FRAMES = -1;
+
+    SubmitInfo submitRequest(in CaptureRequest request, boolean streaming);
+    SubmitInfo submitRequestList(in CaptureRequest[] requestList, boolean streaming);
+
+    /**
+     * Cancel the repeating request specified by requestId
+     * Returns the frame number of the last frame that will be produced from this
+     * repeating request, or NO_IN_FLIGHT_REPEATING_FRAMES if no frames were produced
+     * by this repeating request
+     */
+    long cancelRequest(int requestId);
+
+    /**
+     * Begin the device configuration.
+     *
+     * <p>
+     * beginConfigure must be called before any call to deleteStream, createStream,
+     * or endConfigure.  It is not valid to call this when the device is not idle.
+     * <p>
+     */
+    void beginConfigure();
+
+    /**
+     * End the device configuration.
+     *
+     * <p>
+     * endConfigure must be called after stream configuration is complete (i.e. after
+     * a call to beginConfigure and subsequent createStream/deleteStream calls).  This
+     * must be called before any requests can be submitted.
+     * <p>
+     */
+    void endConfigure(boolean isConstrainedHighSpeed);
+
+    void deleteStream(int streamId);
+
+    /**
+     * Create an output stream
+     *
+     * <p>Create an output stream based on the given output configuration</p>
+     *
+     * @param outputConfiguration size, format, and other parameters for the stream
+     * @return new stream ID
+     */
+    int createStream(in OutputConfiguration outputConfiguration);
+
+    /**
+     * Create an input stream
+     *
+     * <p>Create an input stream of width, height, and format</p>
+     *
+     * @param width Width of the input buffers
+     * @param height Height of the input buffers
+     * @param format Format of the input buffers. One of HAL_PIXEL_FORMAT_*.
+     *
+     * @return new stream ID
+     */
+    int createInputStream(int width, int height, int format);
+
+    /**
+     * Get the surface of the input stream.
+     *
+     * <p>It's valid to call this method only after a stream configuration is completed
+     * successfully and the stream configuration includes a input stream.</p>
+     *
+     * @param surface An output argument for the surface of the input stream buffer queue.
+     */
+    Surface getInputSurface();
+
+    // Keep in sync with public API in
+    // frameworks/base/core/java/android/hardware/camera2/CameraDevice.java
+    const int TEMPLATE_PREVIEW = 1;
+    const int TEMPLATE_STILL_CAPTURE = 2;
+    const int TEMPLATE_RECORD = 3;
+    const int TEMPLATE_VIDEO_SNAPSHOT = 4;
+    const int TEMPLATE_ZERO_SHUTTER_LAG = 5;
+    const int TEMPLATE_MANUAL = 6;
+
+    CameraMetadataNative createDefaultRequest(int templateId);
+
+    CameraMetadataNative getCameraInfo();
+
+    void waitUntilIdle();
+
+    long flush();
+
+    void prepare(int streamId);
+
+    void tearDown(int streamId);
+
+    void prepare2(int maxCount, int streamId);
+}
diff --git a/camera/aidl/android/hardware/camera2/impl/CameraMetadataNative.aidl b/camera/aidl/android/hardware/camera2/impl/CameraMetadataNative.aidl
new file mode 100644
index 0000000..507f575
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/impl/CameraMetadataNative.aidl
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2013 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.camera2.impl;
+
+/** @hide */
+parcelable CameraMetadataNative cpp_header "camera/CameraMetadata.h";
diff --git a/camera/aidl/android/hardware/camera2/impl/CaptureResultExtras.aidl b/camera/aidl/android/hardware/camera2/impl/CaptureResultExtras.aidl
new file mode 100644
index 0000000..5f47eda
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/impl/CaptureResultExtras.aidl
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2014 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.camera2.impl;
+
+/** @hide */
+parcelable CaptureResultExtras cpp_header "camera/CaptureResult.h";
diff --git a/camera/aidl/android/hardware/camera2/params/OutputConfiguration.aidl b/camera/aidl/android/hardware/camera2/params/OutputConfiguration.aidl
new file mode 100644
index 0000000..a8ad832
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/params/OutputConfiguration.aidl
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2015 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.camera2.params;
+
+/** @hide */
+parcelable OutputConfiguration cpp_header "camera/camera2/OutputConfiguration.h";
diff --git a/camera/aidl/android/hardware/camera2/params/VendorTagDescriptor.aidl b/camera/aidl/android/hardware/camera2/params/VendorTagDescriptor.aidl
new file mode 100644
index 0000000..9ee4263
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/params/VendorTagDescriptor.aidl
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+package android.hardware.camera2.params;
+
+/** @hide */
+parcelable VendorTagDescriptor cpp_header "camera/VendorTagDescriptor.h";
diff --git a/camera/aidl/android/hardware/camera2/utils/SubmitInfo.aidl b/camera/aidl/android/hardware/camera2/utils/SubmitInfo.aidl
new file mode 100644
index 0000000..57531ad
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/utils/SubmitInfo.aidl
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2015 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.camera2.utils;
+
+/** @hide */
+parcelable SubmitInfo cpp_header "camera/camera2/SubmitInfo.h";
diff --git a/camera/camera2/CaptureRequest.cpp b/camera/camera2/CaptureRequest.cpp
index 4217bc6..fb43708 100644
--- a/camera/camera2/CaptureRequest.cpp
+++ b/camera/camera2/CaptureRequest.cpp
@@ -25,8 +25,10 @@
 #include <gui/Surface.h>
 
 namespace android {
+namespace hardware {
+namespace camera2 {
 
-status_t CaptureRequest::readFromParcel(Parcel* parcel) {
+status_t CaptureRequest::readFromParcel(const Parcel* parcel) {
     if (parcel == NULL) {
         ALOGE("%s: Null parcel", __FUNCTION__);
         return BAD_VALUE;
@@ -130,4 +132,6 @@
     return OK;
 }
 
-}; // namespace android
+} // namespace camera2
+} // namespace hardware
+} // namespace android
diff --git a/camera/camera2/ICameraDeviceCallbacks.cpp b/camera/camera2/ICameraDeviceCallbacks.cpp
deleted file mode 100644
index f599879..0000000
--- a/camera/camera2/ICameraDeviceCallbacks.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
-**
-** Copyright 2013, 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_NDEBUG 0
-#define LOG_TAG "ICameraDeviceCallbacks"
-#include <utils/Log.h>
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <binder/Parcel.h>
-#include <gui/IGraphicBufferProducer.h>
-#include <gui/Surface.h>
-#include <utils/Mutex.h>
-
-#include <camera/camera2/ICameraDeviceCallbacks.h>
-#include "camera/CameraMetadata.h"
-#include "camera/CaptureResult.h"
-
-namespace android {
-
-enum {
-    CAMERA_ERROR = IBinder::FIRST_CALL_TRANSACTION,
-    CAMERA_IDLE,
-    CAPTURE_STARTED,
-    RESULT_RECEIVED,
-    PREPARED
-};
-
-class BpCameraDeviceCallbacks: public BpInterface<ICameraDeviceCallbacks>
-{
-public:
-    BpCameraDeviceCallbacks(const sp<IBinder>& impl)
-        : BpInterface<ICameraDeviceCallbacks>(impl)
-    {
-    }
-
-    void onDeviceError(CameraErrorCode errorCode, const CaptureResultExtras& resultExtras)
-    {
-        ALOGV("onDeviceError");
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
-        data.writeInt32(static_cast<int32_t>(errorCode));
-        data.writeInt32(1); // to mark presence of CaptureResultExtras object
-        resultExtras.writeToParcel(&data);
-        remote()->transact(CAMERA_ERROR, data, &reply, IBinder::FLAG_ONEWAY);
-        data.writeNoException();
-    }
-
-    void onDeviceIdle()
-    {
-        ALOGV("onDeviceIdle");
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
-        remote()->transact(CAMERA_IDLE, data, &reply, IBinder::FLAG_ONEWAY);
-        data.writeNoException();
-    }
-
-    void onCaptureStarted(const CaptureResultExtras& result, int64_t timestamp)
-    {
-        ALOGV("onCaptureStarted");
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
-        data.writeInt32(1); // to mark presence of CaptureResultExtras object
-        result.writeToParcel(&data);
-        data.writeInt64(timestamp);
-        remote()->transact(CAPTURE_STARTED, data, &reply, IBinder::FLAG_ONEWAY);
-        data.writeNoException();
-    }
-
-    void onResultReceived(const CameraMetadata& metadata,
-            const CaptureResultExtras& resultExtras) {
-        ALOGV("onResultReceived");
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
-        data.writeInt32(1); // to mark presence of metadata object
-        metadata.writeToParcel(&data);
-        data.writeInt32(1); // to mark presence of CaptureResult object
-        resultExtras.writeToParcel(&data);
-        remote()->transact(RESULT_RECEIVED, data, &reply, IBinder::FLAG_ONEWAY);
-        data.writeNoException();
-    }
-
-    void onPrepared(int streamId)
-    {
-        ALOGV("onPrepared");
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
-        data.writeInt32(streamId);
-        remote()->transact(PREPARED, data, &reply, IBinder::FLAG_ONEWAY);
-        data.writeNoException();
-    }
-
-};
-
-IMPLEMENT_META_INTERFACE(CameraDeviceCallbacks,
-                         "android.hardware.camera2.ICameraDeviceCallbacks");
-
-// ----------------------------------------------------------------------
-
-status_t BnCameraDeviceCallbacks::onTransact(
-    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
-    ALOGV("onTransact - code = %d", code);
-    switch(code) {
-        case CAMERA_ERROR: {
-            ALOGV("onDeviceError");
-            CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
-            CameraErrorCode errorCode =
-                    static_cast<CameraErrorCode>(data.readInt32());
-            CaptureResultExtras resultExtras;
-            if (data.readInt32() != 0) {
-                resultExtras.readFromParcel(const_cast<Parcel*>(&data));
-            } else {
-                ALOGE("No CaptureResultExtras object is present!");
-            }
-            onDeviceError(errorCode, resultExtras);
-            data.readExceptionCode();
-            return NO_ERROR;
-        } break;
-        case CAMERA_IDLE: {
-            ALOGV("onDeviceIdle");
-            CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
-            onDeviceIdle();
-            data.readExceptionCode();
-            return NO_ERROR;
-        } break;
-        case CAPTURE_STARTED: {
-            ALOGV("onCaptureStarted");
-            CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
-            CaptureResultExtras result;
-            if (data.readInt32() != 0) {
-                result.readFromParcel(const_cast<Parcel*>(&data));
-            } else {
-                ALOGE("No CaptureResultExtras object is present in result!");
-            }
-            int64_t timestamp = data.readInt64();
-            onCaptureStarted(result, timestamp);
-            data.readExceptionCode();
-            return NO_ERROR;
-        } break;
-        case RESULT_RECEIVED: {
-            ALOGV("onResultReceived");
-            CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
-            CameraMetadata metadata;
-            if (data.readInt32() != 0) {
-                metadata.readFromParcel(const_cast<Parcel*>(&data));
-            } else {
-                ALOGW("No metadata object is present in result");
-            }
-            CaptureResultExtras resultExtras;
-            if (data.readInt32() != 0) {
-                resultExtras.readFromParcel(const_cast<Parcel*>(&data));
-            } else {
-                ALOGW("No capture result extras object is present in result");
-            }
-            onResultReceived(metadata, resultExtras);
-            data.readExceptionCode();
-            return NO_ERROR;
-        } break;
-        case PREPARED: {
-            ALOGV("onPrepared");
-            CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
-            CaptureResultExtras result;
-            int streamId = data.readInt32();
-            onPrepared(streamId);
-            data.readExceptionCode();
-            return NO_ERROR;
-        } break;
-        default:
-            return BBinder::onTransact(code, data, reply, flags);
-    }
-}
-
-// ----------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/camera/camera2/ICameraDeviceUser.cpp b/camera/camera2/ICameraDeviceUser.cpp
deleted file mode 100644
index 2a9fd2b..0000000
--- a/camera/camera2/ICameraDeviceUser.cpp
+++ /dev/null
@@ -1,626 +0,0 @@
-/*
-**
-** Copyright 2013, 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_NDEBUG 0
-#define LOG_TAG "ICameraDeviceUser"
-#include <utils/Log.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <binder/Parcel.h>
-#include <camera/camera2/ICameraDeviceUser.h>
-#include <gui/IGraphicBufferProducer.h>
-#include <gui/Surface.h>
-#include <camera/CameraMetadata.h>
-#include <camera/camera2/CaptureRequest.h>
-#include <camera/camera2/OutputConfiguration.h>
-
-namespace android {
-
-typedef Parcel::WritableBlob WritableBlob;
-typedef Parcel::ReadableBlob ReadableBlob;
-
-enum {
-    DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
-    SUBMIT_REQUEST,
-    SUBMIT_REQUEST_LIST,
-    CANCEL_REQUEST,
-    BEGIN_CONFIGURE,
-    END_CONFIGURE,
-    DELETE_STREAM,
-    CREATE_STREAM,
-    CREATE_INPUT_STREAM,
-    GET_INPUT_SURFACE,
-    CREATE_DEFAULT_REQUEST,
-    GET_CAMERA_INFO,
-    WAIT_UNTIL_IDLE,
-    FLUSH,
-    PREPARE,
-    TEAR_DOWN,
-    PREPARE2
-};
-
-namespace {
-    // Read empty strings without printing a false error message.
-    String16 readMaybeEmptyString16(const Parcel& parcel) {
-        size_t len;
-        const char16_t* str = parcel.readString16Inplace(&len);
-        if (str != NULL) {
-            return String16(str, len);
-        } else {
-            return String16();
-        }
-    }
-};
-
-class BpCameraDeviceUser : public BpInterface<ICameraDeviceUser>
-{
-public:
-    BpCameraDeviceUser(const sp<IBinder>& impl)
-        : BpInterface<ICameraDeviceUser>(impl)
-    {
-    }
-
-    // disconnect from camera service
-    void disconnect()
-    {
-        ALOGV("disconnect");
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        remote()->transact(DISCONNECT, data, &reply);
-        reply.readExceptionCode();
-    }
-
-    virtual int submitRequest(sp<CaptureRequest> request, bool repeating,
-                              int64_t *lastFrameNumber)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-
-        // arg0 = CaptureRequest
-        if (request != 0) {
-            data.writeInt32(1);
-            request->writeToParcel(&data);
-        } else {
-            data.writeInt32(0);
-        }
-
-        // arg1 = streaming (bool)
-        data.writeInt32(repeating);
-
-        remote()->transact(SUBMIT_REQUEST, data, &reply);
-
-        reply.readExceptionCode();
-        status_t res = reply.readInt32();
-
-        status_t resFrameNumber = BAD_VALUE;
-        if (reply.readInt32() != 0) {
-            if (lastFrameNumber != NULL) {
-                resFrameNumber = reply.readInt64(lastFrameNumber);
-            }
-        }
-
-        if (res < 0 || (resFrameNumber != NO_ERROR)) {
-            res = FAILED_TRANSACTION;
-        }
-        return res;
-    }
-
-    virtual int submitRequestList(List<sp<CaptureRequest> > requestList, bool repeating,
-                                  int64_t *lastFrameNumber)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-
-        data.writeInt32(requestList.size());
-
-        for (List<sp<CaptureRequest> >::iterator it = requestList.begin();
-                it != requestList.end(); ++it) {
-            sp<CaptureRequest> request = *it;
-            if (request != 0) {
-                data.writeInt32(1);
-                if (request->writeToParcel(&data) != OK) {
-                    return BAD_VALUE;
-                }
-            } else {
-                data.writeInt32(0);
-            }
-        }
-
-        data.writeInt32(repeating);
-
-        remote()->transact(SUBMIT_REQUEST_LIST, data, &reply);
-
-        reply.readExceptionCode();
-        status_t res = reply.readInt32();
-
-        status_t resFrameNumber = BAD_VALUE;
-        if (reply.readInt32() != 0) {
-            if (lastFrameNumber != NULL) {
-                resFrameNumber = reply.readInt64(lastFrameNumber);
-            }
-        }
-        if (res < 0 || (resFrameNumber != NO_ERROR)) {
-            res = FAILED_TRANSACTION;
-        }
-        return res;
-    }
-
-    virtual status_t cancelRequest(int requestId, int64_t *lastFrameNumber)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        data.writeInt32(requestId);
-
-        remote()->transact(CANCEL_REQUEST, data, &reply);
-
-        reply.readExceptionCode();
-        status_t res = reply.readInt32();
-
-        status_t resFrameNumber = BAD_VALUE;
-        if (reply.readInt32() != 0) {
-            if (lastFrameNumber != NULL) {
-                resFrameNumber = reply.readInt64(lastFrameNumber);
-            }
-        }
-        if ((res != NO_ERROR) || (resFrameNumber != NO_ERROR)) {
-            res = FAILED_TRANSACTION;
-        }
-        return res;
-    }
-
-    virtual status_t beginConfigure()
-    {
-        ALOGV("beginConfigure");
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        remote()->transact(BEGIN_CONFIGURE, data, &reply);
-        reply.readExceptionCode();
-        return reply.readInt32();
-    }
-
-    virtual status_t endConfigure(bool isConstrainedHighSpeed)
-    {
-        ALOGV("endConfigure");
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        data.writeInt32(isConstrainedHighSpeed);
-
-        remote()->transact(END_CONFIGURE, data, &reply);
-        reply.readExceptionCode();
-        return reply.readInt32();
-    }
-
-    virtual status_t deleteStream(int streamId)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        data.writeInt32(streamId);
-
-        remote()->transact(DELETE_STREAM, data, &reply);
-
-        reply.readExceptionCode();
-        return reply.readInt32();
-    }
-
-    virtual status_t createStream(const OutputConfiguration& outputConfiguration)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        if (outputConfiguration.getGraphicBufferProducer() != NULL) {
-            data.writeInt32(1); // marker that OutputConfiguration is not null. Mimic aidl behavior
-            outputConfiguration.writeToParcel(data);
-        } else {
-            data.writeInt32(0);
-        }
-        remote()->transact(CREATE_STREAM, data, &reply);
-
-        reply.readExceptionCode();
-        return reply.readInt32();
-    }
-
-    virtual status_t createInputStream(int width, int height, int format)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        data.writeInt32(width);
-        data.writeInt32(height);
-        data.writeInt32(format);
-
-        remote()->transact(CREATE_INPUT_STREAM, data, &reply);
-
-        reply.readExceptionCode();
-        return reply.readInt32();
-    }
-
-    // get the buffer producer of the input stream
-    virtual status_t getInputBufferProducer(
-            sp<IGraphicBufferProducer> *producer) {
-        if (producer == NULL) {
-            return BAD_VALUE;
-        }
-
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-
-        remote()->transact(GET_INPUT_SURFACE, data, &reply);
-
-        reply.readExceptionCode();
-        status_t result = reply.readInt32() ;
-        if (result != OK) {
-            return result;
-        }
-
-        sp<IGraphicBufferProducer> bp = NULL;
-        if (reply.readInt32() != 0) {
-            String16 name = readMaybeEmptyString16(reply);
-            bp = interface_cast<IGraphicBufferProducer>(
-                    reply.readStrongBinder());
-        }
-
-        *producer = bp;
-
-        return *producer == NULL ? INVALID_OPERATION : OK;
-    }
-
-    // Create a request object from a template.
-    virtual status_t createDefaultRequest(int templateId,
-                                          /*out*/
-                                          CameraMetadata* request)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        data.writeInt32(templateId);
-        remote()->transact(CREATE_DEFAULT_REQUEST, data, &reply);
-
-        reply.readExceptionCode();
-        status_t result = reply.readInt32();
-
-        CameraMetadata out;
-        if (reply.readInt32() != 0) {
-            out.readFromParcel(&reply);
-        }
-
-        if (request != NULL) {
-            request->swap(out);
-        }
-        return result;
-    }
-
-
-    virtual status_t getCameraInfo(CameraMetadata* info)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        remote()->transact(GET_CAMERA_INFO, data, &reply);
-
-        reply.readExceptionCode();
-        status_t result = reply.readInt32();
-
-        CameraMetadata out;
-        if (reply.readInt32() != 0) {
-            out.readFromParcel(&reply);
-        }
-
-        if (info != NULL) {
-            info->swap(out);
-        }
-
-        return result;
-    }
-
-    virtual status_t waitUntilIdle()
-    {
-        ALOGV("waitUntilIdle");
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        remote()->transact(WAIT_UNTIL_IDLE, data, &reply);
-        reply.readExceptionCode();
-        return reply.readInt32();
-    }
-
-    virtual status_t flush(int64_t *lastFrameNumber)
-    {
-        ALOGV("flush");
-        Parcel data, reply;
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        remote()->transact(FLUSH, data, &reply);
-        reply.readExceptionCode();
-        status_t res = reply.readInt32();
-
-        status_t resFrameNumber = BAD_VALUE;
-        if (reply.readInt32() != 0) {
-            if (lastFrameNumber != NULL) {
-                resFrameNumber = reply.readInt64(lastFrameNumber);
-            }
-        }
-        if ((res != NO_ERROR) || (resFrameNumber != NO_ERROR)) {
-            res = FAILED_TRANSACTION;
-        }
-        return res;
-    }
-
-    virtual status_t prepare(int streamId)
-    {
-        ALOGV("prepare");
-        Parcel data, reply;
-
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        data.writeInt32(streamId);
-
-        remote()->transact(PREPARE, data, &reply);
-
-        reply.readExceptionCode();
-        return reply.readInt32();
-    }
-
-    virtual status_t prepare2(int maxCount, int streamId)
-    {
-        ALOGV("prepare2");
-        Parcel data, reply;
-
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        data.writeInt32(maxCount);
-        data.writeInt32(streamId);
-
-        remote()->transact(PREPARE2, data, &reply);
-
-        reply.readExceptionCode();
-        return reply.readInt32();
-    }
-
-    virtual status_t tearDown(int streamId)
-    {
-        ALOGV("tearDown");
-        Parcel data, reply;
-
-        data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-        data.writeInt32(streamId);
-
-        remote()->transact(TEAR_DOWN, data, &reply);
-
-        reply.readExceptionCode();
-        return reply.readInt32();
-    }
-
-private:
-
-
-};
-
-IMPLEMENT_META_INTERFACE(CameraDeviceUser,
-                         "android.hardware.camera2.ICameraDeviceUser");
-
-// ----------------------------------------------------------------------
-
-status_t BnCameraDeviceUser::onTransact(
-    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
-    switch(code) {
-        case DISCONNECT: {
-            ALOGV("DISCONNECT");
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-            disconnect();
-            reply->writeNoException();
-            return NO_ERROR;
-        } break;
-        case SUBMIT_REQUEST: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-
-            // arg0 = request
-            sp<CaptureRequest> request;
-            if (data.readInt32() != 0) {
-                request = new CaptureRequest();
-                request->readFromParcel(const_cast<Parcel*>(&data));
-            }
-
-            // arg1 = streaming (bool)
-            bool repeating = data.readInt32();
-
-            // return code: requestId (int32)
-            reply->writeNoException();
-            int64_t lastFrameNumber = -1;
-            reply->writeInt32(submitRequest(request, repeating, &lastFrameNumber));
-            reply->writeInt32(1);
-            reply->writeInt64(lastFrameNumber);
-
-            return NO_ERROR;
-        } break;
-        case SUBMIT_REQUEST_LIST: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-
-            List<sp<CaptureRequest> > requestList;
-            int requestListSize = data.readInt32();
-            for (int i = 0; i < requestListSize; i++) {
-                if (data.readInt32() != 0) {
-                    sp<CaptureRequest> request = new CaptureRequest();
-                    if (request->readFromParcel(const_cast<Parcel*>(&data)) != OK) {
-                        return BAD_VALUE;
-                    }
-                    requestList.push_back(request);
-                } else {
-                    sp<CaptureRequest> request = 0;
-                    requestList.push_back(request);
-                    ALOGE("A request is missing. Sending in null request.");
-                }
-            }
-
-            bool repeating = data.readInt32();
-
-            reply->writeNoException();
-            int64_t lastFrameNumber = -1;
-            reply->writeInt32(submitRequestList(requestList, repeating, &lastFrameNumber));
-            reply->writeInt32(1);
-            reply->writeInt64(lastFrameNumber);
-
-            return NO_ERROR;
-        } break;
-        case CANCEL_REQUEST: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-            int requestId = data.readInt32();
-            reply->writeNoException();
-            int64_t lastFrameNumber = -1;
-            reply->writeInt32(cancelRequest(requestId, &lastFrameNumber));
-            reply->writeInt32(1);
-            reply->writeInt64(lastFrameNumber);
-            return NO_ERROR;
-        } break;
-        case DELETE_STREAM: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-            int streamId = data.readInt32();
-            reply->writeNoException();
-            reply->writeInt32(deleteStream(streamId));
-            return NO_ERROR;
-        } break;
-        case CREATE_STREAM: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-
-            status_t ret = BAD_VALUE;
-            if (data.readInt32() != 0) {
-                OutputConfiguration outputConfiguration(data);
-                ret = createStream(outputConfiguration);
-            } else {
-                ALOGE("%s: cannot take an empty OutputConfiguration", __FUNCTION__);
-            }
-
-            reply->writeNoException();
-            ALOGV("%s: CREATE_STREAM: write noException", __FUNCTION__);
-            reply->writeInt32(ret);
-            ALOGV("%s: CREATE_STREAM: write ret = %d", __FUNCTION__, ret);
-
-            return NO_ERROR;
-        } break;
-        case CREATE_INPUT_STREAM: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-            int width, height, format;
-
-            width = data.readInt32();
-            height = data.readInt32();
-            format = data.readInt32();
-            status_t ret = createInputStream(width, height, format);
-
-            reply->writeNoException();
-            reply->writeInt32(ret);
-            return NO_ERROR;
-
-        } break;
-        case GET_INPUT_SURFACE: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-
-            sp<IGraphicBufferProducer> bp;
-            status_t ret = getInputBufferProducer(&bp);
-            sp<IBinder> b(IInterface::asBinder(ret == OK ? bp : NULL));
-
-            reply->writeNoException();
-            reply->writeInt32(ret);
-            reply->writeInt32(1);
-            reply->writeString16(String16("camera input")); // name of surface
-            reply->writeStrongBinder(b);
-
-            return NO_ERROR;
-        } break;
-        case CREATE_DEFAULT_REQUEST: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-
-            int templateId = data.readInt32();
-
-            CameraMetadata request;
-            status_t ret;
-            ret = createDefaultRequest(templateId, &request);
-
-            reply->writeNoException();
-            reply->writeInt32(ret);
-
-            // out-variables are after exception and return value
-            reply->writeInt32(1); // to mark presence of metadata object
-            request.writeToParcel(const_cast<Parcel*>(reply));
-
-            return NO_ERROR;
-        } break;
-        case GET_CAMERA_INFO: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-
-            CameraMetadata info;
-            status_t ret;
-            ret = getCameraInfo(&info);
-
-            reply->writeNoException();
-            reply->writeInt32(ret);
-
-            // out-variables are after exception and return value
-            reply->writeInt32(1); // to mark presence of metadata object
-            info.writeToParcel(reply);
-
-            return NO_ERROR;
-        } break;
-        case WAIT_UNTIL_IDLE: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-            reply->writeNoException();
-            reply->writeInt32(waitUntilIdle());
-            return NO_ERROR;
-        } break;
-        case FLUSH: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-            reply->writeNoException();
-            int64_t lastFrameNumber = -1;
-            reply->writeInt32(flush(&lastFrameNumber));
-            reply->writeInt32(1);
-            reply->writeInt64(lastFrameNumber);
-            return NO_ERROR;
-        }
-        case BEGIN_CONFIGURE: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-            reply->writeNoException();
-            reply->writeInt32(beginConfigure());
-            return NO_ERROR;
-        } break;
-        case END_CONFIGURE: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-            bool isConstrainedHighSpeed = data.readInt32();
-            reply->writeNoException();
-            reply->writeInt32(endConfigure(isConstrainedHighSpeed));
-            return NO_ERROR;
-        } break;
-        case PREPARE: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-            int streamId = data.readInt32();
-            reply->writeNoException();
-            reply->writeInt32(prepare(streamId));
-            return NO_ERROR;
-        } break;
-        case TEAR_DOWN: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-            int streamId = data.readInt32();
-            reply->writeNoException();
-            reply->writeInt32(tearDown(streamId));
-            return NO_ERROR;
-        } break;
-        case PREPARE2: {
-            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-            int maxCount = data.readInt32();
-            int streamId = data.readInt32();
-            reply->writeNoException();
-            reply->writeInt32(prepare2(maxCount, streamId));
-            return NO_ERROR;
-        } break;
-        default:
-            return BBinder::onTransact(code, data, reply, flags);
-    }
-}
-
-// ----------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/camera/camera2/OutputConfiguration.cpp b/camera/camera2/OutputConfiguration.cpp
index 3505154..2c2c90b 100644
--- a/camera/camera2/OutputConfiguration.cpp
+++ b/camera/camera2/OutputConfiguration.cpp
@@ -16,9 +16,12 @@
 */
 
 #define LOG_TAG "OutputConfiguration"
+//#define LOG_NDEBUG 0
+
 #include <utils/Log.h>
 
 #include <camera/camera2/OutputConfiguration.h>
+#include <gui/Surface.h>
 #include <binder/Parcel.h>
 
 namespace android {
@@ -27,17 +30,6 @@
 const int OutputConfiguration::INVALID_ROTATION = -1;
 const int OutputConfiguration::INVALID_SET_ID = -1;
 
-// Read empty strings without printing a false error message.
-String16 OutputConfiguration::readMaybeEmptyString16(const Parcel& parcel) {
-    size_t len;
-    const char16_t* str = parcel.readString16Inplace(&len);
-    if (str != NULL) {
-        return String16(str, len);
-    } else {
-        return String16();
-    }
-}
-
 sp<IGraphicBufferProducer> OutputConfiguration::getGraphicBufferProducer() const {
     return mGbp;
 }
@@ -50,33 +42,48 @@
     return mSurfaceSetID;
 }
 
-OutputConfiguration::OutputConfiguration(const Parcel& parcel) {
-    status_t err;
+OutputConfiguration::OutputConfiguration() :
+        mRotation(INVALID_ROTATION),
+        mSurfaceSetID(INVALID_SET_ID) {
+}
+
+OutputConfiguration::OutputConfiguration(const Parcel& parcel) :
+        mRotation(INVALID_ROTATION),
+        mSurfaceSetID(INVALID_SET_ID) {
+    readFromParcel(&parcel);
+}
+
+status_t OutputConfiguration::readFromParcel(const Parcel* parcel) {
+    status_t err = OK;
     int rotation = 0;
-    if ((err = parcel.readInt32(&rotation)) != OK) {
+
+    if (parcel == nullptr) return BAD_VALUE;
+
+    if ((err = parcel->readInt32(&rotation)) != OK) {
         ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
-        mGbp = NULL;
-        mRotation = INVALID_ROTATION;
-        return;
+        return err;
     }
 
     int setID = INVALID_SET_ID;
-    if ((err = parcel.readInt32(&setID)) != OK) {
+    if ((err = parcel->readInt32(&setID)) != OK) {
         ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
-        mGbp = NULL;
-        mSurfaceSetID = INVALID_SET_ID;
-        return;
+        return err;
     }
 
-    String16 name = readMaybeEmptyString16(parcel);
-    const sp<IGraphicBufferProducer>& gbp =
-            interface_cast<IGraphicBufferProducer>(parcel.readStrongBinder());
-    mGbp = gbp;
+    view::Surface surfaceShim;
+    if ((err = surfaceShim.readFromParcel(parcel)) != OK) {
+        ALOGE("%s: Failed to read surface from parcel", __FUNCTION__);
+        return err;
+    }
+
+    mGbp = surfaceShim.graphicBufferProducer;
     mRotation = rotation;
     mSurfaceSetID = setID;
 
     ALOGV("%s: OutputConfiguration: bp = %p, name = %s", __FUNCTION__,
-          gbp.get(), String8(name).string());
+          mGbp.get(), String8(surfaceShim.name).string());
+
+    return err;
 }
 
 OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
@@ -86,16 +93,25 @@
     mSurfaceSetID = surfaceSetID;
 }
 
-status_t OutputConfiguration::writeToParcel(Parcel& parcel) const {
+status_t OutputConfiguration::writeToParcel(Parcel* parcel) const {
 
-    parcel.writeInt32(mRotation);
-    parcel.writeInt32(mSurfaceSetID);
-    parcel.writeString16(String16("unknown_name")); // name of surface
-    sp<IBinder> b(IInterface::asBinder(mGbp));
-    parcel.writeStrongBinder(b);
+    if (parcel == nullptr) return BAD_VALUE;
+    status_t err = OK;
+
+    err = parcel->writeInt32(mRotation);
+    if (err != OK) return err;
+
+    err = parcel->writeInt32(mSurfaceSetID);
+    if (err != OK) return err;
+
+    view::Surface surfaceShim;
+    surfaceShim.name = String16("unknown_name"); // name of surface
+    surfaceShim.graphicBufferProducer = mGbp;
+
+    err = surfaceShim.writeToParcel(parcel);
+    if (err != OK) return err;
 
     return OK;
 }
 
 }; // namespace android
-
diff --git a/camera/camera2/SubmitInfo.cpp b/camera/camera2/SubmitInfo.cpp
new file mode 100644
index 0000000..d739c79
--- /dev/null
+++ b/camera/camera2/SubmitInfo.cpp
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+
+#include "camera/camera2/SubmitInfo.h"
+
+namespace android {
+namespace hardware {
+namespace camera2 {
+namespace utils {
+
+status_t SubmitInfo::writeToParcel(Parcel *parcel) const {
+    status_t res;
+    if (parcel == nullptr) return BAD_VALUE;
+
+    res = parcel->writeInt32(mRequestId);
+    if (res != OK) return res;
+
+    res = parcel->writeInt64(mLastFrameNumber);
+    return res;
+}
+
+status_t SubmitInfo::readFromParcel(const Parcel *parcel) {
+    status_t res;
+    if (parcel == nullptr) return BAD_VALUE;
+
+    res = parcel->readInt32(&mRequestId);
+    if (res != OK) return res;
+
+    res = parcel->readInt64(&mLastFrameNumber);
+    return res;
+}
+
+} // namespace utils
+} // namespace camera2
+} // namespace hardware
+} // namespace android
diff --git a/camera/cameraserver/Android.mk b/camera/cameraserver/Android.mk
index 4d8339c..0207505 100644
--- a/camera/cameraserver/Android.mk
+++ b/camera/cameraserver/Android.mk
@@ -23,11 +23,8 @@
 	libcameraservice \
 	libcutils \
 	libutils \
-	libbinder
-
-LOCAL_C_INCLUDES := \
-    frameworks/av/services/camera/libcameraservice \
-    system/media/camera/include
+	libbinder \
+	libcamera_client
 
 LOCAL_MODULE:= cameraserver
 LOCAL_32_BIT_ONLY := true
diff --git a/camera/ndk/Android.mk b/camera/ndk/Android.mk
index 8e84e40..e43bb2c 100644
--- a/camera/ndk/Android.mk
+++ b/camera/ndk/Android.mk
@@ -34,9 +34,8 @@
 LOCAL_MODULE:= libcamera2ndk
 
 LOCAL_C_INCLUDES := \
-    system/media/camera/include \
     frameworks/av/include/camera/ndk \
-    frameworks/av/include/ndk \
+    frameworks/av/include/ndk
 
 LOCAL_CFLAGS += -fvisibility=hidden -D EXPORT='__attribute__ ((visibility ("default")))'
 
diff --git a/camera/ndk/NdkCameraManager.cpp b/camera/ndk/NdkCameraManager.cpp
index 7d9f84b..ff15263 100644
--- a/camera/ndk/NdkCameraManager.cpp
+++ b/camera/ndk/NdkCameraManager.cpp
@@ -24,6 +24,8 @@
 #include <NdkCameraManager.h>
 #include "impl/ACameraManager.h"
 
+using namespace android;
+
 EXPORT
 ACameraManager* ACameraManager_create() {
     ATRACE_CALL();
diff --git a/camera/ndk/impl/ACameraDevice.cpp b/camera/ndk/impl/ACameraDevice.cpp
index 5f89fa3..1ab6af8 100644
--- a/camera/ndk/impl/ACameraDevice.cpp
+++ b/camera/ndk/impl/ACameraDevice.cpp
@@ -20,6 +20,8 @@
 #include <vector>
 #include <utility>
 #include <inttypes.h>
+#include <android/hardware/ICameraService.h>
+#include <camera2/SubmitInfo.h>
 #include <gui/Surface.h>
 #include "ACameraDevice.h"
 #include "ACameraMetadata.h"
@@ -117,13 +119,14 @@
         return ACAMERA_ERROR_CAMERA_DISCONNECTED;
     }
     CameraMetadata rawRequest;
-    status_t remoteRet = mRemote->createDefaultRequest(templateId, &rawRequest);
-    if (remoteRet == BAD_VALUE) {
+    binder::Status remoteRet = mRemote->createDefaultRequest(templateId, &rawRequest);
+    if (remoteRet.serviceSpecificErrorCode() ==
+            hardware::ICameraService::ERROR_ILLEGAL_ARGUMENT) {
         ALOGW("Create capture request failed! template %d is not supported on this device",
             templateId);
         return ACAMERA_ERROR_UNSUPPORTED;
-    } else if (remoteRet != OK) {
-        ALOGE("Create capture request failed! error %d", remoteRet);
+    } else if (!remoteRet.isOk()) {
+        ALOGE("Create capture request failed: %s", remoteRet.toString8().string());
         return ACAMERA_ERROR_UNKNOWN;
     }
     ACaptureRequest* outReq = new ACaptureRequest();
@@ -201,8 +204,8 @@
         return ret;
     }
 
-    // Form List/Vector of capture request
-    List<sp<CaptureRequest> > requestList;
+    // Form two vectors of capture request, one for internal tracking
+    std::vector<hardware::camera2::CaptureRequest> requestList;
     Vector<sp<CaptureRequest> > requestsV;
     requestsV.setCapacity(numRequests);
     for (int i = 0; i < numRequests; i++) {
@@ -216,7 +219,7 @@
             ALOGE("Capture request without output target cannot be submitted!");
             return ACAMERA_ERROR_INVALID_PARAMETER;
         }
-        requestList.push_back(req);
+        requestList.push_back(*(req.get()));
         requestsV.push_back(req);
     }
 
@@ -228,10 +231,11 @@
         }
     }
 
-    int sequenceId;
-    int64_t lastFrameNumber;
-
-    sequenceId = mRemote->submitRequestList(requestList, isRepeating, &lastFrameNumber);
+    binder::Status remoteRet;
+    hardware::camera2::utils::SubmitInfo info;
+    remoteRet = mRemote->submitRequestList(requestList, isRepeating, &info);
+    int sequenceId = info.mRequestId;
+    int64_t lastFrameNumber = info.mLastFrameNumber;
     if (sequenceId < 0) {
         ALOGE("Camera %s submit request remote failure: ret %d", getId(), sequenceId);
         return ACAMERA_ERROR_UNKNOWN;
@@ -371,9 +375,9 @@
         mRepeatingSequenceId = REQUEST_ID_NONE;
 
         int64_t lastFrameNumber;
-        status_t remoteRet = mRemote->cancelRequest(repeatingSequenceId, &lastFrameNumber);
-        if (remoteRet != OK) {
-            ALOGE("Stop repeating request fails in remote! ret %d", remoteRet);
+        binder::Status remoteRet = mRemote->cancelRequest(repeatingSequenceId, &lastFrameNumber);
+        if (!remoteRet.isOk()) {
+            ALOGE("Stop repeating request fails in remote: %s", remoteRet.toString8().string());
             return ACAMERA_ERROR_UNKNOWN;
         }
         checkRepeatingSequenceCompleteLocked(repeatingSequenceId, lastFrameNumber);
@@ -394,9 +398,9 @@
         return ACAMERA_ERROR_INVALID_OPERATION;
     }
 
-    status_t remoteRet = mRemote->waitUntilIdle();
-    if (remoteRet != OK) {
-        ALOGE("Camera device %s waitUntilIdle failed! ret %d", getId(), remoteRet);
+    binder::Status remoteRet = mRemote->waitUntilIdle();
+    if (!remoteRet.isOk()) {
+        ALOGE("Camera device %s waitUntilIdle failed: %s", getId(), remoteRet.toString8().string());
         // TODO: define a function to convert status_t -> camera_status_t
         return ACAMERA_ERROR_UNKNOWN;
     }
@@ -508,17 +512,18 @@
     }
     mIdle = true;
 
-    status_t remoteRet = mRemote->beginConfigure();
-    if (remoteRet != ACAMERA_OK) {
-        ALOGE("Camera device %s begin configure failed, ret %d", getId(), remoteRet);
+    binder::Status remoteRet = mRemote->beginConfigure();
+    if (!remoteRet.isOk()) {
+        ALOGE("Camera device %s begin configure failed: %s", getId(), remoteRet.toString8().string());
         return ACAMERA_ERROR_UNKNOWN;
     }
 
     // delete to-be-deleted streams
     for (auto streamId : deleteList) {
         remoteRet = mRemote->deleteStream(streamId);
-        if (remoteRet != ACAMERA_OK) {
-            ALOGE("Camera device %s fails to remove stream %d", getId(), streamId);
+        if (!remoteRet.isOk()) {
+            ALOGE("Camera device %s failed to remove stream %d: %s", getId(), streamId,
+                    remoteRet.toString8().string());
             return ACAMERA_ERROR_UNKNOWN;
         }
         mConfiguredOutputs.erase(streamId);
@@ -526,21 +531,23 @@
 
     // add new streams
     for (auto outConfig : addSet) {
-        remoteRet = mRemote->createStream(outConfig);
-        if (remoteRet < 0) {
-            ALOGE("Camera device %s fails to create stream", getId());
+        int streamId;
+        remoteRet = mRemote->createStream(outConfig, &streamId);
+        if (!remoteRet.isOk()) {
+            ALOGE("Camera device %s failed to create stream: %s", getId(),
+                    remoteRet.toString8().string());
             return ACAMERA_ERROR_UNKNOWN;
         }
-        int streamId = remoteRet; // Weird, right?
         mConfiguredOutputs.insert(std::make_pair(streamId, outConfig));
     }
 
-    remoteRet = mRemote->endConfigure();
-    if (remoteRet == BAD_VALUE) {
-        ALOGE("Camera device %s cannnot support app output configuration", getId());
+    remoteRet = mRemote->endConfigure(/*isConstrainedHighSpeed*/ false);
+    if (remoteRet.serviceSpecificErrorCode() == hardware::ICameraService::ERROR_ILLEGAL_ARGUMENT) {
+        ALOGE("Camera device %s cannnot support app output configuration: %s", getId(),
+                remoteRet.toString8().string());
         return ACAMERA_ERROR_STREAM_CONFIGURE_FAIL;
-    } else if (remoteRet != ACAMERA_OK) {
-        ALOGE("Camera device %s end configure failed, ret %d", getId(), remoteRet);
+    } else if (!remoteRet.isOk()) {
+        ALOGE("Camera device %s end configure failed: %s", getId(), remoteRet.toString8().string());
         return ACAMERA_ERROR_UNKNOWN;
     }
 
@@ -548,7 +555,7 @@
 }
 
 void
-CameraDevice::setRemoteDevice(sp<ICameraDeviceUser> remote) {
+CameraDevice::setRemoteDevice(sp<hardware::camera2::ICameraDeviceUser> remote) {
     Mutex::Autolock _l(mDeviceLock);
     mRemote = remote;
 }
@@ -615,14 +622,14 @@
 
 void
 CameraDevice::onCaptureErrorLocked(
-        ICameraDeviceCallbacks::CameraErrorCode errorCode,
+        int32_t errorCode,
         const CaptureResultExtras& resultExtras) {
     int sequenceId = resultExtras.requestId;
     int64_t frameNumber = resultExtras.frameNumber;
     int32_t burstId = resultExtras.burstId;
 
     // No way to report buffer error now
-    if (errorCode == ICameraDeviceCallbacks::CameraErrorCode::ERROR_CAMERA_BUFFER) {
+    if (errorCode == hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER) {
         ALOGE("Camera %s Lost output buffer for frame %" PRId64,
                 getId(), frameNumber);
         return;
@@ -646,7 +653,7 @@
         failure->reason      = CAPTURE_FAILURE_REASON_ERROR;
         failure->sequenceId  = sequenceId;
         failure->wasImageCaptured = (errorCode ==
-                ICameraDeviceCallbacks::CameraErrorCode::ERROR_CAMERA_RESULT);
+                hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_RESULT);
 
         sp<AMessage> msg = new AMessage(kWhatCaptureFail, mHandler);
         msg->setPointer(kContextKey, cbh.mCallbacks.context);
@@ -999,21 +1006,21 @@
 /**
   * Camera service callback implementation
   */
-void
+binder::Status
 CameraDevice::ServiceCallback::onDeviceError(
-        CameraErrorCode errorCode,
+        int32_t errorCode,
         const CaptureResultExtras& resultExtras) {
     ALOGD("Device error received, code %d, frame number %" PRId64 ", request ID %d, subseq ID %d",
             errorCode, resultExtras.frameNumber, resultExtras.requestId, resultExtras.burstId);
-
+    binder::Status ret = binder::Status::ok();
     sp<CameraDevice> dev = mDevice.promote();
     if (dev == nullptr) {
-        return; // device has been closed
+        return ret; // device has been closed
     }
 
     Mutex::Autolock _l(dev->mDeviceLock);
     if (dev->mRemote == nullptr) {
-        return; // device has been closed
+        return ret; // device has been closed
     }
     switch (errorCode) {
         case ERROR_CAMERA_DISCONNECTED:
@@ -1061,24 +1068,26 @@
             dev->onCaptureErrorLocked(errorCode, resultExtras);
             break;
     }
+    return ret;
 }
 
-void
+binder::Status
 CameraDevice::ServiceCallback::onDeviceIdle() {
     ALOGV("Camera is now idle");
+    binder::Status ret = binder::Status::ok();
     sp<CameraDevice> dev = mDevice.promote();
     if (dev == nullptr) {
-        return; // device has been closed
+        return ret; // device has been closed
     }
 
     Mutex::Autolock _l(dev->mDeviceLock);
     if (dev->isClosed() || dev->mRemote == nullptr) {
-        return;
+        return ret;
     }
 
     if (dev->mIdle) {
         // Already in idle state. Possibly other thread did waitUntilIdle
-        return;
+        return ret;
     }
 
     if (dev->mCurrentSession != nullptr) {
@@ -1086,7 +1095,7 @@
         if (dev->mBusySession != dev->mCurrentSession) {
             ALOGE("Current session != busy session");
             dev->setCameraDeviceErrorLocked(ACAMERA_ERROR_CAMERA_DEVICE);
-            return;
+            return ret;
         }
         sp<AMessage> msg = new AMessage(kWhatSessionStateCb, dev->mHandler);
         msg->setPointer(kContextKey, dev->mBusySession->mUserSessionCallback.context);
@@ -1098,19 +1107,22 @@
         msg->post();
     }
     dev->mIdle = true;
+    return ret;
 }
 
-void
+binder::Status
 CameraDevice::ServiceCallback::onCaptureStarted(
         const CaptureResultExtras& resultExtras,
         int64_t timestamp) {
+    binder::Status ret = binder::Status::ok();
+
     sp<CameraDevice> dev = mDevice.promote();
     if (dev == nullptr) {
-        return; // device has been closed
+        return ret; // device has been closed
     }
     Mutex::Autolock _l(dev->mDeviceLock);
     if (dev->isClosed() || dev->mRemote == nullptr) {
-        return;
+        return ret;
     }
 
     int sequenceId = resultExtras.requestId;
@@ -1136,15 +1148,18 @@
         msg->setInt64(kTimeStampKey, timestamp);
         msg->post();
     }
+    return ret;
 }
 
-void
+binder::Status
 CameraDevice::ServiceCallback::onResultReceived(
         const CameraMetadata& metadata,
         const CaptureResultExtras& resultExtras) {
+    binder::Status ret = binder::Status::ok();
+
     sp<CameraDevice> dev = mDevice.promote();
     if (dev == nullptr) {
-        return; // device has been closed
+        return ret; // device has been closed
     }
     int sequenceId = resultExtras.requestId;
     int64_t frameNumber = resultExtras.frameNumber;
@@ -1157,7 +1172,7 @@
 
     Mutex::Autolock _l(dev->mDeviceLock);
     if (dev->mRemote == nullptr) {
-        return; // device has been disconnected
+        return ret; // device has been disconnected
     }
 
     if (dev->isClosed()) {
@@ -1165,7 +1180,7 @@
             dev->mFrameNumberTracker.updateTracker(frameNumber, /*isError*/false);
         }
         // early return to avoid callback sent to closed devices
-        return;
+        return ret;
     }
 
     CameraMetadata metadataCopy = metadata;
@@ -1201,12 +1216,14 @@
         dev->mFrameNumberTracker.updateTracker(frameNumber, /*isError*/false);
         dev->checkAndFireSequenceCompleteLocked();
     }
+
+    return ret;
 }
 
-void
+binder::Status
 CameraDevice::ServiceCallback::onPrepared(int) {
     // Prepare not yet implemented in NDK
-    return;
+    return binder::Status::ok();
 }
 
 } // namespace android
diff --git a/camera/ndk/impl/ACameraDevice.h b/camera/ndk/impl/ACameraDevice.h
index b73e621..46243b9 100644
--- a/camera/ndk/impl/ACameraDevice.h
+++ b/camera/ndk/impl/ACameraDevice.h
@@ -26,20 +26,18 @@
 #include <utils/List.h>
 #include <utils/Vector.h>
 
+#include <android/hardware/camera2/BnCameraDeviceCallbacks.h>
+#include <android/hardware/camera2/ICameraDeviceUser.h>
 #include <media/stagefright/foundation/ALooper.h>
 #include <media/stagefright/foundation/AHandler.h>
 #include <media/stagefright/foundation/AMessage.h>
 #include <camera/CaptureResult.h>
-#include <camera/camera2/ICameraDeviceCallbacks.h>
-#include <camera/camera2/ICameraDeviceUser.h>
 #include <camera/camera2/OutputConfiguration.h>
 #include <camera/camera2/CaptureRequest.h>
 
 #include <NdkCameraDevice.h>
 #include "ACameraMetadata.h"
 
-using namespace android;
-
 namespace android {
 
 // Wrap ACameraCaptureFailure so it can be ref-counter
@@ -64,24 +62,26 @@
             /*out*/ACameraCaptureSession** session);
 
     // Callbacks from camera service
-    class ServiceCallback : public BnCameraDeviceCallbacks {
+    class ServiceCallback : public hardware::camera2::BnCameraDeviceCallbacks {
       public:
         ServiceCallback(CameraDevice* device) : mDevice(device) {}
-        void onDeviceError(CameraErrorCode errorCode,
+        binder::Status onDeviceError(int32_t errorCode,
                            const CaptureResultExtras& resultExtras) override;
-        void onDeviceIdle() override;
-        void onCaptureStarted(const CaptureResultExtras& resultExtras,
+        binder::Status onDeviceIdle() override;
+        binder::Status onCaptureStarted(const CaptureResultExtras& resultExtras,
                               int64_t timestamp) override;
-        void onResultReceived(const CameraMetadata& metadata,
+        binder::Status onResultReceived(const CameraMetadata& metadata,
                               const CaptureResultExtras& resultExtras) override;
-        void onPrepared(int streamId) override;
+        binder::Status onPrepared(int streamId) override;
       private:
         const wp<CameraDevice> mDevice;
     };
-    inline sp<ICameraDeviceCallbacks> getServiceCallback() { return mServiceCallback; };
+    inline sp<hardware::camera2::ICameraDeviceCallbacks> getServiceCallback() {
+        return mServiceCallback;
+    };
 
     // Camera device is only functional after remote being set
-    void setRemoteDevice(sp<ICameraDeviceUser> remote);
+    void setRemoteDevice(sp<hardware::camera2::ICameraDeviceUser> remote);
 
     inline ACameraDevice* getWrapper() const { return mWrapper; };
 
@@ -155,14 +155,14 @@
     bool mInError;
     camera_status_t mError;
     void onCaptureErrorLocked(
-            ICameraDeviceCallbacks::CameraErrorCode errorCode,
+            int32_t errorCode,
             const CaptureResultExtras& resultExtras);
 
     bool mIdle;
     // This will avoid a busy session being deleted before it's back to idle state
     sp<ACameraCaptureSession> mBusySession;
 
-    sp<ICameraDeviceUser> mRemote;
+    sp<hardware::camera2::ICameraDeviceUser> mRemote;
 
     // Looper thread to handle callback to app
     sp<ALooper> mCbLooper;
@@ -294,17 +294,17 @@
     /***********************
      * Device interal APIs *
      ***********************/
-    inline sp<ICameraDeviceCallbacks> getServiceCallback() {
+    inline android::sp<android::hardware::camera2::ICameraDeviceCallbacks> getServiceCallback() {
         return mDevice->getServiceCallback();
     };
 
     // Camera device is only functional after remote being set
-    inline void setRemoteDevice(sp<ICameraDeviceUser> remote) {
+    inline void setRemoteDevice(android::sp<android::hardware::camera2::ICameraDeviceUser> remote) {
         mDevice->setRemoteDevice(remote);
     }
 
   private:
-    sp<CameraDevice> mDevice;
+    android::sp<android::CameraDevice> mDevice;
 };
 
 #endif // _ACAMERA_DEVICE_H
diff --git a/camera/ndk/impl/ACameraManager.cpp b/camera/ndk/impl/ACameraManager.cpp
index ed5c3ba..6fa0864 100644
--- a/camera/ndk/impl/ACameraManager.cpp
+++ b/camera/ndk/impl/ACameraManager.cpp
@@ -71,7 +71,7 @@
     mCameraService.clear();
 }
 
-sp<ICameraService> CameraManagerGlobal::getCameraService() {
+sp<hardware::ICameraService> CameraManagerGlobal::getCameraService() {
     Mutex::Autolock _l(mLock);
     if (mCameraService.get() == nullptr) {
         sp<IServiceManager> sm = defaultServiceManager();
@@ -88,7 +88,7 @@
             mDeathNotifier = new DeathNotifier(this);
         }
         binder->linkToDeath(mDeathNotifier);
-        mCameraService = interface_cast<ICameraService>(binder);
+        mCameraService = interface_cast<hardware::ICameraService>(binder);
 
         // Setup looper thread to perfrom availiability callbacks
         if (mCbLooper == nullptr) {
@@ -111,22 +111,23 @@
         mCameraService->addListener(mCameraServiceListener);
 
         // setup vendor tags
-        sp<VendorTagDescriptor> desc;
-        status_t ret = mCameraService->getCameraVendorTagDescriptor(/*out*/desc);
+        sp<VendorTagDescriptor> desc = new VendorTagDescriptor();
+        binder::Status ret = mCameraService->getCameraVendorTagDescriptor(/*out*/desc.get());
 
-        if (ret == OK) {
-            ret = VendorTagDescriptor::setAsGlobalVendorTagDescriptor(desc);
-            if (ret != OK) {
+        if (ret.isOk()) {
+            status_t err = VendorTagDescriptor::setAsGlobalVendorTagDescriptor(desc);
+            if (err != OK) {
                 ALOGE("%s: Failed to set vendor tag descriptors, received error %s (%d)",
-                        __FUNCTION__, strerror(-ret), ret);
+                        __FUNCTION__, strerror(-err), err);
             }
-        } else if (ret == -EOPNOTSUPP) {
+        } else if (ret.serviceSpecificErrorCode() ==
+                hardware::ICameraService::ERROR_DEPRECATED_HAL) {
             ALOGW("%s: Camera HAL too old; does not support vendor tags",
                     __FUNCTION__);
             VendorTagDescriptor::clearGlobalVendorTagDescriptor();
         } else {
-            ALOGE("%s: Failed to get vendor tag descriptors, received error %s (%d)",
-                    __FUNCTION__, strerror(-ret), ret);
+            ALOGE("%s: Failed to get vendor tag descriptors: %s",
+                    __FUNCTION__, ret.toString8().string());
         }
     }
     ALOGE_IF(mCameraService == nullptr, "no CameraService!?");
@@ -142,7 +143,7 @@
         for (auto pair : cm->mDeviceStatusMap) {
             int32_t cameraId = pair.first;
             cm->onStatusChangedLocked(
-                    ICameraServiceListener::STATUS_NOT_PRESENT, cameraId);
+                    CameraServiceListener::STATUS_NOT_PRESENT, cameraId);
         }
         cm->mCameraService.clear();
         // TODO: consider adding re-connect call here?
@@ -158,7 +159,7 @@
     if (pair.second) {
         for (auto pair : mDeviceStatusMap) {
             int32_t cameraId = pair.first;
-            Status status = pair.second;
+            int32_t status = pair.second;
 
             sp<AMessage> msg = new AMessage(kWhatSendSingleCallback, mHandler);
             ACameraManager_AvailabilityCallback cb = isStatusAvailable(status) ?
@@ -178,21 +179,21 @@
     mCallbacks.erase(cb);
 }
 
-bool CameraManagerGlobal::validStatus(Status status) {
+bool CameraManagerGlobal::validStatus(int32_t status) {
     switch (status) {
-        case ICameraServiceListener::STATUS_NOT_PRESENT:
-        case ICameraServiceListener::STATUS_PRESENT:
-        case ICameraServiceListener::STATUS_ENUMERATING:
-        case ICameraServiceListener::STATUS_NOT_AVAILABLE:
+        case hardware::ICameraServiceListener::STATUS_NOT_PRESENT:
+        case hardware::ICameraServiceListener::STATUS_PRESENT:
+        case hardware::ICameraServiceListener::STATUS_ENUMERATING:
+        case hardware::ICameraServiceListener::STATUS_NOT_AVAILABLE:
             return true;
         default:
             return false;
     }
 }
 
-bool CameraManagerGlobal::isStatusAvailable(Status status) {
+bool CameraManagerGlobal::isStatusAvailable(int32_t status) {
     switch (status) {
-        case ICameraServiceListener::STATUS_PRESENT:
+        case hardware::ICameraServiceListener::STATUS_PRESENT:
             return true;
         default:
             return false;
@@ -239,31 +240,32 @@
     }
 }
 
-void CameraManagerGlobal::CameraServiceListener::onStatusChanged(
-        Status status, int32_t cameraId) {
+binder::Status CameraManagerGlobal::CameraServiceListener::onStatusChanged(
+        int32_t status, int32_t cameraId) {
     sp<CameraManagerGlobal> cm = mCameraManager.promote();
-    if (cm == nullptr) {
+    if (cm != nullptr) {
+        cm->onStatusChanged(status, cameraId);
+    } else {
         ALOGE("Cannot deliver status change. Global camera manager died");
-        return;
     }
-    cm->onStatusChanged(status, cameraId);
+    return binder::Status::ok();
 }
 
 void CameraManagerGlobal::onStatusChanged(
-        Status status, int32_t cameraId) {
+        int32_t status, int32_t cameraId) {
     Mutex::Autolock _l(mLock);
     onStatusChangedLocked(status, cameraId);
 }
 
 void CameraManagerGlobal::onStatusChangedLocked(
-        Status status, int32_t cameraId) {
+        int32_t status, int32_t cameraId) {
         if (!validStatus(status)) {
             ALOGE("%s: Invalid status %d", __FUNCTION__, status);
             return;
         }
 
         bool firstStatus = (mDeviceStatusMap.count(cameraId) == 0);
-        Status oldStatus = firstStatus ?
+        int32_t oldStatus = firstStatus ?
                 status : // first status
                 mDeviceStatusMap[cameraId];
 
@@ -296,19 +298,28 @@
     if (mCachedCameraIdList.numCameras == kCameraIdListNotInit) {
         int numCameras = 0;
         Vector<char *> cameraIds;
-        sp<ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
+        sp<hardware::ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
         if (cs == nullptr) {
             ALOGE("%s: Cannot reach camera service!", __FUNCTION__);
             return ACAMERA_ERROR_CAMERA_DISCONNECTED;
         }
         // Get number of cameras
-        int numAllCameras = cs->getNumberOfCameras(ICameraService::CAMERA_TYPE_ALL);
+        int numAllCameras = 0;
+        binder::Status serviceRet = cs->getNumberOfCameras(hardware::ICameraService::CAMERA_TYPE_ALL,
+                &numAllCameras);
+        if (!serviceRet.isOk()) {
+            ALOGE("%s: Error getting camera count: %s", __FUNCTION__,
+                    serviceRet.toString8().string());
+            numAllCameras = 0;
+        }
         // Filter API2 compatible cameras and push to cameraIds
         for (int i = 0; i < numAllCameras; i++) {
             // TODO: Only suppot HALs that supports API2 directly now
-            status_t camera2Support = cs->supportsCameraApi(i, ICameraService::API_VERSION_2);
+            bool camera2Support = false;
+            serviceRet = cs->supportsCameraApi(i, hardware::ICameraService::API_VERSION_2,
+                    &camera2Support);
             char buf[kMaxCameraIdLen];
-            if (camera2Support == OK) {
+            if (camera2Support) {
                 numCameras++;
                 mCameraIds.insert(i);
                 snprintf(buf, sizeof(buf), "%d", i);
@@ -401,15 +412,16 @@
         ALOGE("%s: Camera ID %s does not exist!", __FUNCTION__, cameraIdStr);
         return ACAMERA_ERROR_INVALID_PARAMETER;
     }
-    sp<ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
+    sp<hardware::ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
     if (cs == nullptr) {
         ALOGE("%s: Cannot reach camera service!", __FUNCTION__);
         return ACAMERA_ERROR_CAMERA_DISCONNECTED;
     }
     CameraMetadata rawMetadata;
-    status_t serviceRet = cs->getCameraCharacteristics(cameraId, &rawMetadata);
-    if (serviceRet != OK) {
-        ALOGE("Get camera characteristics from camera service failed! Err %d", ret);
+    binder::Status serviceRet = cs->getCameraCharacteristics(cameraId, &rawMetadata);
+    if (!serviceRet.isOk()) {
+        ALOGE("Get camera characteristics from camera service failed: %s",
+                serviceRet.toString8().string());
         return ACAMERA_ERROR_UNKNOWN; // should not reach here
     }
 
@@ -436,24 +448,23 @@
 
     ACameraDevice* device = new ACameraDevice(cameraId, callback, std::move(chars));
 
-    sp<ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
+    sp<hardware::ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
     if (cs == nullptr) {
         ALOGE("%s: Cannot reach camera service!", __FUNCTION__);
         return ACAMERA_ERROR_CAMERA_DISCONNECTED;
     }
 
     int id = atoi(cameraId);
-    sp<ICameraDeviceCallbacks> callbacks = device->getServiceCallback();
-    sp<ICameraDeviceUser> deviceRemote;
+    sp<hardware::camera2::ICameraDeviceCallbacks> callbacks = device->getServiceCallback();
+    sp<hardware::camera2::ICameraDeviceUser> deviceRemote;
     // No way to get package name from native.
     // Send a zero length package name and let camera service figure it out from UID
-    status_t serviceRet = cs->connectDevice(
+    binder::Status serviceRet = cs->connectDevice(
             callbacks, id, String16(""),
-            ICameraService::USE_CALLING_UID, /*out*/deviceRemote);
+            hardware::ICameraService::USE_CALLING_UID, /*out*/&deviceRemote);
 
-    if (serviceRet != OK) {
-        ALOGE("%s: connect camera device failed! err %d", __FUNCTION__, serviceRet);
-        // TODO: generate better error message here
+    if (!serviceRet.isOk()) {
+        ALOGE("%s: connect camera device failed: %s", __FUNCTION__, serviceRet.toString8().string());
         delete device;
         return ACAMERA_ERROR_CAMERA_DISCONNECTED;
     }
@@ -476,4 +487,3 @@
         delete[] mCachedCameraIdList.cameraIds;
     }
 }
-
diff --git a/camera/ndk/impl/ACameraManager.h b/camera/ndk/impl/ACameraManager.h
index b68685d..3f2262f 100644
--- a/camera/ndk/impl/ACameraManager.h
+++ b/camera/ndk/impl/ACameraManager.h
@@ -19,9 +19,9 @@
 
 #include "NdkCameraManager.h"
 
+#include <android/hardware/ICameraService.h>
+#include <android/hardware/BnCameraServiceListener.h>
 #include <camera/CameraMetadata.h>
-#include <camera/ICameraService.h>
-#include <camera/ICameraServiceListener.h>
 #include <binder/IServiceManager.h>
 #include <utils/StrongPointer.h>
 #include <utils/Mutex.h>
@@ -33,8 +33,6 @@
 #include <set>
 #include <map>
 
-using namespace android;
-
 namespace android {
 
 /**
@@ -47,7 +45,7 @@
 class CameraManagerGlobal final : public RefBase {
   public:
     static CameraManagerGlobal& getInstance();
-    sp<ICameraService> getCameraService();
+    sp<hardware::ICameraService> getCameraService();
 
     void registerAvailabilityCallback(
             const ACameraManager_AvailabilityCallbacks *callback);
@@ -55,7 +53,7 @@
             const ACameraManager_AvailabilityCallbacks *callback);
 
   private:
-    sp<ICameraService> mCameraService;
+    sp<hardware::ICameraService> mCameraService;
     const int          kCameraServicePollDelay = 500000; // 0.5s
     const char*        kCameraServiceName      = "media.camera";
     Mutex              mLock;
@@ -71,13 +69,16 @@
     };
     sp<DeathNotifier> mDeathNotifier;
 
-    class CameraServiceListener final : public BnCameraServiceListener {
+    class CameraServiceListener final : public hardware::BnCameraServiceListener {
       public:
         CameraServiceListener(CameraManagerGlobal* cm) : mCameraManager(cm) {}
-        virtual void onStatusChanged(Status status, int32_t cameraId);
+        virtual binder::Status onStatusChanged(int32_t status, int32_t cameraId);
 
         // Torch API not implemented yet
-        virtual void onTorchStatusChanged(TorchStatus, const String16&) {};
+        virtual binder::Status onTorchStatusChanged(int32_t, const String16&) {
+            return binder::Status::ok();
+        }
+
       private:
         const wp<CameraManagerGlobal> mCameraManager;
     };
@@ -132,15 +133,14 @@
     sp<CallbackHandler> mHandler;
     sp<ALooper>         mCbLooper; // Looper thread where callbacks actually happen on
 
-    typedef ICameraServiceListener::Status Status;
-    void onStatusChanged(Status status, int32_t cameraId);
-    void onStatusChangedLocked(Status status, int32_t cameraId);
+    void onStatusChanged(int32_t status, int32_t cameraId);
+    void onStatusChangedLocked(int32_t status, int32_t cameraId);
     // Utils for status
-    static bool validStatus(Status status);
-    static bool isStatusAvailable(Status status);
+    static bool validStatus(int32_t status);
+    static bool isStatusAvailable(int32_t status);
 
     // Map camera_id -> status
-    std::map<int32_t, Status> mDeviceStatusMap;
+    std::map<int32_t, int32_t> mDeviceStatusMap;
 
     // For the singleton instance
     static Mutex sLock;
@@ -158,7 +158,7 @@
 struct ACameraManager {
     ACameraManager() :
             mCachedCameraIdList({kCameraIdListNotInit, nullptr}),
-            mGlobalManager(&(CameraManagerGlobal::getInstance())) {}
+            mGlobalManager(&(android::CameraManagerGlobal::getInstance())) {}
     ~ACameraManager();
     camera_status_t getCameraIdList(ACameraIdList** cameraIdList);
     static void     deleteCameraIdList(ACameraIdList* cameraIdList);
@@ -175,10 +175,10 @@
     enum {
         kCameraIdListNotInit = -1
     };
-    Mutex         mLock;
+    android::Mutex         mLock;
     std::set<int> mCameraIds;          // Init by getOrCreateCameraIdListLocked
     ACameraIdList mCachedCameraIdList; // Init by getOrCreateCameraIdListLocked
-    sp<CameraManagerGlobal> mGlobalManager;
+    android::sp<android::CameraManagerGlobal> mGlobalManager;
 };
 
 #endif //_ACAMERA_MANAGER_H
diff --git a/camera/tests/Android.mk b/camera/tests/Android.mk
index 3777d94..cde26dd 100644
--- a/camera/tests/Android.mk
+++ b/camera/tests/Android.mk
@@ -32,12 +32,9 @@
 	libbinder
 
 LOCAL_C_INCLUDES += \
-	system/media/camera/include \
 	system/media/private/camera/include \
 	system/media/camera/tests \
 	frameworks/av/services/camera/libcameraservice \
-	frameworks/av/include/camera \
-	frameworks/native/include \
 
 LOCAL_CFLAGS += -Wall -Wextra
 
diff --git a/camera/tests/CameraBinderTests.cpp b/camera/tests/CameraBinderTests.cpp
index a36d2f9..0b687b4 100644
--- a/camera/tests/CameraBinderTests.cpp
+++ b/camera/tests/CameraBinderTests.cpp
@@ -32,12 +32,15 @@
 #include <hardware/gralloc.h>
 
 #include <camera/CameraMetadata.h>
-#include <camera/ICameraService.h>
-#include <camera/ICameraServiceListener.h>
+#include <android/hardware/ICameraService.h>
+#include <android/hardware/ICameraServiceListener.h>
+#include <android/hardware/BnCameraServiceListener.h>
+#include <android/hardware/camera2/ICameraDeviceUser.h>
+#include <android/hardware/camera2/ICameraDeviceCallbacks.h>
+#include <android/hardware/camera2/BnCameraDeviceCallbacks.h>
 #include <camera/camera2/CaptureRequest.h>
-#include <camera/camera2/ICameraDeviceUser.h>
-#include <camera/camera2/ICameraDeviceCallbacks.h>
 #include <camera/camera2/OutputConfiguration.h>
+#include <camera/camera2/SubmitInfo.h>
 
 #include <gui/BufferItemConsumer.h>
 #include <gui/IGraphicBufferProducer.h>
@@ -60,25 +63,27 @@
 #define IDLE_TIMEOUT 2000000000 // ns
 
 // Stub listener implementation
-class TestCameraServiceListener : public BnCameraServiceListener {
-    std::map<String16, TorchStatus> mCameraTorchStatuses;
-    std::map<int32_t, Status> mCameraStatuses;
+class TestCameraServiceListener : public hardware::BnCameraServiceListener {
+    std::map<String16, int32_t> mCameraTorchStatuses;
+    std::map<int32_t, int32_t> mCameraStatuses;
     mutable Mutex mLock;
     mutable Condition mCondition;
     mutable Condition mTorchCondition;
 public:
     virtual ~TestCameraServiceListener() {};
 
-    virtual void onStatusChanged(Status status, int32_t cameraId) {
+    virtual binder::Status onStatusChanged(int32_t status, int32_t cameraId) {
         Mutex::Autolock l(mLock);
         mCameraStatuses[cameraId] = status;
         mCondition.broadcast();
+        return binder::Status::ok();
     };
 
-    virtual void onTorchStatusChanged(TorchStatus status, const String16& cameraId) {
+    virtual binder::Status onTorchStatusChanged(int32_t status, const String16& cameraId) {
         Mutex::Autolock l(mLock);
         mCameraTorchStatuses[cameraId] = status;
         mTorchCondition.broadcast();
+        return binder::Status::ok();
     };
 
     bool waitForNumCameras(size_t num) const {
@@ -96,7 +101,7 @@
         return true;
     };
 
-    bool waitForTorchState(TorchStatus status, int32_t cameraId) const {
+    bool waitForTorchState(int32_t status, int32_t cameraId) const {
         Mutex::Autolock l(mLock);
 
         const auto& iter = mCameraTorchStatuses.find(String16(String8::format("%d", cameraId)));
@@ -116,27 +121,27 @@
         return true;
     };
 
-    TorchStatus getTorchStatus(int32_t cameraId) const {
+    int32_t getTorchStatus(int32_t cameraId) const {
         Mutex::Autolock l(mLock);
         const auto& iter = mCameraTorchStatuses.find(String16(String8::format("%d", cameraId)));
         if (iter == mCameraTorchStatuses.end()) {
-            return ICameraServiceListener::TORCH_STATUS_UNKNOWN;
+            return hardware::ICameraServiceListener::TORCH_STATUS_UNKNOWN;
         }
         return iter->second;
     };
 
-    Status getStatus(int32_t cameraId) const {
+    int32_t getStatus(int32_t cameraId) const {
         Mutex::Autolock l(mLock);
         const auto& iter = mCameraStatuses.find(cameraId);
         if (iter == mCameraStatuses.end()) {
-            return ICameraServiceListener::STATUS_UNKNOWN;
+            return hardware::ICameraServiceListener::STATUS_UNKNOWN;
         }
         return iter->second;
     };
 };
 
 // Callback implementation
-class TestCameraDeviceCallbacks : public BnCameraDeviceCallbacks {
+class TestCameraDeviceCallbacks : public hardware::camera2::BnCameraDeviceCallbacks {
 public:
     enum Status {
         IDLE,
@@ -149,8 +154,8 @@
 
 protected:
     bool mError;
-    Status mLastStatus;
-    mutable std::vector<Status> mStatusesHit;
+    int32_t mLastStatus;
+    mutable std::vector<int32_t> mStatusesHit;
     mutable Mutex mLock;
     mutable Condition mStatusCondition;
 public:
@@ -158,7 +163,7 @@
 
     virtual ~TestCameraDeviceCallbacks() {}
 
-    virtual void onDeviceError(CameraErrorCode errorCode,
+    virtual binder::Status onDeviceError(int errorCode,
             const CaptureResultExtras& resultExtras) {
         (void) resultExtras;
         ALOGE("%s: onDeviceError occurred with: %d", __FUNCTION__, static_cast<int>(errorCode));
@@ -167,16 +172,18 @@
         mLastStatus = ERROR;
         mStatusesHit.push_back(mLastStatus);
         mStatusCondition.broadcast();
+        return binder::Status::ok();
     }
 
-    virtual void onDeviceIdle() {
+    virtual binder::Status onDeviceIdle() {
         Mutex::Autolock l(mLock);
         mLastStatus = IDLE;
         mStatusesHit.push_back(mLastStatus);
         mStatusCondition.broadcast();
+        return binder::Status::ok();
     }
 
-    virtual void onCaptureStarted(const CaptureResultExtras& resultExtras,
+    virtual binder::Status onCaptureStarted(const CaptureResultExtras& resultExtras,
             int64_t timestamp) {
         (void) resultExtras;
         (void) timestamp;
@@ -184,10 +191,11 @@
         mLastStatus = RUNNING;
         mStatusesHit.push_back(mLastStatus);
         mStatusCondition.broadcast();
+        return binder::Status::ok();
     }
 
 
-    virtual void onResultReceived(const CameraMetadata& metadata,
+    virtual binder::Status onResultReceived(const CameraMetadata& metadata,
             const CaptureResultExtras& resultExtras) {
         (void) metadata;
         (void) resultExtras;
@@ -195,14 +203,16 @@
         mLastStatus = SENT_RESULT;
         mStatusesHit.push_back(mLastStatus);
         mStatusCondition.broadcast();
+        return binder::Status::ok();
     }
 
-    virtual void onPrepared(int streamId) {
+    virtual binder::Status onPrepared(int streamId) {
         (void) streamId;
         Mutex::Autolock l(mLock);
         mLastStatus = PREPARED;
         mStatusesHit.push_back(mLastStatus);
         mStatusCondition.broadcast();
+        return binder::Status::ok();
     }
 
     // Test helper functions:
@@ -269,89 +279,106 @@
         gDeathNotifier = new DeathNotifier();
     }
     binder->linkToDeath(gDeathNotifier);
-    sp<ICameraService> service = interface_cast<ICameraService>(binder);
+    sp<hardware::ICameraService> service =
+            interface_cast<hardware::ICameraService>(binder);
 
+    binder::Status res;
 
-    int32_t numCameras = service->getNumberOfCameras(ICameraService::CAMERA_TYPE_ALL);
+    int32_t numCameras = 0;
+    res = service->getNumberOfCameras(hardware::ICameraService::CAMERA_TYPE_ALL, &numCameras);
+    EXPECT_TRUE(res.isOk()) << res;
     EXPECT_LE(0, numCameras);
 
     // Check listener binder calls
     sp<TestCameraServiceListener> listener(new TestCameraServiceListener());
-    EXPECT_EQ(OK, service->addListener(listener));
+    res = service->addListener(listener);
+    EXPECT_TRUE(res.isOk()) << res;
 
     EXPECT_TRUE(listener->waitForNumCameras(numCameras));
 
     for (int32_t i = 0; i < numCameras; i++) {
+        bool isSupported = false;
+        res = service->supportsCameraApi(i,
+                hardware::ICameraService::API_VERSION_2, &isSupported);
+        EXPECT_TRUE(res.isOk()) << res;
+
         // We only care about binder calls for the Camera2 API.  Camera1 is deprecated.
-        status_t camera2Support = service->supportsCameraApi(i, ICameraService::API_VERSION_2);
-        if (camera2Support != OK) {
-            EXPECT_EQ(-EOPNOTSUPP, camera2Support);
+        if (!isSupported) {
             continue;
         }
 
         // Check metadata binder call
         CameraMetadata metadata;
-        EXPECT_EQ(OK, service->getCameraCharacteristics(i, &metadata));
+        res = service->getCameraCharacteristics(i, &metadata);
+        EXPECT_TRUE(res.isOk()) << res;
         EXPECT_FALSE(metadata.isEmpty());
 
         // Make sure we're available, or skip device tests otherwise
-        ICameraServiceListener::Status s = listener->getStatus(i);
-        EXPECT_EQ(ICameraServiceListener::STATUS_AVAILABLE, s);
-        if (s != ICameraServiceListener::STATUS_AVAILABLE) {
+        int32_t s = listener->getStatus(i);
+        EXPECT_EQ(::android::hardware::ICameraServiceListener::STATUS_PRESENT, s);
+        if (s != ::android::hardware::ICameraServiceListener::STATUS_PRESENT) {
             continue;
         }
 
         // Check connect binder calls
         sp<TestCameraDeviceCallbacks> callbacks(new TestCameraDeviceCallbacks());
-        sp<ICameraDeviceUser> device;
-        EXPECT_EQ(OK, service->connectDevice(callbacks, i, String16("meeeeeeeee!"),
-                ICameraService::USE_CALLING_UID, /*out*/device));
+        sp<hardware::camera2::ICameraDeviceUser> device;
+        res = service->connectDevice(callbacks, i, String16("meeeeeeeee!"),
+                hardware::ICameraService::USE_CALLING_UID, /*out*/&device);
+        EXPECT_TRUE(res.isOk()) << res;
         ASSERT_NE(nullptr, device.get());
         device->disconnect();
         EXPECT_FALSE(callbacks->hadError());
 
-        ICameraServiceListener::TorchStatus torchStatus = listener->getTorchStatus(i);
-        if (torchStatus == ICameraServiceListener::TORCH_STATUS_AVAILABLE_OFF) {
+        int32_t torchStatus = listener->getTorchStatus(i);
+        if (torchStatus == hardware::ICameraServiceListener::TORCH_STATUS_AVAILABLE_OFF) {
             // Check torch calls
-            EXPECT_EQ(OK, service->setTorchMode(String16(String8::format("%d", i)),
-                    /*enabled*/true, callbacks));
+            res = service->setTorchMode(String16(String8::format("%d", i)),
+                    /*enabled*/true, callbacks);
+            EXPECT_TRUE(res.isOk()) << res;
             EXPECT_TRUE(listener->waitForTorchState(
-                    ICameraServiceListener::TORCH_STATUS_AVAILABLE_ON, i));
-            EXPECT_EQ(OK, service->setTorchMode(String16(String8::format("%d", i)),
-                    /*enabled*/false, callbacks));
+                    hardware::ICameraServiceListener::TORCH_STATUS_AVAILABLE_ON, i));
+            res = service->setTorchMode(String16(String8::format("%d", i)),
+                    /*enabled*/false, callbacks);
+            EXPECT_TRUE(res.isOk()) << res;
             EXPECT_TRUE(listener->waitForTorchState(
-                    ICameraServiceListener::TORCH_STATUS_AVAILABLE_OFF, i));
+                    hardware::ICameraServiceListener::TORCH_STATUS_AVAILABLE_OFF, i));
         }
     }
 
-    EXPECT_EQ(OK, service->removeListener(listener));
+    res = service->removeListener(listener);
+    EXPECT_TRUE(res.isOk()) << res;
 }
 
 // Test fixture for client focused binder tests
 class CameraClientBinderTest : public testing::Test {
 protected:
-    sp<ICameraService> service;
+    sp<hardware::ICameraService> service;
     int32_t numCameras;
-    std::vector<std::pair<sp<TestCameraDeviceCallbacks>, sp<ICameraDeviceUser>>> openDeviceList;
+    std::vector<std::pair<sp<TestCameraDeviceCallbacks>, sp<hardware::camera2::ICameraDeviceUser>>>
+            openDeviceList;
     sp<TestCameraServiceListener> serviceListener;
 
-    std::pair<sp<TestCameraDeviceCallbacks>, sp<ICameraDeviceUser>> openNewDevice(int deviceId) {
-
+    std::pair<sp<TestCameraDeviceCallbacks>, sp<hardware::camera2::ICameraDeviceUser>>
+            openNewDevice(int deviceId) {
         sp<TestCameraDeviceCallbacks> callbacks(new TestCameraDeviceCallbacks());
-        sp<ICameraDeviceUser> device;
+        sp<hardware::camera2::ICameraDeviceUser> device;
         {
             SCOPED_TRACE("openNewDevice");
-            EXPECT_EQ(OK, service->connectDevice(callbacks, deviceId, String16("meeeeeeeee!"),
-                    ICameraService::USE_CALLING_UID, /*out*/device));
+            binder::Status res = service->connectDevice(callbacks, deviceId, String16("meeeeeeeee!"),
+                    hardware::ICameraService::USE_CALLING_UID, /*out*/&device);
+            EXPECT_TRUE(res.isOk()) << res;
         }
         auto p = std::make_pair(callbacks, device);
         openDeviceList.push_back(p);
         return p;
     }
 
-    void closeDevice(std::pair<sp<TestCameraDeviceCallbacks>, sp<ICameraDeviceUser>>& p) {
+    void closeDevice(std::pair<sp<TestCameraDeviceCallbacks>,
+            sp<hardware::camera2::ICameraDeviceUser>>& p) {
         if (p.second.get() != nullptr) {
-            p.second->disconnect();
+            binder::Status res = p.second->disconnect();
+            EXPECT_TRUE(res.isOk()) << res;
             {
                 SCOPED_TRACE("closeDevice");
                 EXPECT_FALSE(p.first->hadError());
@@ -367,10 +394,11 @@
         ProcessState::self()->startThreadPool();
         sp<IServiceManager> sm = defaultServiceManager();
         sp<IBinder> binder = sm->getService(String16("media.camera"));
-        service = interface_cast<ICameraService>(binder);
+        service = interface_cast<hardware::ICameraService>(binder);
         serviceListener = new TestCameraServiceListener();
         service->addListener(serviceListener);
-        numCameras = service->getNumberOfCameras();
+        service->getNumberOfCameras(hardware::ICameraService::CAMERA_TYPE_BACKWARD_COMPATIBLE,
+                &numCameras);
     }
 
     virtual void TearDown() {
@@ -385,19 +413,19 @@
 
 TEST_F(CameraClientBinderTest, CheckBinderCameraDeviceUser) {
     ASSERT_NOT_NULL(service);
-
     EXPECT_TRUE(serviceListener->waitForNumCameras(numCameras));
     for (int32_t i = 0; i < numCameras; i++) {
         // Make sure we're available, or skip device tests otherwise
-        ICameraServiceListener::Status s = serviceListener->getStatus(i);
-        EXPECT_EQ(ICameraServiceListener::STATUS_AVAILABLE, s);
-        if (s != ICameraServiceListener::STATUS_AVAILABLE) {
+        int32_t s = serviceListener->getStatus(i);
+        EXPECT_EQ(hardware::ICameraServiceListener::STATUS_PRESENT, s);
+        if (s != hardware::ICameraServiceListener::STATUS_PRESENT) {
             continue;
         }
+        binder::Status res;
 
         auto p = openNewDevice(i);
         sp<TestCameraDeviceCallbacks> callbacks = p.first;
-        sp<ICameraDeviceUser> device = p.second;
+        sp<hardware::camera2::ICameraDeviceUser> device = p.second;
 
         // Setup a buffer queue; I'm just using the vendor opaque format here as that is
         // guaranteed to be present
@@ -418,50 +446,65 @@
         OutputConfiguration output(gbProducer, /*rotation*/0);
 
         // Can we configure?
-        EXPECT_EQ(OK, device->beginConfigure());
-        status_t streamId = device->createStream(output);
+        res = device->beginConfigure();
+        EXPECT_TRUE(res.isOk()) << res;
+        status_t streamId;
+        res = device->createStream(output, &streamId);
+        EXPECT_TRUE(res.isOk()) << res;
         EXPECT_LE(0, streamId);
-        EXPECT_EQ(OK, device->endConfigure());
+        res = device->endConfigure(/*isConstrainedHighSpeed*/ false);
+        EXPECT_TRUE(res.isOk()) << res;
         EXPECT_FALSE(callbacks->hadError());
 
         // Can we make requests?
         CameraMetadata requestTemplate;
-        EXPECT_EQ(OK, device->createDefaultRequest(/*preview template*/1,
-                /*out*/&requestTemplate));
-        sp<CaptureRequest> request(new CaptureRequest());
-        request->mMetadata = requestTemplate;
-        request->mSurfaceList.add(surface);
-        request->mIsReprocess = false;
+        res = device->createDefaultRequest(/*preview template*/1,
+                /*out*/&requestTemplate);
+        EXPECT_TRUE(res.isOk()) << res;
+
+        hardware::camera2::CaptureRequest request;
+        request.mMetadata = requestTemplate;
+        request.mSurfaceList.add(surface);
+        request.mIsReprocess = false;
         int64_t lastFrameNumber = 0;
         int64_t lastFrameNumberPrev = 0;
         callbacks->clearStatus();
-        int requestId = device->submitRequest(request, /*streaming*/true, /*out*/&lastFrameNumber);
+
+        hardware::camera2::utils::SubmitInfo info;
+        res = device->submitRequest(request, /*streaming*/true, /*out*/&info);
+        EXPECT_TRUE(res.isOk()) << res;
         EXPECT_TRUE(callbacks->waitForStatus(TestCameraDeviceCallbacks::SENT_RESULT));
-        EXPECT_LE(0, requestId);
+        EXPECT_LE(0, info.mRequestId);
 
         // Can we stop requests?
-        EXPECT_EQ(OK, device->cancelRequest(requestId, /*out*/&lastFrameNumber));
+        res = device->cancelRequest(info.mRequestId, /*out*/&lastFrameNumber);
+        EXPECT_TRUE(res.isOk()) << res;
         EXPECT_TRUE(callbacks->waitForIdle());
         EXPECT_FALSE(callbacks->hadError());
 
         // Can we do it again?
-        lastFrameNumberPrev = lastFrameNumber;
+        lastFrameNumberPrev = info.mLastFrameNumber;
         lastFrameNumber = 0;
         requestTemplate.clear();
-        EXPECT_EQ(OK, device->createDefaultRequest(/*preview template*/1,
-                /*out*/&requestTemplate));
-        sp<CaptureRequest> request2(new CaptureRequest());
-        request2->mMetadata = requestTemplate;
-        request2->mSurfaceList.add(surface);
-        request2->mIsReprocess = false;
+        res = device->createDefaultRequest(hardware::camera2::ICameraDeviceUser::TEMPLATE_PREVIEW,
+                /*out*/&requestTemplate);
+        EXPECT_TRUE(res.isOk()) << res;
+        hardware::camera2::CaptureRequest request2;
+        request2.mMetadata = requestTemplate;
+        request2.mSurfaceList.add(surface);
+        request2.mIsReprocess = false;
         callbacks->clearStatus();
-        int requestId2 = device->submitRequest(request2, /*streaming*/true,
-                /*out*/&lastFrameNumber);
-        EXPECT_EQ(-1, lastFrameNumber);
+        hardware::camera2::utils::SubmitInfo info2;
+        res = device->submitRequest(request2, /*streaming*/true,
+                /*out*/&info2);
+        EXPECT_TRUE(res.isOk()) << res;
+        EXPECT_EQ(hardware::camera2::ICameraDeviceUser::NO_IN_FLIGHT_REPEATING_FRAMES,
+                info2.mLastFrameNumber);
         lastFrameNumber = 0;
         EXPECT_TRUE(callbacks->waitForStatus(TestCameraDeviceCallbacks::SENT_RESULT));
-        EXPECT_LE(0, requestId2);
-        EXPECT_EQ(OK, device->cancelRequest(requestId2, /*out*/&lastFrameNumber));
+        EXPECT_LE(0, info2.mRequestId);
+        res = device->cancelRequest(info2.mRequestId, /*out*/&lastFrameNumber);
+        EXPECT_TRUE(res.isOk()) << res;
         EXPECT_TRUE(callbacks->waitForIdle());
         EXPECT_LE(lastFrameNumberPrev, lastFrameNumber);
         sleep(/*second*/1); // allow some time for errors to show up, if any
@@ -472,36 +515,44 @@
         lastFrameNumber = 0;
         requestTemplate.clear();
         CameraMetadata requestTemplate2;
-        EXPECT_EQ(OK, device->createDefaultRequest(/*preview template*/1,
-                /*out*/&requestTemplate));
-        EXPECT_EQ(OK, device->createDefaultRequest(/*preview template*/1,
-                /*out*/&requestTemplate2));
-        sp<CaptureRequest> request3(new CaptureRequest());
-        sp<CaptureRequest> request4(new CaptureRequest());
-        request3->mMetadata = requestTemplate;
-        request3->mSurfaceList.add(surface);
-        request3->mIsReprocess = false;
-        request4->mMetadata = requestTemplate2;
-        request4->mSurfaceList.add(surface);
-        request4->mIsReprocess = false;
-        List<sp<CaptureRequest>> requestList;
+        res = device->createDefaultRequest(hardware::camera2::ICameraDeviceUser::TEMPLATE_PREVIEW,
+                /*out*/&requestTemplate);
+        EXPECT_TRUE(res.isOk()) << res;
+        res = device->createDefaultRequest(hardware::camera2::ICameraDeviceUser::TEMPLATE_PREVIEW,
+                /*out*/&requestTemplate2);
+        EXPECT_TRUE(res.isOk()) << res;
+        android::hardware::camera2::CaptureRequest request3;
+        android::hardware::camera2::CaptureRequest request4;
+        request3.mMetadata = requestTemplate;
+        request3.mSurfaceList.add(surface);
+        request3.mIsReprocess = false;
+        request4.mMetadata = requestTemplate2;
+        request4.mSurfaceList.add(surface);
+        request4.mIsReprocess = false;
+        std::vector<hardware::camera2::CaptureRequest> requestList;
         requestList.push_back(request3);
         requestList.push_back(request4);
 
         callbacks->clearStatus();
-        int requestId3 = device->submitRequestList(requestList, /*streaming*/false,
-                /*out*/&lastFrameNumber);
-        EXPECT_LE(0, requestId3);
+        hardware::camera2::utils::SubmitInfo info3;
+        res = device->submitRequestList(requestList, /*streaming*/false,
+                /*out*/&info3);
+        EXPECT_TRUE(res.isOk()) << res;
+        EXPECT_LE(0, info3.mRequestId);
         EXPECT_TRUE(callbacks->waitForStatus(TestCameraDeviceCallbacks::SENT_RESULT));
         EXPECT_TRUE(callbacks->waitForIdle());
-        EXPECT_LE(lastFrameNumberPrev, lastFrameNumber);
+        EXPECT_LE(lastFrameNumberPrev, info3.mLastFrameNumber);
         sleep(/*second*/1); // allow some time for errors to show up, if any
         EXPECT_FALSE(callbacks->hadError());
 
         // Can we unconfigure?
-        EXPECT_EQ(OK, device->beginConfigure());
-        EXPECT_EQ(OK, device->deleteStream(streamId));
-        EXPECT_EQ(OK, device->endConfigure());
+        res = device->beginConfigure();
+        EXPECT_TRUE(res.isOk()) << res;
+        res = device->deleteStream(streamId);
+        EXPECT_TRUE(res.isOk()) << res;
+        res = device->endConfigure(/*isConstrainedHighSpeed*/ false);
+        EXPECT_TRUE(res.isOk()) << res;
+
         sleep(/*second*/1); // allow some time for errors to show up, if any
         EXPECT_FALSE(callbacks->hadError());
 
diff --git a/camera/tests/VendorTagDescriptorTests.cpp b/camera/tests/VendorTagDescriptorTests.cpp
index 9082dbf..75cfb73 100644
--- a/camera/tests/VendorTagDescriptorTests.cpp
+++ b/camera/tests/VendorTagDescriptorTests.cpp
@@ -53,27 +53,27 @@
 
 extern "C" {
 
-static int zero_get_tag_count(const vendor_tag_ops_t* vOps) {
+static int zero_get_tag_count(const vendor_tag_ops_t*) {
     return 0;
 }
 
-static int default_get_tag_count(const vendor_tag_ops_t* vOps) {
+static int default_get_tag_count(const vendor_tag_ops_t*) {
     return VENDOR_TAG_COUNT_ERR;
 }
 
-static void default_get_all_tags(const vendor_tag_ops_t* vOps, uint32_t* tagArray) {
+static void default_get_all_tags(const vendor_tag_ops_t*, uint32_t*) {
     //Noop
 }
 
-static const char* default_get_section_name(const vendor_tag_ops_t* vOps, uint32_t tag) {
+static const char* default_get_section_name(const vendor_tag_ops_t*, uint32_t) {
     return VENDOR_SECTION_NAME_ERR;
 }
 
-static const char* default_get_tag_name(const vendor_tag_ops_t* vOps, uint32_t tag) {
+static const char* default_get_tag_name(const vendor_tag_ops_t*, uint32_t) {
     return VENDOR_TAG_NAME_ERR;
 }
 
-static int default_get_tag_type(const vendor_tag_ops_t* vOps, uint32_t tag) {
+static int default_get_tag_type(const vendor_tag_ops_t*, uint32_t) {
     return VENDOR_TAG_TYPE_ERR;
 }
 
@@ -141,7 +141,8 @@
     // Check whether parcel read/write succeed
     EXPECT_EQ(OK, vDescOriginal->writeToParcel(&p));
     p.setDataPosition(0);
-    ASSERT_EQ(OK, VendorTagDescriptor::createFromParcel(&p, vDescParceled));
+
+    ASSERT_EQ(OK, vDescParceled->readFromParcel(&p));
 
     // Ensure consistent tag count
     int tagCount = vDescOriginal->getTagCount();
@@ -197,7 +198,6 @@
     EXPECT_EQ(VENDOR_TAG_TYPE_ERR, vDesc->getTagType(BAD_TAG));
 
     // Make sure global can be set/cleared
-    const vendor_tag_ops_t *fakeOps = &fakevendor_ops;
     sp<VendorTagDescriptor> prevGlobal = VendorTagDescriptor::getGlobalVendorTagDescriptor();
     VendorTagDescriptor::clearGlobalVendorTagDescriptor();
 
@@ -208,4 +208,3 @@
     EXPECT_EQ(OK, VendorTagDescriptor::setAsGlobalVendorTagDescriptor(prevGlobal));
     EXPECT_EQ(prevGlobal, VendorTagDescriptor::getGlobalVendorTagDescriptor());
 }
-