Android-x86
Fork
捐款

  • R/O
  • HTTP
  • SSH
  • HTTPS

system-core: 提交

system/core


Commit MetaInfo

修訂f7631d3a9c500aeed76bc5d984e4cc688f803e3c (tree)
時間2009-11-14 04:44:00
作者Chih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

vold: rfkill bootstrapping

Simulate rfkill add uevents to change permission of bluetooth devices on boot.
This is better since it works after suspend and wakeup.

Also revert back rfkill handling in hotplug.

Change Summary

差異

--- a/toolbox/hotplug.c
+++ b/toolbox/hotplug.c
@@ -1,7 +1,13 @@
11 /*
22 * Simple hotplug tool
33 *
4- * by Chih-Wei Huang <cwhuang@linux.org.tw> 2009/11/06
4+ * Copyright (C) 2009 The Android-x86 Open Source Project
5+ *
6+ * Author: Chih-Wei Huang <cwhuang@linux.org.tw>
7+ *
8+ * Licensed under the Apache License, Version 2.0.
9+ *
10+ * Last updated: 2009/11/14
511 *
612 */
713
@@ -12,8 +18,6 @@
1218 #include <sys/stat.h>
1319 #include <unistd.h>
1420
15-#include "private/android_filesystem_config.h"
16-
1721 #define HOTPLUG_LOG "/tmp/hotplug.log"
1822 #define FIRMWARE_PATH "/system/lib/firmware"
1923
@@ -60,25 +64,6 @@ static int load_firmware()
6064 return ret;
6165 }
6266
63-static int set_rfkill()
64-{
65- int ret = -1;
66- if (strcmp(getenv("RFKILL_TYPE"), "bluetooth") == 0) {
67- chdir("/sys");
68- chdir(getenv("DEVPATH") + 1);
69- ret = chown("state", AID_BLUETOOTH, AID_BLUETOOTH);
70- ret |= chmod("state", S_IRUSR|S_IRGRP|S_IWUSR|S_IWGRP);
71-#if 0 /* we may not need the hack */
72- if (!strncmp(getenv("RFKILL_NAME"), "hci", 3) && !strcmp(getenv("RFKILL_STATE"), "0")) {
73- int fd = open("state", O_WRONLY);
74- if (fd >= 0)
75- ret |= !(write(fd, "1", 1) == 1);
76- }
77-#endif
78- }
79- return ret;
80-}
81-
8267 int hotplug_main(int argc, char **argv)
8368 {
8469 int ret = -1;
@@ -108,8 +93,6 @@ int hotplug_main(int argc, char **argv)
10893 if (strcmp(action, "add") == 0) {
10994 if (strcmp(argv[1], "firmware") == 0)
11095 ret = load_firmware();
111- else if (strcmp(argv[1], "rfkill") == 0)
112- ret = set_rfkill();
11396 }
11497 }
11598 return ret;
--- a/vold/Android.mk
+++ b/vold/Android.mk
@@ -3,7 +3,7 @@ LOCAL_PATH:= $(call my-dir)
33 include $(CLEAR_VARS)
44
55 LOCAL_SRC_FILES:= \
6- vold.c \
6+ vold.c \
77 cmd_dispatch.c \
88 uevent.c \
99 mmc.c \
@@ -19,6 +19,7 @@ LOCAL_SRC_FILES:= \
1919 logwrapper.c \
2020 ProcessKiller.c\
2121 switch.c \
22+ rfkill.c \
2223 format.c \
2324 devmapper.c
2425
--- a/vold/misc.c
+++ b/vold/misc.c
@@ -27,9 +27,9 @@
2727
2828 void *read_file(char *filename, ssize_t *_size)
2929 {
30- int ret, fd;
30+ int fd;
3131 struct stat sb;
32- ssize_t size;
32+ ssize_t size, ret;
3333 void *buffer = NULL;
3434
3535 /* open the file */
@@ -43,12 +43,13 @@ void *read_file(char *filename, ssize_t *_size)
4343 size = sb.st_size;
4444
4545 /* allocate memory for it to be read into */
46- buffer = malloc(size);
46+ buffer = malloc(size + 1);
4747 if (!buffer)
4848 goto bail;
4949
5050 /* slurp it into our buffer */
5151 ret = read(fd, buffer, size);
52+ ((char *)buffer)[ret] = '\0';
5253 if (ret != size)
5354 goto bail;
5455
--- /dev/null
+++ b/vold/rfkill.c
@@ -0,0 +1,57 @@
1+/*
2+ * Copyright (C) 2009 The Android-x86 Open Source Project
3+ *
4+ * Author: Chih-Wei Huang <cwhuang@linux.org.tw>
5+ *
6+ * Licensed under the Apache License, Version 2.0 (the "License");
7+ * you may not use this file except in compliance with the License.
8+ * You may obtain a copy of the License at
9+ *
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ *
12+ * Unless required by applicable law or agreed to in writing, software
13+ * distributed under the License is distributed on an "AS IS" BASIS,
14+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ * See the License for the specific language governing permissions and
16+ * limitations under the License.
17+ */
18+
19+#include "vold.h"
20+
21+#include <dirent.h>
22+#include <errno.h>
23+
24+#define DEBUG_RFKILL_BOOTSTRAP 0
25+
26+#define SYSFS_CLASS_RFKILL_PATH "/sys/class/rfkill"
27+
28+/*
29+ * Bootstrap rfkill interfaces
30+ */
31+int rfkill_bootstrap()
32+{
33+ DIR *d;
34+ struct dirent *de;
35+
36+ if (!(d = opendir(SYSFS_CLASS_RFKILL_PATH))) {
37+ LOG_ERROR("Unable to open '%s' (%s)", SYSFS_CLASS_RFKILL_PATH,
38+ strerror(errno));
39+ return -errno;
40+ }
41+
42+ while ((de = readdir(d)))
43+ if (de->d_name[0] != '.') {
44+ char path[SYSFS_PATH_MAX];
45+ sprintf(path, "%s/%s", SYSFS_CLASS_RFKILL_PATH, de->d_name);
46+#if DEBUG_RFKILL_BOOTSTRAP
47+ LOG_VOL("Simulate add: %s", de->d_name);
48+#endif
49+ if (simulate_add_device("rfkill", path + 4)) {
50+ LOG_ERROR("Simulate add device %s error: %s", path,
51+ strerror(errno));
52+ }
53+ }
54+
55+ closedir(d);
56+ return 0;
57+}
--- a/vold/uevent.c
+++ b/vold/uevent.c
@@ -30,6 +30,8 @@
3030 #include "volmgr.h"
3131 #include "media.h"
3232
33+#include "private/android_filesystem_config.h"
34+
3335 #define DEBUG_UEVENT 1
3436
3537 #define UEVENT_PARAMS_MAX 32
@@ -62,6 +64,7 @@ static int handle_block_event(struct uevent *);
6264 static int handle_bdi_event(struct uevent *);
6365 static void _cb_blkdev_ok_to_destroy(blkdev_t *dev);
6466 static int handle_scsi_event(struct uevent *event);
67+static int handle_rfkill_event(struct uevent *event);
6568
6669 static struct uevent_dispatch dispatch_table[] = {
6770 { "switch", handle_switch_event },
@@ -71,6 +74,7 @@ static struct uevent_dispatch dispatch_table[] = {
7174 { "bdi", handle_bdi_event },
7275 { "power_supply", handle_powersupply_event },
7376 { "scsi", handle_scsi_event },
77+ { "rfkill", handle_rfkill_event },
7478 { NULL, NULL }
7579 };
7680
@@ -135,7 +139,7 @@ int process_uevent_message(int socket)
135139 return rc;
136140 }
137141
138-int simulate_uevent(char *subsys, char *path, char *action, char **params)
142+int simulate_uevent(const char *subsys, const char *path, const char *action, char **params)
139143 {
140144 struct uevent *event;
141145 char tmp[255];
@@ -174,6 +178,28 @@ int simulate_uevent(char *subsys, char *path, char *action, char **params)
174178 return rc;
175179 }
176180
181+int simulate_add_device(const char *subsys, const char *path)
182+{
183+ int i;
184+ char line[1024];
185+ char devpath[SYSFS_PATH_MAX] = "DEVPATH=";
186+ char *uevent, *saveptr, *uevent_params[UEVENT_PARAMS_MAX];
187+
188+ if (!read_sysfs_var(line, sizeof(line), path, "uevent")) {
189+ LOGE("Unable to open '/sys%s/%s' (%s)", path, "uevent", strerror(errno));
190+ return -errno;
191+ }
192+
193+ strcat(devpath, path);
194+ uevent_params[0] = devpath;
195+ for (i = 1, uevent = line; i < UEVENT_PARAMS_MAX - 1; ++i, uevent = NULL)
196+ if (!(uevent_params[i] = strtok_r(uevent, "\n", &saveptr)))
197+ break;
198+ uevent_params[i] = NULL;
199+
200+ return simulate_uevent(subsys, path, "add", uevent_params);
201+}
202+
177203 static int dispatch_uevent(struct uevent *event)
178204 {
179205 int i;
@@ -244,7 +270,7 @@ static char *get_uevent_param(struct uevent *event, char *param_name)
244270 }
245271
246272 LOGE("get_uevent_param(): No parameter '%s' found", param_name);
247- return NULL;
273+ return ""; /* return a valid pointer to avoid checking */
248274 }
249275
250276 /*
@@ -466,6 +492,21 @@ static int handle_scsi_event(struct uevent *event)
466492 return 0;
467493 }
468494
495+static int handle_rfkill_event(struct uevent *event)
496+{
497+ if (event->action == action_add) {
498+ const char *type = get_uevent_param(event, "RFKILL_TYPE");
499+ if (!strncmp(type, "bluetooth", 9)) {
500+ char path[SYSFS_PATH_MAX];
501+ snprintf(path, sizeof(path), "/sys%s/state", event->path);
502+ chown(path, AID_BLUETOOTH, AID_BLUETOOTH);
503+ chmod(path, S_IRUSR|S_IRGRP|S_IWUSR|S_IWGRP);
504+ LOG_VOL("Change permission for %s", path);
505+ }
506+ }
507+ return 0;
508+}
509+
469510 static void _cb_blkdev_ok_to_destroy(blkdev_t *dev)
470511 {
471512 media_t *media = media_lookup_by_dev(dev);
--- a/vold/usbdrive.c
+++ b/vold/usbdrive.c
@@ -253,32 +253,5 @@ static int usb_bootstrap_sdx(const char *sysfs_path)
253253
254254 static int usb_bootstrap_sdx_partition(const char *sysfs_path)
255255 {
256- int i;
257- char *uevent_params[5];
258- char tmp[SYSFS_PATH_MAX];
259- FILE *fp;
260- char line[1024];
261- char *uevent, *saveptr;
262- const char *devpath = sysfs_path + 4;
263-
264-#if DEBUG_USB_BOOTSTRAP
265- LOG_VOL("usb_bootstrap_sdx_partition(%s):", devpath);
266-#endif
267-
268- if (!read_sysfs_var(line, sizeof(line), devpath, "uevent")) {
269- LOGE("Unable to open '%s/%s' (%s)", sysfs_path, "uevent", strerror(errno));
270- return -errno;
271- }
272- sprintf(tmp, "DEVPATH=%s", devpath);
273- uevent_params[0] = tmp;
274- for (i = 1, uevent = line; i < 4; ++i, uevent = NULL)
275- if (!(uevent_params[i] = strtok_r(uevent, "\n", &saveptr)))
276- break;
277- uevent_params[i] = NULL;
278-
279- if (simulate_uevent("block", tmp + 8, "add", uevent_params) < 0) {
280- LOGE("Error simulating uevent (%s)", strerror(errno));
281- return -errno;
282- }
283- return 0;
256+ return simulate_add_device("block", sysfs_path + 4);
284257 }
--- a/vold/vold.c
+++ b/vold/vold.c
@@ -123,10 +123,14 @@ int main(int argc, char **argv)
123123 // Switch
124124 switch_bootstrap();
125125
126+ // Rfkill interfaces
127+ rfkill_bootstrap();
128+
126129 bootstrap = 0;
127130
128- //USB drive
131+ // USB drive
129132 usb_bootstrap();
133+
130134 /*
131135 * Main loop
132136 */
--- a/vold/vold.h
+++ b/vold/vold.h
@@ -81,7 +81,8 @@ int process_inotify_event(int fd);
8181 int inotify_bootstrap(void);
8282
8383 int process_uevent_message(int socket);
84-int simulate_uevent(char *subsystem, char *path, char *action, char **params);
84+int simulate_uevent(const char *subsys, const char *path, const char *action, char **params);
85+int simulate_add_device(const char *subsys, const char *path);
8586
8687 int mmc_bootstrap(void);
8788 int usb_bootstrap(void);
@@ -91,6 +92,8 @@ int volmgr_bootstrap(void);
9192
9293 int switch_bootstrap(void);
9394
95+int rfkill_bootstrap(void);
96+
9497 void *read_file(char *filename, ssize_t *_size);
9598 char *truncate_sysfs_path(char *path, int num_elements_to_remove, char *buffer, int buffer_size);
9699 char *read_sysfs_var(char *buffer, size_t maxlen, const char *devpath, const char *var);
--- a/vold/volmgr.c
+++ b/vold/volmgr.c
@@ -101,6 +101,7 @@ static boolean _check_mounted(const char *mp, int idx)
101101 char rest[256];
102102 FILE *fp;
103103 char line[1024];
104+ const char *devname;
104105 boolean ret = false;
105106
106107 if (mp == NULL)
@@ -113,18 +114,17 @@ static boolean _check_mounted(const char *mp, int idx)
113114
114115 while (fgets(line, sizeof(line), fp)) {
115116 sscanf(line, "%255s %255s %255s\n", device, mount_path, rest);
116- if (idx == 1) {
117- char *devname = strrchr(device, '/');
118- if (!devname || strcmp(++devname, mp))
119- continue;
120- } else if (idx == 2) {
121- if (strcmp(mount_path, mp))
122- continue;
123- }
117+ if (idx == 1)
118+ ret = (devname = strrchr(device, '/')) && !strcmp(++devname, mp);
119+ else if (idx == 2)
120+ ret = !strcmp(mount_path, mp);
121+ else
122+ break;
124123
125- LOGI("%s is already mounted", mp);
126- ret = true;
127- break;
124+ if (ret) {
125+ LOGI("%s is already mounted", mp);
126+ break;
127+ }
128128 }
129129
130130 fclose(fp);
Show on old repository browser