Instead of a raw AIDL interface, give DropBox a Java
interface (android.os.DropBox); move the Binder interface behind the scenes. Make DropBoxEntry into DropBox.Entry. Make it possible to get a dropbox from an (Application)Context with the usual getSystemService(DROPBOX_SERVICE) type thing. Update the tests accordingly.
This commit is contained in:
@ -108,7 +108,6 @@ LOCAL_SRC_FILES += \
|
|||||||
core/java/android/hardware/ISensorService.aidl \
|
core/java/android/hardware/ISensorService.aidl \
|
||||||
core/java/android/net/IConnectivityManager.aidl \
|
core/java/android/net/IConnectivityManager.aidl \
|
||||||
core/java/android/os/ICheckinService.aidl \
|
core/java/android/os/ICheckinService.aidl \
|
||||||
core/java/android/os/IDropBox.aidl \
|
|
||||||
core/java/android/os/IHardwareService.aidl \
|
core/java/android/os/IHardwareService.aidl \
|
||||||
core/java/android/os/IMessenger.aidl \
|
core/java/android/os/IMessenger.aidl \
|
||||||
core/java/android/os/IMountService.aidl \
|
core/java/android/os/IMountService.aidl \
|
||||||
@ -137,6 +136,7 @@ LOCAL_SRC_FILES += \
|
|||||||
core/java/com/android/internal/appwidget/IAppWidgetService.aidl \
|
core/java/com/android/internal/appwidget/IAppWidgetService.aidl \
|
||||||
core/java/com/android/internal/appwidget/IAppWidgetHost.aidl \
|
core/java/com/android/internal/appwidget/IAppWidgetHost.aidl \
|
||||||
core/java/com/android/internal/backup/IBackupTransport.aidl \
|
core/java/com/android/internal/backup/IBackupTransport.aidl \
|
||||||
|
core/java/com/android/internal/os/IDropBoxService.aidl \
|
||||||
core/java/com/android/internal/os/IResultReceiver.aidl \
|
core/java/com/android/internal/os/IResultReceiver.aidl \
|
||||||
core/java/com/android/internal/view/IInputContext.aidl \
|
core/java/com/android/internal/view/IInputContext.aidl \
|
||||||
core/java/com/android/internal/view/IInputContextCallback.aidl \
|
core/java/com/android/internal/view/IInputContextCallback.aidl \
|
||||||
@ -217,7 +217,7 @@ aidl_files := \
|
|||||||
frameworks/base/core/java/android/appwidget/AppWidgetProviderInfo.aidl \
|
frameworks/base/core/java/android/appwidget/AppWidgetProviderInfo.aidl \
|
||||||
frameworks/base/core/java/android/net/Uri.aidl \
|
frameworks/base/core/java/android/net/Uri.aidl \
|
||||||
frameworks/base/core/java/android/os/Bundle.aidl \
|
frameworks/base/core/java/android/os/Bundle.aidl \
|
||||||
frameworks/base/core/java/android/os/DropBoxEntry.aidl \
|
frameworks/base/core/java/android/os/DropBox.aidl \
|
||||||
frameworks/base/core/java/android/os/ParcelFileDescriptor.aidl \
|
frameworks/base/core/java/android/os/ParcelFileDescriptor.aidl \
|
||||||
frameworks/base/core/java/android/os/ParcelUuid.aidl \
|
frameworks/base/core/java/android/os/ParcelUuid.aidl \
|
||||||
frameworks/base/core/java/android/view/KeyEvent.aidl \
|
frameworks/base/core/java/android/view/KeyEvent.aidl \
|
||||||
|
@ -70,6 +70,7 @@ import android.net.wifi.IWifiManager;
|
|||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.DropBox;
|
||||||
import android.os.FileUtils;
|
import android.os.FileUtils;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@ -93,6 +94,8 @@ import android.view.inputmethod.InputMethodManager;
|
|||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.accounts.IAccountManager;
|
import android.accounts.IAccountManager;
|
||||||
|
|
||||||
|
import com.android.internal.os.IDropBoxService;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -182,6 +185,7 @@ class ApplicationContext extends Context {
|
|||||||
private ClipboardManager mClipboardManager = null;
|
private ClipboardManager mClipboardManager = null;
|
||||||
private boolean mRestricted;
|
private boolean mRestricted;
|
||||||
private AccountManager mAccountManager; // protected by mSync
|
private AccountManager mAccountManager; // protected by mSync
|
||||||
|
private DropBox mDropBox = null;
|
||||||
|
|
||||||
private final Object mSync = new Object();
|
private final Object mSync = new Object();
|
||||||
|
|
||||||
@ -896,6 +900,8 @@ class ApplicationContext extends Context {
|
|||||||
return getClipboardManager();
|
return getClipboardManager();
|
||||||
} else if (WALLPAPER_SERVICE.equals(name)) {
|
} else if (WALLPAPER_SERVICE.equals(name)) {
|
||||||
return getWallpaperManager();
|
return getWallpaperManager();
|
||||||
|
} else if (DROPBOX_SERVICE.equals(name)) {
|
||||||
|
return getDropBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -1045,7 +1051,7 @@ class ApplicationContext extends Context {
|
|||||||
}
|
}
|
||||||
return mVibrator;
|
return mVibrator;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AudioManager getAudioManager()
|
private AudioManager getAudioManager()
|
||||||
{
|
{
|
||||||
if (mAudioManager == null) {
|
if (mAudioManager == null) {
|
||||||
@ -1054,6 +1060,17 @@ class ApplicationContext extends Context {
|
|||||||
return mAudioManager;
|
return mAudioManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DropBox getDropBox() {
|
||||||
|
synchronized (mSync) {
|
||||||
|
if (mDropBox == null) {
|
||||||
|
IBinder b = ServiceManager.getService(DROPBOX_SERVICE);
|
||||||
|
IDropBoxService service = IDropBoxService.Stub.asInterface(b);
|
||||||
|
mDropBox = new DropBox(service);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mDropBox;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int checkPermission(String permission, int pid, int uid) {
|
public int checkPermission(String permission, int pid, int uid) {
|
||||||
if (permission == null) {
|
if (permission == null) {
|
||||||
|
@ -1309,7 +1309,7 @@ public abstract class Context {
|
|||||||
* @see #getSystemService
|
* @see #getSystemService
|
||||||
*/
|
*/
|
||||||
public static final String APPWIDGET_SERVICE = "appwidget";
|
public static final String APPWIDGET_SERVICE = "appwidget";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use with {@link #getSystemService} to retrieve an
|
* Use with {@link #getSystemService} to retrieve an
|
||||||
* {@blink android.backup.IBackupManager IBackupManager} for communicating
|
* {@blink android.backup.IBackupManager IBackupManager} for communicating
|
||||||
@ -1319,7 +1319,16 @@ public abstract class Context {
|
|||||||
* @see #getSystemService
|
* @see #getSystemService
|
||||||
*/
|
*/
|
||||||
public static final String BACKUP_SERVICE = "backup";
|
public static final String BACKUP_SERVICE = "backup";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use with {@link #getSystemService} to retrieve a
|
||||||
|
* {@blink android.os.DropBox DropBox} instance for recording
|
||||||
|
* diagnostic logs.
|
||||||
|
* @hide
|
||||||
|
* @see #getSystemService
|
||||||
|
*/
|
||||||
|
public static final String DROPBOX_SERVICE = "dropbox";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether the given permission is allowed for a particular
|
* Determine whether the given permission is allowed for a particular
|
||||||
* process and user ID running in the system.
|
* process and user ID running in the system.
|
||||||
|
@ -16,4 +16,4 @@
|
|||||||
|
|
||||||
package android.os;
|
package android.os;
|
||||||
|
|
||||||
parcelable DropBoxEntry;
|
parcelable DropBox.Entry;
|
276
core/java/android/os/DropBox.java
Normal file
276
core/java/android/os/DropBox.java
Normal file
@ -0,0 +1,276 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2009 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package android.os;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.internal.os.IDropBoxService;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueues chunks of data (from various sources -- application crashes, kernel
|
||||||
|
* log records, etc.). The queue is size bounded and will drop old data if the
|
||||||
|
* enqueued data exceeds the maximum size. You can think of this as a
|
||||||
|
* persistent, system-wide, blob-oriented "logcat".
|
||||||
|
*
|
||||||
|
* <p>You can obtain an instance of this class by calling
|
||||||
|
* {@link android.content.Context#getSystemService}
|
||||||
|
* with {@link android.content.Context#DROPBOX_SERVICE}.
|
||||||
|
*
|
||||||
|
* <p>DropBox entries are not sent anywhere directly, but other system services
|
||||||
|
* and debugging tools may scan and upload entries for processing.
|
||||||
|
*
|
||||||
|
* {@pending}
|
||||||
|
*/
|
||||||
|
public class DropBox {
|
||||||
|
private static final String TAG = "DropBox";
|
||||||
|
private final IDropBoxService mService;
|
||||||
|
|
||||||
|
/** Flag value: Entry's content was deleted to save space. */
|
||||||
|
public static final int IS_EMPTY = 1;
|
||||||
|
|
||||||
|
/** Flag value: Content is human-readable UTF-8 text (can be combined with IS_GZIPPED). */
|
||||||
|
public static final int IS_TEXT = 2;
|
||||||
|
|
||||||
|
/** Flag value: Content can be decompressed with {@link GZIPOutputStream}. */
|
||||||
|
public static final int IS_GZIPPED = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A single entry retrieved from the drop box.
|
||||||
|
* This may include a reference to a stream, so you must call
|
||||||
|
* {@link #close()} when you are done using it.
|
||||||
|
*/
|
||||||
|
public static class Entry implements Parcelable {
|
||||||
|
private final String mTag;
|
||||||
|
private final long mTimeMillis;
|
||||||
|
|
||||||
|
private final byte[] mData;
|
||||||
|
private final ParcelFileDescriptor mFileDescriptor;
|
||||||
|
private final int mFlags;
|
||||||
|
|
||||||
|
/** Create a new empty Entry with no contents. */
|
||||||
|
public Entry(String tag, long millis) {
|
||||||
|
this(tag, millis, (Object) null, IS_EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Create a new Entry with plain text contents. */
|
||||||
|
public Entry(String tag, long millis, String text) {
|
||||||
|
this(tag, millis, (Object) text.getBytes(), IS_TEXT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Entry with byte array contents.
|
||||||
|
* The data array must not be modified after creating this entry.
|
||||||
|
*/
|
||||||
|
public Entry(String tag, long millis, byte[] data, int flags) {
|
||||||
|
this(tag, millis, (Object) data, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Entry with streaming data contents.
|
||||||
|
* Takes ownership of the ParcelFileDescriptor.
|
||||||
|
*/
|
||||||
|
public Entry(String tag, long millis, ParcelFileDescriptor data, int flags) {
|
||||||
|
this(tag, millis, (Object) data, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Entry with the contents read from a file.
|
||||||
|
* The file will be read when the entry's contents are requested.
|
||||||
|
*/
|
||||||
|
public Entry(String tag, long millis, File data, int flags) throws IOException {
|
||||||
|
this(tag, millis, (Object) ParcelFileDescriptor.open(
|
||||||
|
data, ParcelFileDescriptor.MODE_READ_ONLY), flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Internal constructor for CREATOR.createFromParcel(). */
|
||||||
|
private Entry(String tag, long millis, Object value, int flags) {
|
||||||
|
if (tag == null) throw new NullPointerException();
|
||||||
|
if (((flags & IS_EMPTY) != 0) != (value == null)) throw new IllegalArgumentException();
|
||||||
|
|
||||||
|
mTag = tag;
|
||||||
|
mTimeMillis = millis;
|
||||||
|
mFlags = flags;
|
||||||
|
|
||||||
|
if (value == null) {
|
||||||
|
mData = null;
|
||||||
|
mFileDescriptor = null;
|
||||||
|
} else if (value instanceof byte[]) {
|
||||||
|
mData = (byte[]) value;
|
||||||
|
mFileDescriptor = null;
|
||||||
|
} else if (value instanceof ParcelFileDescriptor) {
|
||||||
|
mData = null;
|
||||||
|
mFileDescriptor = (ParcelFileDescriptor) value;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Close the input stream associated with this entry. */
|
||||||
|
public void close() {
|
||||||
|
try { if (mFileDescriptor != null) mFileDescriptor.close(); } catch (IOException e) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the tag originally attached to the entry. */
|
||||||
|
public String getTag() { return mTag; }
|
||||||
|
|
||||||
|
/** @return time when the entry was originally created. */
|
||||||
|
public long getTimeMillis() { return mTimeMillis; }
|
||||||
|
|
||||||
|
/** @return flags describing the content returned by @{link #getInputStream()}. */
|
||||||
|
public int getFlags() { return mFlags & ~IS_GZIPPED; } // getInputStream() decompresses.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param maxBytes of string to return (will truncate at this length).
|
||||||
|
* @return the uncompressed text contents of the entry, null if the entry is not text.
|
||||||
|
*/
|
||||||
|
public String getText(int maxBytes) {
|
||||||
|
if ((mFlags & IS_TEXT) == 0) return null;
|
||||||
|
if (mData != null) return new String(mData, 0, Math.min(maxBytes, mData.length));
|
||||||
|
|
||||||
|
InputStream is = null;
|
||||||
|
try {
|
||||||
|
is = getInputStream();
|
||||||
|
byte[] buf = new byte[maxBytes];
|
||||||
|
return new String(buf, 0, Math.max(0, is.read(buf)));
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
try { if (is != null) is.close(); } catch (IOException e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the uncompressed contents of the entry, or null if the contents were lost */
|
||||||
|
public InputStream getInputStream() throws IOException {
|
||||||
|
InputStream is;
|
||||||
|
if (mData != null) {
|
||||||
|
is = new ByteArrayInputStream(mData);
|
||||||
|
} else if (mFileDescriptor != null) {
|
||||||
|
is = new ParcelFileDescriptor.AutoCloseInputStream(mFileDescriptor);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (mFlags & IS_GZIPPED) != 0 ? new GZIPInputStream(is) : is;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<Entry> CREATOR = new Parcelable.Creator() {
|
||||||
|
public Entry[] newArray(int size) { return new Entry[size]; }
|
||||||
|
public Entry createFromParcel(Parcel in) {
|
||||||
|
return new Entry(
|
||||||
|
in.readString(), in.readLong(), in.readValue(null), in.readInt());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public int describeContents() {
|
||||||
|
return mFileDescriptor != null ? Parcelable.CONTENTS_FILE_DESCRIPTOR : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeToParcel(Parcel out, int flags) {
|
||||||
|
out.writeString(mTag);
|
||||||
|
out.writeLong(mTimeMillis);
|
||||||
|
if (mFileDescriptor != null) {
|
||||||
|
out.writeValue(mFileDescriptor);
|
||||||
|
} else {
|
||||||
|
out.writeValue(mData);
|
||||||
|
}
|
||||||
|
out.writeInt(mFlags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@hide} */
|
||||||
|
public DropBox(IDropBoxService service) { mService = service; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a dummy instance for testing. All methods will fail unless
|
||||||
|
* overridden with an appropriate mock implementation. To obtain a
|
||||||
|
* functional instance, use {@link android.content.Context#getSystemService}.
|
||||||
|
*/
|
||||||
|
protected DropBox() { mService = null; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores human-readable text. The data may be discarded eventually (or even
|
||||||
|
* immediately) if space is limited, or ignored entirely if the tag has been
|
||||||
|
* blocked (see {@link #isTagEnabled}).
|
||||||
|
*
|
||||||
|
* @param tag describing the type of entry being stored
|
||||||
|
* @param data value to store
|
||||||
|
*/
|
||||||
|
public void addText(String tag, String data) {
|
||||||
|
try { mService.add(new Entry(tag, 0, data)); } catch (RemoteException e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores binary data, which may be ignored or discarded as with {@link #addText}.
|
||||||
|
*
|
||||||
|
* @param tag describing the type of entry being stored
|
||||||
|
* @param data value to store
|
||||||
|
* @param flags describing the data
|
||||||
|
*/
|
||||||
|
public void addData(String tag, byte[] data, int flags) {
|
||||||
|
if (data == null) throw new NullPointerException();
|
||||||
|
try { mService.add(new Entry(tag, 0, data, flags)); } catch (RemoteException e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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!
|
||||||
|
*
|
||||||
|
* @param tag describing the type of entry being stored
|
||||||
|
* @param fd file descriptor to read from
|
||||||
|
* @param flags describing the data
|
||||||
|
*/
|
||||||
|
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) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks any blacklists (set in system settings) to see whether a certain
|
||||||
|
* tag is allowed. Entries with disabled tags will be dropped immediately,
|
||||||
|
* so you can save the work of actually constructing and sending the data.
|
||||||
|
*
|
||||||
|
* @param tag that would be used in {@link #addText} or {@link #addFile}
|
||||||
|
* @return whether events with that tag would be accepted
|
||||||
|
*/
|
||||||
|
public boolean isTagEnabled(String tag) {
|
||||||
|
try { return mService.isTagEnabled(tag); } catch (RemoteException e) { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the next entry from the drop box *after* the specified time.
|
||||||
|
* Requires android.permission.READ_LOGS. You must always call
|
||||||
|
* {@link Entry#close()} on the return value!
|
||||||
|
*
|
||||||
|
* @param tag of entry to look for, null for all tags
|
||||||
|
* @param msec time of the last entry seen
|
||||||
|
* @return the next entry, or null if there are no more entries
|
||||||
|
*/
|
||||||
|
public Entry getNextEntry(String tag, long msec) {
|
||||||
|
try { return mService.getNextEntry(tag, msec); } catch (RemoteException e) { return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: It may be useful to have some sort of notification mechanism
|
||||||
|
// when data is added to the dropbox, for demand-driven readers --
|
||||||
|
// for now readers need to poll the dropbox to find new data.
|
||||||
|
}
|
@ -1,163 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2009 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.os;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A single entry retrieved from an {@link IDropBox} implementation.
|
|
||||||
* This may include a reference to a stream, so you must call
|
|
||||||
* {@link #close()} when you are done using it.
|
|
||||||
*
|
|
||||||
* {@pending}
|
|
||||||
*/
|
|
||||||
public class DropBoxEntry implements Parcelable {
|
|
||||||
private final String mTag;
|
|
||||||
private final long mTimeMillis;
|
|
||||||
|
|
||||||
private final String mText;
|
|
||||||
private final ParcelFileDescriptor mFileDescriptor;
|
|
||||||
private final int mFlags;
|
|
||||||
|
|
||||||
/** Flag value: Entry's content was deleted to save space. */
|
|
||||||
public static final int IS_EMPTY = 1;
|
|
||||||
|
|
||||||
/** Flag value: Content is human-readable UTF-8 text (possibly compressed). */
|
|
||||||
public static final int IS_TEXT = 2;
|
|
||||||
|
|
||||||
/** Flag value: Content can been decompressed with {@link GZIPOutputStream}. */
|
|
||||||
public static final int IS_GZIPPED = 4;
|
|
||||||
|
|
||||||
/** Create a new DropBoxEntry with the specified contents. */
|
|
||||||
public DropBoxEntry(String tag, long timeMillis, String text) {
|
|
||||||
if (tag == null || text == null) throw new NullPointerException();
|
|
||||||
mTag = tag;
|
|
||||||
mTimeMillis = timeMillis;
|
|
||||||
mText = text;
|
|
||||||
mFileDescriptor = null;
|
|
||||||
mFlags = IS_TEXT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Create a new DropBoxEntry with the specified contents. */
|
|
||||||
public DropBoxEntry(String tag, long millis, File data, int flags) throws IOException {
|
|
||||||
if (tag == null) throw new NullPointerException();
|
|
||||||
if (((flags & IS_EMPTY) != 0) != (data == null)) throw new IllegalArgumentException();
|
|
||||||
|
|
||||||
mTag = tag;
|
|
||||||
mTimeMillis = millis;
|
|
||||||
mText = null;
|
|
||||||
mFlags = flags;
|
|
||||||
mFileDescriptor = data == null ? null :
|
|
||||||
ParcelFileDescriptor.open(data, ParcelFileDescriptor.MODE_READ_ONLY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Internal constructor for CREATOR.createFromParcel(). */
|
|
||||||
private DropBoxEntry(String tag, long millis, Object value, int flags) {
|
|
||||||
if (tag == null) throw new NullPointerException();
|
|
||||||
if (((flags & IS_EMPTY) != 0) != (value == null)) throw new IllegalArgumentException();
|
|
||||||
|
|
||||||
mTag = tag;
|
|
||||||
mTimeMillis = millis;
|
|
||||||
mFlags = flags;
|
|
||||||
|
|
||||||
if (value == null) {
|
|
||||||
mText = null;
|
|
||||||
mFileDescriptor = null;
|
|
||||||
} else if (value instanceof String) {
|
|
||||||
if ((flags & IS_TEXT) == 0) throw new IllegalArgumentException();
|
|
||||||
mText = (String) value;
|
|
||||||
mFileDescriptor = null;
|
|
||||||
} else if (value instanceof ParcelFileDescriptor) {
|
|
||||||
mText = null;
|
|
||||||
mFileDescriptor = (ParcelFileDescriptor) value;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Close the input stream associated with this entry. */
|
|
||||||
public synchronized void close() {
|
|
||||||
try { if (mFileDescriptor != null) mFileDescriptor.close(); } catch (IOException e) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return the tag originally attached to the entry. */
|
|
||||||
public String getTag() { return mTag; }
|
|
||||||
|
|
||||||
/** @return time when the entry was originally created. */
|
|
||||||
public long getTimeMillis() { return mTimeMillis; }
|
|
||||||
|
|
||||||
/** @return flags describing the content returned by @{link #getInputStream()}. */
|
|
||||||
public int getFlags() { return mFlags & ~IS_GZIPPED; } // getInputStream() decompresses.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param maxLength of string to return (will truncate at this length).
|
|
||||||
* @return the uncompressed text contents of the entry, null if the entry is not text.
|
|
||||||
*/
|
|
||||||
public String getText(int maxLength) {
|
|
||||||
if (mText != null) return mText.substring(0, Math.min(maxLength, mText.length()));
|
|
||||||
if ((mFlags & IS_TEXT) == 0) return null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
InputStream stream = getInputStream();
|
|
||||||
if (stream == null) return null;
|
|
||||||
char[] buf = new char[maxLength];
|
|
||||||
InputStreamReader reader = new InputStreamReader(stream);
|
|
||||||
return new String(buf, 0, Math.max(0, reader.read(buf)));
|
|
||||||
} catch (IOException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return the uncompressed contents of the entry, or null if the contents were lost */
|
|
||||||
public InputStream getInputStream() throws IOException {
|
|
||||||
if (mText != null) return new ByteArrayInputStream(mText.getBytes("UTF8"));
|
|
||||||
if (mFileDescriptor == null) return null;
|
|
||||||
InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(mFileDescriptor);
|
|
||||||
return (mFlags & IS_GZIPPED) != 0 ? new GZIPInputStream(is) : is;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Parcelable.Creator<DropBoxEntry> CREATOR = new Parcelable.Creator() {
|
|
||||||
public DropBoxEntry[] newArray(int size) { return new DropBoxEntry[size]; }
|
|
||||||
public DropBoxEntry createFromParcel(Parcel in) {
|
|
||||||
return new DropBoxEntry(
|
|
||||||
in.readString(), in.readLong(), in.readValue(null), in.readInt());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public int describeContents() {
|
|
||||||
return mFileDescriptor != null ? Parcelable.CONTENTS_FILE_DESCRIPTOR : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeToParcel(Parcel out, int flags) {
|
|
||||||
out.writeString(mTag);
|
|
||||||
out.writeLong(mTimeMillis);
|
|
||||||
if (mFileDescriptor != null) {
|
|
||||||
out.writeValue(mFileDescriptor);
|
|
||||||
} else {
|
|
||||||
out.writeValue(mText);
|
|
||||||
}
|
|
||||||
out.writeInt(mFlags);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2009 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.os;
|
|
||||||
|
|
||||||
import android.os.DropBoxEntry;
|
|
||||||
import android.os.ParcelFileDescriptor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enqueues chunks of data (from various sources -- application crashes, kernel
|
|
||||||
* log records, etc.). The queue is size bounded and will drop old data if the
|
|
||||||
* enqueued data exceeds the maximum size.
|
|
||||||
*
|
|
||||||
* <p>This interface is implemented by a system service you can access:
|
|
||||||
*
|
|
||||||
* <pre>IDropBox.Stub.asInterface(ServiceManager.getService("dropbox"));</pre>
|
|
||||||
*
|
|
||||||
* <p>Other system services and debugging tools may scan the drop box to upload
|
|
||||||
* entries for processing.
|
|
||||||
*
|
|
||||||
* {@pending}
|
|
||||||
*/
|
|
||||||
interface IDropBox {
|
|
||||||
/**
|
|
||||||
* Stores human-readable text. The data may be discarded eventually (or even
|
|
||||||
* immediately) if space is limited, or ignored entirely if the tag has been
|
|
||||||
* blocked (see {@link #isTagEnabled}).
|
|
||||||
*
|
|
||||||
* @param tag describing the type of entry being stored
|
|
||||||
* @param data value to store
|
|
||||||
*/
|
|
||||||
void addText(String tag, String data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores binary data. The data may be ignored or discarded as with
|
|
||||||
* {@link #addText}.
|
|
||||||
*
|
|
||||||
* @param tag describing the type of entry being stored
|
|
||||||
* @param data value to store
|
|
||||||
* @param flags describing the data, defined in {@link DropBoxEntry}
|
|
||||||
*/
|
|
||||||
void addData(String tag, in byte[] data, int flags);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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!
|
|
||||||
*
|
|
||||||
* @param tag describing the type of entry being stored
|
|
||||||
* @param data file descriptor to read from
|
|
||||||
* @param flags describing the data, defined in {@link DropBoxEntry}
|
|
||||||
*/
|
|
||||||
void addFile(String tag, in ParcelFileDescriptor data, int flags);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks any blacklists (set in system settings) to see whether a certain
|
|
||||||
* tag is allowed. Entries with disabled tags will be dropped immediately,
|
|
||||||
* so you can save the work of actually constructing and sending the data.
|
|
||||||
*
|
|
||||||
* @param tag that would be used in {@link #addText} or {@link #addFile}
|
|
||||||
* @return whether events with that tag would be accepted
|
|
||||||
*/
|
|
||||||
boolean isTagEnabled(String tag);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the next entry from the drop box *after* the specified time.
|
|
||||||
* Requires android.permission.READ_LOGS. You must always call
|
|
||||||
* {@link DropBoxEntry#close()} on the return value!
|
|
||||||
*
|
|
||||||
* @param tag of entry to look for, null for all tags
|
|
||||||
* @param millis time of the last entry seen
|
|
||||||
* @return the next entry, or null if there are no more entries
|
|
||||||
*/
|
|
||||||
DropBoxEntry getNextEntry(String tag, long millis);
|
|
||||||
|
|
||||||
// TODO: It may be useful to have some sort of notification mechanism
|
|
||||||
// when data is added to the dropbox, for demand-driven readers --
|
|
||||||
// for now readers need to poll the dropbox to find new data.
|
|
||||||
}
|
|
42
core/java/com/android/internal/os/IDropBoxService.aidl
Normal file
42
core/java/com/android/internal/os/IDropBoxService.aidl
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2009 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.internal.os;
|
||||||
|
|
||||||
|
import android.os.DropBox;
|
||||||
|
import android.os.ParcelFileDescriptor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Backend" interface used by {@link android.os.DropBox} to talk to the
|
||||||
|
* DropBoxService that actually implements the drop box functionality.
|
||||||
|
*
|
||||||
|
* @see DropBox
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
interface IDropBoxService {
|
||||||
|
/**
|
||||||
|
* @see DropBox#addText
|
||||||
|
* @see DropBox#addData
|
||||||
|
* @see DropBox#addFile
|
||||||
|
*/
|
||||||
|
void add(in DropBox.Entry entry);
|
||||||
|
|
||||||
|
/** @see DropBox#getNextEntry */
|
||||||
|
boolean isTagEnabled(String tag);
|
||||||
|
|
||||||
|
/** @see DropBox#getNextEntry */
|
||||||
|
DropBox.Entry getNextEntry(String tag, long millis);
|
||||||
|
}
|
@ -23,8 +23,7 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.DropBoxEntry;
|
import android.os.DropBox;
|
||||||
import android.os.IDropBox;
|
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.os.StatFs;
|
import android.os.StatFs;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
@ -32,11 +31,13 @@ import android.provider.Settings;
|
|||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.internal.os.IDropBoxService;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
@ -53,11 +54,12 @@ import java.util.TreeSet;
|
|||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link IDropBox} using the filesystem.
|
* Implementation of {@link IDropBoxService} using the filesystem.
|
||||||
|
* Clients use {@link DropBox} to access this service.
|
||||||
*
|
*
|
||||||
* {@hide}
|
* {@hide}
|
||||||
*/
|
*/
|
||||||
public final class DropBoxService extends IDropBox.Stub {
|
public final class DropBoxService extends IDropBoxService.Stub {
|
||||||
private static final String TAG = "DropBoxService";
|
private static final String TAG = "DropBoxService";
|
||||||
private static final int DEFAULT_RESERVE_PERCENT = 10;
|
private static final int DEFAULT_RESERVE_PERCENT = 10;
|
||||||
private static final int DEFAULT_QUOTA_PERCENT = 10;
|
private static final int DEFAULT_QUOTA_PERCENT = 10;
|
||||||
@ -129,50 +131,13 @@ public final class DropBoxService extends IDropBox.Stub {
|
|||||||
mContext.unregisterReceiver(mReceiver);
|
mContext.unregisterReceiver(mReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addText(String tag, String data) {
|
public void add(DropBox.Entry entry) {
|
||||||
addData(tag, data.getBytes(), DropBoxEntry.IS_TEXT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addData(String tag, byte[] data, int flags) {
|
|
||||||
File temp = null;
|
|
||||||
OutputStream out = null;
|
|
||||||
try {
|
|
||||||
if ((flags & DropBoxEntry.IS_EMPTY) != 0) throw new IllegalArgumentException();
|
|
||||||
|
|
||||||
init();
|
|
||||||
if (!isTagEnabled(tag)) return;
|
|
||||||
|
|
||||||
long max = trimToFit();
|
|
||||||
if (data.length > max) {
|
|
||||||
Log.w(TAG, "Dropping: " + tag + " (" + data.length + " > " + max + " bytes)");
|
|
||||||
// Pass temp = null to createEntry() to leave a tombstone
|
|
||||||
} else {
|
|
||||||
temp = new File(mDropBoxDir, "drop" + Thread.currentThread().getId() + ".tmp");
|
|
||||||
out = new FileOutputStream(temp);
|
|
||||||
if (data.length > mBlockSize && ((flags & DropBoxEntry.IS_GZIPPED) == 0)) {
|
|
||||||
flags = flags | DropBoxEntry.IS_GZIPPED;
|
|
||||||
out = new GZIPOutputStream(out);
|
|
||||||
}
|
|
||||||
out.write(data);
|
|
||||||
out.close();
|
|
||||||
out = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
createEntry(temp, tag, flags);
|
|
||||||
temp = null;
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Can't write: " + tag, e);
|
|
||||||
} finally {
|
|
||||||
try { if (out != null) out.close(); } catch (IOException e) {}
|
|
||||||
if (temp != null) temp.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addFile(String tag, ParcelFileDescriptor data, int flags) {
|
|
||||||
File temp = null;
|
File temp = null;
|
||||||
OutputStream output = null;
|
OutputStream output = null;
|
||||||
|
final String tag = entry.getTag();
|
||||||
try {
|
try {
|
||||||
if ((flags & DropBoxEntry.IS_EMPTY) != 0) throw new IllegalArgumentException();
|
int flags = entry.getFlags();
|
||||||
|
if ((flags & DropBox.IS_EMPTY) != 0) throw new IllegalArgumentException();
|
||||||
|
|
||||||
init();
|
init();
|
||||||
if (!isTagEnabled(tag)) return;
|
if (!isTagEnabled(tag)) return;
|
||||||
@ -180,7 +145,7 @@ public final class DropBoxService extends IDropBox.Stub {
|
|||||||
long lastTrim = System.currentTimeMillis();
|
long lastTrim = System.currentTimeMillis();
|
||||||
|
|
||||||
byte[] buffer = new byte[mBlockSize];
|
byte[] buffer = new byte[mBlockSize];
|
||||||
FileInputStream input = new FileInputStream(data.getFileDescriptor());
|
InputStream input = entry.getInputStream();
|
||||||
|
|
||||||
// First, accumulate up to one block worth of data in memory before
|
// First, accumulate up to one block worth of data in memory before
|
||||||
// deciding whether to compress the data or not.
|
// deciding whether to compress the data or not.
|
||||||
@ -197,9 +162,9 @@ public final class DropBoxService extends IDropBox.Stub {
|
|||||||
|
|
||||||
temp = new File(mDropBoxDir, "drop" + Thread.currentThread().getId() + ".tmp");
|
temp = new File(mDropBoxDir, "drop" + Thread.currentThread().getId() + ".tmp");
|
||||||
output = new FileOutputStream(temp);
|
output = new FileOutputStream(temp);
|
||||||
if (read == buffer.length && ((flags & DropBoxEntry.IS_GZIPPED) == 0)) {
|
if (read == buffer.length && ((flags & DropBox.IS_GZIPPED) == 0)) {
|
||||||
output = new GZIPOutputStream(output);
|
output = new GZIPOutputStream(output);
|
||||||
flags = flags | DropBoxEntry.IS_GZIPPED;
|
flags = flags | DropBox.IS_GZIPPED;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -234,7 +199,7 @@ public final class DropBoxService extends IDropBox.Stub {
|
|||||||
Log.e(TAG, "Can't write: " + tag, e);
|
Log.e(TAG, "Can't write: " + tag, e);
|
||||||
} finally {
|
} finally {
|
||||||
try { if (output != null) output.close(); } catch (IOException e) {}
|
try { if (output != null) output.close(); } catch (IOException e) {}
|
||||||
try { data.close(); } catch (IOException e) {}
|
entry.close();
|
||||||
if (temp != null) temp.delete();
|
if (temp != null) temp.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,7 +209,7 @@ public final class DropBoxService extends IDropBox.Stub {
|
|||||||
mContentResolver, Settings.Gservices.DROPBOX_TAG_PREFIX + tag));
|
mContentResolver, Settings.Gservices.DROPBOX_TAG_PREFIX + tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized DropBoxEntry getNextEntry(String tag, long millis) {
|
public synchronized DropBox.Entry getNextEntry(String tag, long millis) {
|
||||||
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.READ_LOGS)
|
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.READ_LOGS)
|
||||||
!= PackageManager.PERMISSION_GRANTED) {
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
throw new SecurityException("READ_LOGS permission required");
|
throw new SecurityException("READ_LOGS permission required");
|
||||||
@ -262,9 +227,11 @@ public final class DropBoxService extends IDropBox.Stub {
|
|||||||
|
|
||||||
for (EntryFile entry : list.contents.tailSet(new EntryFile(millis + 1))) {
|
for (EntryFile entry : list.contents.tailSet(new EntryFile(millis + 1))) {
|
||||||
if (entry.tag == null) continue;
|
if (entry.tag == null) continue;
|
||||||
|
if ((entry.flags & DropBox.IS_EMPTY) != 0) {
|
||||||
|
return new DropBox.Entry(entry.tag, entry.timestampMillis);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
File file = (entry.flags & DropBoxEntry.IS_EMPTY) != 0 ? null : entry.file;
|
return new DropBox.Entry(entry.tag, entry.timestampMillis, entry.file, entry.flags);
|
||||||
return new DropBoxEntry(entry.tag, entry.timestampMillis, file, entry.flags);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "Can't read: " + entry.file, e);
|
Log.e(TAG, "Can't read: " + entry.file, e);
|
||||||
// Continue to next file
|
// Continue to next file
|
||||||
@ -331,25 +298,25 @@ public final class DropBoxService extends IDropBox.Stub {
|
|||||||
if (entry.file == null) {
|
if (entry.file == null) {
|
||||||
pw.println(" (no file)");
|
pw.println(" (no file)");
|
||||||
continue;
|
continue;
|
||||||
} else if ((entry.flags & DropBoxEntry.IS_EMPTY) != 0) {
|
} else if ((entry.flags & DropBox.IS_EMPTY) != 0) {
|
||||||
pw.println(" (contents lost)");
|
pw.println(" (contents lost)");
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
pw.print((entry.flags & DropBoxEntry.IS_GZIPPED) != 0 ? " (comopressed " : " (");
|
pw.print((entry.flags & DropBox.IS_GZIPPED) != 0 ? " (comopressed " : " (");
|
||||||
pw.print((entry.flags & DropBoxEntry.IS_TEXT) != 0 ? "text" : "data");
|
pw.print((entry.flags & DropBox.IS_TEXT) != 0 ? "text" : "data");
|
||||||
pw.format(", %d bytes)", entry.file.length());
|
pw.format(", %d bytes)", entry.file.length());
|
||||||
pw.println();
|
pw.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doFile || (doPrint && (entry.flags & DropBoxEntry.IS_TEXT) == 0)) {
|
if (doFile || (doPrint && (entry.flags & DropBox.IS_TEXT) == 0)) {
|
||||||
if (!doPrint) pw.print(" ");
|
if (!doPrint) pw.print(" ");
|
||||||
pw.println(entry.file.getPath());
|
pw.println(entry.file.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((entry.flags & DropBoxEntry.IS_TEXT) != 0 && (doPrint || !doFile)) {
|
if ((entry.flags & DropBox.IS_TEXT) != 0 && (doPrint || !doFile)) {
|
||||||
DropBoxEntry dbe = null;
|
DropBox.Entry dbe = null;
|
||||||
try {
|
try {
|
||||||
dbe = new DropBoxEntry(
|
dbe = new DropBox.Entry(
|
||||||
entry.tag, entry.timestampMillis, entry.file, entry.flags);
|
entry.tag, entry.timestampMillis, entry.file, entry.flags);
|
||||||
|
|
||||||
if (doPrint) {
|
if (doPrint) {
|
||||||
@ -435,20 +402,20 @@ public final class DropBoxService extends IDropBox.Stub {
|
|||||||
* @param dir to store file in
|
* @param dir to store file in
|
||||||
* @param tag to use for new log file name
|
* @param tag to use for new log file name
|
||||||
* @param timestampMillis of log entry
|
* @param timestampMillis of log entry
|
||||||
* @param flags for the entry data (from {@link DropBoxEntry})
|
* @param flags for the entry data
|
||||||
* @param blockSize to use for space accounting
|
* @param blockSize to use for space accounting
|
||||||
* @throws IOException if the file can't be moved
|
* @throws IOException if the file can't be moved
|
||||||
*/
|
*/
|
||||||
public EntryFile(File temp, File dir, String tag,long timestampMillis,
|
public EntryFile(File temp, File dir, String tag,long timestampMillis,
|
||||||
int flags, int blockSize) throws IOException {
|
int flags, int blockSize) throws IOException {
|
||||||
if ((flags & DropBoxEntry.IS_EMPTY) != 0) throw new IllegalArgumentException();
|
if ((flags & DropBox.IS_EMPTY) != 0) throw new IllegalArgumentException();
|
||||||
|
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
this.timestampMillis = timestampMillis;
|
this.timestampMillis = timestampMillis;
|
||||||
this.flags = flags;
|
this.flags = flags;
|
||||||
this.file = new File(dir, Uri.encode(tag) + "@" + timestampMillis +
|
this.file = new File(dir, Uri.encode(tag) + "@" + timestampMillis +
|
||||||
((flags & DropBoxEntry.IS_TEXT) != 0 ? ".txt" : ".dat") +
|
((flags & DropBox.IS_TEXT) != 0 ? ".txt" : ".dat") +
|
||||||
((flags & DropBoxEntry.IS_GZIPPED) != 0 ? ".gz" : ""));
|
((flags & DropBox.IS_GZIPPED) != 0 ? ".gz" : ""));
|
||||||
|
|
||||||
if (!temp.renameTo(this.file)) {
|
if (!temp.renameTo(this.file)) {
|
||||||
throw new IOException("Can't rename " + temp + " to " + this.file);
|
throw new IOException("Can't rename " + temp + " to " + this.file);
|
||||||
@ -466,7 +433,7 @@ public final class DropBoxService extends IDropBox.Stub {
|
|||||||
public EntryFile(File dir, String tag, long timestampMillis) throws IOException {
|
public EntryFile(File dir, String tag, long timestampMillis) throws IOException {
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
this.timestampMillis = timestampMillis;
|
this.timestampMillis = timestampMillis;
|
||||||
this.flags = DropBoxEntry.IS_EMPTY;
|
this.flags = DropBox.IS_EMPTY;
|
||||||
this.file = new File(dir, Uri.encode(tag) + "@" + timestampMillis + ".lost");
|
this.file = new File(dir, Uri.encode(tag) + "@" + timestampMillis + ".lost");
|
||||||
this.blocks = 0;
|
this.blocks = 0;
|
||||||
new FileOutputStream(this.file).close();
|
new FileOutputStream(this.file).close();
|
||||||
@ -486,26 +453,26 @@ public final class DropBoxService extends IDropBox.Stub {
|
|||||||
if (at < 0) {
|
if (at < 0) {
|
||||||
this.tag = null;
|
this.tag = null;
|
||||||
this.timestampMillis = 0;
|
this.timestampMillis = 0;
|
||||||
this.flags = DropBoxEntry.IS_EMPTY;
|
this.flags = DropBox.IS_EMPTY;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
this.tag = Uri.decode(name.substring(0, at));
|
this.tag = Uri.decode(name.substring(0, at));
|
||||||
if (name.endsWith(".gz")) {
|
if (name.endsWith(".gz")) {
|
||||||
flags |= DropBoxEntry.IS_GZIPPED;
|
flags |= DropBox.IS_GZIPPED;
|
||||||
name = name.substring(0, name.length() - 3);
|
name = name.substring(0, name.length() - 3);
|
||||||
}
|
}
|
||||||
if (name.endsWith(".lost")) {
|
if (name.endsWith(".lost")) {
|
||||||
flags |= DropBoxEntry.IS_EMPTY;
|
flags |= DropBox.IS_EMPTY;
|
||||||
name = name.substring(at + 1, name.length() - 5);
|
name = name.substring(at + 1, name.length() - 5);
|
||||||
} else if (name.endsWith(".txt")) {
|
} else if (name.endsWith(".txt")) {
|
||||||
flags |= DropBoxEntry.IS_TEXT;
|
flags |= DropBox.IS_TEXT;
|
||||||
name = name.substring(at + 1, name.length() - 4);
|
name = name.substring(at + 1, name.length() - 4);
|
||||||
} else if (name.endsWith(".dat")) {
|
} else if (name.endsWith(".dat")) {
|
||||||
name = name.substring(at + 1, name.length() - 4);
|
name = name.substring(at + 1, name.length() - 4);
|
||||||
} else {
|
} else {
|
||||||
this.flags = DropBoxEntry.IS_EMPTY;
|
this.flags = DropBox.IS_EMPTY;
|
||||||
this.timestampMillis = 0;
|
this.timestampMillis = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -523,7 +490,7 @@ public final class DropBoxService extends IDropBox.Stub {
|
|||||||
public EntryFile(long millis) {
|
public EntryFile(long millis) {
|
||||||
this.tag = null;
|
this.tag = null;
|
||||||
this.timestampMillis = millis;
|
this.timestampMillis = millis;
|
||||||
this.flags = DropBoxEntry.IS_EMPTY;
|
this.flags = DropBox.IS_EMPTY;
|
||||||
this.file = null;
|
this.file = null;
|
||||||
this.blocks = 0;
|
this.blocks = 0;
|
||||||
}
|
}
|
||||||
@ -618,7 +585,7 @@ public final class DropBoxService extends IDropBox.Stub {
|
|||||||
mAllFiles.blocks -= late.blocks;
|
mAllFiles.blocks -= late.blocks;
|
||||||
FileList tagFiles = mFilesByTag.get(late.tag);
|
FileList tagFiles = mFilesByTag.get(late.tag);
|
||||||
if (tagFiles.contents.remove(late)) tagFiles.blocks -= late.blocks;
|
if (tagFiles.contents.remove(late)) tagFiles.blocks -= late.blocks;
|
||||||
if ((late.flags & DropBoxEntry.IS_EMPTY) == 0) {
|
if ((late.flags & DropBox.IS_EMPTY) == 0) {
|
||||||
enrollEntry(new EntryFile(
|
enrollEntry(new EntryFile(
|
||||||
late.file, mDropBoxDir, late.tag, t++, late.flags, mBlockSize));
|
late.file, mDropBoxDir, late.tag, t++, late.flags, mBlockSize));
|
||||||
} else {
|
} else {
|
||||||
|
@ -296,7 +296,7 @@ class ServerThread extends Thread {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Log.i(TAG, "DropBox Service");
|
Log.i(TAG, "DropBox Service");
|
||||||
ServiceManager.addService("dropbox",
|
ServiceManager.addService(Context.DROPBOX_SERVICE,
|
||||||
new DropBoxService(context, new File("/data/system/dropbox")));
|
new DropBoxService(context, new File("/data/system/dropbox")));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Log.e(TAG, "Failure starting DropBox Service", e);
|
Log.e(TAG, "Failure starting DropBox Service", e);
|
||||||
|
@ -19,8 +19,7 @@ package com.android.unit_tests;
|
|||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.DropBoxEntry;
|
import android.os.DropBox;
|
||||||
import android.os.IDropBox;
|
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.StatFs;
|
import android.os.StatFs;
|
||||||
@ -36,7 +35,7 @@ import java.io.InputStream;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
/** Test {@link IDropBox} functionality. */
|
/** Test {@link DropBox} functionality. */
|
||||||
public class DropBoxTest extends AndroidTestCase {
|
public class DropBoxTest extends AndroidTestCase {
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
Intent override = new Intent(Settings.Gservices.OVERRIDE_ACTION);
|
Intent override = new Intent(Settings.Gservices.OVERRIDE_ACTION);
|
||||||
@ -47,7 +46,7 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAddText() throws Exception {
|
public void testAddText() throws Exception {
|
||||||
IDropBox dropbox = IDropBox.Stub.asInterface(ServiceManager.getService("dropbox"));
|
DropBox dropbox = (DropBox) getContext().getSystemService(Context.DROPBOX_SERVICE);
|
||||||
long before = System.currentTimeMillis();
|
long before = System.currentTimeMillis();
|
||||||
Thread.sleep(5);
|
Thread.sleep(5);
|
||||||
dropbox.addText("DropBoxTest", "TEST0");
|
dropbox.addText("DropBoxTest", "TEST0");
|
||||||
@ -59,9 +58,9 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
Thread.sleep(5);
|
Thread.sleep(5);
|
||||||
long after = System.currentTimeMillis();
|
long after = System.currentTimeMillis();
|
||||||
|
|
||||||
DropBoxEntry e0 = dropbox.getNextEntry("DropBoxTest", before);
|
DropBox.Entry e0 = dropbox.getNextEntry("DropBoxTest", before);
|
||||||
DropBoxEntry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
|
DropBox.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
|
||||||
DropBoxEntry e2 = dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis());
|
DropBox.Entry e2 = dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis());
|
||||||
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e2.getTimeMillis()));
|
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e2.getTimeMillis()));
|
||||||
|
|
||||||
assertTrue(e0.getTimeMillis() > before);
|
assertTrue(e0.getTimeMillis() > before);
|
||||||
@ -80,12 +79,12 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAddData() throws Exception {
|
public void testAddData() throws Exception {
|
||||||
IDropBox dropbox = IDropBox.Stub.asInterface(ServiceManager.getService("dropbox"));
|
DropBox dropbox = (DropBox) getContext().getSystemService(Context.DROPBOX_SERVICE);
|
||||||
long before = System.currentTimeMillis();
|
long before = System.currentTimeMillis();
|
||||||
dropbox.addData("DropBoxTest", "TEST".getBytes(), 0);
|
dropbox.addData("DropBoxTest", "TEST".getBytes(), 0);
|
||||||
long after = System.currentTimeMillis();
|
long after = System.currentTimeMillis();
|
||||||
|
|
||||||
DropBoxEntry e = dropbox.getNextEntry("DropBoxTest", before);
|
DropBox.Entry e = dropbox.getNextEntry("DropBoxTest", before);
|
||||||
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e.getTimeMillis()));
|
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e.getTimeMillis()));
|
||||||
|
|
||||||
assertEquals("DropBoxTest", e.getTag());
|
assertEquals("DropBoxTest", e.getTag());
|
||||||
@ -123,7 +122,7 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
os2.close();
|
os2.close();
|
||||||
gz3.close();
|
gz3.close();
|
||||||
|
|
||||||
IDropBox dropbox = IDropBox.Stub.asInterface(ServiceManager.getService("dropbox"));
|
DropBox dropbox = (DropBox) getContext().getSystemService(Context.DROPBOX_SERVICE);
|
||||||
int mode = ParcelFileDescriptor.MODE_READ_ONLY;
|
int mode = ParcelFileDescriptor.MODE_READ_ONLY;
|
||||||
|
|
||||||
ParcelFileDescriptor pfd0 = ParcelFileDescriptor.open(f0, mode);
|
ParcelFileDescriptor pfd0 = ParcelFileDescriptor.open(f0, mode);
|
||||||
@ -131,20 +130,20 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
ParcelFileDescriptor pfd2 = ParcelFileDescriptor.open(f2, mode);
|
ParcelFileDescriptor pfd2 = ParcelFileDescriptor.open(f2, mode);
|
||||||
ParcelFileDescriptor pfd3 = ParcelFileDescriptor.open(f3, mode);
|
ParcelFileDescriptor pfd3 = ParcelFileDescriptor.open(f3, mode);
|
||||||
|
|
||||||
dropbox.addFile("DropBoxTest", pfd0, DropBoxEntry.IS_TEXT);
|
dropbox.addFile("DropBoxTest", pfd0, DropBox.IS_TEXT);
|
||||||
dropbox.addFile("DropBoxTest", pfd1, DropBoxEntry.IS_TEXT | DropBoxEntry.IS_GZIPPED);
|
dropbox.addFile("DropBoxTest", pfd1, DropBox.IS_TEXT | DropBox.IS_GZIPPED);
|
||||||
dropbox.addFile("DropBoxTest", pfd2, 0);
|
dropbox.addFile("DropBoxTest", pfd2, 0);
|
||||||
dropbox.addFile("DropBoxTest", pfd3, DropBoxEntry.IS_GZIPPED);
|
dropbox.addFile("DropBoxTest", pfd3, DropBox.IS_GZIPPED);
|
||||||
|
|
||||||
pfd0.close();
|
pfd0.close();
|
||||||
pfd1.close();
|
pfd1.close();
|
||||||
pfd2.close();
|
pfd2.close();
|
||||||
pfd3.close();
|
pfd3.close();
|
||||||
|
|
||||||
DropBoxEntry e0 = dropbox.getNextEntry("DropBoxTest", before);
|
DropBox.Entry e0 = dropbox.getNextEntry("DropBoxTest", before);
|
||||||
DropBoxEntry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
|
DropBox.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
|
||||||
DropBoxEntry e2 = dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis());
|
DropBox.Entry e2 = dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis());
|
||||||
DropBoxEntry e3 = dropbox.getNextEntry("DropBoxTest", e2.getTimeMillis());
|
DropBox.Entry e3 = dropbox.getNextEntry("DropBoxTest", e2.getTimeMillis());
|
||||||
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e3.getTimeMillis()));
|
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e3.getTimeMillis()));
|
||||||
|
|
||||||
assertTrue(e0.getTimeMillis() > before);
|
assertTrue(e0.getTimeMillis() > before);
|
||||||
@ -152,8 +151,8 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
assertTrue(e2.getTimeMillis() > e1.getTimeMillis());
|
assertTrue(e2.getTimeMillis() > e1.getTimeMillis());
|
||||||
assertTrue(e3.getTimeMillis() > e2.getTimeMillis());
|
assertTrue(e3.getTimeMillis() > e2.getTimeMillis());
|
||||||
|
|
||||||
assertEquals(DropBoxEntry.IS_TEXT, e0.getFlags());
|
assertEquals(DropBox.IS_TEXT, e0.getFlags());
|
||||||
assertEquals(DropBoxEntry.IS_TEXT, e1.getFlags());
|
assertEquals(DropBox.IS_TEXT, e1.getFlags());
|
||||||
assertEquals(0, e2.getFlags());
|
assertEquals(0, e2.getFlags());
|
||||||
assertEquals(0, e3.getFlags());
|
assertEquals(0, e3.getFlags());
|
||||||
|
|
||||||
@ -199,13 +198,14 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
// Tombstone in the far future
|
// Tombstone in the far future
|
||||||
new FileOutputStream(new File(dir, "DropBoxTest@" + (before + 100002) + ".lost")).close();
|
new FileOutputStream(new File(dir, "DropBoxTest@" + (before + 100002) + ".lost")).close();
|
||||||
|
|
||||||
DropBoxService dropbox = new DropBoxService(getContext(), dir);
|
DropBoxService service = new DropBoxService(getContext(), dir);
|
||||||
|
DropBox dropbox = new DropBox(service);
|
||||||
|
|
||||||
// Until a write, the timestamps are taken at face value
|
// Until a write, the timestamps are taken at face value
|
||||||
DropBoxEntry e0 = dropbox.getNextEntry(null, before);
|
DropBox.Entry e0 = dropbox.getNextEntry(null, before);
|
||||||
DropBoxEntry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
|
DropBox.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
|
||||||
DropBoxEntry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
|
DropBox.Entry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
|
||||||
DropBoxEntry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
|
DropBox.Entry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
|
||||||
assertTrue(null == dropbox.getNextEntry(null, e3.getTimeMillis()));
|
assertTrue(null == dropbox.getNextEntry(null, e3.getTimeMillis()));
|
||||||
|
|
||||||
assertEquals("FUTURE0", e0.getText(80));
|
assertEquals("FUTURE0", e0.getText(80));
|
||||||
@ -245,11 +245,11 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
e1.close();
|
e1.close();
|
||||||
e2.close();
|
e2.close();
|
||||||
e3.close();
|
e3.close();
|
||||||
dropbox.stop();
|
service.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIsTagEnabled() throws Exception {
|
public void testIsTagEnabled() throws Exception {
|
||||||
IDropBox dropbox = IDropBox.Stub.asInterface(ServiceManager.getService("dropbox"));
|
DropBox dropbox = (DropBox) getContext().getSystemService(Context.DROPBOX_SERVICE);
|
||||||
long before = System.currentTimeMillis();
|
long before = System.currentTimeMillis();
|
||||||
dropbox.addText("DropBoxTest", "TEST-ENABLED");
|
dropbox.addText("DropBoxTest", "TEST-ENABLED");
|
||||||
assertTrue(dropbox.isTagEnabled("DropBoxTest"));
|
assertTrue(dropbox.isTagEnabled("DropBoxTest"));
|
||||||
@ -268,8 +268,8 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
dropbox.addText("DropBoxTest", "TEST-ENABLED-AGAIN");
|
dropbox.addText("DropBoxTest", "TEST-ENABLED-AGAIN");
|
||||||
assertTrue(dropbox.isTagEnabled("DropBoxTest"));
|
assertTrue(dropbox.isTagEnabled("DropBoxTest"));
|
||||||
|
|
||||||
DropBoxEntry e0 = dropbox.getNextEntry("DropBoxTest", before);
|
DropBox.Entry e0 = dropbox.getNextEntry("DropBoxTest", before);
|
||||||
DropBoxEntry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
|
DropBox.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
|
||||||
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis()));
|
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis()));
|
||||||
|
|
||||||
assertEquals("TEST-ENABLED", e0.getText(80));
|
assertEquals("TEST-ENABLED", e0.getText(80));
|
||||||
@ -281,23 +281,24 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
|
|
||||||
public void testGetNextEntry() throws Exception {
|
public void testGetNextEntry() throws Exception {
|
||||||
File dir = getEmptyDir("testGetNextEntry");
|
File dir = getEmptyDir("testGetNextEntry");
|
||||||
DropBoxService dropbox = new DropBoxService(getContext(), dir);
|
DropBoxService service = new DropBoxService(getContext(), dir);
|
||||||
|
DropBox dropbox = new DropBox(service);
|
||||||
|
|
||||||
long before = System.currentTimeMillis();
|
long before = System.currentTimeMillis();
|
||||||
dropbox.addText("DropBoxTest.A", "A0");
|
dropbox.addText("DropBoxTest.A", "A0");
|
||||||
dropbox.addText("DropBoxTest.B", "B0");
|
dropbox.addText("DropBoxTest.B", "B0");
|
||||||
dropbox.addText("DropBoxTest.A", "A1");
|
dropbox.addText("DropBoxTest.A", "A1");
|
||||||
|
|
||||||
DropBoxEntry a0 = dropbox.getNextEntry("DropBoxTest.A", before);
|
DropBox.Entry a0 = dropbox.getNextEntry("DropBoxTest.A", before);
|
||||||
DropBoxEntry a1 = dropbox.getNextEntry("DropBoxTest.A", a0.getTimeMillis());
|
DropBox.Entry a1 = dropbox.getNextEntry("DropBoxTest.A", a0.getTimeMillis());
|
||||||
assertTrue(null == dropbox.getNextEntry("DropBoxTest.A", a1.getTimeMillis()));
|
assertTrue(null == dropbox.getNextEntry("DropBoxTest.A", a1.getTimeMillis()));
|
||||||
|
|
||||||
DropBoxEntry b0 = dropbox.getNextEntry("DropBoxTest.B", before);
|
DropBox.Entry b0 = dropbox.getNextEntry("DropBoxTest.B", before);
|
||||||
assertTrue(null == dropbox.getNextEntry("DropBoxTest.B", b0.getTimeMillis()));
|
assertTrue(null == dropbox.getNextEntry("DropBoxTest.B", b0.getTimeMillis()));
|
||||||
|
|
||||||
DropBoxEntry x0 = dropbox.getNextEntry(null, before);
|
DropBox.Entry x0 = dropbox.getNextEntry(null, before);
|
||||||
DropBoxEntry x1 = dropbox.getNextEntry(null, x0.getTimeMillis());
|
DropBox.Entry x1 = dropbox.getNextEntry(null, x0.getTimeMillis());
|
||||||
DropBoxEntry x2 = dropbox.getNextEntry(null, x1.getTimeMillis());
|
DropBox.Entry x2 = dropbox.getNextEntry(null, x1.getTimeMillis());
|
||||||
assertTrue(null == dropbox.getNextEntry(null, x2.getTimeMillis()));
|
assertTrue(null == dropbox.getNextEntry(null, x2.getTimeMillis()));
|
||||||
|
|
||||||
assertEquals("DropBoxTest.A", a0.getTag());
|
assertEquals("DropBoxTest.A", a0.getTag());
|
||||||
@ -321,7 +322,7 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
x0.close();
|
x0.close();
|
||||||
x1.close();
|
x1.close();
|
||||||
x2.close();
|
x2.close();
|
||||||
dropbox.stop();
|
service.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSizeLimits() throws Exception {
|
public void testSizeLimits() throws Exception {
|
||||||
@ -344,7 +345,9 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
|
|
||||||
final int overhead = 64;
|
final int overhead = 64;
|
||||||
long before = System.currentTimeMillis();
|
long before = System.currentTimeMillis();
|
||||||
DropBoxService dropbox = new DropBoxService(getContext(), dir);
|
DropBoxService service = new DropBoxService(getContext(), dir);
|
||||||
|
DropBox dropbox = new DropBox(service);
|
||||||
|
|
||||||
addRandomEntry(dropbox, "DropBoxTest0", blockSize - overhead);
|
addRandomEntry(dropbox, "DropBoxTest0", blockSize - overhead);
|
||||||
addRandomEntry(dropbox, "DropBoxTest0", blockSize - overhead);
|
addRandomEntry(dropbox, "DropBoxTest0", blockSize - overhead);
|
||||||
|
|
||||||
@ -358,16 +361,16 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
addRandomEntry(dropbox, "DropBoxTest2", blockSize - overhead);
|
addRandomEntry(dropbox, "DropBoxTest2", blockSize - overhead);
|
||||||
addRandomEntry(dropbox, "DropBoxTest2", blockSize - overhead);
|
addRandomEntry(dropbox, "DropBoxTest2", blockSize - overhead);
|
||||||
|
|
||||||
DropBoxEntry e0 = dropbox.getNextEntry(null, before);
|
DropBox.Entry e0 = dropbox.getNextEntry(null, before);
|
||||||
DropBoxEntry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
|
DropBox.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
|
||||||
DropBoxEntry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
|
DropBox.Entry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
|
||||||
DropBoxEntry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
|
DropBox.Entry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
|
||||||
DropBoxEntry e4 = dropbox.getNextEntry(null, e3.getTimeMillis());
|
DropBox.Entry e4 = dropbox.getNextEntry(null, e3.getTimeMillis());
|
||||||
DropBoxEntry e5 = dropbox.getNextEntry(null, e4.getTimeMillis());
|
DropBox.Entry e5 = dropbox.getNextEntry(null, e4.getTimeMillis());
|
||||||
DropBoxEntry e6 = dropbox.getNextEntry(null, e5.getTimeMillis());
|
DropBox.Entry e6 = dropbox.getNextEntry(null, e5.getTimeMillis());
|
||||||
DropBoxEntry e7 = dropbox.getNextEntry(null, e6.getTimeMillis());
|
DropBox.Entry e7 = dropbox.getNextEntry(null, e6.getTimeMillis());
|
||||||
DropBoxEntry e8 = dropbox.getNextEntry(null, e7.getTimeMillis());
|
DropBox.Entry e8 = dropbox.getNextEntry(null, e7.getTimeMillis());
|
||||||
DropBoxEntry e9 = dropbox.getNextEntry(null, e8.getTimeMillis());
|
DropBox.Entry e9 = dropbox.getNextEntry(null, e8.getTimeMillis());
|
||||||
assertTrue(null == dropbox.getNextEntry(null, e9.getTimeMillis()));
|
assertTrue(null == dropbox.getNextEntry(null, e9.getTimeMillis()));
|
||||||
|
|
||||||
assertEquals("DropBoxTest0", e0.getTag());
|
assertEquals("DropBoxTest0", e0.getTag());
|
||||||
@ -406,9 +409,9 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
|
|
||||||
// Specifying a tag name skips tombstone records.
|
// Specifying a tag name skips tombstone records.
|
||||||
|
|
||||||
DropBoxEntry t0 = dropbox.getNextEntry("DropBoxTest1", before);
|
DropBox.Entry t0 = dropbox.getNextEntry("DropBoxTest1", before);
|
||||||
DropBoxEntry t1 = dropbox.getNextEntry("DropBoxTest1", t0.getTimeMillis());
|
DropBox.Entry t1 = dropbox.getNextEntry("DropBoxTest1", t0.getTimeMillis());
|
||||||
DropBoxEntry t2 = dropbox.getNextEntry("DropBoxTest1", t1.getTimeMillis());
|
DropBox.Entry t2 = dropbox.getNextEntry("DropBoxTest1", t1.getTimeMillis());
|
||||||
assertTrue(null == dropbox.getNextEntry("DropBoxTest1", t2.getTimeMillis()));
|
assertTrue(null == dropbox.getNextEntry("DropBoxTest1", t2.getTimeMillis()));
|
||||||
|
|
||||||
assertEquals("DropBoxTest1", t0.getTag());
|
assertEquals("DropBoxTest1", t0.getTag());
|
||||||
@ -422,7 +425,7 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
t0.close();
|
t0.close();
|
||||||
t1.close();
|
t1.close();
|
||||||
t2.close();
|
t2.close();
|
||||||
dropbox.stop();
|
service.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAgeLimits() throws Exception {
|
public void testAgeLimits() throws Exception {
|
||||||
@ -438,13 +441,15 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
|
|
||||||
// Write one normal entry and another so big that it is instantly tombstoned
|
// Write one normal entry and another so big that it is instantly tombstoned
|
||||||
long before = System.currentTimeMillis();
|
long before = System.currentTimeMillis();
|
||||||
DropBoxService dropbox = new DropBoxService(getContext(), dir);
|
DropBoxService service = new DropBoxService(getContext(), dir);
|
||||||
|
DropBox dropbox = new DropBox(service);
|
||||||
|
|
||||||
dropbox.addText("DropBoxTest", "TEST");
|
dropbox.addText("DropBoxTest", "TEST");
|
||||||
addRandomEntry(dropbox, "DropBoxTest", blockSize * 20);
|
addRandomEntry(dropbox, "DropBoxTest", blockSize * 20);
|
||||||
|
|
||||||
// Verify that things are as expected
|
// Verify that things are as expected
|
||||||
DropBoxEntry e0 = dropbox.getNextEntry(null, before);
|
DropBox.Entry e0 = dropbox.getNextEntry(null, before);
|
||||||
DropBoxEntry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
|
DropBox.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
|
||||||
assertTrue(null == dropbox.getNextEntry(null, e1.getTimeMillis()));
|
assertTrue(null == dropbox.getNextEntry(null, e1.getTimeMillis()));
|
||||||
|
|
||||||
assertEquals("TEST", e0.getText(80));
|
assertEquals("TEST", e0.getText(80));
|
||||||
@ -471,7 +476,8 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
|
|
||||||
File dir = new File(getEmptyDir("testCreateDropBoxWith"), "InvalidDirectory");
|
File dir = new File(getEmptyDir("testCreateDropBoxWith"), "InvalidDirectory");
|
||||||
new FileOutputStream(dir).close(); // Create an empty file
|
new FileOutputStream(dir).close(); // Create an empty file
|
||||||
DropBoxService dropbox = new DropBoxService(getContext(), dir);
|
DropBoxService service = new DropBoxService(getContext(), dir);
|
||||||
|
DropBox dropbox = new DropBox(service);
|
||||||
|
|
||||||
dropbox.addText("DropBoxTest", "should be ignored");
|
dropbox.addText("DropBoxTest", "should be ignored");
|
||||||
dropbox.addData("DropBoxTest", "should be ignored".getBytes(), 0);
|
dropbox.addData("DropBoxTest", "should be ignored".getBytes(), 0);
|
||||||
@ -479,15 +485,15 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
|
|
||||||
dir.delete(); // Remove the file so a directory can be created
|
dir.delete(); // Remove the file so a directory can be created
|
||||||
dropbox.addText("DropBoxTest", "TEST");
|
dropbox.addText("DropBoxTest", "TEST");
|
||||||
DropBoxEntry e = dropbox.getNextEntry("DropBoxTest", 0);
|
DropBox.Entry e = dropbox.getNextEntry("DropBoxTest", 0);
|
||||||
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e.getTimeMillis()));
|
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e.getTimeMillis()));
|
||||||
assertEquals("DropBoxTest", e.getTag());
|
assertEquals("DropBoxTest", e.getTag());
|
||||||
assertEquals("TEST", e.getText(80));
|
assertEquals("TEST", e.getText(80));
|
||||||
e.close();
|
e.close();
|
||||||
dropbox.stop();
|
service.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addRandomEntry(IDropBox dropbox, String tag, int size) throws Exception {
|
private void addRandomEntry(DropBox dropbox, String tag, int size) throws Exception {
|
||||||
byte[] bytes = new byte[size];
|
byte[] bytes = new byte[size];
|
||||||
new Random(System.currentTimeMillis()).nextBytes(bytes);
|
new Random(System.currentTimeMillis()).nextBytes(bytes);
|
||||||
|
|
||||||
@ -501,7 +507,7 @@ public class DropBoxTest extends AndroidTestCase {
|
|||||||
fd.close();
|
fd.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getEntrySize(DropBoxEntry e) throws Exception {
|
private int getEntrySize(DropBox.Entry e) throws Exception {
|
||||||
InputStream is = e.getInputStream();
|
InputStream is = e.getInputStream();
|
||||||
if (is == null) return -1;
|
if (is == null) return -1;
|
||||||
int length = 0;
|
int length = 0;
|
||||||
|
Reference in New Issue
Block a user