Skip to content

Commit

Permalink
[android8] Add fake SensorManager service. JB#44947
Browse files Browse the repository at this point in the history
SensorManager service is needed on some Android 8 based devices.
  • Loading branch information
mlehtima committed Feb 26, 2019
1 parent 3a5b55f commit 77504eb
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ LOCAL_C_INCLUDES += frameworks/native/libs/sensor/include \
LOCAL_SHARED_LIBRARIES += liblog \
libhidlbase \
libhidltransport \
libhwbinder \
libsensor \
[email protected] \
[email protected] \
[email protected]
endif
Expand Down Expand Up @@ -130,7 +132,9 @@ LOCAL_C_INCLUDES := frameworks/native/libs/sensor/include \
LOCAL_SHARED_LIBRARIES += liblog \
libhidlbase \
libhidltransport \
libhwbinder \
libsensor \
[email protected] \
[email protected] \
[email protected]
endif
Expand Down Expand Up @@ -170,7 +174,9 @@ LOCAL_SHARED_LIBRARIES += liblog \
libcamera_client \
libhidlbase \
libhidltransport \
libhwbinder \
libsensor \
[email protected] \
[email protected] \
[email protected]
endif
Expand Down
4 changes: 4 additions & 0 deletions minimedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ main(int, char**)
usleep(BINDER_SERVICE_CHECK_INTERVAL);
} while (true);
ALOGD("Allowing use of the camera for users root and bin");
#if ANDROID_MAJOR >= 8
sp<android::frameworks::sensorservice::V1_0::ISensorManager> sensorManager = new FakeSensorManager;
status_t status = sensorManager->registerAsService();
#endif
#if ANDROID_MAJOR >= 7
sp<hardware::ICameraService> gCameraService = interface_cast<hardware::ICameraService>(binder);
std::vector<int32_t> users = {0, 1};
Expand Down
68 changes: 68 additions & 0 deletions services/services_8_1_0.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,71 @@ class FakeResourceManagerService : public BinderService<FakeResourceManagerServi
}
};

#include <android/frameworks/sensorservice/1.0/IEventQueue.h>
#include <android/frameworks/sensorservice/1.0/ISensorManager.h>
#include <android/frameworks/sensorservice/1.0/types.h>
#include <android/hardware/sensors/1.0/types.h>

class FakeEventQueue :
public android::frameworks::sensorservice::V1_0::IEventQueue
{
public:
FakeEventQueue() {}

android::hardware::Return<android::frameworks::sensorservice::V1_0::Result> enableSensor(
int32_t sensorHandle, int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs) {
return android::frameworks::sensorservice::V1_0::Result::BAD_VALUE;
}

android::hardware::Return<android::frameworks::sensorservice::V1_0::Result> disableSensor(
int32_t sensorHandle) {
return android::frameworks::sensorservice::V1_0::Result::BAD_VALUE;
}
};

class FakeSensorManager :
public android::frameworks::sensorservice::V1_0::ISensorManager
{

// Methods from ::android::frameworks::sensorservice::V1_0::ISensorManager follow.
android::hardware::Return<void> getSensorList(getSensorList_cb _hidl_cb) {
android::hardware::hidl_vec<::android::hardware::sensors::V1_0::SensorInfo> ret;
_hidl_cb(ret, android::frameworks::sensorservice::V1_0::Result::OK);
return android::hardware::Void();
}

android::hardware::Return<void> getDefaultSensor(
android::hardware::sensors::V1_0::SensorType type,
getDefaultSensor_cb _hidl_cb) {
_hidl_cb({}, android::frameworks::sensorservice::V1_0::Result::NOT_EXIST);
return android::hardware::Void();
}

android::hardware::Return<void> createAshmemDirectChannel(
const android::hardware::hidl_memory& mem, uint64_t size,
createAshmemDirectChannel_cb _hidl_cb) {
_hidl_cb(nullptr, android::frameworks::sensorservice::V1_0::Result::BAD_VALUE);
return android::hardware::Void();
}

android::hardware::Return<void> createGrallocDirectChannel(
const android::hardware::hidl_handle& buffer, uint64_t size,
createGrallocDirectChannel_cb _hidl_cb) {
_hidl_cb(nullptr, android::frameworks::sensorservice::V1_0::Result::UNKNOWN_ERROR);
return android::hardware::Void();
}

android::hardware::Return<void> createEventQueue(
const sp<android::frameworks::sensorservice::V1_0::IEventQueueCallback> &callback,
createEventQueue_cb _hidl_cb) {
if (callback == nullptr) {
_hidl_cb(nullptr, android::frameworks::sensorservice::V1_0::Result::BAD_VALUE);
return android::hardware::Void();
}

sp<android::frameworks::sensorservice::V1_0::IEventQueue> queue = new FakeEventQueue();

_hidl_cb(queue, android::frameworks::sensorservice::V1_0::Result::OK);
return android::hardware::Void();
}
};

0 comments on commit 77504eb

Please sign in to comment.