OSDN Git Service

TIF: fix NPE at onHdmiDeviceUpdated()
authorWonsik Kim <wonsik@google.com>
Wed, 8 Oct 2014 04:05:56 +0000 (13:05 +0900)
committerWonsik Kim <wonsik@google.com>
Wed, 8 Oct 2014 07:06:38 +0000 (16:06 +0900)
The input ID of HDMI input may not be initialized at the time
HdmiDeviceEventListener.onStatusChanged() is called. Retrieve the
input ID at the time of operation instead.

Bug: 17887925
Change-Id: I7517247294a4467feb334170b19ce2a7987dc495

services/core/java/com/android/server/tv/TvInputHardwareManager.java

index 48ac228..7d72a2e 100644 (file)
@@ -914,11 +914,18 @@ class TvInputHardwareManager implements TvInputHal.Callback {
                     break;
                 }
                 case HDMI_DEVICE_UPDATED: {
-                    SomeArgs args = (SomeArgs) msg.obj;
-                    String inputId = (String) args.arg1;
-                    HdmiDeviceInfo info = (HdmiDeviceInfo) args.arg2;
-                    args.recycle();
-                    mListener.onHdmiDeviceUpdated(inputId, info);
+                    HdmiDeviceInfo info = (HdmiDeviceInfo) msg.obj;
+                    String inputId = null;
+                    synchronized (mLock) {
+                        inputId = mHdmiInputIdMap.get(info.getId());
+                    }
+                    if (inputId != null) {
+                        mListener.onHdmiDeviceUpdated(inputId, info);
+                    } else {
+                        Slog.w(TAG, "Could not resolve input ID matching the device info; "
+                                + "ignoring.");
+                    }
+                    break;
                 }
                 default: {
                     Slog.w(TAG, "Unhandled message: " + msg);
@@ -986,11 +993,7 @@ class TvInputHardwareManager implements TvInputHal.Callback {
                         }
                         mHdmiDeviceList.add(deviceInfo);
                         messageType = ListenerHandler.HDMI_DEVICE_UPDATED;
-                        String inputId = mHdmiInputIdMap.get(deviceInfo.getId());
-                        SomeArgs args = SomeArgs.obtain();
-                        args.arg1 = inputId;
-                        args.arg2 = deviceInfo;
-                        obj = args;
+                        obj = deviceInfo;
                         break;
                     }
                 }