OSDN Git Service

Fix null pointer exception in DocumentLoader.
authorDaichi Hirono <hirono@google.com>
Fri, 4 Mar 2016 09:43:21 +0000 (18:43 +0900)
committerDaichi Hirono <hirono@google.com>
Mon, 7 Mar 2016 10:41:10 +0000 (19:41 +0900)
BUG=27489909

Change-Id: I1ebc9953f6db6639241d0c46257d110c5b0eb5b0

packages/MtpDocumentsProvider/src/com/android/mtp/DocumentLoader.java
packages/MtpDocumentsProvider/src/com/android/mtp/MtpManager.java
packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDocumentsProviderTest.java
packages/MtpDocumentsProvider/tests/src/com/android/mtp/TestMtpManager.java

index 044a061..0705214 100644 (file)
@@ -276,7 +276,7 @@ class DocumentLoader implements AutoCloseable {
         static final int STATE_ERROR = 2;
 
         final MtpDatabase mDatabase;
-        int[] mOperationsSupported;
+        final int[] mOperationsSupported;
         final Identifier mIdentifier;
         final int[] mObjectHandles;
         Date mLastNotified;
@@ -285,6 +285,8 @@ class DocumentLoader implements AutoCloseable {
 
         LoaderTask(MtpDatabase database, int[] operationsSupported, Identifier identifier,
                 int[] objectHandles) {
+            Preconditions.checkNotNull(operationsSupported);
+            Preconditions.checkNotNull(objectHandles);
             mDatabase = database;
             mOperationsSupported = operationsSupported;
             mIdentifier = identifier;
index 1966e61..0202343 100644 (file)
@@ -143,7 +143,12 @@ class MtpManager {
             throws IOException {
         final MtpDevice device = getDevice(deviceId);
         synchronized (device) {
-            return device.getObjectHandles(storageId, 0 /* all format */, parentObjectHandle);
+            final int[] handles =
+                    device.getObjectHandles(storageId, 0 /* all format */, parentObjectHandle);
+            if (handles == null) {
+                throw new IOException("Failed to fetch object handles.");
+            }
+            return handles;
         }
     }
 
index 3dfa4ad..d6ad0f3 100644 (file)
@@ -596,7 +596,7 @@ public class MtpDocumentsProviderTest extends AndroidTestCase {
                 0,
                 "Device A",
                 "device key",
-                true /* unopened */,
+                true /* opened */,
                 new MtpRoot[] {
                     new MtpRoot(
                             0 /* deviceId */,
@@ -606,7 +606,7 @@ public class MtpDocumentsProviderTest extends AndroidTestCase {
                             2048 /* total space */,
                             "" /* no volume identifier */)
                 },
-                null,
+                OPERATIONS_SUPPORTED,
                 null));
 
         final String[] names = strings("Directory A", "Directory B", "Directory C");
index 5e0ee1e..5171bd2 100644 (file)
@@ -106,7 +106,7 @@ public class TestMtpManager extends MtpManager {
         mDevices.put(
                 deviceId,
                 new MtpDeviceRecord(device.deviceId, device.name, device.deviceKey, false,
-                        device.roots, null, null));
+                        device.roots, device.operationsSupported, device.eventsSupported));
     }
 
     @Override