@@ -66,7 +66,7 @@ public UEventInfo(String devName, int state1Bits, int state2Bits) {
6666 public String getDevName () { return mDevName ; }
6767
6868 public String getDevPath () {
69- return String .format ("DEVPATH= /devices/virtual/switch/%s" , mDevName );
69+ return String .format ("/devices/virtual/switch/%s" , mDevName );
7070 }
7171
7272 public String getSwitchStatePath () {
@@ -158,7 +158,7 @@ public void onReceive(Context context, Intent intent) {
158158 init (); // set initial status
159159 for (int i = 0 ; i < uEventInfo .size (); ++i ) {
160160 UEventInfo uei = uEventInfo .get (i );
161- startObserving (uei .getDevPath ());
161+ startObserving ("DEVPATH=" + uei .getDevPath ());
162162 }
163163 }
164164 }
@@ -168,29 +168,20 @@ public void onUEvent(UEventObserver.UEvent event) {
168168 if (LOG ) Slog .v (TAG , "Headset UEVENT: " + event .toString ());
169169
170170 try {
171+ String devPath = event .get ("DEVPATH" );
171172 String name = event .get ("SWITCH_NAME" );
172173 int state = Integer .parseInt (event .get ("SWITCH_STATE" ));
173- updateState (name , state );
174+ updateState (devPath , name , state );
174175 } catch (NumberFormatException e ) {
175176 Slog .e (TAG , "Could not parse switch state from event " + event );
176177 }
177178 }
178179
179- private synchronized final void updateState (String name , int state )
180+ private synchronized final void updateState (String devPath , String name , int state )
180181 {
181- // FIXME: When ueventd informs of a change in state for a switch, it does not have to be
182- // the case that the name reported by /sys/class/switch/<device>/name is the same as
183- // <device>. For normal users of the linux switch class driver, it will be. But it is
184- // technically possible to hook the print_name method in the class driver and return a
185- // different name each and every time the name sysfs entry is queried.
186- //
187- // Right now this is not the case for any of the switch implementations used here. I'm not
188- // certain anyone would ever choose to implement such a dynamic name, or what it would mean
189- // for the implementation at this level, but if it ever happens, we will need to revisit
190- // this code.
191182 for (int i = 0 ; i < uEventInfo .size (); ++i ) {
192183 UEventInfo uei = uEventInfo .get (i );
193- if (name .equals (uei .getDevName ())) {
184+ if (devPath .equals (uei .getDevPath ())) {
194185 update (name , uei .computeNewHeadsetState (mHeadsetState , state ));
195186 return ;
196187 }
@@ -213,7 +204,7 @@ private synchronized final void init() {
213204 curState = Integer .valueOf ((new String (buffer , 0 , len )).trim ());
214205
215206 if (curState > 0 ) {
216- updateState (uei .getDevName (), curState );
207+ updateState (uei .getDevPath (), uei . getDevName (), curState );
217208 }
218209
219210 } catch (FileNotFoundException e ) {
0 commit comments