Change the DropBoxManager API slightly (this is public, but not yet released) --
take a File instead of a ParcelFileDescriptor (gets opened internally) -- that way the caller doesn't have to worry about closing their PFD and so on. (Pretty much 100% of the time the caller will be uploading a file, anyway.)
This commit is contained in:
@ -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"
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user