Permalink
Browse files

Instead of using a property to get the tethering state, use the real USB

state.

Change-Id: I4c4f70b3974fcd6fa93a4cbfe54be3dd7a942245
  • Loading branch information...
1 parent 039e474 commit a66a295c48267ac702677e36de2b607b38f7520d @maniac103 maniac103 committed with Aug 22, 2011
Showing with 26 additions and 10 deletions.
  1. +21 −10 UsbController.cpp
  2. +5 −0 overlay/packages/apps/Usb/res/values/config.xml
View
@@ -15,11 +15,12 @@
*/
#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
#define LOG_NDEBUG 0
#define LOG_TAG "UsbController"
#include <cutils/log.h>
-#include <cutils/properties.h>
#include "UsbController.h"
@@ -41,22 +42,32 @@ int UsbController::stopRNDIS() {
}
int UsbController::enableRNDIS(bool enable) {
- const char *state = enable ? "1" : "0";
char buffer[128];
- property_set("sys.usb.tethered", state);
snprintf(buffer, sizeof(buffer),
- "/system/bin/am broadcast -a com.motorola.intent.action.USB_TETHERING_TOGGLED --ei state %s",
- state);
+ "/system/bin/am broadcast -a com.motorola.intent.action.USB_TETHERING_TOGGLED --ei state %d",
+ enable ? 1 : 0);
system(buffer);
return 0;
}
bool UsbController::isRNDISStarted() {
- char value[PROPERTY_VALUE_MAX];
- if (property_get("sys.usb.tethered", value, "0") <= 0) {
- return false;
+ bool rndisActive = false;
+ FILE *stateFile = fopen("/tmp/usbd_current_state", "r");
+
+ if (stateFile != NULL) {
+ char buffer[128];
+
+ memset(buffer, 0, sizeof(buffer));
+ if (fread(buffer, 1, sizeof(buffer), stateFile) > 0) {
+ LOGD("Got USBD state %s", buffer);
+ rndisActive = strstr(buffer, "rndis") != NULL;
+ } else {
+ LOGD("Could not read USBD state file (errno %d)", errno);
+ }
+
+ fclose(stateFile);
}
- LOGD("Tethering state: %s", value);
- return atoi(value) != 0;
+
+ return rndisActive;
}
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources>
+ <!-- If the currently active USB state should be written to a file, put file name here -->
+ <string name="current_usb_state_file_name" translatable="false">/tmp/usbd_current_state</string>
+</resources>

0 comments on commit a66a295

Please sign in to comment.