Skip to content

Commit 1a7408c

Browse files
digit-androidmikeandroid
authored andcommitted
UsbService: Remove stack-trace message during boot. DO NOT MERGE
This removes a stack trace message during the boot under emulation. The observers tried to access a null reference when no USB configuration is supported by the emulated device. So do not start them in this case. + Change a Slog.w into a Slog.i since this is an acceptable condition. Change-Id: I801f352574716d7868f182bb6e5ee49e5b12e4f1
1 parent f13ec7a commit 1a7408c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

services/java/com/android/server/UsbService.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,17 @@ public UsbService(Context context) {
134134
mContext = context;
135135
init(); // set initial status
136136

137-
mUEventObserver.startObserving(USB_CONNECTED_MATCH);
138-
mUEventObserver.startObserving(USB_CONFIGURATION_MATCH);
139-
mUEventObserver.startObserving(USB_FUNCTIONS_MATCH);
137+
if (mConfiguration >= 0) {
138+
mUEventObserver.startObserving(USB_CONNECTED_MATCH);
139+
mUEventObserver.startObserving(USB_CONFIGURATION_MATCH);
140+
mUEventObserver.startObserving(USB_FUNCTIONS_MATCH);
141+
}
140142
}
141143

142144
private final void init() {
143145
char[] buffer = new char[1024];
144146

147+
mConfiguration = -1;
145148
try {
146149
FileReader file = new FileReader(USB_CONNECTED_PATH);
147150
int len = file.read(buffer, 0, 1024);
@@ -153,10 +156,12 @@ private final void init() {
153156
file.close();
154157
mConfiguration = Integer.valueOf((new String(buffer, 0, len)).trim());
155158
} catch (FileNotFoundException e) {
156-
Slog.w(TAG, "This kernel does not have USB configuration switch support");
159+
Slog.i(TAG, "This kernel does not have USB configuration switch support");
157160
} catch (Exception e) {
158161
Slog.e(TAG, "" , e);
159162
}
163+
if (mConfiguration < 0)
164+
return;
160165

161166
try {
162167
File[] files = new File(USB_COMPOSITE_CLASS_PATH).listFiles();

0 commit comments

Comments
 (0)