author | Ting Li <ting.li@amlogic.com> | 2016-07-29 07:16:33 (GMT) |
---|---|---|
committer | Ting Li <ting.li@amlogic.com> | 2017-06-01 05:55:44 (GMT) |
commit | 6b739f644b435cc150872bfd6b1ea698e7acfc79 (patch) | |
tree | 0c242463a65aa6f7addc49d1b5a7d6bbf1fde421 | |
parent | 95a08b945f084752f3855ecfe8bd563c2de839e7 (diff) | |
download | libbt-6b739f644b435cc150872bfd6b1ea698e7acfc79.zip libbt-6b739f644b435cc150872bfd6b1ea698e7acfc79.tar.gz libbt-6b739f644b435cc150872bfd6b1ea698e7acfc79.tar.bz2 |
pd#129023 operate bt state file with systemcontrol
Change-Id: Iedaf5e387625e5a6d1d49a7591befd555d582388
-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
@@ -11,15 +11,22 @@ LOCAL_SRC_FILES := \ src/hardware.c \ src/userial_vendor.c \ src/upio.c \ - src/conf.c + src/conf.c \ + src/sysbridge.cpp LOCAL_C_INCLUDES += \ $(LOCAL_PATH)/include \ - $(BDROID_DIR)/hci/include + $(BDROID_DIR)/hci/include \ + $(TOP)/vendor/amlogic/frameworks/services LOCAL_SHARED_LIBRARIES := \ libcutils \ - liblog + liblog \ + libbinder \ + libsystemcontrolservice \ + libutils \ + libdl +LOCAL_CFLAGS += -DANDROID_PLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) -DUSE_SYS_WRITE_SERVICE=1 LOCAL_MODULE := libbt-vendor LOCAL_MODULE_TAGS := optional diff --git a/include/sysbridge.h b/include/sysbridge.h new file mode 100644 index 0000000..9f0af2a --- a/dev/null +++ b/include/sysbridge.h @@ -0,0 +1,8 @@ +#ifndef SYSBRIDGE_H +#define SYSBRIDGE_H + + +int amSystemWriteSetProperty(const char* key, const char* value, int leth); +int amSystemWriteGetProperty(const char* key, char* value); + +#endif
\ No newline at end of file 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 diff --git a/src/upio.c b/src/upio.c index 3f73482..8c87793 100755..100644 --- a/src/upio.c +++ b/src/upio.c @@ -36,7 +36,7 @@ #include "bt_vendor_brcm.h" #include "upio.h" #include "userial_vendor.h" - +#include "sysbridge.h" /****************************************************************************** ** Constants & Macros ******************************************************************************/ @@ -148,29 +148,39 @@ static int init_rfkill() char path[64]; char buf[16]; int fd, sz, id; - + sz = -1;//initial if (is_rfkill_disabled()) return -1; for (id = 0; ; id++) { + snprintf(path, sizeof(path), "/sys/class/rfkill/rfkill%d/type", id); fd = open(path, O_RDONLY); if (fd < 0) { ALOGE("init_rfkill : open(%s) failed: %s (%d)\n", \ path, strerror(errno), errno); - return -1; + ALOGE("open failed,use syscontrol\n"); + sz = amSystemWriteGetProperty(path,&buf); + goto end; + //return -1; } sz = read(fd, &buf, sizeof(buf)); close(fd); - - if (sz >= 9 && memcmp(buf, "bluetooth", 9) == 0) - { - rfkill_id = id; - break; - } + end:if (sz >= 9 && memcmp(buf, "bluetooth", 9) == 0) + { + ALOGE("break"); + rfkill_id = id; + break; + } + else if (sz == -1) + { + ALOGE("init_rfkill : open(%s) failed: %s (%d)\n", \ + path, strerror(errno), errno); + return -1; + } } asprintf(&rfkill_state_path, "/sys/class/rfkill/rfkill%d/state", rfkill_id); @@ -329,20 +339,20 @@ int upio_set_bluetooth_power(int on) { ALOGE("set_bluetooth_power : open(%s) for write failed: %s (%d)", rfkill_state_path, strerror(errno), errno); - return ret; + sz = amSystemWriteSetProperty(rfkill_state_path, &buffer, 1); + goto last; + //return ret; } sz = write(fd, &buffer, 1); - - if (sz < 0) { - ALOGE("set_bluetooth_power : write(%s) failed: %s (%d)", - rfkill_state_path, strerror(errno),errno); - } - else - ret = 0; - if (fd >= 0) close(fd); + last: if (sz < 0) { + ALOGE("set_bluetooth_power : write(%s) failed: %s (%d)", + rfkill_state_path, strerror(errno),errno); + } + else + ret = 0; return ret; } |