Loading include/android/sensor.h +2 −1 Original line number Diff line number Diff line Loading @@ -267,7 +267,8 @@ enum { * {@link ASENSOR_TYPE_HEAD_TRACKER} * reporting-mode: continuous * * Measures the orientation and rotational velocity of a user's head. * Measures the orientation and rotational velocity of a user's head. Only for internal use * within the Android system. */ ASENSOR_TYPE_HEAD_TRACKER = 37, /** Loading libs/gralloc/types/Gralloc4.cpp +34 −89 Original line number Diff line number Diff line Loading @@ -195,35 +195,6 @@ using ErrorHandler = void(*)(T*); status_t encodeMetadataType(const MetadataType& input, OutputHidlVec* output); status_t validateMetadataType(InputHidlVec* input, const MetadataType& expectedMetadataType); /** * Private helper functions */ template <class T> status_t encodeInteger(const T& input, OutputHidlVec* output) { static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value || std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value || std::is_same<T, float>::value || std::is_same<T, double>::value); if (!output) { return BAD_VALUE; } const uint8_t* tmp = reinterpret_cast<const uint8_t*>(&input); return output->encode(tmp, sizeof(input)); } template <class T> status_t decodeInteger(InputHidlVec* input, T* output) { static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value || std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value || std::is_same<T, float>::value || std::is_same<T, double>::value); if (!output) { return BAD_VALUE; } uint8_t* tmp = reinterpret_cast<uint8_t*>(output); return input->decode(tmp, sizeof(*output)); } /** * encode/encodeMetadata are the main encoding functions. They take in T and uses the encodeHelper * function to turn T into the hidl_vec byte stream. Loading Loading @@ -280,46 +251,11 @@ status_t encodeMetadata(const MetadataType& metadataType, const T& input, hidl_v template <class T> status_t encodeOptionalMetadata(const MetadataType& metadataType, const std::optional<T>& input, hidl_vec<uint8_t>* output, EncodeHelper<T> encodeHelper) { OutputHidlVec outputHidlVec{output}; status_t err = encodeMetadataType(metadataType, &outputHidlVec); if (err) { return err; } err = encodeInteger<uint32_t>(input.has_value() ? 1 : 0, &outputHidlVec); if (err) { return err; } if (input) { err = encodeHelper(*input, &outputHidlVec); if (err) { return err; } } err = outputHidlVec.resize(); if (err) { return err; } err = encodeMetadataType(metadataType, &outputHidlVec); if (err) { return err; } err = encodeInteger<uint32_t>(input.has_value() ? 1 : 0, &outputHidlVec); if (err) { return err; } if (input) { return encodeHelper(*input, &outputHidlVec); } if (!input) { return NO_ERROR; } return encodeMetadata(metadataType, *input, output, encodeHelper); } /** * decode/decodeMetadata are the main decoding functions. They take in a hidl_vec and use the Loading Loading @@ -379,36 +315,45 @@ status_t decodeOptionalMetadata(const MetadataType& metadataType, const hidl_vec if (!output) { return BAD_VALUE; } InputHidlVec inputHidlVec{&input}; status_t err = validateMetadataType(&inputHidlVec, metadataType); if (err) { return err; if (input.size() <= 0) { output->reset(); return NO_ERROR; } T tmp; status_t err = decodeMetadata(metadataType, input, &tmp, decodeHelper); if (!err) { *output = tmp; } uint32_t present = 0; err = decodeInteger<uint32_t>(&inputHidlVec, &present); if (err) { return err; } if (present) { T tmp; err = decodeHelper(&inputHidlVec, &tmp); if (err) { return err; /** * Private helper functions */ template <class T> status_t encodeInteger(const T& input, OutputHidlVec* output) { static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value || std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value || std::is_same<T, float>::value || std::is_same<T, double>::value); if (!output) { return BAD_VALUE; } *output = tmp; const uint8_t* tmp = reinterpret_cast<const uint8_t*>(&input); return output->encode(tmp, sizeof(input)); } err = inputHidlVec.hasRemainingData(); if (err) { template <class T> status_t decodeInteger(InputHidlVec* input, T* output) { static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value || std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value || std::is_same<T, float>::value || std::is_same<T, double>::value); if (!output) { return BAD_VALUE; } return NO_ERROR; uint8_t* tmp = reinterpret_cast<uint8_t*>(output); return input->decode(tmp, sizeof(*output)); } status_t encodeString(const std::string& input, OutputHidlVec* output) { Loading services/sensorservice/SensorDirectConnection.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -157,7 +157,7 @@ int32_t SensorService::SensorDirectConnection::configureChannel(int handle, int } const Sensor& s = si->getSensor(); if (!SensorService::canAccessSensor(s, "config direct channel", mOpPackageName)) { if (!mService->canAccessSensor(s, "config direct channel", mOpPackageName)) { return PERMISSION_DENIED; } Loading services/sensorservice/SensorEventConnection.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -162,7 +162,8 @@ bool SensorService::SensorEventConnection::addSensor(int32_t handle) { Mutex::Autolock _l(mConnectionLock); sp<SensorInterface> si = mService->getSensorInterfaceFromHandle(handle); if (si == nullptr || !canAccessSensor(si->getSensor(), "Add to SensorEventConnection: ", mOpPackageName) || !mService->canAccessSensor(si->getSensor(), "Add to SensorEventConnection: ", mOpPackageName) || mSensorInfo.count(handle) > 0) { return false; } Loading services/sensorservice/SensorService.cpp +23 −3 Original line number Diff line number Diff line Loading @@ -814,6 +814,12 @@ status_t SensorService::shellCommand(int in, int out, int err, Vector<String16>& return handleResetUidState(args, err); } else if (args[0] == String16("get-uid-state")) { return handleGetUidState(args, out, err); } else if (args[0] == String16("unrestrict-ht")) { mHtRestricted = false; return NO_ERROR; } else if (args[0] == String16("restrict-ht")) { mHtRestricted = true; return NO_ERROR; } else if (args.size() == 1 && args[0] == String16("help")) { printHelp(out); return NO_ERROR; Loading Loading @@ -1338,11 +1344,11 @@ Vector<Sensor> SensorService::getSensorList(const String16& opPackageName) { Vector<Sensor> SensorService::getDynamicSensorList(const String16& opPackageName) { Vector<Sensor> accessibleSensorList; mSensors.forEachSensor( [&opPackageName, &accessibleSensorList] (const Sensor& sensor) -> bool { [this, &opPackageName, &accessibleSensorList] (const Sensor& sensor) -> bool { if (sensor.isDynamicSensor()) { if (canAccessSensor(sensor, "getDynamicSensorList", opPackageName)) { if (canAccessSensor(sensor, "can't see", opPackageName)) { accessibleSensorList.add(sensor); } else { } else if (sensor.getType() != SENSOR_TYPE_HEAD_TRACKER) { ALOGI("Skipped sensor %s because it requires permission %s and app op %" PRId32, sensor.getName().string(), sensor.getRequiredPermission().string(), Loading Loading @@ -1989,6 +1995,20 @@ status_t SensorService::flushSensor(const sp<SensorEventConnection>& connection, bool SensorService::canAccessSensor(const Sensor& sensor, const char* operation, const String16& opPackageName) { // Special case for Head Tracker sensor type: currently restricted to system usage only, unless // the restriction is specially lifted for testing if (sensor.getType() == SENSOR_TYPE_HEAD_TRACKER && !isAudioServerOrSystemServerUid(IPCThreadState::self()->getCallingUid())) { if (!mHtRestricted) { ALOGI("Permitting access to HT sensor type outside system (%s)", String8(opPackageName).string()); } else { ALOGW("%s %s a sensor (%s) as a non-system client", String8(opPackageName).string(), operation, sensor.getName().string()); return false; } } // Check if a permission is required for this sensor if (sensor.getRequiredPermission().length() <= 0) { return true; Loading Loading
include/android/sensor.h +2 −1 Original line number Diff line number Diff line Loading @@ -267,7 +267,8 @@ enum { * {@link ASENSOR_TYPE_HEAD_TRACKER} * reporting-mode: continuous * * Measures the orientation and rotational velocity of a user's head. * Measures the orientation and rotational velocity of a user's head. Only for internal use * within the Android system. */ ASENSOR_TYPE_HEAD_TRACKER = 37, /** Loading
libs/gralloc/types/Gralloc4.cpp +34 −89 Original line number Diff line number Diff line Loading @@ -195,35 +195,6 @@ using ErrorHandler = void(*)(T*); status_t encodeMetadataType(const MetadataType& input, OutputHidlVec* output); status_t validateMetadataType(InputHidlVec* input, const MetadataType& expectedMetadataType); /** * Private helper functions */ template <class T> status_t encodeInteger(const T& input, OutputHidlVec* output) { static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value || std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value || std::is_same<T, float>::value || std::is_same<T, double>::value); if (!output) { return BAD_VALUE; } const uint8_t* tmp = reinterpret_cast<const uint8_t*>(&input); return output->encode(tmp, sizeof(input)); } template <class T> status_t decodeInteger(InputHidlVec* input, T* output) { static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value || std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value || std::is_same<T, float>::value || std::is_same<T, double>::value); if (!output) { return BAD_VALUE; } uint8_t* tmp = reinterpret_cast<uint8_t*>(output); return input->decode(tmp, sizeof(*output)); } /** * encode/encodeMetadata are the main encoding functions. They take in T and uses the encodeHelper * function to turn T into the hidl_vec byte stream. Loading Loading @@ -280,46 +251,11 @@ status_t encodeMetadata(const MetadataType& metadataType, const T& input, hidl_v template <class T> status_t encodeOptionalMetadata(const MetadataType& metadataType, const std::optional<T>& input, hidl_vec<uint8_t>* output, EncodeHelper<T> encodeHelper) { OutputHidlVec outputHidlVec{output}; status_t err = encodeMetadataType(metadataType, &outputHidlVec); if (err) { return err; } err = encodeInteger<uint32_t>(input.has_value() ? 1 : 0, &outputHidlVec); if (err) { return err; } if (input) { err = encodeHelper(*input, &outputHidlVec); if (err) { return err; } } err = outputHidlVec.resize(); if (err) { return err; } err = encodeMetadataType(metadataType, &outputHidlVec); if (err) { return err; } err = encodeInteger<uint32_t>(input.has_value() ? 1 : 0, &outputHidlVec); if (err) { return err; } if (input) { return encodeHelper(*input, &outputHidlVec); } if (!input) { return NO_ERROR; } return encodeMetadata(metadataType, *input, output, encodeHelper); } /** * decode/decodeMetadata are the main decoding functions. They take in a hidl_vec and use the Loading Loading @@ -379,36 +315,45 @@ status_t decodeOptionalMetadata(const MetadataType& metadataType, const hidl_vec if (!output) { return BAD_VALUE; } InputHidlVec inputHidlVec{&input}; status_t err = validateMetadataType(&inputHidlVec, metadataType); if (err) { return err; if (input.size() <= 0) { output->reset(); return NO_ERROR; } T tmp; status_t err = decodeMetadata(metadataType, input, &tmp, decodeHelper); if (!err) { *output = tmp; } uint32_t present = 0; err = decodeInteger<uint32_t>(&inputHidlVec, &present); if (err) { return err; } if (present) { T tmp; err = decodeHelper(&inputHidlVec, &tmp); if (err) { return err; /** * Private helper functions */ template <class T> status_t encodeInteger(const T& input, OutputHidlVec* output) { static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value || std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value || std::is_same<T, float>::value || std::is_same<T, double>::value); if (!output) { return BAD_VALUE; } *output = tmp; const uint8_t* tmp = reinterpret_cast<const uint8_t*>(&input); return output->encode(tmp, sizeof(input)); } err = inputHidlVec.hasRemainingData(); if (err) { template <class T> status_t decodeInteger(InputHidlVec* input, T* output) { static_assert(std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value || std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value || std::is_same<T, float>::value || std::is_same<T, double>::value); if (!output) { return BAD_VALUE; } return NO_ERROR; uint8_t* tmp = reinterpret_cast<uint8_t*>(output); return input->decode(tmp, sizeof(*output)); } status_t encodeString(const std::string& input, OutputHidlVec* output) { Loading
services/sensorservice/SensorDirectConnection.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -157,7 +157,7 @@ int32_t SensorService::SensorDirectConnection::configureChannel(int handle, int } const Sensor& s = si->getSensor(); if (!SensorService::canAccessSensor(s, "config direct channel", mOpPackageName)) { if (!mService->canAccessSensor(s, "config direct channel", mOpPackageName)) { return PERMISSION_DENIED; } Loading
services/sensorservice/SensorEventConnection.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -162,7 +162,8 @@ bool SensorService::SensorEventConnection::addSensor(int32_t handle) { Mutex::Autolock _l(mConnectionLock); sp<SensorInterface> si = mService->getSensorInterfaceFromHandle(handle); if (si == nullptr || !canAccessSensor(si->getSensor(), "Add to SensorEventConnection: ", mOpPackageName) || !mService->canAccessSensor(si->getSensor(), "Add to SensorEventConnection: ", mOpPackageName) || mSensorInfo.count(handle) > 0) { return false; } Loading
services/sensorservice/SensorService.cpp +23 −3 Original line number Diff line number Diff line Loading @@ -814,6 +814,12 @@ status_t SensorService::shellCommand(int in, int out, int err, Vector<String16>& return handleResetUidState(args, err); } else if (args[0] == String16("get-uid-state")) { return handleGetUidState(args, out, err); } else if (args[0] == String16("unrestrict-ht")) { mHtRestricted = false; return NO_ERROR; } else if (args[0] == String16("restrict-ht")) { mHtRestricted = true; return NO_ERROR; } else if (args.size() == 1 && args[0] == String16("help")) { printHelp(out); return NO_ERROR; Loading Loading @@ -1338,11 +1344,11 @@ Vector<Sensor> SensorService::getSensorList(const String16& opPackageName) { Vector<Sensor> SensorService::getDynamicSensorList(const String16& opPackageName) { Vector<Sensor> accessibleSensorList; mSensors.forEachSensor( [&opPackageName, &accessibleSensorList] (const Sensor& sensor) -> bool { [this, &opPackageName, &accessibleSensorList] (const Sensor& sensor) -> bool { if (sensor.isDynamicSensor()) { if (canAccessSensor(sensor, "getDynamicSensorList", opPackageName)) { if (canAccessSensor(sensor, "can't see", opPackageName)) { accessibleSensorList.add(sensor); } else { } else if (sensor.getType() != SENSOR_TYPE_HEAD_TRACKER) { ALOGI("Skipped sensor %s because it requires permission %s and app op %" PRId32, sensor.getName().string(), sensor.getRequiredPermission().string(), Loading Loading @@ -1989,6 +1995,20 @@ status_t SensorService::flushSensor(const sp<SensorEventConnection>& connection, bool SensorService::canAccessSensor(const Sensor& sensor, const char* operation, const String16& opPackageName) { // Special case for Head Tracker sensor type: currently restricted to system usage only, unless // the restriction is specially lifted for testing if (sensor.getType() == SENSOR_TYPE_HEAD_TRACKER && !isAudioServerOrSystemServerUid(IPCThreadState::self()->getCallingUid())) { if (!mHtRestricted) { ALOGI("Permitting access to HT sensor type outside system (%s)", String8(opPackageName).string()); } else { ALOGW("%s %s a sensor (%s) as a non-system client", String8(opPackageName).string(), operation, sensor.getName().string()); return false; } } // Check if a permission is required for this sensor if (sensor.getRequiredPermission().length() <= 0) { return true; Loading