-rw-r--r-- | Android.mk | 13 | ||||
-rw-r--r-- | include/sysbridge.h | 8 | ||||
-rw-r--r-- | src/sysbridge.cpp | 90 | ||||
-rw-r--r--[-rwxr-xr-x] | src/upio.c | 46 |
4 files changed, 136 insertions, 21 deletions
diff --git a/src/sysbridge.cpp b/src/sysbridge.cpp new file mode 100644 index 0000000..9e00324 --- a/dev/null +++ b/src/sysbridge.cpp @@ -0,0 +1,90 @@ +#define LOG_TAG "bridge" +#include <android/log.h> +#include <cutils/properties.h> +#include <binder/Binder.h> +#include <binder/IServiceManager.h> +#include <utils/Log.h> +#include <utils/RefBase.h> +#include <utils/String16.h> +#include <utils/String8.h> +#include <utils/threads.h> +#include <systemcontrol/ISystemControlService.h> + +#define SYST_SERVICES_NAME "system_control" + + +using namespace android; +extern "C" int amSystemWriteSetProperty(const char* key, const char* value, int lengthval); +extern "C" int amSystemWriteGetProperty(const char* key, char* value); +class DeathNotifier: public IBinder::DeathRecipient +{ + public: + DeathNotifier() { + } + + void binderDied(const wp<IBinder>& who) { + ALOGW("system_write died!"); + } +}; +static sp<ISystemControlService> amSystemWriteService; +static sp<DeathNotifier> amDeathNotifier; +static Mutex amgLock; + +const sp<ISystemControlService>& getSystemWriteService() +{ + Mutex::Autolock _l(amgLock); + if (amSystemWriteService.get() == 0) { + sp<IServiceManager> sm = defaultServiceManager(); +#if 0 + sp<IBinder> binder; + do { + binder = sm->getService(String16("system_write")); + if (binder != 0) + break; + ALOGW("SystemWriteService not published, waiting..."); + usleep(500000); // 0.5 s + } while(true); + if (amDeathNotifier == NULL) { + amDeathNotifier = new DeathNotifier(); + } + binder->linkToDeath(amDeathNotifier); + amSystemWriteService = interface_cast<ISystemWriteService>(binder); +#endif + + + amSystemWriteService = interface_cast<ISystemControlService>(sm->getService(String16(SYST_SERVICES_NAME))); + + } + ALOGE_IF(amSystemWriteService==0, "no SystemWrite Service!?"); + + return amSystemWriteService; +} +int amSystemWriteSetProperty(const char* key, const char* value, int leth) +{ + const sp<ISystemControlService>& sws = getSystemWriteService(); + char *buf = new char[leth+1]; + strncpy(buf, value, leth); + if (sws != 0) { + sws->writeSysfs(String16(key), String16(buf)); + delete[] buf; + ALOGE("write value %s %s\n",key,buf); + return 0; + } + delete[] buf; + return -1; +} +int amSystemWriteGetProperty(const char* key, char* value) +{ + const sp<ISystemControlService>& sws = getSystemWriteService(); + if (sws != 0) { + String16 read_value; + sws->readSysfs(String16(key), read_value); + String8 name8 = String8(read_value); + const char *C_name8 = (char *)name8.string(); + strcpy(value,C_name8); + ALOGE("read_value(%s) %s %d;\n",key,value,strlen(value)); + return strlen(value); + }else{ + return -1; + } +}
\ No newline at end of file |