Merge "SensorService flush fixes." into lmp-dev
diff --git a/include/android/keycodes.h b/include/android/keycodes.h
index 813d411..75d0ab6 100644
--- a/include/android/keycodes.h
+++ b/include/android/keycodes.h
@@ -274,7 +274,35 @@
     AKEYCODE_12              = 228,
     AKEYCODE_LAST_CHANNEL    = 229,
     AKEYCODE_TV_DATA_SERVICE = 230,
-    AKEYCODE_VOICE_ASSIST    = 231
+    AKEYCODE_VOICE_ASSIST    = 231,
+    AKEYCODE_TV_RADIO_SERVICE = 232,
+    AKEYCODE_TV_TELETEXT     = 233,
+    AKEYCODE_TV_NUMBER_ENTRY = 234,
+    AKEYCODE_TV_TERRESTRIAL_ANALOG = 235,
+    AKEYCODE_TV_TERRESTRIAL_DIGITAL = 236,
+    AKEYCODE_TV_SATELLITE    = 237,
+    AKEYCODE_TV_SATELLITE_BS = 238,
+    AKEYCODE_TV_SATELLITE_CS = 239,
+    AKEYCODE_TV_SATELLITE_SERVICE = 240,
+    AKEYCODE_TV_NETWORK      = 241,
+    AKEYCODE_TV_ANTENNA_CABLE = 242,
+    AKEYCODE_TV_INPUT_HDMI_1 = 243,
+    AKEYCODE_TV_INPUT_HDMI_2 = 244,
+    AKEYCODE_TV_INPUT_HDMI_3 = 245,
+    AKEYCODE_TV_INPUT_HDMI_4 = 246,
+    AKEYCODE_TV_INPUT_COMPOSITE_1 = 247,
+    AKEYCODE_TV_INPUT_COMPOSITE_2 = 248,
+    AKEYCODE_TV_INPUT_COMPONENT_1 = 249,
+    AKEYCODE_TV_INPUT_COMPONENT_2 = 250,
+    AKEYCODE_TV_INPUT_VGA_1  = 251,
+    AKEYCODE_TV_AUDIO_DESCRIPTION = 252,
+    AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP = 253,
+    AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN = 254,
+    AKEYCODE_TV_ZOOM_MODE    = 255,
+    AKEYCODE_TV_CONTENTS_MENU = 256,
+    AKEYCODE_TV_MEDIA_CONTEXT_MENU = 257,
+    AKEYCODE_TV_TIMER_PROGRAMMING = 258,
+    AKEYCODE_HELP            = 259
 
     // NOTE: If you add a new keycode here you must also add it to several other files.
     //       Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
diff --git a/include/binder/Binder.h b/include/binder/Binder.h
index ba3ac4b..86628a0 100644
--- a/include/binder/Binder.h
+++ b/include/binder/Binder.h
@@ -17,6 +17,8 @@
 #ifndef ANDROID_BINDER_H
 #define ANDROID_BINDER_H
 
+#include <stdatomic.h>
+#include <stdint.h>
 #include <binder/IBinder.h>
 
 // ---------------------------------------------------------------------------
@@ -69,7 +71,7 @@
 
     class Extras;
 
-            Extras*     mExtras;
+    atomic_uintptr_t    mExtras;  // should be atomic<Extras *>
             void*       mReserved0;
 };
 
diff --git a/include/input/InputEventLabels.h b/include/input/InputEventLabels.h
index 279ac40..df50237 100644
--- a/include/input/InputEventLabels.h
+++ b/include/input/InputEventLabels.h
@@ -271,6 +271,34 @@
     DEFINE_KEYCODE(LAST_CHANNEL),
     DEFINE_KEYCODE(TV_DATA_SERVICE),
     DEFINE_KEYCODE(VOICE_ASSIST),
+    DEFINE_KEYCODE(TV_RADIO_SERVICE),
+    DEFINE_KEYCODE(TV_TELETEXT),
+    DEFINE_KEYCODE(TV_NUMBER_ENTRY),
+    DEFINE_KEYCODE(TV_TERRESTRIAL_ANALOG),
+    DEFINE_KEYCODE(TV_TERRESTRIAL_DIGITAL),
+    DEFINE_KEYCODE(TV_SATELLITE),
+    DEFINE_KEYCODE(TV_SATELLITE_BS),
+    DEFINE_KEYCODE(TV_SATELLITE_CS),
+    DEFINE_KEYCODE(TV_SATELLITE_SERVICE),
+    DEFINE_KEYCODE(TV_NETWORK),
+    DEFINE_KEYCODE(TV_ANTENNA_CABLE),
+    DEFINE_KEYCODE(TV_INPUT_HDMI_1),
+    DEFINE_KEYCODE(TV_INPUT_HDMI_2),
+    DEFINE_KEYCODE(TV_INPUT_HDMI_3),
+    DEFINE_KEYCODE(TV_INPUT_HDMI_4),
+    DEFINE_KEYCODE(TV_INPUT_COMPOSITE_1),
+    DEFINE_KEYCODE(TV_INPUT_COMPOSITE_2),
+    DEFINE_KEYCODE(TV_INPUT_COMPONENT_1),
+    DEFINE_KEYCODE(TV_INPUT_COMPONENT_2),
+    DEFINE_KEYCODE(TV_INPUT_VGA_1),
+    DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION),
+    DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION_MIX_UP),
+    DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION_MIX_DOWN),
+    DEFINE_KEYCODE(TV_ZOOM_MODE),
+    DEFINE_KEYCODE(TV_CONTENTS_MENU),
+    DEFINE_KEYCODE(TV_MEDIA_CONTEXT_MENU),
+    DEFINE_KEYCODE(TV_TIMER_PROGRAMMING),
+    DEFINE_KEYCODE(HELP),
 
     { NULL, 0 }
 };
diff --git a/include/ui/mat4.h b/include/ui/mat4.h
index d9647cc..4fd1eff 100644
--- a/include/ui/mat4.h
+++ b/include/ui/mat4.h
@@ -322,6 +322,7 @@
         r[ 1] =  xy*nc + zs;    r[ 5] = y*y*nc +  c;    r[ 9] =  yz*nc - xs;
         r[ 2] =  zx*nc - ys;    r[ 6] =  yz*nc + xs;    r[10] = z*z*nc +  c;
     }
+    return rotation;
 }
 
 // ----------------------------------------------------------------------------------------
diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp
index 71e62ab..2554351 100644
--- a/libs/binder/Binder.cpp
+++ b/libs/binder/Binder.cpp
@@ -16,7 +16,7 @@
 
 #include <binder/Binder.h>
 
-#include <utils/Atomic.h>
+#include <stdatomic.h>
 #include <utils/misc.h>
 #include <binder/BpBinder.h>
 #include <binder/IInterface.h>
@@ -71,8 +71,8 @@
 // ---------------------------------------------------------------------------
 
 BBinder::BBinder()
-    : mExtras(NULL)
 {
+    atomic_init(&mExtras, 0);
 }
 
 bool BBinder::isBinderAlive() const
@@ -139,19 +139,19 @@
     const void* objectID, void* object, void* cleanupCookie,
     object_cleanup_func func)
 {
-    Extras* e = mExtras;
+    Extras* e = reinterpret_cast<Extras*>(
+                    atomic_load_explicit(&mExtras, memory_order_acquire));
 
     if (!e) {
         e = new Extras;
-#ifdef __LP64__
-        if (android_atomic_release_cas64(0, reinterpret_cast<int64_t>(e),
-                reinterpret_cast<volatile int64_t*>(&mExtras)) != 0) {
-#else
-        if (android_atomic_cmpxchg(0, reinterpret_cast<int32_t>(e),
-                reinterpret_cast<volatile int32_t*>(&mExtras)) != 0) {
-#endif
+        uintptr_t expected = 0;
+        if (!atomic_compare_exchange_strong_explicit(
+                                        &mExtras, &expected,
+                                        reinterpret_cast<uintptr_t>(e),
+                                        memory_order_release,
+                                        memory_order_acquire)) {
             delete e;
-            e = mExtras;
+            e = reinterpret_cast<Extras*>(expected);  // Filled in by CAS
         }
         if (e == 0) return; // out of memory
     }
@@ -162,7 +162,8 @@
 
 void* BBinder::findObject(const void* objectID) const
 {
-    Extras* e = mExtras;
+    Extras* e = reinterpret_cast<Extras*>(
+                    atomic_load_explicit(&mExtras, memory_order_acquire));
     if (!e) return NULL;
 
     AutoMutex _l(e->mLock);
@@ -171,7 +172,8 @@
 
 void BBinder::detachObject(const void* objectID)
 {
-    Extras* e = mExtras;
+    Extras* e = reinterpret_cast<Extras*>(
+                    atomic_load_explicit(&mExtras, memory_order_acquire));
     if (!e) return;
 
     AutoMutex _l(e->mLock);
@@ -185,7 +187,9 @@
 
 BBinder::~BBinder()
 {
-    if (mExtras) delete mExtras;
+    Extras* e = reinterpret_cast<Extras*>(
+                    atomic_load_explicit(&mExtras, memory_order_relaxed));
+    if (e) delete e;
 }
 
 
diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp
index b7c7ff4..8634e42 100644
--- a/services/inputflinger/InputReader.cpp
+++ b/services/inputflinger/InputReader.cpp
@@ -1851,7 +1851,7 @@
 
 void SwitchInputMapper::sync(nsecs_t when) {
     if (mUpdatedSwitchMask) {
-        int32_t updatedSwitchValues = mSwitchValues & mUpdatedSwitchMask;
+        uint32_t updatedSwitchValues = mSwitchValues & mUpdatedSwitchMask;
         NotifySwitchArgs args(when, 0, updatedSwitchValues, mUpdatedSwitchMask);
         getListener()->notifySwitch(&args);
 
diff --git a/services/powermanager/IPowerManager.cpp b/services/powermanager/IPowerManager.cpp
index ee730d6..926c050 100644
--- a/services/powermanager/IPowerManager.cpp
+++ b/services/powermanager/IPowerManager.cpp
@@ -56,7 +56,7 @@
         data.writeString16(packageName);
         data.writeInt32(0); // no WorkSource
         data.writeString16(NULL, 0); // no history tag
-        return remote()->transact(ACQUIRE_WAKE_LOCK, data, &reply);
+        return remote()->transact(ACQUIRE_WAKE_LOCK, data, &reply, IBinder::FLAG_ONEWAY);
     }
 
     virtual status_t acquireWakeLockWithUid(int flags, const sp<IBinder>& lock, const String16& tag,
@@ -70,7 +70,7 @@
         data.writeString16(tag);
         data.writeString16(packageName);
         data.writeInt32(uid); // uid to blame for the work
-        return remote()->transact(ACQUIRE_WAKE_LOCK_UID, data, &reply);
+        return remote()->transact(ACQUIRE_WAKE_LOCK_UID, data, &reply, IBinder::FLAG_ONEWAY);
     }
 
     virtual status_t releaseWakeLock(const sp<IBinder>& lock, int flags)
@@ -79,7 +79,7 @@
         data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
         data.writeStrongBinder(lock);
         data.writeInt32(flags);
-        return remote()->transact(RELEASE_WAKE_LOCK, data, &reply);
+        return remote()->transact(RELEASE_WAKE_LOCK, data, &reply, IBinder::FLAG_ONEWAY);
     }
 
     virtual status_t updateWakeLockUids(const sp<IBinder>& lock, int len, const int *uids) {