From 6b739f644b435cc150872bfd6b1ea698e7acfc79 Mon Sep 17 00:00:00 2001 From: Ting Li Date: Fri, 29 Jul 2016 07:16:33 +0000 Subject: pd#129023 operate bt state file with systemcontrol Change-Id: Iedaf5e387625e5a6d1d49a7591befd555d582388 --- diff --git a/Android.mk b/Android.mk index b3b81c6..14670b5 100644 --- a/Android.mk +++ b/Android.mk @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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& who) { + ALOGW("system_write died!"); + } +}; +static sp amSystemWriteService; +static sp amDeathNotifier; +static Mutex amgLock; + +const sp& getSystemWriteService() +{ + Mutex::Autolock _l(amgLock); + if (amSystemWriteService.get() == 0) { + sp sm = defaultServiceManager(); +#if 0 + sp 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(binder); +#endif + + + amSystemWriteService = interface_cast(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& 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& 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; } -- cgit