am 568689b1: am 3a2a32b5: Merge "AudioSystem: fix cross deadlock" into lmp-mr1-dev

* commit '568689b169d8b0ae2cc252b88602db5e5acaa604':
  AudioSystem: fix cross deadlock
diff --git a/camera/Camera.cpp b/camera/Camera.cpp
index 85f44f0..3a9fb4c 100644
--- a/camera/Camera.cpp
+++ b/camera/Camera.cpp
@@ -55,7 +55,7 @@
     if (camera->connect(c) == NO_ERROR) {
         c->mStatus = NO_ERROR;
         c->mCamera = camera;
-        camera->asBinder()->linkToDeath(c);
+        IInterface::asBinder(camera)->linkToDeath(c);
         return c;
     }
     return 0;
@@ -93,7 +93,7 @@
                                         clientUid, /*out*/c->mCamera);
     }
     if (status == OK && c->mCamera != 0) {
-        c->mCamera->asBinder()->linkToDeath(c);
+        IInterface::asBinder(c->mCamera)->linkToDeath(c);
         c->mStatus = NO_ERROR;
         camera = c;
     } else {
diff --git a/camera/CameraBase.cpp b/camera/CameraBase.cpp
index 04694cd..65a1a47 100644
--- a/camera/CameraBase.cpp
+++ b/camera/CameraBase.cpp
@@ -107,7 +107,7 @@
                                              /*out*/ c->mCamera);
     }
     if (status == OK && c->mCamera != 0) {
-        c->mCamera->asBinder()->linkToDeath(c);
+        IInterface::asBinder(c->mCamera)->linkToDeath(c);
         c->mStatus = NO_ERROR;
     } else {
         ALOGW("An error occurred while connecting to camera: %d", cameraId);
@@ -122,7 +122,7 @@
     ALOGV("%s: disconnect", __FUNCTION__);
     if (mCamera != 0) {
         mCamera->disconnect();
-        mCamera->asBinder()->unlinkToDeath(this);
+        IInterface::asBinder(mCamera)->unlinkToDeath(this);
         mCamera = 0;
     }
     ALOGV("%s: disconnect (done)", __FUNCTION__);
diff --git a/camera/ICamera.cpp b/camera/ICamera.cpp
index 8c6e1f7..9943be6 100644
--- a/camera/ICamera.cpp
+++ b/camera/ICamera.cpp
@@ -75,7 +75,7 @@
         ALOGV("setPreviewTarget");
         Parcel data, reply;
         data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
-        sp<IBinder> b(bufferProducer->asBinder());
+        sp<IBinder> b(IInterface::asBinder(bufferProducer));
         data.writeStrongBinder(b);
         remote()->transact(SET_PREVIEW_TARGET, data, &reply);
         return reply.readInt32();
@@ -98,7 +98,7 @@
         ALOGV("setPreviewCallbackTarget");
         Parcel data, reply;
         data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
-        sp<IBinder> b(callbackProducer->asBinder());
+        sp<IBinder> b(IInterface::asBinder(callbackProducer));
         data.writeStrongBinder(b);
         remote()->transact(SET_PREVIEW_CALLBACK_TARGET, data, &reply);
         return reply.readInt32();
@@ -147,7 +147,7 @@
         ALOGV("releaseRecordingFrame");
         Parcel data, reply;
         data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
-        data.writeStrongBinder(mem->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(mem));
         remote()->transact(RELEASE_RECORDING_FRAME, data, &reply);
     }
 
@@ -250,7 +250,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
-        data.writeStrongBinder(cameraClient->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(cameraClient));
         remote()->transact(CONNECT, data, &reply);
         return reply.readInt32();
     }
diff --git a/camera/ICameraClient.cpp b/camera/ICameraClient.cpp
index 205c8ba..179a341 100644
--- a/camera/ICameraClient.cpp
+++ b/camera/ICameraClient.cpp
@@ -58,7 +58,7 @@
         Parcel data, reply;
         data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
         data.writeInt32(msgType);
-        data.writeStrongBinder(imageData->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(imageData));
         if (metadata) {
             data.writeInt32(metadata->number_of_faces);
             data.write(metadata->faces, sizeof(camera_face_t) * metadata->number_of_faces);
@@ -74,7 +74,7 @@
         data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
         data.writeInt64(timestamp);
         data.writeInt32(msgType);
-        data.writeStrongBinder(imageData->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(imageData));
         remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY);
     }
 };
diff --git a/camera/ICameraRecordingProxy.cpp b/camera/ICameraRecordingProxy.cpp
index 7223b6d..3dc0ffb 100644
--- a/camera/ICameraRecordingProxy.cpp
+++ b/camera/ICameraRecordingProxy.cpp
@@ -45,7 +45,7 @@
         ALOGV("startRecording");
         Parcel data, reply;
         data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
-        data.writeStrongBinder(listener->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(listener));
         remote()->transact(START_RECORDING, data, &reply);
         return reply.readInt32();
     }
@@ -63,7 +63,7 @@
         ALOGV("releaseRecordingFrame");
         Parcel data, reply;
         data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
-        data.writeStrongBinder(mem->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(mem));
         remote()->transact(RELEASE_RECORDING_FRAME, data, &reply);
     }
 };
diff --git a/camera/ICameraRecordingProxyListener.cpp b/camera/ICameraRecordingProxyListener.cpp
index cb17f19..cf848fc 100644
--- a/camera/ICameraRecordingProxyListener.cpp
+++ b/camera/ICameraRecordingProxyListener.cpp
@@ -42,7 +42,7 @@
         data.writeInterfaceToken(ICameraRecordingProxyListener::getInterfaceDescriptor());
         data.writeInt64(timestamp);
         data.writeInt32(msgType);
-        data.writeStrongBinder(imageData->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(imageData));
         remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY);
     }
 };
diff --git a/camera/ICameraService.cpp b/camera/ICameraService.cpp
index 5485205..fc3e437 100644
--- a/camera/ICameraService.cpp
+++ b/camera/ICameraService.cpp
@@ -172,7 +172,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeStrongBinder(cameraClient->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(cameraClient));
         data.writeInt32(cameraId);
         data.writeString16(clientPackageName);
         data.writeInt32(clientUid);
@@ -194,7 +194,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeStrongBinder(cameraClient->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(cameraClient));
         data.writeInt32(cameraId);
         data.writeInt32(halVersion);
         data.writeString16(clientPackageName);
@@ -217,7 +217,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeStrongBinder(cameraCb->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(cameraCb));
         data.writeInt32(cameraId);
         data.writeString16(clientPackageName);
         data.writeInt32(clientUid);
@@ -242,7 +242,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeStrongBinder(cameraCb->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(cameraCb));
         data.writeInt32(cameraId);
         data.writeString16(clientPackageName);
         data.writeInt32(clientUid);
@@ -260,7 +260,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeStrongBinder(listener->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(listener));
         remote()->transact(BnCameraService::ADD_LISTENER, data, &reply);
 
         if (readExceptionCode(reply)) return -EPROTO;
@@ -271,7 +271,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-        data.writeStrongBinder(listener->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(listener));
         remote()->transact(BnCameraService::REMOVE_LISTENER, data, &reply);
 
         if (readExceptionCode(reply)) return -EPROTO;
@@ -384,7 +384,7 @@
             reply->writeInt32(status);
             if (camera != NULL) {
                 reply->writeInt32(1);
-                reply->writeStrongBinder(camera->asBinder());
+                reply->writeStrongBinder(IInterface::asBinder(camera));
             } else {
                 reply->writeInt32(0);
             }
@@ -404,7 +404,7 @@
             reply->writeInt32(status);
             if (camera != NULL) {
                 reply->writeInt32(1);
-                reply->writeStrongBinder(camera->asBinder());
+                reply->writeStrongBinder(IInterface::asBinder(camera));
             } else {
                 reply->writeInt32(0);
             }
@@ -424,7 +424,7 @@
             reply->writeInt32(status);
             if (camera != NULL) {
                 reply->writeInt32(1);
-                reply->writeStrongBinder(camera->asBinder());
+                reply->writeStrongBinder(IInterface::asBinder(camera));
             } else {
                 reply->writeInt32(0);
             }
@@ -484,7 +484,7 @@
             reply->writeInt32(status);
             if (camera != NULL) {
                 reply->writeInt32(1);
-                reply->writeStrongBinder(camera->asBinder());
+                reply->writeStrongBinder(IInterface::asBinder(camera));
             } else {
                 reply->writeInt32(0);
             }
diff --git a/camera/IProCameraUser.cpp b/camera/IProCameraUser.cpp
index 8f22124..9bd7597 100644
--- a/camera/IProCameraUser.cpp
+++ b/camera/IProCameraUser.cpp
@@ -65,7 +65,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(IProCameraUser::getInterfaceDescriptor());
-        data.writeStrongBinder(cameraClient->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(cameraClient));
         remote()->transact(CONNECT, data, &reply);
         return reply.readInt32();
     }
@@ -150,7 +150,7 @@
         data.writeInt32(height);
         data.writeInt32(format);
 
-        sp<IBinder> b(bufferProducer->asBinder());
+        sp<IBinder> b(IInterface::asBinder(bufferProducer));
         data.writeStrongBinder(b);
 
         remote()->transact(CREATE_STREAM, data, &reply);
diff --git a/camera/camera2/CaptureRequest.cpp b/camera/camera2/CaptureRequest.cpp
index 57e5319..d5e1c5b 100644
--- a/camera/camera2/CaptureRequest.cpp
+++ b/camera/camera2/CaptureRequest.cpp
@@ -106,7 +106,7 @@
 
         sp<IBinder> binder;
         if (surface != 0) {
-            binder = surface->getIGraphicBufferProducer()->asBinder();
+            binder = IInterface::asBinder(surface->getIGraphicBufferProducer());
         }
 
         // not sure if readParcelableArray does this, hard to tell from source
diff --git a/camera/camera2/ICameraDeviceUser.cpp b/camera/camera2/ICameraDeviceUser.cpp
index ff4a0c2..35345d2 100644
--- a/camera/camera2/ICameraDeviceUser.cpp
+++ b/camera/camera2/ICameraDeviceUser.cpp
@@ -219,7 +219,7 @@
 
         data.writeInt32(1); // marker that bufferProducer is not null
         data.writeString16(String16("unknown_name")); // name of surface
-        sp<IBinder> b(bufferProducer->asBinder());
+        sp<IBinder> b(IInterface::asBinder(bufferProducer));
         data.writeStrongBinder(b);
 
         remote()->transact(CREATE_STREAM, data, &reply);
diff --git a/camera/tests/Android.mk b/camera/tests/Android.mk
index 61385e5..2db4c14 100644
--- a/camera/tests/Android.mk
+++ b/camera/tests/Android.mk
@@ -14,16 +14,15 @@
 
 LOCAL_PATH:= $(call my-dir)
 include $(CLEAR_VARS)
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 
 LOCAL_SRC_FILES:= \
-	main.cpp \
 	ProCameraTests.cpp \
 	VendorTagDescriptorTests.cpp
 
 LOCAL_SHARED_LIBRARIES := \
 	libutils \
 	libcutils \
-	libstlport \
 	libcamera_metadata \
 	libcamera_client \
 	libgui \
@@ -32,14 +31,7 @@
 	libdl \
 	libbinder
 
-LOCAL_STATIC_LIBRARIES := \
-	libgtest
-
 LOCAL_C_INCLUDES += \
-	bionic \
-	bionic/libstdc++/include \
-	external/gtest/include \
-	external/stlport/stlport \
 	system/media/camera/include \
 	system/media/private/camera/include \
 	system/media/camera/tests \
diff --git a/camera/tests/main.cpp b/camera/tests/main.cpp
deleted file mode 100644
index 8c8c515..0000000
--- a/camera/tests/main.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.
- */
-
-#include <gtest/gtest.h>
-
-
-int main(int argc, char **argv) {
-
-    ::testing::InitGoogleTest(&argc, argv);
-
-    int ret = RUN_ALL_TESTS();
-
-    return ret;
-}
diff --git a/cmds/stagefright/SineSource.h b/cmds/stagefright/SineSource.h
index 76ab669..be05661 100644
--- a/cmds/stagefright/SineSource.h
+++ b/cmds/stagefright/SineSource.h
@@ -3,10 +3,11 @@
 #define SINE_SOURCE_H_
 
 #include <media/stagefright/MediaSource.h>
+#include <utils/Compat.h>
 
 namespace android {
 
-struct MediaBufferGroup;
+class MediaBufferGroup;
 
 struct SineSource : public MediaSource {
     SineSource(int32_t sampleRate, int32_t numChannels);
@@ -24,7 +25,7 @@
 
 private:
     enum { kBufferSize = 8192 };
-    static const double kFrequency = 500.0;
+    static const CONSTEXPR double kFrequency = 500.0;
 
     bool mStarted;
     int32_t mSampleRate;
diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp
index db41e0b..3f62ed7 100644
--- a/drm/common/IDrmManagerService.cpp
+++ b/drm/common/IDrmManagerService.cpp
@@ -148,7 +148,7 @@
 
     data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
     data.writeInt32(uniqueId);
-    data.writeStrongBinder(drmServiceListener->asBinder());
+    data.writeStrongBinder(IInterface::asBinder(drmServiceListener));
     remote()->transact(SET_DRM_SERVICE_LISTENER, data, &reply);
     return reply.readInt32();
 }
diff --git a/drm/drmserver/Android.mk b/drm/drmserver/Android.mk
index aa0ab9b..48ea385 100644
--- a/drm/drmserver/Android.mk
+++ b/drm/drmserver/Android.mk
@@ -26,7 +26,8 @@
     libutils \
     liblog \
     libbinder \
-    libdl
+    libdl \
+    libselinux
 
 LOCAL_STATIC_LIBRARIES := libdrmframeworkcommon
 
diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp
index 63341e0..857d73e 100644
--- a/drm/drmserver/DrmManagerService.cpp
+++ b/drm/drmserver/DrmManagerService.cpp
@@ -29,20 +29,68 @@
 #include "DrmManagerService.h"
 #include "DrmManager.h"
 
+#include <selinux/android.h>
+
 using namespace android;
 
+static int selinux_enabled;
+static char *drmserver_context;
 static Vector<uid_t> trustedUids;
 
-static bool isProtectedCallAllowed() {
+const char *const DrmManagerService::drm_perm_labels[] = {
+    "consumeRights",
+    "setPlaybackStatus",
+    "openDecryptSession",
+    "closeDecryptSession",
+    "initializeDecryptUnit",
+    "decrypt",
+    "finalizeDecryptUnit",
+    "pread"
+};
+
+const char *DrmManagerService::get_perm_label(drm_perm_t perm) {
+    unsigned int index = perm;
+
+    if (index < 0 ||
+            index >= (sizeof(drm_perm_labels) / sizeof(drm_perm_labels[0]))) {
+        ALOGE("SELinux: Failed to retrieve permission label(perm=%d).\n", perm);
+        abort();
+    }
+    return drm_perm_labels[index];
+}
+
+bool DrmManagerService::selinuxIsProtectedCallAllowed(pid_t spid, drm_perm_t perm) {
+    if (selinux_enabled <= 0) {
+        return true;
+    }
+
+    char *sctx;
+    const char *selinux_class = "drmservice";
+    const char *str_perm = get_perm_label(perm);
+
+    if (getpidcon(spid, &sctx) != 0) {
+        ALOGE("SELinux: getpidcon(pid=%d) failed.\n", spid);
+        return false;
+    }
+
+    bool allowed = (selinux_check_access(sctx, drmserver_context, selinux_class,
+            str_perm, NULL) == 0);
+    freecon(sctx);
+
+    return allowed;
+}
+
+bool DrmManagerService::isProtectedCallAllowed(drm_perm_t perm) {
     // TODO
     // Following implementation is just for reference.
     // Each OEM manufacturer should implement/replace with their own solutions.
     IPCThreadState* ipcState = IPCThreadState::self();
     uid_t uid = ipcState->getCallingUid();
+    pid_t spid = ipcState->getCallingPid();
 
     for (unsigned int i = 0; i < trustedUids.size(); ++i) {
         if (trustedUids[i] == uid) {
-            return true;
+            return selinuxIsProtectedCallAllowed(spid, perm);
         }
     }
     return false;
@@ -60,6 +108,16 @@
         // Add trusted uids here
         trustedUids.push(AID_MEDIA);
     }
+
+    selinux_enabled = is_selinux_enabled();
+    if (selinux_enabled > 0 && getcon(&drmserver_context) != 0) {
+        ALOGE("SELinux: DrmManagerService failed to get context for DrmManagerService. Aborting.\n");
+        abort();
+    }
+
+    union selinux_callback cb;
+    cb.func_log = selinux_log_callback;
+    selinux_set_callback(SELINUX_CB_LOG, cb);
 }
 
 DrmManagerService::DrmManagerService() :
@@ -151,7 +209,7 @@
 status_t DrmManagerService::consumeRights(
             int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
     ALOGV("Entering consumeRights");
-    if (!isProtectedCallAllowed()) {
+    if (!isProtectedCallAllowed(CONSUME_RIGHTS)) {
         return DRM_ERROR_NO_PERMISSION;
     }
     return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve);
@@ -160,7 +218,7 @@
 status_t DrmManagerService::setPlaybackStatus(
             int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) {
     ALOGV("Entering setPlaybackStatus");
-    if (!isProtectedCallAllowed()) {
+    if (!isProtectedCallAllowed(SET_PLAYBACK_STATUS)) {
         return DRM_ERROR_NO_PERMISSION;
     }
     return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
@@ -208,7 +266,7 @@
 DecryptHandle* DrmManagerService::openDecryptSession(
             int uniqueId, int fd, off64_t offset, off64_t length, const char* mime) {
     ALOGV("Entering DrmManagerService::openDecryptSession");
-    if (isProtectedCallAllowed()) {
+    if (isProtectedCallAllowed(OPEN_DECRYPT_SESSION)) {
         return mDrmManager->openDecryptSession(uniqueId, fd, offset, length, mime);
     }
 
@@ -218,7 +276,7 @@
 DecryptHandle* DrmManagerService::openDecryptSession(
             int uniqueId, const char* uri, const char* mime) {
     ALOGV("Entering DrmManagerService::openDecryptSession with uri");
-    if (isProtectedCallAllowed()) {
+    if (isProtectedCallAllowed(OPEN_DECRYPT_SESSION)) {
         return mDrmManager->openDecryptSession(uniqueId, uri, mime);
     }
 
@@ -228,7 +286,7 @@
 DecryptHandle* DrmManagerService::openDecryptSession(
             int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
     ALOGV("Entering DrmManagerService::openDecryptSession for streaming");
-    if (isProtectedCallAllowed()) {
+    if (isProtectedCallAllowed(OPEN_DECRYPT_SESSION)) {
         return mDrmManager->openDecryptSession(uniqueId, buf, mimeType);
     }
 
@@ -237,7 +295,7 @@
 
 status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     ALOGV("Entering closeDecryptSession");
-    if (!isProtectedCallAllowed()) {
+    if (!isProtectedCallAllowed(CLOSE_DECRYPT_SESSION)) {
         return DRM_ERROR_NO_PERMISSION;
     }
     return mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
@@ -246,7 +304,7 @@
 status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
             int decryptUnitId, const DrmBuffer* headerInfo) {
     ALOGV("Entering initializeDecryptUnit");
-    if (!isProtectedCallAllowed()) {
+    if (!isProtectedCallAllowed(INITIALIZE_DECRYPT_UNIT)) {
         return DRM_ERROR_NO_PERMISSION;
     }
     return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo);
@@ -256,7 +314,7 @@
             int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
             const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
     ALOGV("Entering decrypt");
-    if (!isProtectedCallAllowed()) {
+    if (!isProtectedCallAllowed(DECRYPT)) {
         return DRM_ERROR_NO_PERMISSION;
     }
     return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
@@ -265,7 +323,7 @@
 status_t DrmManagerService::finalizeDecryptUnit(
             int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
     ALOGV("Entering finalizeDecryptUnit");
-    if (!isProtectedCallAllowed()) {
+    if (!isProtectedCallAllowed(FINALIZE_DECRYPT_UNIT)) {
         return DRM_ERROR_NO_PERMISSION;
     }
     return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
@@ -274,7 +332,7 @@
 ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle,
             void* buffer, ssize_t numBytes, off64_t offset) {
     ALOGV("Entering pread");
-    if (!isProtectedCallAllowed()) {
+    if (!isProtectedCallAllowed(PREAD)) {
         return DRM_ERROR_NO_PERMISSION;
     }
     return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset);
diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp
index 2d2c90e..9457bb6 100644
--- a/drm/libdrmframework/DrmManagerClientImpl.cpp
+++ b/drm/libdrmframework/DrmManagerClientImpl.cpp
@@ -346,7 +346,7 @@
 DrmManagerClientImpl::DeathNotifier::~DeathNotifier() {
     Mutex::Autolock lock(sMutex);
     if (NULL != sDrmManagerService.get()) {
-        sDrmManagerService->asBinder()->unlinkToDeath(this);
+        IInterface::asBinder(sDrmManagerService)->unlinkToDeath(this);
     }
 }
 
diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h
index 8bc59b4..45cee2e 100644
--- a/drm/libdrmframework/include/DrmManagerService.h
+++ b/drm/libdrmframework/include/DrmManagerService.h
@@ -42,9 +42,28 @@
     static void instantiate();
 
 private:
+    enum drm_perm_t {
+        CONSUME_RIGHTS          = 0,
+        SET_PLAYBACK_STATUS     = 1,
+        OPEN_DECRYPT_SESSION    = 2,
+        CLOSE_DECRYPT_SESSION   = 3,
+        INITIALIZE_DECRYPT_UNIT = 4,
+        DECRYPT                 = 5,
+        FINALIZE_DECRYPT_UNIT   = 6,
+        PREAD                   = 7,
+    };
+
+    static const char *const drm_perm_labels[];
+
     DrmManagerService();
     virtual ~DrmManagerService();
 
+    static const char *get_perm_label(drm_perm_t perm);
+
+    static bool selinuxIsProtectedCallAllowed(pid_t spid, drm_perm_t perm);
+
+    static bool isProtectedCallAllowed(drm_perm_t perm);
+
 public:
     int addUniqueId(bool isNative);
 
diff --git a/drm/libdrmframework/include/PlugInManager.h b/drm/libdrmframework/include/PlugInManager.h
index c1d019a..466844d 100644
--- a/drm/libdrmframework/include/PlugInManager.h
+++ b/drm/libdrmframework/include/PlugInManager.h
@@ -234,14 +234,6 @@
     }
 
     /**
-     * True if the input entry is "." or ".."
-     */
-    bool isDotOrDDot(const struct dirent* pEntry) const {
-        String8 sName(pEntry->d_name);
-        return "." == sName || ".." == sName;
-    }
-
-    /**
      * True if input entry is directory
      */
     bool isDirectory(const struct dirent* pEntry) const {
diff --git a/drm/mediadrm/plugins/clearkey/Android.mk b/drm/mediadrm/plugins/clearkey/Android.mk
index 22a85b4..b713a7f 100644
--- a/drm/mediadrm/plugins/clearkey/Android.mk
+++ b/drm/mediadrm/plugins/clearkey/Android.mk
@@ -31,7 +31,6 @@
     Utils.cpp \
 
 LOCAL_C_INCLUDES := \
-    bionic \
     external/jsmn \
     external/openssl/include \
     frameworks/av/drm/mediadrm/plugins/clearkey \
diff --git a/drm/mediadrm/plugins/clearkey/tests/Android.mk b/drm/mediadrm/plugins/clearkey/tests/Android.mk
index ac5bb21..80f94e0 100644
--- a/drm/mediadrm/plugins/clearkey/tests/Android.mk
+++ b/drm/mediadrm/plugins/clearkey/tests/Android.mk
@@ -28,25 +28,17 @@
     JsonWebKeyUnittest.cpp \
 
 LOCAL_C_INCLUDES := \
-    bionic \
-    external/gtest/include \
     external/jsmn \
     external/openssl/include \
-    external/stlport/stlport \
     frameworks/av/drm/mediadrm/plugins/clearkey \
     frameworks/av/include \
     frameworks/native/include \
 
-LOCAL_STATIC_LIBRARIES := \
-    libgtest \
-    libgtest_main \
-
 LOCAL_SHARED_LIBRARIES := \
     libcrypto \
     libdrmclearkeyplugin \
     liblog \
     libstagefright_foundation \
-    libstlport \
     libutils \
 
 include $(BUILD_NATIVE_TEST)
diff --git a/include/media/ToneGenerator.h b/include/media/ToneGenerator.h
index 98c4332..8406ed6 100644
--- a/include/media/ToneGenerator.h
+++ b/include/media/ToneGenerator.h
@@ -17,11 +17,12 @@
 #ifndef ANDROID_TONEGENERATOR_H_
 #define ANDROID_TONEGENERATOR_H_
 
-#include <utils/RefBase.h>
-#include <utils/KeyedVector.h>
-#include <utils/threads.h>
 #include <media/AudioSystem.h>
 #include <media/AudioTrack.h>
+#include <utils/Compat.h>
+#include <utils/KeyedVector.h>
+#include <utils/RefBase.h>
+#include <utils/threads.h>
 
 namespace android {
 
@@ -207,7 +208,7 @@
     static const unsigned int TONEGEN_MAX_WAVES = 3;     // Maximun number of sine waves in a tone segment
     static const unsigned int TONEGEN_MAX_SEGMENTS = 12;  // Maximun number of segments in a tone descriptor
     static const unsigned int TONEGEN_INF = 0xFFFFFFFF;  // Represents infinite time duration
-    static const float TONEGEN_GAIN = 0.9;  // Default gain passed to  WaveGenerator().
+    static const CONSTEXPR float TONEGEN_GAIN = 0.9;  // Default gain passed to  WaveGenerator().
 
     // ToneDescriptor class contains all parameters needed to generate a tone:
     //    - The array waveFreq[]:
diff --git a/include/media/stagefright/AACWriter.h b/include/media/stagefright/AACWriter.h
index df1b053..d22707a 100644
--- a/include/media/stagefright/AACWriter.h
+++ b/include/media/stagefright/AACWriter.h
@@ -17,6 +17,7 @@
 #ifndef AAC_WRITER_H_
 #define AAC_WRITER_H_
 
+#include "foundation/ABase.h"
 #include <media/stagefright/MediaWriter.h>
 #include <utils/threads.h>
 
diff --git a/include/media/stagefright/ClockEstimator.h b/include/media/stagefright/ClockEstimator.h
index 2fd6e75..1455b7f 100644
--- a/include/media/stagefright/ClockEstimator.h
+++ b/include/media/stagefright/ClockEstimator.h
@@ -19,7 +19,7 @@
 
 #define CLOCK_ESTIMATOR_H_
 
-
+#include "foundation/ABase.h"
 #include <utils/RefBase.h>
 #include <utils/Vector.h>
 
diff --git a/include/media/stagefright/MediaMuxer.h b/include/media/stagefright/MediaMuxer.h
index bbe4303..9da98d9 100644
--- a/include/media/stagefright/MediaMuxer.h
+++ b/include/media/stagefright/MediaMuxer.h
@@ -22,6 +22,8 @@
 #include <utils/Vector.h>
 #include <utils/threads.h>
 
+#include "foundation/ABase.h"
+
 namespace android {
 
 struct ABuffer;
diff --git a/include/media/stagefright/SurfaceMediaSource.h b/include/media/stagefright/SurfaceMediaSource.h
index d15a226..2177c00 100644
--- a/include/media/stagefright/SurfaceMediaSource.h
+++ b/include/media/stagefright/SurfaceMediaSource.h
@@ -25,6 +25,8 @@
 #include <media/stagefright/MediaSource.h>
 #include <media/stagefright/MediaBuffer.h>
 
+#include "foundation/ABase.h"
+
 namespace android {
 // ----------------------------------------------------------------------------
 
@@ -233,7 +235,7 @@
     Condition mMediaBuffersAvailableCondition;
 
     // Avoid copying and equating and default constructor
-    DISALLOW_IMPLICIT_CONSTRUCTORS(SurfaceMediaSource);
+    DISALLOW_EVIL_CONSTRUCTORS(SurfaceMediaSource);
 };
 
 // ----------------------------------------------------------------------------
diff --git a/include/media/stagefright/foundation/AString.h b/include/media/stagefright/foundation/AString.h
index 7c98699..c3a68e1 100644
--- a/include/media/stagefright/foundation/AString.h
+++ b/include/media/stagefright/foundation/AString.h
@@ -23,7 +23,7 @@
 
 namespace android {
 
-struct String8;
+class String8;
 struct Parcel;
 
 struct AString {
diff --git a/media/common_time/ICommonClock.cpp b/media/common_time/ICommonClock.cpp
index 25ae69e..19b7d6e 100644
--- a/media/common_time/ICommonClock.cpp
+++ b/media/common_time/ICommonClock.cpp
@@ -206,7 +206,7 @@
             const sp<ICommonClockListener>& listener) {
         Parcel data, reply;
         data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        data.writeStrongBinder(listener->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(listener));
 
         status_t status = remote()->transact(REGISTER_LISTENER, data, &reply);
 
@@ -221,7 +221,7 @@
             const sp<ICommonClockListener>& listener) {
         Parcel data, reply;
         data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        data.writeStrongBinder(listener->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(listener));
         status_t status = remote()->transact(UNREGISTER_LISTENER, data, &reply);
 
         if (status == OK) {
diff --git a/media/libeffects/loudness/Android.mk b/media/libeffects/loudness/Android.mk
index edf964e..55d0611 100644
--- a/media/libeffects/loudness/Android.mk
+++ b/media/libeffects/loudness/Android.mk
@@ -12,16 +12,11 @@
 LOCAL_SHARED_LIBRARIES := \
 	libcutils \
 	liblog \
-	libstlport
 
 LOCAL_MODULE_RELATIVE_PATH := soundfx
 LOCAL_MODULE:= libldnhncr
 
 LOCAL_C_INCLUDES := \
 	$(call include-path-for, audio-effects) \
-	bionic \
-	bionic/libstdc++/include \
-	external/stlport/stlport
-
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libeffects/proxy/Android.mk b/media/libeffects/proxy/Android.mk
index b438796..2ba452e 100644
--- a/media/libeffects/proxy/Android.mk
+++ b/media/libeffects/proxy/Android.mk
@@ -28,7 +28,6 @@
 
 LOCAL_C_INCLUDES := \
         system/media/audio_effects/include \
-        bionic/libc/include \
         frameworks/av/media/libeffects/factory
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libmedia/Android.mk b/media/libmedia/Android.mk
index e012116..50d9a0f 100644
--- a/media/libmedia/Android.mk
+++ b/media/libmedia/Android.mk
@@ -74,6 +74,8 @@
 
 LOCAL_MODULE:= libmedia
 
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
+
 LOCAL_C_INCLUDES := \
     $(TOP)/frameworks/native/include/media/openmax \
     $(TOP)/frameworks/av/include/media/ \
@@ -87,8 +89,6 @@
 
 include $(CLEAR_VARS)
 
-# for <cutils/atomic-inline.h>
-LOCAL_CFLAGS += -DANDROID_SMP=$(if $(findstring true,$(TARGET_CPU_SMP)),1,0)
 LOCAL_SRC_FILES += SingleStateQueue.cpp
 LOCAL_CFLAGS += -DSINGLE_STATE_QUEUE_INSTANTIATIONS='"SingleStateQueueInstantiations.cpp"'
 
diff --git a/media/libmedia/AudioEffect.cpp b/media/libmedia/AudioEffect.cpp
index 0d5d7e4..af103c1 100644
--- a/media/libmedia/AudioEffect.cpp
+++ b/media/libmedia/AudioEffect.cpp
@@ -150,7 +150,7 @@
     int bufOffset = ((sizeof(effect_param_cblk_t) - 1) / sizeof(int) + 1) * sizeof(int);
     mCblk->buffer = (uint8_t *)mCblk + bufOffset;
 
-    iEffect->asBinder()->linkToDeath(mIEffectClient);
+    IInterface::asBinder(iEffect)->linkToDeath(mIEffectClient);
     mClientPid = IPCThreadState::self()->getCallingPid();
     ALOGV("set() %p OK effect: %s id: %d status %d enabled %d pid %d", this, mDescriptor.name, mId,
             mStatus, mEnabled, mClientPid);
@@ -173,7 +173,7 @@
         }
         if (mIEffect != NULL) {
             mIEffect->disconnect();
-            mIEffect->asBinder()->unlinkToDeath(mIEffectClient);
+            IInterface::asBinder(mIEffect)->unlinkToDeath(mIEffectClient);
         }
         IPCThreadState::self()->flushCommands();
     }
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 9e7ba88..9d92cfe 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -105,7 +105,7 @@
             mAudioRecordThread->requestExitAndWait();
             mAudioRecordThread.clear();
         }
-        mAudioRecord->asBinder()->unlinkToDeath(mDeathNotifier, this);
+        IInterface::asBinder(mAudioRecord)->unlinkToDeath(mDeathNotifier, this);
         mAudioRecord.clear();
         mCblkMemory.clear();
         mBufferMemory.clear();
@@ -516,7 +516,7 @@
 
     // invariant that mAudioRecord != 0 is true only after set() returns successfully
     if (mAudioRecord != 0) {
-        mAudioRecord->asBinder()->unlinkToDeath(mDeathNotifier, this);
+        IInterface::asBinder(mAudioRecord)->unlinkToDeath(mDeathNotifier, this);
         mDeathNotifier.clear();
     }
     mAudioRecord = record;
@@ -566,7 +566,7 @@
     mProxy->setMinimum(mNotificationFramesAct);
 
     mDeathNotifier = new DeathNotifier(this);
-    mAudioRecord->asBinder()->linkToDeath(mDeathNotifier, this);
+    IInterface::asBinder(mAudioRecord)->linkToDeath(mDeathNotifier, this);
 
     return NO_ERROR;
     }
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index c11050e..3248adb 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -193,7 +193,7 @@
             mAudioTrackThread->requestExitAndWait();
             mAudioTrackThread.clear();
         }
-        mAudioTrack->asBinder()->unlinkToDeath(mDeathNotifier, this);
+        IInterface::asBinder(mAudioTrack)->unlinkToDeath(mDeathNotifier, this);
         mAudioTrack.clear();
         mCblkMemory.clear();
         mSharedBuffer.clear();
@@ -1123,7 +1123,7 @@
     }
     // invariant that mAudioTrack != 0 is true only after set() returns successfully
     if (mAudioTrack != 0) {
-        mAudioTrack->asBinder()->unlinkToDeath(mDeathNotifier, this);
+        IInterface::asBinder(mAudioTrack)->unlinkToDeath(mDeathNotifier, this);
         mDeathNotifier.clear();
     }
     mAudioTrack = track;
@@ -1226,7 +1226,7 @@
     mProxy->setMinimum(mNotificationFramesAct);
 
     mDeathNotifier = new DeathNotifier(this);
-    mAudioTrack->asBinder()->linkToDeath(mDeathNotifier, this);
+    IInterface::asBinder(mAudioTrack)->linkToDeath(mDeathNotifier, this);
 
     return NO_ERROR;
     }
diff --git a/media/libmedia/IAudioFlinger.cpp b/media/libmedia/IAudioFlinger.cpp
index 346a192..8e3b633 100644
--- a/media/libmedia/IAudioFlinger.cpp
+++ b/media/libmedia/IAudioFlinger.cpp
@@ -119,7 +119,7 @@
         // haveSharedBuffer
         if (sharedBuffer != 0) {
             data.writeInt32(true);
-            data.writeStrongBinder(sharedBuffer->asBinder());
+            data.writeStrongBinder(IInterface::asBinder(sharedBuffer));
         } else {
             data.writeInt32(false);
         }
@@ -419,7 +419,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
-        data.writeStrongBinder(client->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(client));
         remote()->transact(REGISTER_CLIENT, data, &reply);
     }
 
@@ -716,7 +716,7 @@
 
         data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
         data.write(pDesc, sizeof(effect_descriptor_t));
-        data.writeStrongBinder(client->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(client));
         data.writeInt32(priority);
         data.writeInt32((int32_t) output);
         data.writeInt32(sessionId);
@@ -939,7 +939,7 @@
             reply->writeInt32(flags);
             reply->writeInt32(sessionId);
             reply->writeInt32(status);
-            reply->writeStrongBinder(track->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(track));
             return NO_ERROR;
         } break;
         case OPEN_RECORD: {
@@ -966,9 +966,9 @@
             reply->writeInt32(sessionId);
             reply->writeInt64(notificationFrames);
             reply->writeInt32(status);
-            reply->writeStrongBinder(record->asBinder());
-            reply->writeStrongBinder(cblk->asBinder());
-            reply->writeStrongBinder(buffers->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(record));
+            reply->writeStrongBinder(IInterface::asBinder(cblk));
+            reply->writeStrongBinder(IInterface::asBinder(buffers));
             return NO_ERROR;
         } break;
         case SAMPLE_RATE: {
@@ -1254,7 +1254,7 @@
             reply->writeInt32(status);
             reply->writeInt32(id);
             reply->writeInt32(enabled);
-            reply->writeStrongBinder(effect->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(effect));
             reply->write(&desc, sizeof(effect_descriptor_t));
             return NO_ERROR;
         } break;
diff --git a/media/libmedia/IAudioPolicyService.cpp b/media/libmedia/IAudioPolicyService.cpp
index 89178f1..9349662 100644
--- a/media/libmedia/IAudioPolicyService.cpp
+++ b/media/libmedia/IAudioPolicyService.cpp
@@ -572,7 +572,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
-        data.writeStrongBinder(client->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(client));
         remote()->transact(REGISTER_CLIENT, data, &reply);
     }
 
diff --git a/media/libmedia/IAudioTrack.cpp b/media/libmedia/IAudioTrack.cpp
index 265bb1b..df209fd 100644
--- a/media/libmedia/IAudioTrack.cpp
+++ b/media/libmedia/IAudioTrack.cpp
@@ -137,7 +137,7 @@
                                       int64_t pts) {
         Parcel data, reply;
         data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
-        data.writeStrongBinder(buffer->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(buffer));
         data.writeInt64(pts);
         status_t status = remote()->transact(QUEUE_TIMED_BUFFER,
                                              data, &reply);
@@ -207,7 +207,7 @@
     switch (code) {
         case GET_CBLK: {
             CHECK_INTERFACE(IAudioTrack, data, reply);
-            reply->writeStrongBinder(getCblk()->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(getCblk()));
             return NO_ERROR;
         } break;
         case START: {
@@ -241,7 +241,7 @@
             status_t status = allocateTimedBuffer(data.readInt64(), &buffer);
             reply->writeInt32(status);
             if (status == NO_ERROR) {
-                reply->writeStrongBinder(buffer->asBinder());
+                reply->writeStrongBinder(IInterface::asBinder(buffer));
             }
             return NO_ERROR;
         } break;
diff --git a/media/libmedia/IDrm.cpp b/media/libmedia/IDrm.cpp
index 7e74de9..b08fa82 100644
--- a/media/libmedia/IDrm.cpp
+++ b/media/libmedia/IDrm.cpp
@@ -450,7 +450,7 @@
     virtual status_t setListener(const sp<IDrmClient>& listener) {
         Parcel data, reply;
         data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
-        data.writeStrongBinder(listener->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(listener));
         remote()->transact(SET_LISTENER, data, &reply);
         return reply.readInt32();
     }
diff --git a/media/libmedia/IEffect.cpp b/media/libmedia/IEffect.cpp
index b94012a..c2fff78 100644
--- a/media/libmedia/IEffect.cpp
+++ b/media/libmedia/IEffect.cpp
@@ -190,7 +190,7 @@
 
         case GET_CBLK: {
             CHECK_INTERFACE(IEffect, data, reply);
-            reply->writeStrongBinder(getCblk()->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(getCblk()));
             return NO_ERROR;
         } break;
 
diff --git a/media/libmedia/IHDCP.cpp b/media/libmedia/IHDCP.cpp
index 1cf987a..9122f75 100644
--- a/media/libmedia/IHDCP.cpp
+++ b/media/libmedia/IHDCP.cpp
@@ -65,7 +65,7 @@
     virtual status_t setObserver(const sp<IHDCPObserver> &observer) {
         Parcel data, reply;
         data.writeInterfaceToken(IHDCP::getInterfaceDescriptor());
-        data.writeStrongBinder(observer->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(observer));
         remote()->transact(HDCP_SET_OBSERVER, data, &reply);
         return reply.readInt32();
     }
diff --git a/media/libmedia/IMediaDeathNotifier.cpp b/media/libmedia/IMediaDeathNotifier.cpp
index 10b4934..38e9ca0 100644
--- a/media/libmedia/IMediaDeathNotifier.cpp
+++ b/media/libmedia/IMediaDeathNotifier.cpp
@@ -104,7 +104,7 @@
     Mutex::Autolock _l(sServiceLock);
     sObitRecipients.clear();
     if (sMediaPlayerService != 0) {
-        sMediaPlayerService->asBinder()->unlinkToDeath(this);
+        IInterface::asBinder(sMediaPlayerService)->unlinkToDeath(this);
     }
 }
 
diff --git a/media/libmedia/IMediaLogService.cpp b/media/libmedia/IMediaLogService.cpp
index 8a66c7c..a4af7b7 100644
--- a/media/libmedia/IMediaLogService.cpp
+++ b/media/libmedia/IMediaLogService.cpp
@@ -42,7 +42,7 @@
     virtual void    registerWriter(const sp<IMemory>& shared, size_t size, const char *name) {
         Parcel data, reply;
         data.writeInterfaceToken(IMediaLogService::getInterfaceDescriptor());
-        data.writeStrongBinder(shared->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(shared));
         data.writeInt64((int64_t) size);
         data.writeCString(name);
         status_t status = remote()->transact(REGISTER_WRITER, data, &reply);
@@ -52,7 +52,7 @@
     virtual void    unregisterWriter(const sp<IMemory>& shared) {
         Parcel data, reply;
         data.writeInterfaceToken(IMediaLogService::getInterfaceDescriptor());
-        data.writeStrongBinder(shared->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(shared));
         status_t status = remote()->transact(UNREGISTER_WRITER, data, &reply);
         // FIXME ignores status
     }
diff --git a/media/libmedia/IMediaMetadataRetriever.cpp b/media/libmedia/IMediaMetadataRetriever.cpp
index 38f717c..aa2665a 100644
--- a/media/libmedia/IMediaMetadataRetriever.cpp
+++ b/media/libmedia/IMediaMetadataRetriever.cpp
@@ -95,7 +95,7 @@
         data.writeInterfaceToken(IMediaMetadataRetriever::getInterfaceDescriptor());
         data.writeInt32(httpService != NULL);
         if (httpService != NULL) {
-            data.writeStrongBinder(httpService->asBinder());
+            data.writeStrongBinder(IInterface::asBinder(httpService));
         }
         data.writeCString(srcUrl);
 
@@ -246,7 +246,7 @@
             sp<IMemory> bitmap = getFrameAtTime(timeUs, option);
             if (bitmap != 0) {  // Don't send NULL across the binder interface
                 reply->writeInt32(NO_ERROR);
-                reply->writeStrongBinder(bitmap->asBinder());
+                reply->writeStrongBinder(IInterface::asBinder(bitmap));
             } else {
                 reply->writeInt32(UNKNOWN_ERROR);
             }
@@ -263,7 +263,7 @@
             sp<IMemory> albumArt = extractAlbumArt();
             if (albumArt != 0) {  // Don't send NULL across the binder interface
                 reply->writeInt32(NO_ERROR);
-                reply->writeStrongBinder(albumArt->asBinder());
+                reply->writeStrongBinder(IInterface::asBinder(albumArt));
             } else {
                 reply->writeInt32(UNKNOWN_ERROR);
             }
diff --git a/media/libmedia/IMediaPlayer.cpp b/media/libmedia/IMediaPlayer.cpp
index d778d05..7f3e5cc 100644
--- a/media/libmedia/IMediaPlayer.cpp
+++ b/media/libmedia/IMediaPlayer.cpp
@@ -85,7 +85,7 @@
         data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
         data.writeInt32(httpService != NULL);
         if (httpService != NULL) {
-            data.writeStrongBinder(httpService->asBinder());
+            data.writeStrongBinder(IInterface::asBinder(httpService));
         }
         data.writeCString(url);
         if (headers == NULL) {
@@ -115,7 +115,7 @@
     status_t setDataSource(const sp<IStreamSource> &source) {
         Parcel data, reply;
         data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
-        data.writeStrongBinder(source->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(source));
         remote()->transact(SET_DATA_SOURCE_STREAM, data, &reply);
         return reply.readInt32();
     }
@@ -125,7 +125,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
-        sp<IBinder> b(bufferProducer->asBinder());
+        sp<IBinder> b(IInterface::asBinder(bufferProducer));
         data.writeStrongBinder(b);
         remote()->transact(SET_VIDEO_SURFACETEXTURE, data, &reply);
         return reply.readInt32();
@@ -323,7 +323,7 @@
     status_t setNextPlayer(const sp<IMediaPlayer>& player) {
         Parcel data, reply;
         data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
-        sp<IBinder> b(player->asBinder());
+        sp<IBinder> b(IInterface::asBinder(player));
         data.writeStrongBinder(b);
         remote()->transact(SET_NEXT_PLAYER, data, &reply);
         return reply.readInt32();
diff --git a/media/libmedia/IMediaPlayerService.cpp b/media/libmedia/IMediaPlayerService.cpp
index 2e02d17..a7568b9 100644
--- a/media/libmedia/IMediaPlayerService.cpp
+++ b/media/libmedia/IMediaPlayerService.cpp
@@ -73,7 +73,7 @@
             const sp<IMediaPlayerClient>& client, int audioSessionId) {
         Parcel data, reply;
         data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
-        data.writeStrongBinder(client->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(client));
         data.writeInt32(audioSessionId);
 
         remote()->transact(CREATE, data, &reply);
@@ -101,10 +101,10 @@
         data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
         data.writeInt32(httpService != NULL);
         if (httpService != NULL) {
-            data.writeStrongBinder(httpService->asBinder());
+            data.writeStrongBinder(IInterface::asBinder(httpService));
         }
         data.writeCString(url);
-        data.writeStrongBinder(heap->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(heap));
         status_t status = remote()->transact(DECODE_URL, data, &reply);
         if (status == NO_ERROR) {
             status = (status_t)reply.readInt32();
@@ -127,7 +127,7 @@
         data.writeFileDescriptor(fd);
         data.writeInt64(offset);
         data.writeInt64(length);
-        data.writeStrongBinder(heap->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(heap));
         status_t status = remote()->transact(DECODE_FD, data, &reply);
         if (status == NO_ERROR) {
             status = (status_t)reply.readInt32();
@@ -188,7 +188,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
-        data.writeStrongBinder(client->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(client));
         data.writeString8(iface);
         remote()->transact(LISTEN_FOR_REMOTE_DISPLAY, data, &reply);
         return interface_cast<IRemoteDisplay>(reply.readStrongBinder());
@@ -216,7 +216,7 @@
                 interface_cast<IMediaPlayerClient>(data.readStrongBinder());
             int audioSessionId = data.readInt32();
             sp<IMediaPlayer> player = create(client, audioSessionId);
-            reply->writeStrongBinder(player->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(player));
             return NO_ERROR;
         } break;
         case DECODE_URL: {
@@ -273,38 +273,38 @@
         case CREATE_MEDIA_RECORDER: {
             CHECK_INTERFACE(IMediaPlayerService, data, reply);
             sp<IMediaRecorder> recorder = createMediaRecorder();
-            reply->writeStrongBinder(recorder->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(recorder));
             return NO_ERROR;
         } break;
         case CREATE_METADATA_RETRIEVER: {
             CHECK_INTERFACE(IMediaPlayerService, data, reply);
             sp<IMediaMetadataRetriever> retriever = createMetadataRetriever();
-            reply->writeStrongBinder(retriever->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(retriever));
             return NO_ERROR;
         } break;
         case GET_OMX: {
             CHECK_INTERFACE(IMediaPlayerService, data, reply);
             sp<IOMX> omx = getOMX();
-            reply->writeStrongBinder(omx->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(omx));
             return NO_ERROR;
         } break;
         case MAKE_CRYPTO: {
             CHECK_INTERFACE(IMediaPlayerService, data, reply);
             sp<ICrypto> crypto = makeCrypto();
-            reply->writeStrongBinder(crypto->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(crypto));
             return NO_ERROR;
         } break;
         case MAKE_DRM: {
             CHECK_INTERFACE(IMediaPlayerService, data, reply);
             sp<IDrm> drm = makeDrm();
-            reply->writeStrongBinder(drm->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(drm));
             return NO_ERROR;
         } break;
         case MAKE_HDCP: {
             CHECK_INTERFACE(IMediaPlayerService, data, reply);
             bool createEncryptionModule = data.readInt32();
             sp<IHDCP> hdcp = makeHDCP(createEncryptionModule);
-            reply->writeStrongBinder(hdcp->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(hdcp));
             return NO_ERROR;
         } break;
         case ADD_BATTERY_DATA: {
@@ -324,13 +324,13 @@
                     interface_cast<IRemoteDisplayClient>(data.readStrongBinder()));
             String8 iface(data.readString8());
             sp<IRemoteDisplay> display(listenForRemoteDisplay(client, iface));
-            reply->writeStrongBinder(display->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(display));
             return NO_ERROR;
         } break;
         case GET_CODEC_LIST: {
             CHECK_INTERFACE(IMediaPlayerService, data, reply);
             sp<IMediaCodecList> mcl = getCodecList();
-            reply->writeStrongBinder(mcl->asBinder());
+            reply->writeStrongBinder(IInterface::asBinder(mcl));
             return NO_ERROR;
         } break;
         default:
diff --git a/media/libmedia/IMediaRecorder.cpp b/media/libmedia/IMediaRecorder.cpp
index 95af006..a733b68 100644
--- a/media/libmedia/IMediaRecorder.cpp
+++ b/media/libmedia/IMediaRecorder.cpp
@@ -70,8 +70,8 @@
         ALOGV("setCamera(%p,%p)", camera.get(), proxy.get());
         Parcel data, reply;
         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
-        data.writeStrongBinder(camera->asBinder());
-        data.writeStrongBinder(proxy->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(camera));
+        data.writeStrongBinder(IInterface::asBinder(proxy));
         remote()->transact(SET_CAMERA, data, &reply);
         return reply.readInt32();
     }
@@ -94,7 +94,7 @@
         ALOGV("setPreviewSurface(%p)", surface.get());
         Parcel data, reply;
         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
-        data.writeStrongBinder(surface->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(surface));
         remote()->transact(SET_PREVIEW_SURFACE, data, &reply);
         return reply.readInt32();
     }
@@ -215,7 +215,7 @@
         ALOGV("setListener(%p)", listener.get());
         Parcel data, reply;
         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
-        data.writeStrongBinder(listener->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(listener));
         remote()->transact(SET_LISTENER, data, &reply);
         return reply.readInt32();
     }
@@ -468,7 +468,7 @@
             int returnedNull= (surfaceMediaSource == NULL) ? 1 : 0 ;
             reply->writeInt32(returnedNull);
             if (!returnedNull) {
-                reply->writeStrongBinder(surfaceMediaSource->asBinder());
+                reply->writeStrongBinder(IInterface::asBinder(surfaceMediaSource));
             }
             return NO_ERROR;
         } break;
diff --git a/media/libmedia/IOMX.cpp b/media/libmedia/IOMX.cpp
index c583d32..e208df9 100644
--- a/media/libmedia/IOMX.cpp
+++ b/media/libmedia/IOMX.cpp
@@ -100,7 +100,7 @@
         Parcel data, reply;
         data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
         data.writeCString(name);
-        data.writeStrongBinder(observer->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(observer));
         remote()->transact(ALLOCATE_NODE, data, &reply);
 
         status_t err = reply.readInt32();
@@ -248,7 +248,7 @@
         data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
         data.writeInt32((int32_t)node);
         data.writeInt32(port_index);
-        data.writeStrongBinder(params->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(params));
         remote()->transact(USE_BUFFER, data, &reply);
 
         status_t err = reply.readInt32();
@@ -418,7 +418,7 @@
         data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
         data.writeInt32((int32_t)node);
         data.writeInt32(port_index);
-        data.writeStrongBinder(params->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(params));
         remote()->transact(ALLOC_BUFFER_WITH_BACKUP, data, &reply);
 
         status_t err = reply.readInt32();
@@ -775,7 +775,7 @@
             reply->writeInt32(err);
 
             if (err == OK) {
-                reply->writeStrongBinder(bufferProducer->asBinder());
+                reply->writeStrongBinder(IInterface::asBinder(bufferProducer));
             }
 
             return NO_ERROR;
diff --git a/media/libmedia/IRemoteDisplayClient.cpp b/media/libmedia/IRemoteDisplayClient.cpp
index 7190879..9d63bc9 100644
--- a/media/libmedia/IRemoteDisplayClient.cpp
+++ b/media/libmedia/IRemoteDisplayClient.cpp
@@ -42,7 +42,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(IRemoteDisplayClient::getInterfaceDescriptor());
-        data.writeStrongBinder(bufferProducer->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(bufferProducer));
         data.writeInt32(width);
         data.writeInt32(height);
         data.writeInt32(flags);
diff --git a/media/libmedia/IStreamSource.cpp b/media/libmedia/IStreamSource.cpp
index fe2cc61..d480aef 100644
--- a/media/libmedia/IStreamSource.cpp
+++ b/media/libmedia/IStreamSource.cpp
@@ -55,7 +55,7 @@
     virtual void setListener(const sp<IStreamListener> &listener) {
         Parcel data, reply;
         data.writeInterfaceToken(IStreamSource::getInterfaceDescriptor());
-        data.writeStrongBinder(listener->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(listener));
         remote()->transact(SET_LISTENER, data, &reply);
     }
 
@@ -64,7 +64,7 @@
         data.writeInterfaceToken(IStreamSource::getInterfaceDescriptor());
         data.writeInt64(static_cast<int64_t>(buffers.size()));
         for (size_t i = 0; i < buffers.size(); ++i) {
-            data.writeStrongBinder(buffers.itemAt(i)->asBinder());
+            data.writeStrongBinder(IInterface::asBinder(buffers.itemAt(i)));
         }
         remote()->transact(SET_BUFFERS, data, &reply);
     }
diff --git a/media/libmedia/SingleStateQueue.cpp b/media/libmedia/SingleStateQueue.cpp
index 3503baa..c241184 100644
--- a/media/libmedia/SingleStateQueue.cpp
+++ b/media/libmedia/SingleStateQueue.cpp
@@ -16,7 +16,6 @@
 
 #include <new>
 #include <cutils/atomic.h>
-#include <cutils/atomic-inline.h> // for android_memory_barrier()
 #include <media/SingleStateQueue.h>
 
 namespace android {
diff --git a/media/libmedia/ToneGenerator.cpp b/media/libmedia/ToneGenerator.cpp
index 61b6d36..2cc4685 100644
--- a/media/libmedia/ToneGenerator.cpp
+++ b/media/libmedia/ToneGenerator.cpp
@@ -28,718 +28,718 @@
 
 // Descriptors for all available tones (See ToneGenerator::ToneDescriptor class declaration for details)
 const ToneGenerator::ToneDescriptor ToneGenerator::sToneDescriptors[] = {
-        { segments: {{ duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 941, 0 }, 0, 0},
-                     { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_0
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 697, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_1
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 697, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_2
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 697, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_3
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 770, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_4
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 770, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_5
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 770, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_6
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 852, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_7
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 852, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_8
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 852, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_9
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 941, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_S
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 941, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_P
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 697, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_A
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 770, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                             // TONE_DTMF_B
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 852, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_C
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 941, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_DTMF_D
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 425, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_SUP_DIAL
-        { segments: { { duration: 500 , waveFreq: { 425, 0 }, 0, 0},
-                      { duration: 500, waveFreq: { 0 }, 0, 0},
-                         { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_SUP_BUSY
-        { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_SUP_CONGESTION
-        { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 0,
-          repeatSegment: 0 },                              // TONE_SUP_RADIO_ACK
-        { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0},
-                      { duration: 200, waveFreq: { 0 }, 0, 0},
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 2,
-          repeatSegment: 0 },                              // TONE_SUP_RADIO_NOTAVAIL
-        { segments: { { duration: 330, waveFreq: { 950, 1400, 1800, 0 }, 0, 0},
-                      { duration: 1000, waveFreq: { 0 }, 0, 0},
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_SUP_ERROR
-        { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
-                      { duration: 600, waveFreq: { 0 }, 0, 0 },
-                      { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
-                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_SUP_CALL_WAITING
-        { segments: { { duration: 1000, waveFreq: { 425, 0 }, 0, 0 },
-                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_SUP_RINGTONE
-        { segments: { { duration: 40, waveFreq: { 400, 1200, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 0,
-          repeatSegment: 0 },                              // TONE_PROP_BEEP
-        { segments: { { duration: 100, waveFreq: { 1200, 0 }, 0, 0 },
-                      { duration: 100, waveFreq: { 0 }, 0, 0  },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 1,
-          repeatSegment: 0 },                              // TONE_PROP_ACK
-        { segments: { { duration: 400, waveFreq: { 300, 400, 500, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 0,
-          repeatSegment: 0 },                              // TONE_PROP_NACK
-        { segments: { { duration: 200, waveFreq: { 400, 1200, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 0,
-          repeatSegment: 0 },                              // TONE_PROP_PROMPT
-        { segments: { { duration: 40, waveFreq: { 400, 1200, 0 }, 0, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 40, waveFreq: { 400, 1200, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 0,
-          repeatSegment: 0 },                             // TONE_PROP_BEEP2
-        { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
-                      { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_SUP_INTERCEPT
-        { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
-                      { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 7,
-          repeatSegment: 0 },                             // TONE_SUP_INTERCEPT_ABBREV
-        { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
-                      { duration: 250, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 7,
-          repeatSegment: 0 },                             // TONE_SUP_CONGESTION_ABBREV
-        { segments: { { duration: 100, waveFreq: { 350, 440, 0 }, 0, 0 },
-                      { duration: 100, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 2,
-          repeatSegment: 0 },                             // TONE_SUP_CONFIRM
-        { segments: { { duration: 100, waveFreq: { 480, 0 }, 0, 0 },
-                      { duration: 100, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 3,
-          repeatSegment: 0 },                              // TONE_SUP_PIP
-        { segments: {{ duration: ToneGenerator::TONEGEN_INF, waveFreq: { 425, 0 }, 0, 0},
-                     { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_CDMA_DIAL_TONE_LITE
-        { segments: { { duration: 2000, waveFreq: { 440, 480, 0 }, 0, 0 },
-                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_CDMA_NETWORK_USA_RINGBACK
-        { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
-                      { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt:  ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                             // TONE_CDMA_INTERCEPT
-        { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
-                      { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt:  0,
-          repeatSegment: 0 },                             // TONE_CDMA_ABBR_INTERCEPT
-        { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
-                      { duration: 250, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_CDMA_REORDER
-        { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
-                      { duration: 250, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 7,
-          repeatSegment: 0 },                              // TONE_CDMA_ABBR_REORDER
-        { segments: { { duration: 500, waveFreq: { 480, 620, 0 }, 0, 0 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_CDMA_NETWORK_BUSY
-        { segments: { { duration: 100, waveFreq: { 350, 440, 0 }, 0, 0 },
-                      { duration: 100, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 2,
-          repeatSegment: 0 },                              // TONE_CDMA_CONFIRM
-        { segments: { { duration: 500, waveFreq: { 660, 1000, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 0,
-          repeatSegment: 0 },                              // TONE_CDMA_ANSWER
-        { segments: { { duration: 300, waveFreq: { 440, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 0,
-          repeatSegment: 0 },                              // TONE_CDMA_NETWORK_CALLWAITING
-        { segments: { { duration: 100, waveFreq: { 480, 0 }, 0, 0 },
-                      { duration: 100, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 3,
-          repeatSegment: 0 },                              // TONE_CDMA_PIP
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1336, 941, 0 }, 0, 0},
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_0
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1209, 697, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_1
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1336, 697, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_2
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1477, 697, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_3
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1209, 770, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_4
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1336, 770, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_5
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1477, 770, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_6
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1209, 852, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_7
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1336, 852, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_8
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1477, 852, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_9
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1209, 941, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_S
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1477, 941, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_P
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1633, 697, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_A
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1633, 770, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                             // TONE_DTMF_B
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1633, 852, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_C
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 1633, 941, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_DTMF_D
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 425, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_SUP_DIAL
+        { .segments = { { .duration = 500 , .waveFreq = { 425, 0 }, 0, 0},
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0},
+                           { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_SUP_BUSY
+        { .segments = { { .duration = 200, .waveFreq = { 425, 0 }, 0, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_SUP_CONGESTION
+        { .segments = { { .duration = 200, .waveFreq = { 425, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                              // TONE_SUP_RADIO_ACK
+        { .segments = { { .duration = 200, .waveFreq = { 425, 0 }, 0, 0},
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0},
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 2,
+          .repeatSegment = 0 },                              // TONE_SUP_RADIO_NOTAVAIL
+        { .segments = { { .duration = 330, .waveFreq = { 950, 1400, 1800, 0 }, 0, 0},
+                        { .duration = 1000, .waveFreq = { 0 }, 0, 0},
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_SUP_ERROR
+        { .segments = { { .duration = 200, .waveFreq = { 425, 0 }, 0, 0 },
+                        { .duration = 600, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 200, .waveFreq = { 425, 0 }, 0, 0 },
+                        { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_SUP_CALL_WAITING
+        { .segments = { { .duration = 1000, .waveFreq = { 425, 0 }, 0, 0 },
+                        { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_SUP_RINGTONE
+        { .segments = { { .duration = 40, .waveFreq = { 400, 1200, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                              // TONE_PROP_BEEP
+        { .segments = { { .duration = 100, .waveFreq = { 1200, 0 }, 0, 0 },
+                        { .duration = 100, .waveFreq = { 0 }, 0, 0  },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 1,
+          .repeatSegment = 0 },                              // TONE_PROP_ACK
+        { .segments = { { .duration = 400, .waveFreq = { 300, 400, 500, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                              // TONE_PROP_NACK
+        { .segments = { { .duration = 200, .waveFreq = { 400, 1200, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                              // TONE_PROP_PROMPT
+        { .segments = { { .duration = 40, .waveFreq = { 400, 1200, 0 }, 0, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 40, .waveFreq = { 400, 1200, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                             // TONE_PROP_BEEP2
+        { .segments = { { .duration = 250, .waveFreq = { 440, 0 }, 0, 0 },
+                        { .duration = 250, .waveFreq = { 620, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_SUP_INTERCEPT
+        { .segments = { { .duration = 250, .waveFreq = { 440, 0 }, 0, 0 },
+                        { .duration = 250, .waveFreq = { 620, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 7,
+          .repeatSegment = 0 },                             // TONE_SUP_INTERCEPT_ABBREV
+        { .segments = { { .duration = 250, .waveFreq = { 480, 620, 0 }, 0, 0 },
+                        { .duration = 250, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 7,
+          .repeatSegment = 0 },                             // TONE_SUP_CONGESTION_ABBREV
+        { .segments = { { .duration = 100, .waveFreq = { 350, 440, 0 }, 0, 0 },
+                        { .duration = 100, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 2,
+          .repeatSegment = 0 },                             // TONE_SUP_CONFIRM
+        { .segments = { { .duration = 100, .waveFreq = { 480, 0 }, 0, 0 },
+                        { .duration = 100, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 3,
+          .repeatSegment = 0 },                              // TONE_SUP_PIP
+        { .segments = {{ .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 425, 0 }, 0, 0},
+                       { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_CDMA_DIAL_TONE_LITE
+        { .segments = { { .duration = 2000, .waveFreq = { 440, 480, 0 }, 0, 0 },
+                        { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_CDMA_NETWORK_USA_RINGBACK
+        { .segments = { { .duration = 250, .waveFreq = { 440, 0 }, 0, 0 },
+                        { .duration = 250, .waveFreq = { 620, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt =  ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                             // TONE_CDMA_INTERCEPT
+        { .segments = { { .duration = 250, .waveFreq = { 440, 0 }, 0, 0 },
+                        { .duration = 250, .waveFreq = { 620, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt =  0,
+          .repeatSegment = 0 },                             // TONE_CDMA_ABBR_INTERCEPT
+        { .segments = { { .duration = 250, .waveFreq = { 480, 620, 0 }, 0, 0 },
+                        { .duration = 250, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_CDMA_REORDER
+        { .segments = { { .duration = 250, .waveFreq = { 480, 620, 0 }, 0, 0 },
+                        { .duration = 250, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 7,
+          .repeatSegment = 0 },                              // TONE_CDMA_ABBR_REORDER
+        { .segments = { { .duration = 500, .waveFreq = { 480, 620, 0 }, 0, 0 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_CDMA_NETWORK_BUSY
+        { .segments = { { .duration = 100, .waveFreq = { 350, 440, 0 }, 0, 0 },
+                        { .duration = 100, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 2,
+          .repeatSegment = 0 },                              // TONE_CDMA_CONFIRM
+        { .segments = { { .duration = 500, .waveFreq = { 660, 1000, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                              // TONE_CDMA_ANSWER
+        { .segments = { { .duration = 300, .waveFreq = { 440, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                              // TONE_CDMA_NETWORK_CALLWAITING
+        { .segments = { { .duration = 100, .waveFreq = { 480, 0 }, 0, 0 },
+                        { .duration = 100, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 3,
+          .repeatSegment = 0 },                              // TONE_CDMA_PIP
 
-        { segments: { { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
-                      { duration: 64, waveFreq: { 2556, 0}, 19, 0},
-                      { duration: 32, waveFreq: { 2091, 0}, 0, 0},
-                      { duration: 48, waveFreq: { 2556, 0}, 0, 0},
-                      { duration: 4000, waveFreq: { 0 }, 0, 0},
-                      { duration: 0,  waveFreq: { 0 }, 0, 0}},
-          repeatCnt: 0,
-          repeatSegment: 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_NORMAL
-        { segments: { { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
-                      { duration: 64, waveFreq: { 2556, 0}, 7, 0 },
-                      { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
-                      { duration: 400, waveFreq: { 0 }, 0, 0 },
-                      { duration: 32,  waveFreq: { 2091, 0}, 0, 0 },
-                      { duration: 64,  waveFreq: { 2556, 0}, 7, 4 },
-                      { duration: 32,  waveFreq: { 2091, 0}, 0, 0 },
-                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0,    waveFreq: { 0 }, 0, 0 } },
-          repeatCnt: 0,
-          repeatSegment: 0 },                              // TONE_CDMA_CALL_SIGNAL_ISDN_INTERGROUP
-        { segments: { { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
-                      { duration: 64, waveFreq: { 2556, 0}, 3, 0 },
-                      { duration: 16, waveFreq: { 2091, 0}, 0, 0 },
-                      { duration: 200, waveFreq: { 0 },     0, 0 },
-                      { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
-                      { duration: 64, waveFreq: { 2556, 0}, 3, 4 },
-                      { duration: 16, waveFreq: { 2091, 0}, 0, 0 },
-                      { duration: 200, waveFreq: { 0 },     0, 0 },
-                      { duration: 0,   waveFreq: { 0 },     0, 0 } },
-          repeatCnt: 0,
-          repeatSegment: 0 },                            // TONE_CDMA_CALL_SIGNAL_ISDN_SP_PRI
-        { segments: { { duration: 0,  waveFreq: { 0 }, 0, 0} },
-          repeatCnt: 0,
-          repeatSegment: 0 },                            // TONE_CDMA_CALL_SIGNAL_ISDN_PAT3
-        { segments: { { duration: 32, waveFreq: { 2091, 0 }, 0, 0 },
-                      { duration: 64, waveFreq: { 2556, 0 }, 4, 0 },
-                      { duration: 20, waveFreq: { 2091, 0 }, 0, 0 },
-                      { duration: 0,  waveFreq: { 0 }      , 0, 0 } },
-          repeatCnt: 0,
-          repeatSegment: 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_PING_RING
-        { segments: { { duration: 0,  waveFreq: { 0 }, 0, 0} },
-          repeatCnt: 0,
-          repeatSegment: 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_PAT5
-        { segments: { { duration: 0,  waveFreq: { 0 }, 0, 0} },
-          repeatCnt: 0,
-          repeatSegment: 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_PAT6
-        { segments: { { duration: 0,  waveFreq: { 0 }, 0, 0} },
-          repeatCnt: 0,
-          repeatSegment: 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_PAT7
+        { .segments = { { .duration = 32, .waveFreq = { 2091, 0}, 0, 0 },
+                        { .duration = 64, .waveFreq = { 2556, 0}, 19, 0},
+                        { .duration = 32, .waveFreq = { 2091, 0}, 0, 0},
+                        { .duration = 48, .waveFreq = { 2556, 0}, 0, 0},
+                        { .duration = 4000, .waveFreq = { 0 }, 0, 0},
+                        { .duration = 0,  .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_NORMAL
+        { .segments = { { .duration = 32, .waveFreq = { 2091, 0}, 0, 0 },
+                        { .duration = 64, .waveFreq = { 2556, 0}, 7, 0 },
+                        { .duration = 32, .waveFreq = { 2091, 0}, 0, 0 },
+                        { .duration = 400, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 32,  .waveFreq = { 2091, 0}, 0, 0 },
+                        { .duration = 64,  .waveFreq = { 2556, 0}, 7, 4 },
+                        { .duration = 32,  .waveFreq = { 2091, 0}, 0, 0 },
+                        { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0,    .waveFreq = { 0 }, 0, 0 } },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                              // TONE_CDMA_CALL_SIGNAL_ISDN_INTERGROUP
+        { .segments = { { .duration = 32, .waveFreq = { 2091, 0}, 0, 0 },
+                        { .duration = 64, .waveFreq = { 2556, 0}, 3, 0 },
+                        { .duration = 16, .waveFreq = { 2091, 0}, 0, 0 },
+                        { .duration = 200, .waveFreq = { 0 },     0, 0 },
+                        { .duration = 32, .waveFreq = { 2091, 0}, 0, 0 },
+                        { .duration = 64, .waveFreq = { 2556, 0}, 3, 4 },
+                        { .duration = 16, .waveFreq = { 2091, 0}, 0, 0 },
+                        { .duration = 200, .waveFreq = { 0 },     0, 0 },
+                        { .duration = 0,   .waveFreq = { 0 },     0, 0 } },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                            // TONE_CDMA_CALL_SIGNAL_ISDN_SP_PRI
+        { .segments = { { .duration = 0,  .waveFreq = { 0 }, 0, 0} },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                            // TONE_CDMA_CALL_SIGNAL_ISDN_PAT3
+        { .segments = { { .duration = 32, .waveFreq = { 2091, 0 }, 0, 0 },
+                        { .duration = 64, .waveFreq = { 2556, 0 }, 4, 0 },
+                        { .duration = 20, .waveFreq = { 2091, 0 }, 0, 0 },
+                        { .duration = 0,  .waveFreq = { 0 }      , 0, 0 } },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_PING_RING
+        { .segments = { { .duration = 0,  .waveFreq = { 0 }, 0, 0} },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_PAT5
+        { .segments = { { .duration = 0,  .waveFreq = { 0 }, 0, 0} },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_PAT6
+        { .segments = { { .duration = 0,  .waveFreq = { 0 }, 0, 0} },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_PAT7
 
-        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 39, 0 },
-                      { duration: 4000, waveFreq: { 0 },     0, 0 },
-                      { duration: 0,    waveFreq: { 0 },     0, 0 } },
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_HIGH_L
-        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 39, 0 },
-                      { duration: 4000, waveFreq: { 0 },     0, 0 },
-                      { duration: 0,    waveFreq: { 0 },     0, 0 } },
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_MED_L
-        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 39, 0 },
-                      { duration: 4000, waveFreq: { 0 },     0, 0 },
-                      { duration: 0,    waveFreq: { 0 },     0, 0 } },
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_LOW_L
-        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 15, 0 },
-                      { duration: 400, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 } },
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_HIGH_SS
-        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 15, 0 },
-                      { duration: 400, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_MED_SS
-        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 15, 0 },
-                      { duration: 400, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_LOW_SS
-        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 7, 3 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 15, 6 },
-                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_HIGH_SSL
-        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 7, 3 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 15, 6 },
-                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_MED_SSL
-        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 7, 3 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 15, 6 },
-                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_LOW_SSL
-        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 19, 0 },
-                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 19, 3 },
-                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_HIGH_SS_2
-        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 19, 0 },
-                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 19, 3 },
-                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_MED_SS_2
-        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 19, 0 },
-                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 19, 3 },
-                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_LOW_SS_2
-        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 9, 0 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 19, 3 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 9, 6 },
-                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_HIGH_SLS
-        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 9, 0 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 19, 3 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 9, 6 },
-                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_MED_SLS
-        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 9, 0 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 19, 3 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 9, 6 },
-                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_LOW_SLS
-        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 9, 0 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 9, 3 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 9, 6 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 9, 9 },
-                      { duration: 2500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_HIGH_S_X4
-        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 9, 0 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 9, 3 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 9, 6 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 9, 9 },
-                      { duration: 2500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_MED_S_X4
-        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 9, 0 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 9, 3 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 9, 6 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 9, 9 },
-                      { duration: 2500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_LOW_S_X4
-        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 19, 0 },
-                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_HIGH_PBX_L
-        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 19, 0 },
-                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_MED_PBX_L
-        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 19, 0 },
-                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_LOW_PBX_L
-        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 7, 3 },
-                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_HIGH_PBX_SS
-        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 7, 3 },
-                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_MED_PBX_SS
-        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 7, 3 },
-                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_LOW_PBX_SS
-        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 7, 3 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 15, 6 },
-                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_HIGH_PBX_SSL
-        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 7, 3 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 15, 6 },
-                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_MED_PBX_SSL
-        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 7, 3 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 15, 6 },
-                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_LOW_PBX_SSL
-        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 15, 3 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 7, 6 },
-                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_HIGH_PBX_SLS
-        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 15, 3 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 7, 6 },
-                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_MED_PBX_SLS
-        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 15, 3 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 7, 6 },
-                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_LOW_PBX_SLS
-        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 7, 3 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 7, 6 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 4000, 0 }, 7, 9 },
-                      { duration: 800, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_HIGH_PBX_S_X4
-        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 7, 3 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 7, 6 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 2900, 0 }, 7, 9 },
-                      { duration: 800, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_MED_PBX_S_X4
-        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 7, 3 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 7, 6 },
-                      { duration: 200, waveFreq: { 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
-                      { duration: 25, waveFreq: { 1450, 0 }, 7, 9 },
-                      { duration: 800, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                           // TONE_CDMA_LOW_PBX_S_X4
+        { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 39, 0 },
+                        { .duration = 4000, .waveFreq = { 0 },     0, 0 },
+                        { .duration = 0,    .waveFreq = { 0 },     0, 0 } },
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_HIGH_L
+        { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 39, 0 },
+                        { .duration = 4000, .waveFreq = { 0 },     0, 0 },
+                        { .duration = 0,    .waveFreq = { 0 },     0, 0 } },
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_MED_L
+        { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 39, 0 },
+                        { .duration = 4000, .waveFreq = { 0 },     0, 0 },
+                        { .duration = 0,    .waveFreq = { 0 },     0, 0 } },
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_LOW_L
+        { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 15, 0 },
+                        { .duration = 400, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 } },
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_HIGH_SS
+        { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 15, 0 },
+                        { .duration = 400, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_MED_SS
+        { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 15, 0 },
+                        { .duration = 400, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_LOW_SS
+        { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 7, 3 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 15, 6 },
+                        { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_HIGH_SSL
+        { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 7, 3 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 15, 6 },
+                        { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_MED_SSL
+        { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 7, 3 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 15, 6 },
+                        { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_LOW_SSL
+        { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                          { .duration = 25, .waveFreq = { 4000, 0 }, 19, 0 },
+                        { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 19, 3 },
+                        { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_HIGH_SS_2
+        { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 19, 0 },
+                        { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 19, 3 },
+                        { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_MED_SS_2
+        { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 19, 0 },
+                        { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 19, 3 },
+                        { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_LOW_SS_2
+        { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 9, 0 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 19, 3 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 9, 6 },
+                        { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_HIGH_SLS
+        { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 9, 0 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 19, 3 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 9, 6 },
+                        { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_MED_SLS
+        { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 9, 0 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 19, 3 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 9, 6 },
+                        { .duration = 3000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_LOW_SLS
+        { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 9, 0 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 9, 3 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 9, 6 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 9, 9 },
+                        { .duration = 2500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_HIGH_S_X4
+        { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 9, 0 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 9, 3 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 9, 6 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 9, 9 },
+                        { .duration = 2500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_MED_S_X4
+        { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 9, 0 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 9, 3 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 9, 6 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 9, 9 },
+                        { .duration = 2500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_LOW_S_X4
+        { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 19, 0 },
+                        { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_HIGH_PBX_L
+        { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 19, 0 },
+                        { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_MED_PBX_L
+        { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 19, 0 },
+                        { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_LOW_PBX_L
+        { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 7, 3 },
+                        { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_HIGH_PBX_SS
+        { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 7, 3 },
+                        { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_MED_PBX_SS
+        { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 7, 3 },
+                        { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_LOW_PBX_SS
+        { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 7, 3 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 15, 6 },
+                        { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_HIGH_PBX_SSL
+        { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 7, 3 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 15, 6 },
+                        { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_MED_PBX_SSL
+        { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 7, 3 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 15, 6 },
+                        { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_LOW_PBX_SSL
+        { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 15, 3 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 7, 6 },
+                        { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_HIGH_PBX_SLS
+        { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 15, 3 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 7, 6 },
+                        { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_MED_PBX_SLS
+        { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 15, 3 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 7, 6 },
+                        { .duration = 1000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+           .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_LOW_PBX_SLS
+        { .segments = { { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 7, 3 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 7, 6 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 3700, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 4000, 0 }, 7, 9 },
+                        { .duration = 800, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_HIGH_PBX_S_X4
+        { .segments = { { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 7, 3 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 7, 6 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2600, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 2900, 0 }, 7, 9 },
+                        { .duration = 800, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_MED_PBX_S_X4
+        { .segments = { { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 7, 0 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 7, 3 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 7, 6 },
+                        { .duration = 200, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1300, 0 }, 0, 0 },
+                        { .duration = 25, .waveFreq = { 1450, 0 }, 7, 9 },
+                        { .duration = 800, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                           // TONE_CDMA_LOW_PBX_S_X4
 
-        { segments: { { duration: 62, waveFreq: { 1109, 0 }, 0, 0 },
-                      { duration: 62, waveFreq: { 784, 0 },  0, 0 },
-                      { duration: 62, waveFreq: { 740, 0 },  0, 0 },
-                      { duration: 62, waveFreq: { 622, 0 },  0, 0 },
-                      { duration: 62, waveFreq: { 1109, 0 }, 0, 0 },
-                      { duration: 0,  waveFreq: { 0 },       0, 0 } },
-          repeatCnt: 0,
-          repeatSegment: 0 },                            // TONE_CDMA_ALERT_NETWORK_LITE
-        { segments: { { duration: 62, waveFreq: { 1245, 0 }, 0, 0 },
-                      { duration: 62, waveFreq: { 659, 0 },  2, 0 },
-                      { duration: 62, waveFreq: { 1245, 0 }, 0, 0 },
-                      { duration: 0,  waveFreq: { 0 },       0, 0 } },
-          repeatCnt: 0,
-          repeatSegment: 0 },                            // TONE_CDMA_ALERT_AUTOREDIAL_LITE
-        { segments: { { duration: 400, waveFreq: { 1150, 770, 0 }, 0, 0 },
-                      { duration: 0,   waveFreq: { 0 },            0, 0 } },
-          repeatCnt: 0,
-          repeatSegment: 0 },                            // TONE_CDMA_ONE_MIN_BEEP
-        { segments: { { duration: 120, waveFreq: { 941, 1477, 0 }, 0, 0 },
-                      { duration: 0,   waveFreq: { 0 },            0, 0 } },
-          repeatCnt: 0,
-          repeatSegment: 0 },                            // TONE_CDMA_KEYPAD_VOLUME_KEY_LITE
-        { segments: { { duration: 375, waveFreq: { 587, 0 }, 0, 0 },
-                      { duration: 125, waveFreq: { 1175, 0 }, 0, 0 },
-                      { duration: 0,   waveFreq: { 0 },       0, 0 } },
-          repeatCnt: 0,
-          repeatSegment: 0 },                            // TONE_CDMA_PRESSHOLDKEY_LITE
-        { segments: { { duration: 62, waveFreq: { 587, 0 }, 0, 0 },
-                      { duration: 62, waveFreq: { 784, 0 }, 0, 0 },
-                      { duration: 62, waveFreq: { 831, 0 }, 0, 0 },
-                      { duration: 62, waveFreq: { 784, 0 }, 0, 0 },
-                      { duration: 62, waveFreq: { 1109, 0 }, 0, 0 },
-                      { duration: 62, waveFreq: { 784, 0 }, 0, 0 },
-                      { duration: 62, waveFreq: { 831, 0 }, 0, 0 },
-                      { duration: 62, waveFreq: { 784, 0 }, 0, 0 },
-                      { duration: 0,  waveFreq: { 0 },      0, 0 } },
-          repeatCnt: 0,
-          repeatSegment: 0 },                             // TONE_CDMA_ALERT_INCALL_LITE
-        { segments: { { duration: 125, waveFreq: { 941, 0 }, 0, 0 },
-                      { duration: 10,  waveFreq: { 0 },      2, 0 },
-                      { duration: 4990, waveFreq: { 0 },     0, 0 },
-                      { duration: 0,    waveFreq: { 0 },     0, 0 } },
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                            // TONE_CDMA_EMERGENCY_RINGBACK
-        { segments: { { duration: 125, waveFreq: { 1319, 0 }, 0, 0 },
-                      { duration: 125, waveFreq: { 0 },       0, 0 },
-                      { duration: 0,   waveFreq: { 0 },       0, 0 } },
-          repeatCnt: 2,
-          repeatSegment: 0 },                            // TONE_CDMA_ALERT_CALL_GUARD
-        { segments: { { duration: 125, waveFreq: { 1047, 0 }, 0, 0 },
-                      { duration: 125, waveFreq: { 370,  0 }, 0, 0 },
-                      { duration: 0,   waveFreq: { 0 },       0, 0 } },
-          repeatCnt: 0,
-          repeatSegment: 0 },                            // TONE_CDMA_SOFT_ERROR_LITE
-        { segments: { { duration: 125, waveFreq: { 1480, 0 }, 0, 0 },
-                      { duration: 125, waveFreq: { 1397, 0 }, 0, 0 },
-                      { duration: 125, waveFreq: { 784, 0 },  0, 0 },
-                      { duration: 0,   waveFreq: { 0 },       0, 0 } },
-          repeatCnt: 0,
-          repeatSegment: 0 },                            // TONE_CDMA_CALLDROP_LITE
+        { .segments = { { .duration = 62, .waveFreq = { 1109, 0 }, 0, 0 },
+                        { .duration = 62, .waveFreq = { 784, 0 },  0, 0 },
+                        { .duration = 62, .waveFreq = { 740, 0 },  0, 0 },
+                        { .duration = 62, .waveFreq = { 622, 0 },  0, 0 },
+                        { .duration = 62, .waveFreq = { 1109, 0 }, 0, 0 },
+                        { .duration = 0,  .waveFreq = { 0 },       0, 0 } },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                            // TONE_CDMA_ALERT_NETWORK_LITE
+        { .segments = { { .duration = 62, .waveFreq = { 1245, 0 }, 0, 0 },
+                        { .duration = 62, .waveFreq = { 659, 0 },  2, 0 },
+                        { .duration = 62, .waveFreq = { 1245, 0 }, 0, 0 },
+                        { .duration = 0,  .waveFreq = { 0 },       0, 0 } },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                            // TONE_CDMA_ALERT_AUTOREDIAL_LITE
+        { .segments = { { .duration = 400, .waveFreq = { 1150, 770, 0 }, 0, 0 },
+                        { .duration = 0,   .waveFreq = { 0 },            0, 0 } },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                            // TONE_CDMA_ONE_MIN_BEEP
+        { .segments = { { .duration = 120, .waveFreq = { 941, 1477, 0 }, 0, 0 },
+                        { .duration = 0,   .waveFreq = { 0 },            0, 0 } },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                            // TONE_CDMA_KEYPAD_VOLUME_KEY_LITE
+        { .segments = { { .duration = 375, .waveFreq = { 587, 0 }, 0, 0 },
+                        { .duration = 125, .waveFreq = { 1175, 0 }, 0, 0 },
+                        { .duration = 0,   .waveFreq = { 0 },       0, 0 } },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                            // TONE_CDMA_PRESSHOLDKEY_LITE
+        { .segments = { { .duration = 62, .waveFreq = { 587, 0 }, 0, 0 },
+                        { .duration = 62, .waveFreq = { 784, 0 }, 0, 0 },
+                        { .duration = 62, .waveFreq = { 831, 0 }, 0, 0 },
+                        { .duration = 62, .waveFreq = { 784, 0 }, 0, 0 },
+                        { .duration = 62, .waveFreq = { 1109, 0 }, 0, 0 },
+                        { .duration = 62, .waveFreq = { 784, 0 }, 0, 0 },
+                        { .duration = 62, .waveFreq = { 831, 0 }, 0, 0 },
+                        { .duration = 62, .waveFreq = { 784, 0 }, 0, 0 },
+                        { .duration = 0,  .waveFreq = { 0 },      0, 0 } },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                             // TONE_CDMA_ALERT_INCALL_LITE
+        { .segments = { { .duration = 125, .waveFreq = { 941, 0 }, 0, 0 },
+                        { .duration = 10,  .waveFreq = { 0 },      2, 0 },
+                        { .duration = 4990, .waveFreq = { 0 },     0, 0 },
+                        { .duration = 0,    .waveFreq = { 0 },     0, 0 } },
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                            // TONE_CDMA_EMERGENCY_RINGBACK
+        { .segments = { { .duration = 125, .waveFreq = { 1319, 0 }, 0, 0 },
+                        { .duration = 125, .waveFreq = { 0 },       0, 0 },
+                        { .duration = 0,   .waveFreq = { 0 },       0, 0 } },
+          .repeatCnt = 2,
+          .repeatSegment = 0 },                            // TONE_CDMA_ALERT_CALL_GUARD
+        { .segments = { { .duration = 125, .waveFreq = { 1047, 0 }, 0, 0 },
+                        { .duration = 125, .waveFreq = { 370,  0 }, 0, 0 },
+                        { .duration = 0,   .waveFreq = { 0 },       0, 0 } },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                            // TONE_CDMA_SOFT_ERROR_LITE
+        { .segments = { { .duration = 125, .waveFreq = { 1480, 0 }, 0, 0 },
+                        { .duration = 125, .waveFreq = { 1397, 0 }, 0, 0 },
+                        { .duration = 125, .waveFreq = { 784, 0 },  0, 0 },
+                        { .duration = 0,   .waveFreq = { 0 },       0, 0 } },
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                            // TONE_CDMA_CALLDROP_LITE
 
-        { segments: { { duration: 500, waveFreq: { 425, 0 }, 0, 0 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: 0,
-          repeatSegment: 0 },                           // TONE_CDMA_NETWORK_BUSY_ONE_SHOT
-        { segments: { { duration: 400, waveFreq: { 1150, 770 }, 0, 0 },
-                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: 0,
-          repeatSegment: 0 },                           // TONE_CDMA_ABBR_ALERT
-          { segments: { { duration: 0, waveFreq: { 0 }, 0, 0 }},
-          repeatCnt: 0,
-          repeatSegment: 0 },                            // TONE_CDMA_SIGNAL_OFF
+        { .segments = { { .duration = 500, .waveFreq = { 425, 0 }, 0, 0 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                           // TONE_CDMA_NETWORK_BUSY_ONE_SHOT
+        { .segments = { { .duration = 400, .waveFreq = { 1150, 770 }, 0, 0 },
+                        { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                           // TONE_CDMA_ABBR_ALERT
+          { .segments = { { .duration = 0, .waveFreq = { 0 }, 0, 0 }},
+          .repeatCnt = 0,
+          .repeatSegment = 0 },                            // TONE_CDMA_SIGNAL_OFF
 
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 350, 440, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_ANSI_DIAL
-        { segments: { { duration: 500, waveFreq: { 480, 620, 0 }, 0, 0 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_ANSI_BUSY
-        { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
-                      { duration: 250, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_ANSI_CONGESTION
-        { segments: { { duration: 300, waveFreq: { 440, 0 }, 0, 0 },
-                      { duration: 9700, waveFreq: { 0 }, 0, 0 },
-                      { duration: 100, waveFreq: { 440, 0 }, 0, 0 },
-                      { duration: 100, waveFreq: { 0 }, 0, 0 },
-                      { duration: 100, waveFreq: { 440, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 1 },                              // TONE_ANSI_CALL_WAITING
-        { segments: { { duration: 2000, waveFreq: { 440, 480, 0 }, 0, 0 },
-                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_ANSI_RINGTONE
-        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 400, 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_JAPAN_DIAL
-        { segments: { { duration: 500, waveFreq: { 400, 0 }, 0, 0 },
-                      { duration: 500, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_JAPAN_BUSY
-        { segments: { { duration: 1000, waveFreq: { 400, 0 }, 0, 0 },
-                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
-                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
-          repeatCnt: ToneGenerator::TONEGEN_INF,
-          repeatSegment: 0 },                              // TONE_JAPAN_RADIO_ACK
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 350, 440, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_ANSI_DIAL
+        { .segments = { { .duration = 500, .waveFreq = { 480, 620, 0 }, 0, 0 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_ANSI_BUSY
+        { .segments = { { .duration = 250, .waveFreq = { 480, 620, 0 }, 0, 0 },
+                        { .duration = 250, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_ANSI_CONGESTION
+        { .segments = { { .duration = 300, .waveFreq = { 440, 0 }, 0, 0 },
+                        { .duration = 9700, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 100, .waveFreq = { 440, 0 }, 0, 0 },
+                        { .duration = 100, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 100, .waveFreq = { 440, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 1 },                              // TONE_ANSI_CALL_WAITING
+        { .segments = { { .duration = 2000, .waveFreq = { 440, 480, 0 }, 0, 0 },
+                        { .duration = 4000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_ANSI_RINGTONE
+        { .segments = { { .duration = ToneGenerator::TONEGEN_INF, .waveFreq = { 400, 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_JAPAN_DIAL
+        { .segments = { { .duration = 500, .waveFreq = { 400, 0 }, 0, 0 },
+                        { .duration = 500, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_JAPAN_BUSY
+        { .segments = { { .duration = 1000, .waveFreq = { 400, 0 }, 0, 0 },
+                        { .duration = 2000, .waveFreq = { 0 }, 0, 0 },
+                        { .duration = 0 , .waveFreq = { 0 }, 0, 0}},
+          .repeatCnt = ToneGenerator::TONEGEN_INF,
+          .repeatSegment = 0 },                              // TONE_JAPAN_RADIO_ACK
 
 
 
diff --git a/media/libmedia/mediametadataretriever.cpp b/media/libmedia/mediametadataretriever.cpp
index 39a239d..8e8a1ed 100644
--- a/media/libmedia/mediametadataretriever.cpp
+++ b/media/libmedia/mediametadataretriever.cpp
@@ -172,7 +172,7 @@
 {
     Mutex::Autolock lock(sServiceLock);
     if (sService != 0) {
-        sService->asBinder()->unlinkToDeath(this);
+        IInterface::asBinder(sService)->unlinkToDeath(this);
     }
 }
 
diff --git a/media/libmediaplayerservice/Drm.cpp b/media/libmediaplayerservice/Drm.cpp
index 81dad41..73f1a2a 100644
--- a/media/libmediaplayerservice/Drm.cpp
+++ b/media/libmediaplayerservice/Drm.cpp
@@ -84,10 +84,10 @@
 {
     Mutex::Autolock lock(mEventLock);
     if (mListener != NULL){
-        mListener->asBinder()->unlinkToDeath(this);
+        IInterface::asBinder(mListener)->unlinkToDeath(this);
     }
     if (listener != NULL) {
-        listener->asBinder()->linkToDeath(this);
+        IInterface::asBinder(listener)->linkToDeath(this);
     }
     mListener = listener;
     return NO_ERROR;
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index d461af3..071b894 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -817,8 +817,7 @@
     sp<MediaPlayerBase> p = getPlayer();
     if (p == 0) return UNKNOWN_ERROR;
 
-    sp<IBinder> binder(bufferProducer == NULL ? NULL :
-            bufferProducer->asBinder());
+    sp<IBinder> binder(IInterface::asBinder(bufferProducer));
     if (mConnectedWindowBinder == binder) {
         return OK;
     }
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.h b/media/libmediaplayerservice/nuplayer/NuPlayer.h
index 901cfbd..524f197 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.h
@@ -26,7 +26,7 @@
 
 struct ABuffer;
 struct AMessage;
-struct MetaData;
+class MetaData;
 struct NuPlayerDriver;
 
 struct NuPlayer : public AHandler {
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerSource.h b/media/libmediaplayerservice/nuplayer/NuPlayerSource.h
index 2b0ac47..e92cd36 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerSource.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerSource.h
@@ -28,7 +28,6 @@
 namespace android {
 
 struct ABuffer;
-struct MetaData;
 struct MediaBuffer;
 
 struct NuPlayer::Source : public AHandler {
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index 1413635..73abca7 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -4437,7 +4437,7 @@
     ALOGV("Now uninitialized");
 
     if (mDeathNotifier != NULL) {
-        mCodec->mOMX->asBinder()->unlinkToDeath(mDeathNotifier);
+        IInterface::asBinder(mCodec->mOMX)->unlinkToDeath(mDeathNotifier);
         mDeathNotifier.clear();
     }
 
@@ -4530,7 +4530,7 @@
     sp<AMessage> notify = new AMessage(kWhatOMXDied, mCodec->id());
 
     mDeathNotifier = new DeathNotifier(notify);
-    if (omx->asBinder()->linkToDeath(mDeathNotifier) != OK) {
+    if (IInterface::asBinder(omx)->linkToDeath(mDeathNotifier) != OK) {
         // This was a local binder, if it dies so do we, we won't care
         // about any notifications in the afterlife.
         mDeathNotifier.clear();
@@ -4575,7 +4575,7 @@
         componentName = matchingCodecs.itemAt(matchIndex).mName.string();
         quirks = matchingCodecs.itemAt(matchIndex).mQuirks;
 
-        pid_t tid = androidGetTid();
+        pid_t tid = gettid();
         int prevPriority = androidGetThreadPriority(tid);
         androidSetThreadPriority(tid, ANDROID_PRIORITY_FOREGROUND);
         status_t err = omx->allocateNode(componentName.c_str(), observer, &node);
diff --git a/media/libstagefright/CameraSource.cpp b/media/libstagefright/CameraSource.cpp
index c3a940a..ad12bdd 100644
--- a/media/libstagefright/CameraSource.cpp
+++ b/media/libstagefright/CameraSource.cpp
@@ -219,7 +219,7 @@
         mCameraFlags |= FLAGS_HOT_CAMERA;
         mDeathNotifier = new DeathNotifier();
         // isBinderAlive needs linkToDeath to work.
-        mCameraRecordingProxy->asBinder()->linkToDeath(mDeathNotifier);
+        IInterface::asBinder(mCameraRecordingProxy)->linkToDeath(mDeathNotifier);
     }
 
     mCamera->lock();
@@ -702,7 +702,7 @@
     {
         Mutex::Autolock autoLock(mLock);
         if (mCameraRecordingProxy != 0) {
-            mCameraRecordingProxy->asBinder()->unlinkToDeath(mDeathNotifier);
+            IInterface::asBinder(mCameraRecordingProxy)->unlinkToDeath(mDeathNotifier);
             mCameraRecordingProxy.clear();
         }
         mCameraFlags = 0;
@@ -825,7 +825,7 @@
                 mFrameAvailableCondition.waitRelative(mLock,
                     mTimeBetweenFrameCaptureUs * 1000LL + CAMERA_SOURCE_TIMEOUT_NS)) {
                 if (mCameraRecordingProxy != 0 &&
-                    !mCameraRecordingProxy->asBinder()->isBinderAlive()) {
+                    !IInterface::asBinder(mCameraRecordingProxy)->isBinderAlive()) {
                     ALOGW("camera recording proxy is gone");
                     return ERROR_END_OF_STREAM;
                 }
diff --git a/media/libstagefright/OMXClient.cpp b/media/libstagefright/OMXClient.cpp
index ca031aa..230c1f7 100644
--- a/media/libstagefright/OMXClient.cpp
+++ b/media/libstagefright/OMXClient.cpp
@@ -37,7 +37,7 @@
     MuxOMX(const sp<IOMX> &remoteOMX);
     virtual ~MuxOMX();
 
-    virtual IBinder *onAsBinder() { return mRemoteOMX->asBinder().get(); }
+    virtual IBinder *onAsBinder() { return IInterface::asBinder(mRemoteOMX).get(); }
 
     virtual bool livesLocally(node_id node, pid_t pid);
 
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index f26563e..3731a4a 100644
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -101,10 +101,10 @@
 #undef FACTORY_CREATE_ENCODER
 #undef FACTORY_REF
 
-#define CODEC_LOGI(x, ...) ALOGI("[%s] "x, mComponentName, ##__VA_ARGS__)
-#define CODEC_LOGV(x, ...) ALOGV("[%s] "x, mComponentName, ##__VA_ARGS__)
-#define CODEC_LOGW(x, ...) ALOGW("[%s] "x, mComponentName, ##__VA_ARGS__)
-#define CODEC_LOGE(x, ...) ALOGE("[%s] "x, mComponentName, ##__VA_ARGS__)
+#define CODEC_LOGI(x, ...) ALOGI("[%s] " x, mComponentName, ##__VA_ARGS__)
+#define CODEC_LOGV(x, ...) ALOGV("[%s] " x, mComponentName, ##__VA_ARGS__)
+#define CODEC_LOGW(x, ...) ALOGW("[%s] " x, mComponentName, ##__VA_ARGS__)
+#define CODEC_LOGE(x, ...) ALOGE("[%s] " x, mComponentName, ##__VA_ARGS__)
 
 struct OMXCodecObserver : public BnOMXObserver {
     OMXCodecObserver() {
diff --git a/media/libstagefright/TimedEventQueue.cpp b/media/libstagefright/TimedEventQueue.cpp
index 1fdb244..7d15220 100644
--- a/media/libstagefright/TimedEventQueue.cpp
+++ b/media/libstagefright/TimedEventQueue.cpp
@@ -52,7 +52,7 @@
 TimedEventQueue::~TimedEventQueue() {
     stop();
     if (mPowerManager != 0) {
-        sp<IBinder> binder = mPowerManager->asBinder();
+        sp<IBinder> binder = IInterface::asBinder(mPowerManager);
         binder->unlinkToDeath(mDeathRecipient);
     }
 }
diff --git a/media/libstagefright/codecs/aacenc/src/bitenc.c b/media/libstagefright/codecs/aacenc/src/bitenc.c
index d1fd647..9c81204 100644
--- a/media/libstagefright/codecs/aacenc/src/bitenc.c
+++ b/media/libstagefright/codecs/aacenc/src/bitenc.c
@@ -547,7 +547,7 @@
     totFillBits = totFillBits - (3+4);
 
 
-    if ((cnt == (1<<4)-1)) {
+    if (cnt == (1<<4)-1) {
 
       esc_count = min( ((totFillBits >> 3) - ((1<<4)-1)), (1<<8)-1);
       WriteBits(hBitStream,esc_count,8);
diff --git a/media/libstagefright/codecs/amrnb/dec/Android.mk b/media/libstagefright/codecs/amrnb/dec/Android.mk
index b067456..4aa8c17 100644
--- a/media/libstagefright/codecs/amrnb/dec/Android.mk
+++ b/media/libstagefright/codecs/amrnb/dec/Android.mk
@@ -83,3 +83,24 @@
 LOCAL_MODULE_TAGS := optional
 
 include $(BUILD_SHARED_LIBRARY)
+
+################################################################################
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := \
+        test/amrnbdec_test.cpp
+
+LOCAL_C_INCLUDES := \
+        $(LOCAL_PATH)/src \
+        $(LOCAL_PATH)/../common/include \
+        $(call include-path-for, audio-utils)
+
+LOCAL_STATIC_LIBRARIES := \
+        libstagefright_amrnbdec libsndfile
+
+LOCAL_SHARED_LIBRARIES := \
+        libstagefright_amrnb_common libaudioutils
+
+LOCAL_MODULE := libstagefright_amrnbdec_test
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_EXECUTABLE)
diff --git a/media/libstagefright/codecs/amrnb/dec/test/amrnbdec_test.cpp b/media/libstagefright/codecs/amrnb/dec/test/amrnbdec_test.cpp
new file mode 100644
index 0000000..521fe2b
--- /dev/null
+++ b/media/libstagefright/codecs/amrnb/dec/test/amrnbdec_test.cpp
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <assert.h>
+
+#include "gsmamr_dec.h"
+#include <audio_utils/sndfile.h>
+
+// Constants for AMR-NB
+enum {
+    kInputBufferSize = 64,
+    kSamplesPerFrame = 160,
+    kBitsPerSample = 16,
+    kOutputBufferSize = kSamplesPerFrame * kBitsPerSample/8,
+    kSampleRate = 8000,
+    kChannels = 1,
+    kFileHeaderSize = 6
+};
+const uint32_t kFrameSizes[] = {12, 13, 15, 17, 19, 20, 26, 31};
+
+
+int main(int argc, char *argv[]) {
+
+    if(argc != 3) {
+        fprintf(stderr, "Usage %s <input file> <output file>\n", argv[0]);
+        return 1;
+    }
+
+    // Open the input file
+    FILE* fpInput = fopen(argv[1], "rb");
+    if (!fpInput) {
+        fprintf(stderr, "Could not open %s\n", argv[1]);
+        return 1;
+    }
+
+    // Validate the input AMR file
+    char header[kFileHeaderSize];
+    int bytesRead = fread(header, 1, kFileHeaderSize, fpInput);
+    if (bytesRead != kFileHeaderSize || memcmp(header, "#!AMR\n", kFileHeaderSize)) {
+        fprintf(stderr, "Invalid AMR-NB file\n");
+        return 1;
+    }
+
+    // Open the output file
+    SF_INFO sfInfo;
+    memset(&sfInfo, 0, sizeof(SF_INFO));
+    sfInfo.channels = kChannels;
+    sfInfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
+    sfInfo.samplerate = kSampleRate;
+    SNDFILE *handle = sf_open(argv[2], SFM_WRITE, &sfInfo);
+    if(!handle){
+        fprintf(stderr, "Could not create %s\n", argv[2]);
+        return 1;
+    }
+
+    // Create AMR-NB decoder instance
+    void* amrHandle;
+    int err = GSMInitDecode(&amrHandle, (Word8*)"AMRNBDecoder");
+    if(err != 0){
+        fprintf(stderr, "Error creating AMR-NB decoder instance\n");
+        return 1;
+    }
+
+    //Allocate input buffer
+    void *inputBuf = malloc(kInputBufferSize);
+    assert(inputBuf != NULL);
+
+    //Allocate output buffer
+    void *outputBuf = malloc(kOutputBufferSize);
+    assert(outputBuf != NULL);
+
+
+    // Decode loop
+    uint32_t retVal = 0;
+    while (1) {
+        // Read mode
+        uint8_t mode;
+        bytesRead = fread(&mode, 1, 1, fpInput);
+        if (bytesRead != 1) break;
+
+        // Find frame type
+        Frame_Type_3GPP frameType = (Frame_Type_3GPP)((mode >> 3) & 0x0f);
+        if (frameType >= AMR_SID){
+            fprintf(stderr, "Frame type %d not supported\n",frameType);
+            retVal = 1;
+            break;
+        }
+
+        // Find frame type
+        int32_t frameSize = kFrameSizes[frameType];
+        bytesRead = fread(inputBuf, 1, frameSize, fpInput);
+        if (bytesRead != frameSize) break;
+
+        //Decode frame
+        int32_t decodeStatus;
+        decodeStatus = AMRDecode(amrHandle, frameType, (uint8_t*)inputBuf,
+                                 (int16_t*)outputBuf, MIME_IETF);
+        if(decodeStatus == -1) {
+            fprintf(stderr, "Decoder encountered error\n");
+            retVal = 1;
+            break;
+        }
+
+        //Write output to wav
+        sf_writef_short(handle, (int16_t*)outputBuf, kSamplesPerFrame);
+
+    }
+
+    // Close input and output file
+    fclose(fpInput);
+    sf_close(handle);
+
+    //Free allocated memory
+    free(inputBuf);
+    free(outputBuf);
+
+    // Close decoder instance
+    GSMDecodeFrameExit(&amrHandle);
+
+    return retVal;
+}
diff --git a/media/libstagefright/codecs/amrwbenc/Android.mk b/media/libstagefright/codecs/amrwbenc/Android.mk
index 64fe8d1..024a292 100644
--- a/media/libstagefright/codecs/amrwbenc/Android.mk
+++ b/media/libstagefright/codecs/amrwbenc/Android.mk
@@ -86,6 +86,9 @@
 
 endif
 
+# ARMV5E/Filt_6k_7k_opt.s does not compile with Clang.
+LOCAL_CLANG_ASFLAGS_arm += -no-integrated-as
+
 LOCAL_MODULE := libstagefright_amrwbenc
 
 LOCAL_ARM_MODE := arm
diff --git a/media/libstagefright/codecs/amrwbenc/src/wb_vad.c b/media/libstagefright/codecs/amrwbenc/src/wb_vad.c
index 13dd2aa..2beaefd 100644
--- a/media/libstagefright/codecs/amrwbenc/src/wb_vad.c
+++ b/media/libstagefright/codecs/amrwbenc/src/wb_vad.c
@@ -404,7 +404,7 @@
 		alpha_down = ALPHA_DOWN1;
 	} else
 	{
-		if ((st->stat_count == 0))
+		if (st->stat_count == 0)
 		{
 			alpha_up = ALPHA_UP2;
 			alpha_down = ALPHA_DOWN2;
diff --git a/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp b/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp
index bb55871..cfc37b7 100644
--- a/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp
+++ b/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp
@@ -794,13 +794,6 @@
                 videoInput.coding_timestamp = (inHeader->nTimeStamp + 500) / 1000;  // in ms
                 const uint8_t *inputData = NULL;
                 if (mStoreMetaDataInBuffers) {
-                    if (inHeader->nFilledLen != 8) {
-                        ALOGE("MetaData buffer is wrong size! "
-                                "(got %u bytes, expected 8)", inHeader->nFilledLen);
-                        mSignalledError = true;
-                        notify(OMX_EventError, OMX_ErrorUndefined, 0, 0);
-                        return;
-                    }
                     inputData =
                         extractGraphicBuffer(
                                 mInputFrameData, (mVideoWidth * mVideoHeight * 3) >> 1,
diff --git a/media/libstagefright/codecs/m4v_h263/enc/SoftMPEG4Encoder.cpp b/media/libstagefright/codecs/m4v_h263/enc/SoftMPEG4Encoder.cpp
index 400f320..1d0a2f0 100644
--- a/media/libstagefright/codecs/m4v_h263/enc/SoftMPEG4Encoder.cpp
+++ b/media/libstagefright/codecs/m4v_h263/enc/SoftMPEG4Encoder.cpp
@@ -664,13 +664,6 @@
         if (inHeader->nFilledLen > 0) {
             const uint8_t *inputData = NULL;
             if (mStoreMetaDataInBuffers) {
-                if (inHeader->nFilledLen != 8) {
-                    ALOGE("MetaData buffer is wrong size! "
-                            "(got %u bytes, expected 8)", inHeader->nFilledLen);
-                    mSignalledError = true;
-                    notify(OMX_EventError, OMX_ErrorUndefined, 0, 0);
-                    return;
-                }
                 inputData =
                     extractGraphicBuffer(
                             mInputFrameData, (mVideoWidth * mVideoHeight * 3) >> 1,
diff --git a/media/libstagefright/codecs/m4v_h263/enc/src/vlc_encode.cpp b/media/libstagefright/codecs/m4v_h263/enc/src/vlc_encode.cpp
index 7ea5dc4..2aec815 100644
--- a/media/libstagefright/codecs/m4v_h263/enc/src/vlc_encode.cpp
+++ b/media/libstagefright/codecs/m4v_h263/enc/src/vlc_encode.cpp
@@ -271,7 +271,7 @@
     Int ind;
     Int length;
 
-    if ((intra == 0))
+    if (intra == 0)
         cbpy = 15 - cbpy;
 
     ind = cbpy;
diff --git a/media/libstagefright/codecs/on2/h264dec/Android.mk b/media/libstagefright/codecs/on2/h264dec/Android.mk
index bf03ad9..e63b6b1 100644
--- a/media/libstagefright/codecs/on2/h264dec/Android.mk
+++ b/media/libstagefright/codecs/on2/h264dec/Android.mk
@@ -94,6 +94,8 @@
     LOCAL_C_INCLUDES += $(LOCAL_PATH)/./omxdl/arm_neon/api \
                         $(LOCAL_PATH)/./omxdl/arm_neon/vc/api \
                         $(LOCAL_PATH)/./omxdl/arm_neon/vc/m4p10/api
+    # h264bsdWriteMacroblock.S does not compile with Clang.
+    LOCAL_CLANG_ASFLAGS_arm += -no-integrated-as
   endif
 endif
 
diff --git a/media/libstagefright/codecs/on2/h264dec/inc/H264SwDecApi.h b/media/libstagefright/codecs/on2/h264dec/inc/H264SwDecApi.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/inc/basetype.h b/media/libstagefright/codecs/on2/h264dec/inc/basetype.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_BitDec_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_BitDec_s.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_Bitstream.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_Bitstream.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_IDCTTable.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_IDCTTable.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_IDCT_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_IDCT_s.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_MaskTable.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_MaskTable.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_Version.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_Version.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armCOMM_s.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armOMX.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/armOMX.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/omxtypes.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/omxtypes.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/omxtypes_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/api/omxtypes_s.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_Bitstream.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_Bitstream.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_IDCTTable.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_IDCTTable.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_MaskTable.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/src/armCOMM_MaskTable.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/armVC.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/armVC.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/armVCCOMM_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/armVCCOMM_s.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/omxVC.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/omxVC.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/omxVC_s.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/api/omxVC_s.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/api/armVCM4P10_CAVLCTables.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/api/armVCM4P10_CAVLCTables.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_CAVLCTables.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/armVCM4P10_CAVLCTables.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockChroma_I.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DeblockLuma_I.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_DecodeCoeffsToPairCAVLC.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src/omxVCM4P10_InterpolateChroma.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/api/armVCM4P2_Huff_Tables_VLC.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/api/armVCM4P2_ZigZag_Tables.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Huff_Tables_VLC.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Lookup_Tables.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Lookup_Tables.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/armVCM4P2_Zigzag_Tables.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Inter.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p2/src/omxVCM4P2_DecodeBlockCoef_Intra.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/src/armVC_Version.c b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/src/armVC_Version.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/DecTestBench.c b/media/libstagefright/codecs/on2/h264dec/source/DecTestBench.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/EvaluationTestBench.c b/media/libstagefright/codecs/on2/h264dec/source/EvaluationTestBench.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/TestBenchMultipleInstance.c b/media/libstagefright/codecs/on2/h264dec/source/TestBenchMultipleInstance.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_byte_stream.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_byte_stream.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_byte_stream.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_byte_stream.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cfg.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cfg.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_conceal.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_conceal.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_conceal.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_conceal.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_container.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_container.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_deblocking.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_deblocking.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_deblocking.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_deblocking.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_dpb.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_dpb.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_dpb.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_dpb.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_image.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_image.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_image.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_image.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_inter_prediction.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_inter_prediction.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_inter_prediction.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_inter_prediction.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_intra_prediction.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_intra_prediction.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_intra_prediction.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_intra_prediction.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_macroblock_layer.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_macroblock_layer.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_macroblock_layer.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_macroblock_layer.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_nal_unit.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_nal_unit.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_nal_unit.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_nal_unit.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_neighbour.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_neighbour.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_neighbour.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_neighbour.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_order_cnt.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_order_cnt.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_order_cnt.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_order_cnt.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_param_set.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_param_set.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_param_set.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_pic_param_set.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_reconstruct.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_reconstruct.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_reconstruct.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_reconstruct.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_sei.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_sei.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_sei.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_sei.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_seq_param_set.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_seq_param_set.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_data.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_data.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_data.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_data.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_group_map.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_group_map.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_group_map.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_group_map.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_header.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_header.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_header.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_slice_header.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_storage.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_storage.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_storage.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_storage.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_stream.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_stream.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_stream.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_stream.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_transform.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_transform.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_transform.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_transform.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vlc.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vlc.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vlc.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vlc.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vui.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vui.c
old mode 100755
new mode 100644
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vui.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_vui.h
old mode 100755
new mode 100644
diff --git a/media/libstagefright/httplive/PlaylistFetcher.h b/media/libstagefright/httplive/PlaylistFetcher.h
index 78c358f..76cc852 100644
--- a/media/libstagefright/httplive/PlaylistFetcher.h
+++ b/media/libstagefright/httplive/PlaylistFetcher.h
@@ -31,7 +31,7 @@
 struct HTTPBase;
 struct LiveDataSource;
 struct M3UParser;
-struct String8;
+class String8;
 
 struct PlaylistFetcher : public AHandler {
     enum {
diff --git a/media/libstagefright/include/AACEncoder.h b/media/libstagefright/include/AACEncoder.h
index 3d5fc60..52beb0e 100644
--- a/media/libstagefright/include/AACEncoder.h
+++ b/media/libstagefright/include/AACEncoder.h
@@ -25,7 +25,7 @@
 
 namespace android {
 
-struct MediaBufferGroup;
+class MediaBufferGroup;
 
 class AACEncoder: public MediaSource {
     public:
diff --git a/media/libstagefright/include/ID3.h b/media/libstagefright/include/ID3.h
index e83f3ef..c2c4a6d 100644
--- a/media/libstagefright/include/ID3.h
+++ b/media/libstagefright/include/ID3.h
@@ -22,8 +22,8 @@
 
 namespace android {
 
-struct DataSource;
-struct String8;
+class DataSource;
+class String8;
 
 struct ID3 {
     enum Version {
diff --git a/media/libstagefright/include/MPEG2TSExtractor.h b/media/libstagefright/include/MPEG2TSExtractor.h
index c5e86a6..db1187d 100644
--- a/media/libstagefright/include/MPEG2TSExtractor.h
+++ b/media/libstagefright/include/MPEG2TSExtractor.h
@@ -28,7 +28,7 @@
 struct AMessage;
 struct AnotherPacketSource;
 struct ATSParser;
-struct DataSource;
+class DataSource;
 struct MPEG2TSSource;
 struct String8;
 
diff --git a/media/libstagefright/include/avc_utils.h b/media/libstagefright/include/avc_utils.h
index d517320..c270bc1 100644
--- a/media/libstagefright/include/avc_utils.h
+++ b/media/libstagefright/include/avc_utils.h
@@ -23,7 +23,7 @@
 
 namespace android {
 
-struct ABitReader;
+class ABitReader;
 
 enum {
     kAVCProfileBaseline      = 0x42,
@@ -49,7 +49,7 @@
         const uint8_t **nalStart, size_t *nalSize,
         bool startCodeFollows = false);
 
-struct MetaData;
+class MetaData;
 sp<MetaData> MakeAVCCodecSpecificData(const sp<ABuffer> &accessUnit);
 
 bool IsIDR(const sp<ABuffer> &accessUnit);
diff --git a/media/libstagefright/mpeg2ts/ATSParser.h b/media/libstagefright/mpeg2ts/ATSParser.h
index 5d76cbd..75d76dc 100644
--- a/media/libstagefright/mpeg2ts/ATSParser.h
+++ b/media/libstagefright/mpeg2ts/ATSParser.h
@@ -28,7 +28,7 @@
 
 namespace android {
 
-struct ABitReader;
+class ABitReader;
 struct ABuffer;
 struct MediaSource;
 
diff --git a/media/libstagefright/mpeg2ts/ESQueue.h b/media/libstagefright/mpeg2ts/ESQueue.h
index 7c81ff0..eb4b1c9 100644
--- a/media/libstagefright/mpeg2ts/ESQueue.h
+++ b/media/libstagefright/mpeg2ts/ESQueue.h
@@ -26,7 +26,7 @@
 namespace android {
 
 struct ABuffer;
-struct MetaData;
+class MetaData;
 
 struct ElementaryStreamQueue {
     enum Mode {
diff --git a/media/libstagefright/omx/OMX.cpp b/media/libstagefright/omx/OMX.cpp
index 6d46eee..f8d38ff 100644
--- a/media/libstagefright/omx/OMX.cpp
+++ b/media/libstagefright/omx/OMX.cpp
@@ -245,8 +245,8 @@
 
     instance->setHandle(*node, handle);
 
-    mLiveNodes.add(observer->asBinder(), instance);
-    observer->asBinder()->linkToDeath(this);
+    mLiveNodes.add(IInterface::asBinder(observer), instance);
+    IInterface::asBinder(observer)->linkToDeath(this);
 
     return OK;
 }
@@ -256,7 +256,7 @@
 
     {
         Mutex::Autolock autoLock(mLock);
-        ssize_t index = mLiveNodes.indexOfKey(instance->observer()->asBinder());
+        ssize_t index = mLiveNodes.indexOfKey(IInterface::asBinder(instance->observer()));
         if (index < 0) {
             // This could conceivably happen if the observer dies at roughly the
             // same time that a client attempts to free the node explicitly.
@@ -265,7 +265,7 @@
         mLiveNodes.removeItemsAt(index);
     }
 
-    instance->observer()->asBinder()->unlinkToDeath(this);
+    IInterface::asBinder(instance->observer())->unlinkToDeath(this);
 
     status_t err = instance->freeNode(mMaster);
 
diff --git a/media/libstagefright/omx/SoftVideoEncoderOMXComponent.cpp b/media/libstagefright/omx/SoftVideoEncoderOMXComponent.cpp
index 8bff142..70ec6e4 100644
--- a/media/libstagefright/omx/SoftVideoEncoderOMXComponent.cpp
+++ b/media/libstagefright/omx/SoftVideoEncoderOMXComponent.cpp
@@ -195,12 +195,12 @@
     size_t srcStride;
     size_t srcVStride;
     if (usingGraphicBuffer) {
-        if (srcSize < 4 + sizeof(GraphicBuffer *)) {
-            ALOGE("Metadata is too small (%zu vs %zu)", srcSize, 4 + sizeof(GraphicBuffer *));
+        if (srcSize < sizeof(OMX_U32) + sizeof(GraphicBuffer *)) {
+            ALOGE("Metadata is too small (%zu vs %zu)", srcSize, sizeof(OMX_U32) + sizeof(GraphicBuffer *));
             return NULL;
         }
 
-        GraphicBuffer *buffer = *(GraphicBuffer **)(src + 4);
+        GraphicBuffer *buffer = *(GraphicBuffer **)(src + sizeof(OMX_U32));
         handle = buffer->handle;
         format = buffer->format;
         srcStride = buffer->stride;
@@ -214,12 +214,12 @@
     } else {
         // TODO: remove this part.  Check if anyone uses this.
 
-        if (srcSize < 4 + sizeof(buffer_handle_t)) {
-            ALOGE("Metadata is too small (%zu vs %zu)", srcSize, 4 + sizeof(buffer_handle_t));
+        if (srcSize < sizeof(OMX_U32) + sizeof(buffer_handle_t)) {
+            ALOGE("Metadata is too small (%zu vs %zu)", srcSize, sizeof(OMX_U32) + sizeof(buffer_handle_t));
             return NULL;
         }
 
-        handle = *(buffer_handle_t *)(src + 4);
+        handle = *(buffer_handle_t *)(src + sizeof(OMX_U32));
         // assume HAL_PIXEL_FORMAT_RGBA_8888
         // there is no way to get the src stride without the graphic buffer
         format = HAL_PIXEL_FORMAT_RGBA_8888;
diff --git a/media/libstagefright/rtsp/AMPEG2TSAssembler.h b/media/libstagefright/rtsp/AMPEG2TSAssembler.h
index 712e18e..f39c2b5 100644
--- a/media/libstagefright/rtsp/AMPEG2TSAssembler.h
+++ b/media/libstagefright/rtsp/AMPEG2TSAssembler.h
@@ -24,7 +24,7 @@
 
 struct AMessage;
 struct AString;
-struct MetaData;
+class MetaData;
 
 struct AMPEG2TSAssembler : public ARTPAssembler {
     AMPEG2TSAssembler(
diff --git a/media/libstagefright/rtsp/ARawAudioAssembler.h b/media/libstagefright/rtsp/ARawAudioAssembler.h
index ed7af08..bc1dea6 100644
--- a/media/libstagefright/rtsp/ARawAudioAssembler.h
+++ b/media/libstagefright/rtsp/ARawAudioAssembler.h
@@ -24,7 +24,7 @@
 
 struct AMessage;
 struct AString;
-struct MetaData;
+class MetaData;
 
 struct ARawAudioAssembler : public ARTPAssembler {
     ARawAudioAssembler(
diff --git a/media/libstagefright/rtsp/SDPLoader.cpp b/media/libstagefright/rtsp/SDPLoader.cpp
index 424badf..a24eb69 100644
--- a/media/libstagefright/rtsp/SDPLoader.cpp
+++ b/media/libstagefright/rtsp/SDPLoader.cpp
@@ -105,7 +105,7 @@
         headers = NULL;
     }
 
-    off64_t sdpSize;
+    off64_t sdpSize = 0;
     if (err == OK && !mCancelled) {
         err = mHTTPDataSource->getSize(&sdpSize);
 
diff --git a/media/libstagefright/tests/Android.mk b/media/libstagefright/tests/Android.mk
index 99b480ad..8d6ff5b 100644
--- a/media/libstagefright/tests/Android.mk
+++ b/media/libstagefright/tests/Android.mk
@@ -1,8 +1,7 @@
 # Build the unit tests.
 LOCAL_PATH:= $(call my-dir)
 include $(CLEAR_VARS)
-
-ifneq ($(TARGET_SIMULATOR),true)
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 
 LOCAL_MODULE := SurfaceMediaSource_test
 
@@ -22,33 +21,23 @@
 	libstagefright \
 	libstagefright_foundation \
 	libstagefright_omx \
-	libstlport \
 	libsync \
 	libui \
 	libutils \
 	liblog
 
-LOCAL_STATIC_LIBRARIES := \
-	libgtest \
-	libgtest_main \
-
 LOCAL_C_INCLUDES := \
-	bionic \
-	bionic/libstdc++/include \
-	external/gtest/include \
-	external/stlport/stlport \
 	frameworks/av/media/libstagefright \
 	frameworks/av/media/libstagefright/include \
 	$(TOP)/frameworks/native/include/media/openmax \
 
 LOCAL_32_BIT_ONLY := true
 
-include $(BUILD_EXECUTABLE)
-
-endif
+include $(BUILD_NATIVE_TEST)
 
 
 include $(CLEAR_VARS)
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 
 LOCAL_MODULE := Utils_test
 
@@ -64,23 +53,14 @@
 	libstagefright \
 	libstagefright_foundation \
 	libstagefright_omx \
-	libstlport \
-
-LOCAL_STATIC_LIBRARIES := \
-	libgtest \
-	libgtest_main \
 
 LOCAL_C_INCLUDES := \
-	bionic \
-	bionic/libstdc++/include \
-	external/gtest/include \
-	external/stlport/stlport \
 	frameworks/av/include \
 	frameworks/av/media/libstagefright \
 	frameworks/av/media/libstagefright/include \
 	$(TOP)/frameworks/native/include/media/openmax \
 
-include $(BUILD_EXECUTABLE)
+include $(BUILD_NATIVE_TEST)
 
 # Include subdirectory makefiles
 # ============================================================
diff --git a/media/libstagefright/timedtext/TimedTextPlayer.h b/media/libstagefright/timedtext/TimedTextPlayer.h
index ec8ed25..9cb49ec 100644
--- a/media/libstagefright/timedtext/TimedTextPlayer.h
+++ b/media/libstagefright/timedtext/TimedTextPlayer.h
@@ -27,7 +27,7 @@
 
 namespace android {
 
-class AMessage;
+struct AMessage;
 class MediaPlayerBase;
 class TimedTextDriver;
 class TimedTextSource;
diff --git a/media/libstagefright/timedtext/TimedTextSRTSource.h b/media/libstagefright/timedtext/TimedTextSRTSource.h
index 598c200..232675e 100644
--- a/media/libstagefright/timedtext/TimedTextSRTSource.h
+++ b/media/libstagefright/timedtext/TimedTextSRTSource.h
@@ -25,7 +25,7 @@
 
 namespace android {
 
-class AString;
+struct AString;
 class DataSource;
 class MediaBuffer;
 class Parcel;
diff --git a/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp b/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp
index da405e2..0c39ccf 100644
--- a/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp
+++ b/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp
@@ -43,6 +43,10 @@
 namespace android {
 
 // static
+const int64_t WifiDisplaySource::kReaperIntervalUs;
+const int64_t WifiDisplaySource::kTeardownTriggerTimeouSecs;
+const int64_t WifiDisplaySource::kPlaybackSessionTimeoutSecs;
+const int64_t WifiDisplaySource::kPlaybackSessionTimeoutUs;
 const AString WifiDisplaySource::sUserAgent = MakeUserAgent();
 
 WifiDisplaySource::WifiDisplaySource(
diff --git a/media/mtp/MtpDevice.cpp b/media/mtp/MtpDevice.cpp
index e0d679d..3eafd6f 100644
--- a/media/mtp/MtpDevice.cpp
+++ b/media/mtp/MtpDevice.cpp
@@ -131,13 +131,22 @@
             struct usb_endpoint_descriptor *ep_in_desc = NULL;
             struct usb_endpoint_descriptor *ep_out_desc = NULL;
             struct usb_endpoint_descriptor *ep_intr_desc = NULL;
+            //USB3 add USB_DT_SS_ENDPOINT_COMP as companion descriptor;
+            struct usb_ss_ep_comp_descriptor *ep_ss_ep_comp_desc = NULL;
             for (int i = 0; i < 3; i++) {
                 ep = (struct usb_endpoint_descriptor *)usb_descriptor_iter_next(&iter);
+                if (ep && ep->bDescriptorType == USB_DT_SS_ENDPOINT_COMP) {
+                    ALOGD("Descriptor type is USB_DT_SS_ENDPOINT_COMP for USB3 \n");
+                    ep_ss_ep_comp_desc = (usb_ss_ep_comp_descriptor*)ep;
+                    ep = (struct usb_endpoint_descriptor *)usb_descriptor_iter_next(&iter);
+                 }
+
                 if (!ep || ep->bDescriptorType != USB_DT_ENDPOINT) {
                     ALOGE("endpoints not found\n");
                     usb_device_close(device);
                     return NULL;
                 }
+
                 if (ep->bmAttributes == USB_ENDPOINT_XFER_BULK) {
                     if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
                         ep_in_desc = ep;
diff --git a/services/audioflinger/Android.mk b/services/audioflinger/Android.mk
index 697fb37..f3290c6 100644
--- a/services/audioflinger/Android.mk
+++ b/services/audioflinger/Android.mk
@@ -23,6 +23,12 @@
 
 include $(CLEAR_VARS)
 
+# Clang++ aborts on AudioMixer.cpp,
+# b/18373866, "do not know how to split this operator."
+ifeq ($(filter $(TARGET_ARCH),arm arm64),$(TARGET_ARCH))
+    LOCAL_CLANG := false
+endif
+
 LOCAL_SRC_FILES:=               \
     AudioFlinger.cpp            \
     Threads.cpp                 \
@@ -68,13 +74,6 @@
 
 LOCAL_CFLAGS += -DSTATE_QUEUE_INSTANTIATIONS='"StateQueueInstantiations.cpp"'
 
-# Define ANDROID_SMP appropriately. Used to get inline tracing fast-path.
-ifeq ($(TARGET_CPU_SMP),true)
-    LOCAL_CFLAGS += -DANDROID_SMP=1
-else
-    LOCAL_CFLAGS += -DANDROID_SMP=0
-endif
-
 LOCAL_CFLAGS += -fvisibility=hidden
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index ea9d7d3..fed85e9 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1188,7 +1188,7 @@
 
             mNotificationClients.add(pid, notificationClient);
 
-            sp<IBinder> binder = client->asBinder();
+            sp<IBinder> binder = IInterface::asBinder(client);
             binder->linkToDeath(notificationClient);
             clientAdded = true;
         }
diff --git a/services/audioflinger/AudioMixer.h b/services/audioflinger/AudioMixer.h
index 3b972bb..f4f142b 100644
--- a/services/audioflinger/AudioMixer.h
+++ b/services/audioflinger/AudioMixer.h
@@ -21,15 +21,15 @@
 #include <stdint.h>
 #include <sys/types.h>
 
+#include <hardware/audio_effect.h>
+#include <media/AudioBufferProvider.h>
+#include <media/nbaio/NBLog.h>
+#include <system/audio.h>
+#include <utils/Compat.h>
 #include <utils/threads.h>
 
-#include <media/AudioBufferProvider.h>
 #include "AudioResampler.h"
 
-#include <hardware/audio_effect.h>
-#include <system/audio.h>
-#include <media/nbaio/NBLog.h>
-
 // FIXME This is actually unity gain, which might not be max in future, expressed in U.12
 #define MAX_GAIN_INT AudioMixer::UNITY_GAIN_INT
 
@@ -58,7 +58,7 @@
     static const uint32_t MAX_NUM_CHANNELS_TO_DOWNMIX = AUDIO_CHANNEL_COUNT_MAX;
 
     static const uint16_t UNITY_GAIN_INT = 0x1000;
-    static const float    UNITY_GAIN_FLOAT = 1.0f;
+    static const CONSTEXPR float UNITY_GAIN_FLOAT = 1.0f;
 
     enum { // names
 
diff --git a/services/audioflinger/AudioResampler.h b/services/audioflinger/AudioResampler.h
index cdc6d92..069d946 100644
--- a/services/audioflinger/AudioResampler.h
+++ b/services/audioflinger/AudioResampler.h
@@ -19,7 +19,9 @@
 
 #include <stdint.h>
 #include <sys/types.h>
+
 #include <cutils/compiler.h>
+#include <utils/Compat.h>
 
 #include <media/AudioBufferProvider.h>
 #include <system/audio.h>
@@ -47,7 +49,7 @@
         DYN_HIGH_QUALITY=7,
     };
 
-    static const float UNITY_GAIN_FLOAT = 1.0f;
+    static const CONSTEXPR float UNITY_GAIN_FLOAT = 1.0f;
 
     static AudioResampler* create(audio_format_t format, int inChannelCount,
             int32_t sampleRate, src_quality quality=DEFAULT_QUALITY);
diff --git a/services/audioflinger/AudioResamplerFirGen.h b/services/audioflinger/AudioResamplerFirGen.h
index d024b2f..f3718b6 100644
--- a/services/audioflinger/AudioResamplerFirGen.h
+++ b/services/audioflinger/AudioResamplerFirGen.h
@@ -17,6 +17,8 @@
 #ifndef ANDROID_AUDIO_RESAMPLER_FIR_GEN_H
 #define ANDROID_AUDIO_RESAMPLER_FIR_GEN_H
 
+#include "utils/Compat.h"
+
 namespace android {
 
 /*
@@ -187,22 +189,22 @@
 
 template <int N>
 struct I0Term {
-    static const double value = I0Term<N-1>::value / (4. * N * N);
+    static const CONSTEXPR double value = I0Term<N-1>::value / (4. * N * N);
 };
 
 template <>
 struct I0Term<0> {
-    static const double value = 1.;
+    static const CONSTEXPR double value = 1.;
 };
 
 template <int N>
 struct I0ATerm {
-    static const double value = I0ATerm<N-1>::value * (2.*N-1.) * (2.*N-1.) / (8. * N);
+    static const CONSTEXPR double value = I0ATerm<N-1>::value * (2.*N-1.) * (2.*N-1.) / (8. * N);
 };
 
 template <>
 struct I0ATerm<0> { // 1/sqrt(2*PI);
-    static const double value = 0.398942280401432677939946059934381868475858631164934657665925;
+    static const CONSTEXPR double value = 0.398942280401432677939946059934381868475858631164934657665925;
 };
 
 #if USE_HORNERS_METHOD
diff --git a/services/audioflinger/AudioResamplerSinc.cpp b/services/audioflinger/AudioResamplerSinc.cpp
index d03e578..e6fb76c 100644
--- a/services/audioflinger/AudioResamplerSinc.cpp
+++ b/services/audioflinger/AudioResamplerSinc.cpp
@@ -31,7 +31,10 @@
 
 #include "AudioResamplerSinc.h"
 
-
+#if defined(__clang__) && !__has_builtin(__builtin_assume_aligned)
+#define __builtin_assume_aligned(p, a) \
+	(((uintptr_t(p) % (a)) == 0) ? (p) : (__builtin_unreachable(), (p)))
+#endif
 
 #if defined(__arm__) && !defined(__thumb__)
 #define USE_INLINE_ASSEMBLY (true)
diff --git a/services/audioflinger/StateQueue.cpp b/services/audioflinger/StateQueue.cpp
index 40d7bcd..9d4188f 100644
--- a/services/audioflinger/StateQueue.cpp
+++ b/services/audioflinger/StateQueue.cpp
@@ -48,7 +48,7 @@
     , mObserverDump(&mObserverDummyDump), mMutatorDump(&mMutatorDummyDump)
 #endif
 {
-    atomic_init(&mNext, 0);
+    atomic_init(&mNext, static_cast<uintptr_t>(0));
 }
 
 template<typename T> StateQueue<T>::~StateQueue()
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 71a6a73..a75f784 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -338,7 +338,7 @@
     // do not lock the mutex in destructor
     releaseWakeLock_l();
     if (mPowerManager != 0) {
-        sp<IBinder> binder = mPowerManager->asBinder();
+        sp<IBinder> binder = IInterface::asBinder(mPowerManager);
         binder->unlinkToDeath(mDeathRecipient);
     }
 }
diff --git a/services/audioflinger/tests/Android.mk b/services/audioflinger/tests/Android.mk
index 7bba05b..8604ef5 100644
--- a/services/audioflinger/tests/Android.mk
+++ b/services/audioflinger/tests/Android.mk
@@ -10,19 +10,10 @@
 	liblog \
 	libutils \
 	libcutils \
-	libstlport \
 	libaudioutils \
 	libaudioresampler
 
-LOCAL_STATIC_LIBRARIES := \
-	libgtest \
-	libgtest_main
-
 LOCAL_C_INCLUDES := \
-	bionic \
-	bionic/libstdc++/include \
-	external/gtest/include \
-	external/stlport/stlport \
 	$(call include-path-for, audio-utils) \
 	frameworks/av/services/audioflinger
 
@@ -32,21 +23,24 @@
 LOCAL_MODULE := resampler_tests
 LOCAL_MODULE_TAGS := tests
 
-include $(BUILD_EXECUTABLE)
+include $(BUILD_NATIVE_TEST)
 
 #
 # audio mixer test tool
 #
 include $(CLEAR_VARS)
 
+# Clang++ aborts on AudioMixer.cpp,
+# b/18373866, "do not know how to split this operator."
+ifeq ($(filter $(TARGET_ARCH),arm arm64),$(TARGET_ARCH))
+    LOCAL_CLANG := false
+endif
+
 LOCAL_SRC_FILES:= \
 	test-mixer.cpp \
 	../AudioMixer.cpp.arm \
 
 LOCAL_C_INCLUDES := \
-	bionic \
-	bionic/libstdc++/include \
-	external/stlport/stlport \
 	$(call include-path-for, audio-effects) \
 	$(call include-path-for, audio-utils) \
 	frameworks/av/services/audioflinger
@@ -55,7 +49,6 @@
 	libsndfile
 
 LOCAL_SHARED_LIBRARIES := \
-	libstlport \
 	libeffects \
 	libnbaio \
 	libcommon_time_client \
@@ -70,4 +63,6 @@
 
 LOCAL_MODULE_TAGS := optional
 
+LOCAL_CXX_STL := libc++
+
 include $(BUILD_EXECUTABLE)
diff --git a/services/audiopolicy/AudioPolicyService.cpp b/services/audiopolicy/AudioPolicyService.cpp
index 6a4a669..127c25b 100644
--- a/services/audiopolicy/AudioPolicyService.cpp
+++ b/services/audiopolicy/AudioPolicyService.cpp
@@ -35,6 +35,7 @@
 #include <hardware_legacy/power.h>
 #include <media/AudioEffect.h>
 #include <media/EffectsFactoryApi.h>
+#include <media/AudioParameter.h>
 
 #include <hardware/hardware.h>
 #include <system/audio.h>
@@ -160,7 +161,7 @@
 
         mNotificationClients.add(uid, notificationClient);
 
-        sp<IBinder> binder = client->asBinder();
+        sp<IBinder> binder = IInterface::asBinder(client);
         binder->linkToDeath(notificationClient);
     }
 }
diff --git a/services/audiopolicy/AudioPolicyService.h b/services/audiopolicy/AudioPolicyService.h
index f1db309..2ac31df 100644
--- a/services/audiopolicy/AudioPolicyService.h
+++ b/services/audiopolicy/AudioPolicyService.h
@@ -30,7 +30,9 @@
 #include <media/IAudioPolicyService.h>
 #include <media/ToneGenerator.h>
 #include <media/AudioEffect.h>
+#ifdef USE_LEGACY_AUDIO_POLICY
 #include <hardware_legacy/AudioPolicyInterface.h>
+#endif
 #include "AudioPolicyEffects.h"
 #include "AudioPolicyManager.h"
 
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index fd5a426..4229538 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -755,7 +755,7 @@
         Mutex::Autolock lock(mServiceLock);
         sp<BasicClient> clientTmp;
         if (!canConnectUnsafe(cameraId, clientPackageName,
-                              cameraClient->asBinder(),
+                              IInterface::asBinder(cameraClient),
                               /*out*/clientTmp)) {
             return -EBUSY;
         } else if (client.get() != NULL) {
@@ -818,7 +818,7 @@
         Mutex::Autolock lock(mServiceLock);
         sp<BasicClient> clientTmp;
         if (!canConnectUnsafe(cameraId, clientPackageName,
-                              cameraClient->asBinder(),
+                              IInterface::asBinder(cameraClient),
                               /*out*/clientTmp)) {
             return -EBUSY;
         } else if (client.get() != NULL) {
@@ -888,7 +888,7 @@
         {
             sp<BasicClient> client;
             if (!canConnectUnsafe(cameraId, clientPackageName,
-                                  cameraCb->asBinder(),
+                                  IInterface::asBinder(cameraCb),
                                   /*out*/client)) {
                 return -EBUSY;
             }
@@ -961,7 +961,7 @@
         {
             sp<BasicClient> client;
             if (!canConnectUnsafe(cameraId, clientPackageName,
-                                  cameraCb->asBinder(),
+                                  IInterface::asBinder(cameraCb),
                                   /*out*/client)) {
                 return -EBUSY;
             }
@@ -1023,7 +1023,7 @@
 
     Vector<sp<ICameraServiceListener> >::iterator it, end;
     for (it = mListenerList.begin(); it != mListenerList.end(); ++it) {
-        if ((*it)->asBinder() == listener->asBinder()) {
+        if (IInterface::asBinder(*it) == IInterface::asBinder(listener)) {
             ALOGW("%s: Tried to add listener %p which was already subscribed",
                   __FUNCTION__, listener.get());
             return ALREADY_EXISTS;
@@ -1056,7 +1056,7 @@
 
     Vector<sp<ICameraServiceListener> >::iterator it;
     for (it = mListenerList.begin(); it != mListenerList.end(); ++it) {
-        if ((*it)->asBinder() == listener->asBinder()) {
+        if (IInterface::asBinder(*it) == IInterface::asBinder(listener)) {
             mListenerList.erase(it);
             return OK;
         }
@@ -1169,7 +1169,7 @@
             // Found our camera, clear and leave.
             LOG1("removeClient: clear pro %p", clientPro.get());
 
-            clientPro->getRemoteCallback()->asBinder()->unlinkToDeath(this);
+            IInterface::asBinder(clientPro->getRemoteCallback())->unlinkToDeath(this);
         }
     }
 
@@ -1363,7 +1363,8 @@
         int cameraId, int cameraFacing,
         int clientPid, uid_t clientUid,
         int servicePid) :
-        CameraService::BasicClient(cameraService, cameraClient->asBinder(),
+        CameraService::BasicClient(cameraService,
+                IInterface::asBinder(cameraClient),
                 clientPackageName,
                 cameraId, cameraFacing,
                 clientPid, clientUid,
@@ -1476,7 +1477,9 @@
 
     }
     // Always stop watching, even if no camera op is active
-    mAppOpsManager.stopWatchingMode(mOpsCallback);
+    if (mOpsCallback != NULL) {
+        mAppOpsManager.stopWatchingMode(mOpsCallback);
+    }
     mOpsCallback.clear();
 
     return OK;
@@ -1572,7 +1575,7 @@
         int clientPid,
         uid_t clientUid,
         int servicePid)
-        : CameraService::BasicClient(cameraService, remoteCallback->asBinder(),
+        : CameraService::BasicClient(cameraService, IInterface::asBinder(remoteCallback),
                 clientPackageName, cameraId, cameraFacing,
                 clientPid,  clientUid, servicePid)
 {
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index a7328cf..126d8d9 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -273,7 +273,7 @@
         }
 
         virtual sp<IBinder> asBinderWrapper() {
-            return asBinder();
+            return asBinder(this);
         }
 
     protected:
diff --git a/services/camera/libcameraservice/api1/Camera2Client.cpp b/services/camera/libcameraservice/api1/Camera2Client.cpp
index 6e7824e..60939f9 100644
--- a/services/camera/libcameraservice/api1/Camera2Client.cpp
+++ b/services/camera/libcameraservice/api1/Camera2Client.cpp
@@ -165,7 +165,8 @@
     String8 result;
     result.appendFormat("Client2[%d] (%p) Client: %s PID: %d, dump:\n",
             mCameraId,
-            getRemoteCallback()->asBinder().get(),
+            (getRemoteCallback() != NULL ?
+                    (IInterface::asBinder(getRemoteCallback()).get()) : NULL),
             String8(mClientPackageName).string(),
             mClientPid);
     result.append("  State: ");
@@ -531,7 +532,7 @@
     sp<IBinder> binder;
     sp<ANativeWindow> window;
     if (bufferProducer != 0) {
-        binder = bufferProducer->asBinder();
+        binder = IInterface::asBinder(bufferProducer);
         // Using controlledByApp flag to ensure that the buffer queue remains in
         // async mode for the old camera API, where many applications depend
         // on that behavior.
diff --git a/services/camera/libcameraservice/api1/CameraClient.cpp b/services/camera/libcameraservice/api1/CameraClient.cpp
index 1a4d9a6..bbb2fe0 100644
--- a/services/camera/libcameraservice/api1/CameraClient.cpp
+++ b/services/camera/libcameraservice/api1/CameraClient.cpp
@@ -118,7 +118,8 @@
 
     size_t len = snprintf(buffer, SIZE, "Client[%d] (%p) PID: %d\n",
             mCameraId,
-            getRemoteCallback()->asBinder().get(),
+            (getRemoteCallback() != NULL ?
+                    IInterface::asBinder(getRemoteCallback()).get() : NULL),
             mClientPid);
     len = (len > SIZE - 1) ? SIZE - 1 : len;
     write(fd, buffer, len);
@@ -205,7 +206,7 @@
     }
 
     if (mRemoteCallback != 0 &&
-        (client->asBinder() == mRemoteCallback->asBinder())) {
+        (IInterface::asBinder(client) == IInterface::asBinder(mRemoteCallback))) {
         LOG1("Connect to the same client");
         return NO_ERROR;
     }
@@ -328,7 +329,7 @@
     sp<IBinder> binder;
     sp<ANativeWindow> window;
     if (bufferProducer != 0) {
-        binder = bufferProducer->asBinder();
+        binder = IInterface::asBinder(bufferProducer);
         // Using controlledByApp flag to ensure that the buffer queue remains in
         // async mode for the old camera API, where many applications depend
         // on that behavior.
diff --git a/services/camera/libcameraservice/api1/client2/Parameters.h b/services/camera/libcameraservice/api1/client2/Parameters.h
index 7e5be84..e628a7e 100644
--- a/services/camera/libcameraservice/api1/client2/Parameters.h
+++ b/services/camera/libcameraservice/api1/client2/Parameters.h
@@ -19,11 +19,13 @@
 
 #include <system/graphics.h>
 
+#include <utils/Compat.h>
 #include <utils/Errors.h>
+#include <utils/KeyedVector.h>
 #include <utils/Mutex.h>
 #include <utils/String8.h>
 #include <utils/Vector.h>
-#include <utils/KeyedVector.h>
+
 #include <camera/CameraParameters.h>
 #include <camera/CameraParameters2.h>
 #include <camera/CameraMetadata.h>
@@ -187,7 +189,7 @@
     static const int MAX_INITIAL_PREVIEW_WIDTH = 1920;
     static const int MAX_INITIAL_PREVIEW_HEIGHT = 1080;
     // Aspect ratio tolerance
-    static const float ASPECT_RATIO_TOLERANCE = 0.001;
+    static const CONSTEXPR float ASPECT_RATIO_TOLERANCE = 0.001;
 
     // Full static camera info, object owned by someone else, such as
     // Camera2Device.
diff --git a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
index e3301aa..920adf6 100644
--- a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
+++ b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
@@ -42,8 +42,14 @@
         int clientPid,
         uid_t clientUid,
         int servicePid) :
-    BasicClient(cameraService, remoteCallback->asBinder(), clientPackageName,
-                cameraId, cameraFacing, clientPid, clientUid, servicePid),
+    BasicClient(cameraService,
+            IInterface::asBinder(remoteCallback),
+            clientPackageName,
+            cameraId,
+            cameraFacing,
+            clientPid,
+            clientUid,
+            servicePid),
     mRemoteCallback(remoteCallback) {
 }
 
@@ -157,7 +163,7 @@
             if (surface == 0) continue;
 
             sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
-            int idx = mStreamMap.indexOfKey(gbp->asBinder());
+            int idx = mStreamMap.indexOfKey(IInterface::asBinder(gbp));
 
             // Trying to submit request with surface that wasn't created
             if (idx == NAME_NOT_FOUND) {
@@ -327,7 +333,7 @@
 
     // Don't create multiple streams for the same target surface
     {
-        ssize_t index = mStreamMap.indexOfKey(bufferProducer->asBinder());
+        ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
         if (index != NAME_NOT_FOUND) {
             ALOGW("%s: Camera %d: Buffer producer already has a stream for it "
                   "(ID %zd)",
@@ -353,12 +359,8 @@
         useAsync = true;
     }
 
-    sp<IBinder> binder;
-    sp<ANativeWindow> anw;
-    if (bufferProducer != 0) {
-        binder = bufferProducer->asBinder();
-        anw = new Surface(bufferProducer, useAsync);
-    }
+    sp<IBinder> binder = IInterface::asBinder(bufferProducer);
+    sp<ANativeWindow> anw = new Surface(bufferProducer, useAsync);
 
     // TODO: remove w,h,f since we are ignoring them
 
@@ -395,7 +397,7 @@
     res = mDevice->createStream(anw, width, height, format, &streamId);
 
     if (res == OK) {
-        mStreamMap.add(bufferProducer->asBinder(), streamId);
+        mStreamMap.add(binder, streamId);
 
         ALOGV("%s: Camera %d: Successfully created a new stream ID %d",
               __FUNCTION__, mCameraId, streamId);
@@ -514,7 +516,8 @@
     String8 result;
     result.appendFormat("CameraDeviceClient[%d] (%p) dump:\n",
             mCameraId,
-            getRemoteCallback()->asBinder().get());
+            (getRemoteCallback() != NULL ?
+                    IInterface::asBinder(getRemoteCallback()).get() : NULL) );
     result.appendFormat("  Current client: %s (PID %d, UID %u)\n",
             String8(mClientPackageName).string(),
             mClientPid, mClientUid);
diff --git a/services/camera/libcameraservice/api_pro/ProCamera2Client.cpp b/services/camera/libcameraservice/api_pro/ProCamera2Client.cpp
index 2ea460f..59e5083 100644
--- a/services/camera/libcameraservice/api_pro/ProCamera2Client.cpp
+++ b/services/camera/libcameraservice/api_pro/ProCamera2Client.cpp
@@ -276,7 +276,7 @@
     sp<IBinder> binder;
     sp<ANativeWindow> window;
     if (bufferProducer != 0) {
-        binder = bufferProducer->asBinder();
+        binder = IInterface::asBinder(bufferProducer);
         window = new Surface(bufferProducer);
     }
 
@@ -334,7 +334,8 @@
     String8 result;
     result.appendFormat("ProCamera2Client[%d] (%p) PID: %d, dump:\n",
             mCameraId,
-            getRemoteCallback()->asBinder().get(),
+            (getRemoteCallback() != NULL ?
+                    IInterface::asBinder(getRemoteCallback()).get() : NULL),
             mClientPid);
     result.append("  State:\n");
     write(fd, result.string(), result.size());
diff --git a/services/camera/libcameraservice/common/Camera2ClientBase.cpp b/services/camera/libcameraservice/common/Camera2ClientBase.cpp
index d6db151..453c8bd 100644
--- a/services/camera/libcameraservice/common/Camera2ClientBase.cpp
+++ b/services/camera/libcameraservice/common/Camera2ClientBase.cpp
@@ -128,7 +128,8 @@
     String8 result;
     result.appendFormat("Camera2ClientBase[%d] (%p) PID: %d, dump:\n",
             TClientBase::mCameraId,
-            TClientBase::getRemoteCallback()->asBinder().get(),
+            (TClientBase::getRemoteCallback() != NULL ?
+                    IInterface::asBinder(TClientBase::getRemoteCallback()).get() : NULL),
             TClientBase::mClientPid);
     result.append("  State: ");
 
diff --git a/services/camera/libcameraservice/common/Camera2ClientBase.h b/services/camera/libcameraservice/common/Camera2ClientBase.h
index d198e4e..e09c1b5 100644
--- a/services/camera/libcameraservice/common/Camera2ClientBase.h
+++ b/services/camera/libcameraservice/common/Camera2ClientBase.h
@@ -111,7 +111,7 @@
     pid_t mInitialClientPid;
 
     virtual sp<IBinder> asBinderWrapper() {
-        return IInterface::asBinder();
+        return IInterface::asBinder(this);
     }
 
     virtual status_t      dumpDevice(int fd, const Vector<String16>& args);
diff --git a/services/camera/libcameraservice/device1/CameraHardwareInterface.h b/services/camera/libcameraservice/device1/CameraHardwareInterface.h
index 6386838..1935c2b 100644
--- a/services/camera/libcameraservice/device1/CameraHardwareInterface.h
+++ b/services/camera/libcameraservice/device1/CameraHardwareInterface.h
@@ -588,7 +588,7 @@
 
 #ifndef container_of
 #define container_of(ptr, type, member) ({                      \
-        const typeof(((type *) 0)->member) *__mptr = (ptr);     \
+        const __typeof__(((type *) 0)->member) *__mptr = (ptr);     \
         (type *) ((char *) __mptr - (char *)(&((type *)0)->member)); })
 #endif
 
diff --git a/services/soundtrigger/SoundTriggerHwService.cpp b/services/soundtrigger/SoundTriggerHwService.cpp
index b5aaee3..b625b01 100644
--- a/services/soundtrigger/SoundTriggerHwService.cpp
+++ b/services/soundtrigger/SoundTriggerHwService.cpp
@@ -143,7 +143,7 @@
     sp<Module> module = mModules.valueAt(index);
 
     module->setClient(client);
-    client->asBinder()->linkToDeath(module);
+    IInterface::asBinder(client)->linkToDeath(module);
     moduleInterface = module;
 
     module->setCaptureState_l(mCaptureState);
@@ -510,7 +510,7 @@
         mModels.clear();
     }
     if (mClient != 0) {
-        mClient->asBinder()->unlinkToDeath(this);
+        IInterface::asBinder(mClient)->unlinkToDeath(this);
     }
     sp<SoundTriggerHwService> service = mService.promote();
     if (service == 0) {
diff --git a/soundtrigger/ISoundTrigger.cpp b/soundtrigger/ISoundTrigger.cpp
index 42280d1..eecc1ea 100644
--- a/soundtrigger/ISoundTrigger.cpp
+++ b/soundtrigger/ISoundTrigger.cpp
@@ -58,7 +58,7 @@
         }
         Parcel data, reply;
         data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
-        data.writeStrongBinder(modelMemory->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(modelMemory));
         status_t status = remote()->transact(LOAD_SOUND_MODEL, data, &reply);
         if (status != NO_ERROR ||
                 (status = (status_t)reply.readInt32()) != NO_ERROR) {
@@ -91,7 +91,7 @@
         } else {
             data.writeInt32(dataMemory->size());
         }
-        data.writeStrongBinder(dataMemory->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(dataMemory));
         status_t status = remote()->transact(START_RECOGNITION, data, &reply);
         if (status != NO_ERROR) {
             status = (status_t)reply.readInt32();
diff --git a/soundtrigger/ISoundTriggerClient.cpp b/soundtrigger/ISoundTriggerClient.cpp
index b0b4428..e0d3add 100644
--- a/soundtrigger/ISoundTriggerClient.cpp
+++ b/soundtrigger/ISoundTriggerClient.cpp
@@ -44,7 +44,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(ISoundTriggerClient::getInterfaceDescriptor());
-        data.writeStrongBinder(eventMemory->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(eventMemory));
         remote()->transact(ON_RECOGNITION_EVENT,
                            data,
                            &reply);
@@ -54,7 +54,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(ISoundTriggerClient::getInterfaceDescriptor());
-        data.writeStrongBinder(eventMemory->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(eventMemory));
         remote()->transact(ON_SOUNDMODEL_EVENT,
                            data,
                            &reply);
@@ -63,7 +63,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(ISoundTriggerClient::getInterfaceDescriptor());
-        data.writeStrongBinder(eventMemory->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(eventMemory));
         remote()->transact(ON_SERVICE_STATE_CHANGE,
                            data,
                            &reply);
diff --git a/soundtrigger/ISoundTriggerHwService.cpp b/soundtrigger/ISoundTriggerHwService.cpp
index 05728e9..75f68b8 100644
--- a/soundtrigger/ISoundTriggerHwService.cpp
+++ b/soundtrigger/ISoundTriggerHwService.cpp
@@ -82,7 +82,7 @@
         Parcel data, reply;
         data.writeInterfaceToken(ISoundTriggerHwService::getInterfaceDescriptor());
         data.write(&handle, sizeof(sound_trigger_module_handle_t));
-        data.writeStrongBinder(client->asBinder());
+        data.writeStrongBinder(IInterface::asBinder(client));
         remote()->transact(ATTACH, data, &reply);
         status_t status = reply.readInt32();
         if (reply.readInt32() != 0) {
@@ -147,7 +147,7 @@
             reply->writeInt32(status);
             if (module != 0) {
                 reply->writeInt32(1);
-                reply->writeStrongBinder(module->asBinder());
+                reply->writeStrongBinder(IInterface::asBinder(module));
             } else {
                 reply->writeInt32(0);
             }
diff --git a/soundtrigger/SoundTrigger.cpp b/soundtrigger/SoundTrigger.cpp
index 0015c30..2138cb7 100644
--- a/soundtrigger/SoundTrigger.cpp
+++ b/soundtrigger/SoundTrigger.cpp
@@ -104,7 +104,7 @@
     status_t status = service->attach(module, soundTrigger, soundTrigger->mISoundTrigger);
 
     if (status == NO_ERROR && soundTrigger->mISoundTrigger != 0) {
-        soundTrigger->mISoundTrigger->asBinder()->linkToDeath(soundTrigger);
+        IInterface::asBinder(soundTrigger->mISoundTrigger)->linkToDeath(soundTrigger);
     } else {
         ALOGW("Error %d connecting to sound trigger service", status);
         soundTrigger.clear();
@@ -144,7 +144,7 @@
     mCallback.clear();
     if (mISoundTrigger != 0) {
         mISoundTrigger->detach();
-        mISoundTrigger->asBinder()->unlinkToDeath(this);
+        IInterface::asBinder(mISoundTrigger)->unlinkToDeath(this);
         mISoundTrigger = 0;
     }
 }