summaryrefslogtreecommitdiffstats
path: root/libs/gui
diff options
context:
space:
mode:
authorSvetoslav <svetoslavganov@google.com>2015-05-01 23:10:55 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-05-01 23:10:56 +0000
commitc28fe8f5c54c5e98be7664dcffdbd5b324b850d6 (patch)
treee767fa8dffa041373996bf2e5d0951e26f3331f6 /libs/gui
parent326842fca4883f1256aa9ed019bb3206ee76fca7 (diff)
parentb412f6e203b38f8047f760261a5e3dc6d0722f08 (diff)
downloadframeworks_native-c28fe8f5c54c5e98be7664dcffdbd5b324b850d6.zip
frameworks_native-c28fe8f5c54c5e98be7664dcffdbd5b324b850d6.tar.gz
frameworks_native-c28fe8f5c54c5e98be7664dcffdbd5b324b850d6.tar.bz2
Merge "Add body sensors app op - framework native" into mnc-dev
Diffstat (limited to 'libs/gui')
-rw-r--r--libs/gui/ISensorServer.cpp13
-rw-r--r--libs/gui/Sensor.cpp35
-rw-r--r--libs/gui/SensorManager.cpp10
3 files changed, 45 insertions, 13 deletions
diff --git a/libs/gui/ISensorServer.cpp b/libs/gui/ISensorServer.cpp
index 140712e..5dde9f9 100644
--- a/libs/gui/ISensorServer.cpp
+++ b/libs/gui/ISensorServer.cpp
@@ -48,10 +48,11 @@ public:
virtual ~BpSensorServer();
- virtual Vector<Sensor> getSensorList()
+ virtual Vector<Sensor> getSensorList(const String16& opPackageName)
{
Parcel data, reply;
data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
+ data.writeString16(opPackageName);
remote()->transact(GET_SENSOR_LIST, data, &reply);
Sensor s;
Vector<Sensor> v;
@@ -65,12 +66,13 @@ public:
}
virtual sp<ISensorEventConnection> createSensorEventConnection(const String8& packageName,
- int mode)
+ int mode, const String16& opPackageName)
{
Parcel data, reply;
data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
data.writeString8(packageName);
data.writeInt32(mode);
+ data.writeString16(opPackageName);
remote()->transact(CREATE_SENSOR_EVENT_CONNECTION, data, &reply);
return interface_cast<ISensorEventConnection>(reply.readStrongBinder());
}
@@ -98,7 +100,8 @@ status_t BnSensorServer::onTransact(
switch(code) {
case GET_SENSOR_LIST: {
CHECK_INTERFACE(ISensorServer, data, reply);
- Vector<Sensor> v(getSensorList());
+ const String16& opPackageName = data.readString16();
+ Vector<Sensor> v(getSensorList(opPackageName));
size_t n = v.size();
reply->writeUint32(static_cast<uint32_t>(n));
for (size_t i = 0; i < n; i++) {
@@ -110,7 +113,9 @@ status_t BnSensorServer::onTransact(
CHECK_INTERFACE(ISensorServer, data, reply);
String8 packageName = data.readString8();
int32_t mode = data.readInt32();
- sp<ISensorEventConnection> connection(createSensorEventConnection(packageName, mode));
+ const String16& opPackageName = data.readString16();
+ sp<ISensorEventConnection> connection(createSensorEventConnection(packageName, mode,
+ opPackageName));
reply->writeStrongBinder(IInterface::asBinder(connection));
return NO_ERROR;
}
diff --git a/libs/gui/Sensor.cpp b/libs/gui/Sensor.cpp
index 35661f2..2545eec 100644
--- a/libs/gui/Sensor.cpp
+++ b/libs/gui/Sensor.cpp
@@ -25,6 +25,9 @@
#include <hardware/sensors.h>
+#include <binder/AppOpsManager.h>
+#include <binder/IServiceManager.h>
+
#include <gui/Sensor.h>
#include <log/log.h>
@@ -113,11 +116,13 @@ Sensor::Sensor(struct sensor_t const* hwSensor, int halVersion)
mStringType = SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED;
mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
- case SENSOR_TYPE_HEART_RATE:
+ case SENSOR_TYPE_HEART_RATE: {
mStringType = SENSOR_STRING_TYPE_HEART_RATE;
mRequiredPermission = SENSOR_PERMISSION_BODY_SENSORS;
+ AppOpsManager appOps;
+ mRequiredAppOp = appOps.permissionToOpCode(String16(SENSOR_PERMISSION_BODY_SENSORS));
mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
- break;
+ } break;
case SENSOR_TYPE_LIGHT:
mStringType = SENSOR_STRING_TYPE_LIGHT;
mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
@@ -252,6 +257,17 @@ Sensor::Sensor(struct sensor_t const* hwSensor, int halVersion)
}
}
+
+ if (mRequiredPermission.length() > 0) {
+ // If the sensor is protected by a permission we need to know if it is
+ // a runtime one to determine whether we can use the permission cache.
+ sp<IBinder> binder = defaultServiceManager()->getService(String16("permission"));
+ if (binder != 0) {
+ sp<IPermissionController> permCtrl = interface_cast<IPermissionController>(binder);
+ mRequiredPermissionRuntime = permCtrl->isRuntimePermission(
+ String16(mRequiredPermission));
+ }
+ }
}
Sensor::~Sensor()
@@ -318,6 +334,14 @@ const String8& Sensor::getRequiredPermission() const {
return mRequiredPermission;
}
+bool Sensor::isRequiredPermissionRuntime() const {
+ return mRequiredPermissionRuntime;
+}
+
+int32_t Sensor::getRequiredAppOp() const {
+ return mRequiredAppOp;
+}
+
int32_t Sensor::getMaxDelay() const {
return mMaxDelay;
}
@@ -339,7 +363,8 @@ size_t Sensor::getFlattenedSize() const
size_t fixedSize =
sizeof(int32_t) * 3 +
sizeof(float) * 4 +
- sizeof(int32_t) * 5;
+ sizeof(int32_t) * 6 +
+ sizeof(bool);
size_t variableSize =
sizeof(uint32_t) + FlattenableUtils::align<4>(mName.length()) +
@@ -369,6 +394,8 @@ status_t Sensor::flatten(void* buffer, size_t size) const {
FlattenableUtils::write(buffer, size, mFifoMaxEventCount);
flattenString8(buffer, size, mStringType);
flattenString8(buffer, size, mRequiredPermission);
+ FlattenableUtils::write(buffer, size, mRequiredPermissionRuntime);
+ FlattenableUtils::write(buffer, size, mRequiredAppOp);
FlattenableUtils::write(buffer, size, mMaxDelay);
FlattenableUtils::write(buffer, size, mFlags);
return NO_ERROR;
@@ -407,6 +434,8 @@ status_t Sensor::unflatten(void const* buffer, size_t size) {
if (!unflattenString8(buffer, size, mRequiredPermission)) {
return NO_MEMORY;
}
+ FlattenableUtils::read(buffer, size, mRequiredPermissionRuntime);
+ FlattenableUtils::read(buffer, size, mRequiredAppOp);
FlattenableUtils::read(buffer, size, mMaxDelay);
FlattenableUtils::read(buffer, size, mFlags);
return NO_ERROR;
diff --git a/libs/gui/SensorManager.cpp b/libs/gui/SensorManager.cpp
index cedcf56..8c9f95b 100644
--- a/libs/gui/SensorManager.cpp
+++ b/libs/gui/SensorManager.cpp
@@ -36,10 +36,8 @@
namespace android {
// ----------------------------------------------------------------------------
-ANDROID_SINGLETON_STATIC_INSTANCE(SensorManager)
-
-SensorManager::SensorManager()
- : mSensorList(0)
+SensorManager::SensorManager(const String16& opPackageName)
+ : mSensorList(0), mOpPackageName(opPackageName)
{
// okay we're not locked here, but it's not needed during construction
assertStateLocked();
@@ -88,7 +86,7 @@ status_t SensorManager::assertStateLocked() const {
mDeathObserver = new DeathObserver(*const_cast<SensorManager *>(this));
IInterface::asBinder(mSensorServer)->linkToDeath(mDeathObserver);
- mSensors = mSensorServer->getSensorList();
+ mSensors = mSensorServer->getSensorList(mOpPackageName);
size_t count = mSensors.size();
mSensorList =
static_cast<Sensor const**>(malloc(count * sizeof(Sensor*)));
@@ -143,7 +141,7 @@ sp<SensorEventQueue> SensorManager::createEventQueue(String8 packageName, int mo
Mutex::Autolock _l(mLock);
while (assertStateLocked() == NO_ERROR) {
sp<ISensorEventConnection> connection =
- mSensorServer->createSensorEventConnection(packageName, mode);
+ mSensorServer->createSensorEventConnection(packageName, mode, mOpPackageName);
if (connection == NULL) {
// SensorService just died or the app doesn't have required permissions.
ALOGE("createEventQueue: connection is NULL.");