diff options
-rw-r--r-- | api/current.xml | 4 | ||||
-rw-r--r-- | core/java/android/os/DropBoxManager.java | 21 | ||||
-rw-r--r-- | services/java/com/android/server/BootReceiver.java | 7 | ||||
-rw-r--r-- | tests/AndroidTests/src/com/android/unit_tests/DropBoxTest.java | 24 |
4 files changed, 23 insertions, 33 deletions
diff --git a/api/current.xml b/api/current.xml index 12c2eee..ef8f78f 100644 --- a/api/current.xml +++ b/api/current.xml @@ -102263,10 +102263,12 @@ > <parameter name="tag" type="java.lang.String"> </parameter> -<parameter name="fd" type="android.os.ParcelFileDescriptor"> +<parameter name="file" type="java.io.File"> </parameter> <parameter name="flags" type="int"> </parameter> +<exception name="IOException" type="java.io.IOException"> +</exception> </method> <method name="addText" return="void" diff --git a/core/java/android/os/DropBoxManager.java b/core/java/android/os/DropBoxManager.java index 7827676..7889a92 100644 --- a/core/java/android/os/DropBoxManager.java +++ b/core/java/android/os/DropBoxManager.java @@ -230,17 +230,24 @@ public class DropBoxManager { } /** - * Stores data read from a file descriptor. The data may be ignored or - * discarded as with {@link #addText}. You must close your - * ParcelFileDescriptor object after calling this method! + * Stores the contents of a file, which may be ignored or discarded as with + * {@link #addText}. * * @param tag describing the type of entry being stored - * @param fd file descriptor to read from + * @param file to read from * @param flags describing the data + * @throws IOException if the file can't be opened */ - public void addFile(String tag, ParcelFileDescriptor fd, int flags) { - if (fd == null) throw new NullPointerException(); - try { mService.add(new Entry(tag, 0, fd, flags)); } catch (RemoteException e) {} + public void addFile(String tag, File file, int flags) throws IOException { + if (file == null) throw new NullPointerException(); + Entry entry = new Entry(tag, 0, file, flags); + try { + mService.add(new Entry(tag, 0, file, flags)); + } catch (RemoteException e) { + // ignore + } finally { + entry.close(); + } } /** diff --git a/services/java/com/android/server/BootReceiver.java b/services/java/com/android/server/BootReceiver.java index 565e50b..84f0068 100644 --- a/services/java/com/android/server/BootReceiver.java +++ b/services/java/com/android/server/BootReceiver.java @@ -23,7 +23,6 @@ import android.content.Intent; import android.os.Build; import android.os.DropBoxManager; import android.os.FileUtils; -import android.os.ParcelFileDescriptor; import android.os.SystemProperties; import android.provider.Settings; import android.util.Log; @@ -100,10 +99,6 @@ public class BootReceiver extends BroadcastReceiver { String setting = "logfile:" + filename; long lastTime = Settings.Secure.getLong(cr, setting, 0); if (lastTime == fileTime) return; // Already logged this particular file - - ParcelFileDescriptor pfd = - ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); - db.addFile(tag, pfd, DropBoxManager.IS_TEXT); - pfd.close(); + db.addFile(tag, file, DropBoxManager.IS_TEXT); } } diff --git a/tests/AndroidTests/src/com/android/unit_tests/DropBoxTest.java b/tests/AndroidTests/src/com/android/unit_tests/DropBoxTest.java index a0d096e..305788d 100644 --- a/tests/AndroidTests/src/com/android/unit_tests/DropBoxTest.java +++ b/tests/AndroidTests/src/com/android/unit_tests/DropBoxTest.java @@ -20,7 +20,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.DropBoxManager; -import android.os.ParcelFileDescriptor; import android.os.ServiceManager; import android.os.StatFs; import android.provider.Settings; @@ -126,22 +125,11 @@ public class DropBoxTest extends AndroidTestCase { DropBoxManager dropbox = (DropBoxManager) getContext().getSystemService( Context.DROPBOX_SERVICE); - int mode = ParcelFileDescriptor.MODE_READ_ONLY; - ParcelFileDescriptor pfd0 = ParcelFileDescriptor.open(f0, mode); - ParcelFileDescriptor pfd1 = ParcelFileDescriptor.open(f1, mode); - ParcelFileDescriptor pfd2 = ParcelFileDescriptor.open(f2, mode); - ParcelFileDescriptor pfd3 = ParcelFileDescriptor.open(f3, mode); - - dropbox.addFile("DropBoxTest", pfd0, DropBoxManager.IS_TEXT); - dropbox.addFile("DropBoxTest", pfd1, DropBoxManager.IS_TEXT | DropBoxManager.IS_GZIPPED); - dropbox.addFile("DropBoxTest", pfd2, 0); - dropbox.addFile("DropBoxTest", pfd3, DropBoxManager.IS_GZIPPED); - - pfd0.close(); - pfd1.close(); - pfd2.close(); - pfd3.close(); + dropbox.addFile("DropBoxTest", f0, DropBoxManager.IS_TEXT); + dropbox.addFile("DropBoxTest", f1, DropBoxManager.IS_TEXT | DropBoxManager.IS_GZIPPED); + dropbox.addFile("DropBoxTest", f2, 0); + dropbox.addFile("DropBoxTest", f3, DropBoxManager.IS_GZIPPED); DropBoxManager.Entry e0 = dropbox.getNextEntry("DropBoxTest", before); DropBoxManager.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis()); @@ -506,9 +494,7 @@ public class DropBoxTest extends AndroidTestCase { os.write(bytes); os.close(); - ParcelFileDescriptor fd = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY); - dropbox.addFile(tag, fd, 0); - fd.close(); + dropbox.addFile(tag, f, 0); } private int getEntrySize(DropBoxManager.Entry e) throws Exception { |