Return 16 values when sending on-change sensor\'s last event
am: 95f13901ed

* commit '95f13901edc77650f4bb8d727169e553af28a9d1':
  Return 16 values when sending on-change sensor's last event
diff --git a/cmds/atrace/atrace.cpp b/cmds/atrace/atrace.cpp
index 26c5b4a..7201e77 100644
--- a/cmds/atrace/atrace.cpp
+++ b/cmds/atrace/atrace.cpp
@@ -93,6 +93,7 @@
     { "sched",      "CPU Scheduling",   0, {
         { REQ,      "/sys/kernel/debug/tracing/events/sched/sched_switch/enable" },
         { REQ,      "/sys/kernel/debug/tracing/events/sched/sched_wakeup/enable" },
+        { OPT,      "/sys/kernel/debug/tracing/events/sched/sched_blocked_reason/enable" },
     } },
     { "irq",        "IRQ Events",   0, {
         { REQ,      "/sys/kernel/debug/tracing/events/irq/enable" },
diff --git a/cmds/dumpstate/dumpstate.c b/cmds/dumpstate/dumpstate.c
index b88b605..a2e4f4b 100644
--- a/cmds/dumpstate/dumpstate.c
+++ b/cmds/dumpstate/dumpstate.c
@@ -262,6 +262,8 @@
 
 /* End copy from system/core/logd/LogBuffer.cpp */
 
+static const unsigned long logcat_min_timeout = 40000; /* ms */
+
 /* dumps the current system state to stdout */
 static void dumpstate() {
     unsigned long timeout;
@@ -334,18 +336,18 @@
     // dump_file("EVENT LOG TAGS", "/etc/event-log-tags");
     // calculate timeout
     timeout = logcat_timeout("main") + logcat_timeout("system") + logcat_timeout("crash");
-    if (timeout < 20000) {
-        timeout = 20000;
+    if (timeout < logcat_min_timeout) {
+        timeout = logcat_min_timeout;
     }
     run_command("SYSTEM LOG", timeout / 1000, "logcat", "-v", "threadtime", "-d", "*:v", NULL);
     timeout = logcat_timeout("events");
-    if (timeout < 20000) {
-        timeout = 20000;
+    if (timeout < logcat_min_timeout) {
+        timeout = logcat_min_timeout;
     }
     run_command("EVENT LOG", timeout / 1000, "logcat", "-b", "events", "-v", "threadtime", "-d", "*:v", NULL);
     timeout = logcat_timeout("radio");
-    if (timeout < 20000) {
-        timeout = 20000;
+    if (timeout < logcat_min_timeout) {
+        timeout = logcat_min_timeout;
     }
     run_command("RADIO LOG", timeout / 1000, "logcat", "-b", "radio", "-v", "threadtime", "-d", "*:v", NULL);
 
diff --git a/include/gui/SensorManager.h b/include/gui/SensorManager.h
index f039caf..0cff46c 100644
--- a/include/gui/SensorManager.h
+++ b/include/gui/SensorManager.h
@@ -22,11 +22,9 @@
 #include <stdint.h>
 #include <sys/types.h>
 
-#include <binder/BinderService.h>
 #include <binder/IBinder.h>
 #include <binder/IPCThreadState.h>
 #include <binder/IServiceManager.h>
-#include <binder/PermissionCache.h>
 
 #include <utils/Errors.h>
 #include <utils/RefBase.h>
@@ -56,8 +54,7 @@
     static SensorManager& getInstanceForPackage(const String16& packageName);
     ~SensorManager();
 
-    ssize_t getSensorList(Sensor const* const** list);
-    ssize_t getAvailableSensorList(Sensor const* const** list);
+    ssize_t getSensorList(Sensor const* const** list) const;
     Sensor const* getDefaultSensor(int type);
     sp<SensorEventQueue> createEventQueue(String8 packageName = String8(""), int mode = 0);
     bool isDataInjectionEnabled();
@@ -67,27 +64,18 @@
     void sensorManagerDied();
 
     SensorManager(const String16& opPackageName);
-    status_t assertStateLocked();
-    void updateAvailableSensorList();
+    status_t assertStateLocked() const;
 
 private:
     static Mutex sLock;
     static std::map<String16, SensorManager*> sPackageInstances;
 
-    Mutex mLock;
-    sp<ISensorServer> mSensorServer;
-
-    // for Java API
-    Sensor const** mSensorList;
-
-    // for NDK API
-    Sensor const** mAvailableSensorList;
-    ssize_t mNumAvailableSensor;
-
-    Vector<Sensor> mSensors;
-    sp<IBinder::DeathRecipient> mDeathObserver;
+    mutable Mutex mLock;
+    mutable sp<ISensorServer> mSensorServer;
+    mutable Sensor const** mSensorList;
+    mutable Vector<Sensor> mSensors;
+    mutable sp<IBinder::DeathRecipient> mDeathObserver;
     const String16 mOpPackageName;
-    bool mBodyPermission;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/libs/gui/SensorManager.cpp b/libs/gui/SensorManager.cpp
index 4277032..33608b5 100644
--- a/libs/gui/SensorManager.cpp
+++ b/libs/gui/SensorManager.cpp
@@ -89,8 +89,7 @@
 }
 
 SensorManager::SensorManager(const String16& opPackageName)
-    : mSensorList(NULL), mAvailableSensorList(NULL), mNumAvailableSensor(0),
-      mOpPackageName(opPackageName), mBodyPermission(false)
+    : mSensorList(0), mOpPackageName(opPackageName)
 {
     // okay we're not locked here, but it's not needed during construction
     assertStateLocked();
@@ -99,9 +98,6 @@
 SensorManager::~SensorManager()
 {
     free(mSensorList);
-    if (mAvailableSensorList) {
-        free(mAvailableSensorList);
-    }
 }
 
 void SensorManager::sensorManagerDied()
@@ -110,14 +106,10 @@
     mSensorServer.clear();
     free(mSensorList);
     mSensorList = NULL;
-    if (mAvailableSensorList) {
-        free(mAvailableSensorList);
-        mAvailableSensorList = NULL;
-    }
     mSensors.clear();
 }
 
-status_t SensorManager::assertStateLocked() {
+status_t SensorManager::assertStateLocked() const {
     bool initSensorManager = false;
     if (mSensorServer == NULL) {
         initSensorManager = true;
@@ -167,14 +159,13 @@
         for (size_t i=0 ; i<count ; i++) {
             mSensorList[i] = mSensors.array() + i;
         }
-
-        updateAvailableSensorList();
     }
 
     return NO_ERROR;
 }
 
-ssize_t SensorManager::getSensorList(Sensor const* const** list) {
+ssize_t SensorManager::getSensorList(Sensor const* const** list) const
+{
     Mutex::Autolock _l(mLock);
     status_t err = assertStateLocked();
     if (err < 0) {
@@ -184,76 +175,10 @@
     return static_cast<ssize_t>(mSensors.size());
 }
 
-void SensorManager::updateAvailableSensorList() {
-    const int uid = static_cast<int>(IPCThreadState::self()->getCallingUid());
-    const int pid = static_cast<int>(IPCThreadState::self()->getCallingPid());
-    const String16 BODY_SENSOR_PERMISSION("android.permission.BODY_SENSORS");
-    const String8 BODY_SENSOR_PERMISSION8("android.permission.BODY_SENSORS");
-
-    bool bodySensorPermission = false;
-
-    sp<IBinder> binder = defaultServiceManager()->getService(String16("permission"));
-    if (binder != NULL) {
-        bodySensorPermission = interface_cast<IPermissionController>(binder)->
-                checkPermission(BODY_SENSOR_PERMISSION, pid, uid);
-    }
-
-    // only update if app got BODY_SENSORS permission after last call or the sensor list has not
-    // been populated.
-    //
-    // it is not possible for the reverse transition, as the app will be killed when permission is
-    // revoked.
-    if ( (bodySensorPermission && !mBodyPermission) || mAvailableSensorList == NULL) {
-
-        // allocate only when necessary
-        if (mAvailableSensorList == NULL) {
-            // allocate a list big enough to fit all sensors (including those requires permission
-            // that the app do not have;
-            mAvailableSensorList =
-                    static_cast<Sensor const**>(malloc(mSensors.size() * sizeof(Sensor*)));
-
-            // first populate all sensors that do not need body sensor permission
-            ssize_t& n = mNumAvailableSensor;
-            for (size_t i = 0; i < mSensors.size() ; i++) {
-                if (mSensors[i].getRequiredPermission() != BODY_SENSOR_PERMISSION8) {
-                    mAvailableSensorList[n++] = mSensors.array() + i;
-                }
-            }
-        }
-
-        if (bodySensorPermission) {
-            // if the app just got the sensor permission back, fill the sensor at the end of list
-            ssize_t& n = mNumAvailableSensor;
-            for (size_t i = 0; i < mSensors.size() ; i++) {
-                if (mSensors[i].getRequiredPermission() == BODY_SENSOR_PERMISSION8) {
-                    mAvailableSensorList[n++] = mSensors.array() + i;
-                }
-            }
-        }
-
-        mBodyPermission = bodySensorPermission;
-    }
-}
-
-ssize_t SensorManager::getAvailableSensorList(Sensor const* const** list) {
-    Mutex::Autolock _l(mLock);
-    status_t err = assertStateLocked();
-    if (err < 0) {
-        return static_cast<ssize_t>(err);
-    }
-
-    updateAvailableSensorList();
-
-    *list = mAvailableSensorList;
-    return mNumAvailableSensor;
-}
-
-Sensor const* SensorManager::getDefaultSensor(int type) {
+Sensor const* SensorManager::getDefaultSensor(int type)
+{
     Mutex::Autolock _l(mLock);
     if (assertStateLocked() == NO_ERROR) {
-
-        updateAvailableSensorList();
-
         bool wakeUpSensor = false;
         // For the following sensor types, return a wake-up sensor. These types are by default
         // defined as wake-up sensors. For the rest of the sensor types defined in sensors.h return
@@ -267,9 +192,9 @@
         // in the future it will make sense to let the SensorService make
         // that decision.
         for (size_t i=0 ; i<mSensors.size() ; i++) {
-            if (mAvailableSensorList[i]->getType() == type &&
-                mAvailableSensorList[i]->isWakeUpSensor() == wakeUpSensor) {
-                return mAvailableSensorList[i];
+            if (mSensorList[i]->getType() == type &&
+                mSensorList[i]->isWakeUpSensor() == wakeUpSensor) {
+                return mSensorList[i];
             }
         }
     }
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index fc54383..2f64558 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -723,7 +723,14 @@
     Vector<Sensor> accessibleSensorList;
     for (size_t i = 0; i < initialSensorList.size(); i++) {
         Sensor sensor = initialSensorList[i];
-        accessibleSensorList.add(sensor);
+        if (canAccessSensor(sensor, "getSensorList", opPackageName)) {
+            accessibleSensorList.add(sensor);
+        } else {
+            ALOGI("Skipped sensor %s because it requires permission %s and app op %d",
+                  sensor.getName().string(),
+                  sensor.getRequiredPermission().string(),
+                  sensor.getRequiredAppOp());
+        }
     }
     return accessibleSensorList;
 }
diff --git a/services/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk
index 1eb2361..1901ef9 100644
--- a/services/surfaceflinger/Android.mk
+++ b/services/surfaceflinger/Android.mk
@@ -122,6 +122,10 @@
 LOCAL_CFLAGS := -DLOG_TAG=\"SurfaceFlinger\"
 LOCAL_CPPFLAGS := -std=c++11
 
+ifneq ($(ENABLE_CPUSETS),)
+    LOCAL_CFLAGS += -DENABLE_CPUSETS
+endif
+
 LOCAL_SRC_FILES := \
     main_surfaceflinger.cpp
 
diff --git a/services/surfaceflinger/main_surfaceflinger.cpp b/services/surfaceflinger/main_surfaceflinger.cpp
index a74bc4c..6fa8b53 100644
--- a/services/surfaceflinger/main_surfaceflinger.cpp
+++ b/services/surfaceflinger/main_surfaceflinger.cpp
@@ -41,6 +41,13 @@
 
     set_sched_policy(0, SP_FOREGROUND);
 
+#ifdef ENABLE_CPUSETS
+    // Put most SurfaceFlinger threads in the system-background cpuset
+    // Keeps us from unnecessarily using big cores
+    // Do this after the binder thread pool init
+    set_cpuset_policy(0, SP_SYSTEM);
+#endif
+
     // initialize before clients can connect
     flinger->init();