summaryrefslogtreecommitdiff
authorTellen Yu <tellen.yu@amlogic.com>2017-06-06 08:46:54 (GMT)
committer Gerrit Code Review <gituser@scgit.amlogic.com>2017-06-06 08:46:54 (GMT)
commita47891eb5b4d6100d55f6f9526322c568e945ab8 (patch)
tree9297ff5addd039d06017db18a7bec3f74bab5474
parent4c026e9e7833ae92f8ee67ce6df2fe2bc30fd2ca (diff)
parent6b739f644b435cc150872bfd6b1ea698e7acfc79 (diff)
downloadlibbt-a47891eb5b4d6100d55f6f9526322c568e945ab8.zip
libbt-a47891eb5b4d6100d55f6f9526322c568e945ab8.tar.gz
libbt-a47891eb5b4d6100d55f6f9526322c568e945ab8.tar.bz2
Merge "pd#129023 operate bt state file with systemcontrol" into m-amlogic
Diffstat
-rw-r--r--Android.mk13
-rw-r--r--include/sysbridge.h8
-rw-r--r--src/sysbridge.cpp90
-rw-r--r--[-rwxr-xr-x]src/upio.c46
4 files changed, 136 insertions, 21 deletions
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 <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;
}