Rename [I]DropBox[Service] to [I]DropBoxManager[Service].

Un-hide the DropBoxManager interface, and update the public API accordingly.
This commit is contained in:
Dan Egnor
2009-11-12 11:32:50 -08:00
parent 897a744bb7
commit f18a01c77e
11 changed files with 468 additions and 134 deletions

View File

@@ -136,7 +136,7 @@ LOCAL_SRC_FILES += \
core/java/com/android/internal/appwidget/IAppWidgetService.aidl \
core/java/com/android/internal/appwidget/IAppWidgetHost.aidl \
core/java/com/android/internal/backup/IBackupTransport.aidl \
core/java/com/android/internal/os/IDropBoxService.aidl \
core/java/com/android/internal/os/IDropBoxManagerService.aidl \
core/java/com/android/internal/os/IResultReceiver.aidl \
core/java/com/android/internal/view/IInputContext.aidl \
core/java/com/android/internal/view/IInputContextCallback.aidl \
@@ -218,7 +218,7 @@ aidl_files := \
frameworks/base/core/java/android/appwidget/AppWidgetProviderInfo.aidl \
frameworks/base/core/java/android/net/Uri.aidl \
frameworks/base/core/java/android/os/Bundle.aidl \
frameworks/base/core/java/android/os/DropBox.aidl \
frameworks/base/core/java/android/os/DropBoxManager.aidl \
frameworks/base/core/java/android/os/ParcelFileDescriptor.aidl \
frameworks/base/core/java/android/os/ParcelUuid.aidl \
frameworks/base/core/java/android/view/KeyEvent.aidl \

View File

@@ -32012,6 +32012,17 @@
visibility="public"
>
</field>
<field name="DROPBOX_SERVICE"
type="java.lang.String"
transient="false"
volatile="false"
value="&quot;dropbox&quot;"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="INPUT_METHOD_SERVICE"
type="java.lang.String"
transient="false"
@@ -102116,6 +102127,326 @@
>
</field>
</class>
<class name="DropBoxManager"
extends="java.lang.Object"
abstract="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<constructor name="DropBoxManager"
type="android.os.DropBoxManager"
static="false"
final="false"
deprecated="not deprecated"
visibility="protected"
>
</constructor>
<method name="addData"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="tag" type="java.lang.String">
</parameter>
<parameter name="data" type="byte[]">
</parameter>
<parameter name="flags" type="int">
</parameter>
</method>
<method name="addFile"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="tag" type="java.lang.String">
</parameter>
<parameter name="fd" type="android.os.ParcelFileDescriptor">
</parameter>
<parameter name="flags" type="int">
</parameter>
</method>
<method name="addText"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="tag" type="java.lang.String">
</parameter>
<parameter name="data" type="java.lang.String">
</parameter>
</method>
<method name="getNextEntry"
return="android.os.DropBoxManager.Entry"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="tag" type="java.lang.String">
</parameter>
<parameter name="msec" type="long">
</parameter>
</method>
<method name="isTagEnabled"
return="boolean"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="tag" type="java.lang.String">
</parameter>
</method>
<field name="IS_EMPTY"
type="int"
transient="false"
volatile="false"
value="1"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="IS_GZIPPED"
type="int"
transient="false"
volatile="false"
value="4"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="IS_TEXT"
type="int"
transient="false"
volatile="false"
value="2"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
</class>
<class name="DropBoxManager.Entry"
extends="java.lang.Object"
abstract="false"
static="true"
final="false"
deprecated="not deprecated"
visibility="public"
>
<implements name="android.os.Parcelable">
</implements>
<constructor name="DropBoxManager.Entry"
type="android.os.DropBoxManager.Entry"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="tag" type="java.lang.String">
</parameter>
<parameter name="millis" type="long">
</parameter>
</constructor>
<constructor name="DropBoxManager.Entry"
type="android.os.DropBoxManager.Entry"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="tag" type="java.lang.String">
</parameter>
<parameter name="millis" type="long">
</parameter>
<parameter name="text" type="java.lang.String">
</parameter>
</constructor>
<constructor name="DropBoxManager.Entry"
type="android.os.DropBoxManager.Entry"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="tag" type="java.lang.String">
</parameter>
<parameter name="millis" type="long">
</parameter>
<parameter name="data" type="byte[]">
</parameter>
<parameter name="flags" type="int">
</parameter>
</constructor>
<constructor name="DropBoxManager.Entry"
type="android.os.DropBoxManager.Entry"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="tag" type="java.lang.String">
</parameter>
<parameter name="millis" type="long">
</parameter>
<parameter name="data" type="android.os.ParcelFileDescriptor">
</parameter>
<parameter name="flags" type="int">
</parameter>
</constructor>
<constructor name="DropBoxManager.Entry"
type="android.os.DropBoxManager.Entry"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="tag" type="java.lang.String">
</parameter>
<parameter name="millis" type="long">
</parameter>
<parameter name="data" type="java.io.File">
</parameter>
<parameter name="flags" type="int">
</parameter>
<exception name="IOException" type="java.io.IOException">
</exception>
</constructor>
<method name="close"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="describeContents"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getFlags"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getInputStream"
return="java.io.InputStream"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<exception name="IOException" type="java.io.IOException">
</exception>
</method>
<method name="getTag"
return="java.lang.String"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getText"
return="java.lang.String"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="maxBytes" type="int">
</parameter>
</method>
<method name="getTimeMillis"
return="long"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="writeToParcel"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="out" type="android.os.Parcel">
</parameter>
<parameter name="flags" type="int">
</parameter>
</method>
<field name="CREATOR"
type="android.os.Parcelable.Creator"
transient="false"
volatile="false"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
</class>
<class name="Environment"
extends="java.lang.Object"
abstract="false"

1
cleanspec.mk Normal file
View File

@@ -0,0 +1 @@
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/com/android/internal/os/IDropBoxService.java)

View File

@@ -70,7 +70,7 @@ import android.net.wifi.IWifiManager;
import android.net.wifi.WifiManager;
import android.os.Binder;
import android.os.Bundle;
import android.os.DropBox;
import android.os.DropBoxManager;
import android.os.FileUtils;
import android.os.Handler;
import android.os.IBinder;
@@ -94,7 +94,7 @@ import android.view.inputmethod.InputMethodManager;
import android.accounts.AccountManager;
import android.accounts.IAccountManager;
import com.android.internal.os.IDropBoxService;
import com.android.internal.os.IDropBoxManagerService;
import java.io.File;
import java.io.FileInputStream;
@@ -185,7 +185,7 @@ class ApplicationContext extends Context {
private ClipboardManager mClipboardManager = null;
private boolean mRestricted;
private AccountManager mAccountManager; // protected by mSync
private DropBox mDropBox = null;
private DropBoxManager mDropBoxManager = null;
private final Object mSync = new Object();
@@ -901,7 +901,7 @@ class ApplicationContext extends Context {
} else if (WALLPAPER_SERVICE.equals(name)) {
return getWallpaperManager();
} else if (DROPBOX_SERVICE.equals(name)) {
return getDropBox();
return getDropBoxManager();
}
return null;
@@ -1060,15 +1060,15 @@ class ApplicationContext extends Context {
return mAudioManager;
}
private DropBox getDropBox() {
private DropBoxManager getDropBoxManager() {
synchronized (mSync) {
if (mDropBox == null) {
if (mDropBoxManager == null) {
IBinder b = ServiceManager.getService(DROPBOX_SERVICE);
IDropBoxService service = IDropBoxService.Stub.asInterface(b);
mDropBox = new DropBox(service);
IDropBoxManagerService service = IDropBoxManagerService.Stub.asInterface(b);
mDropBoxManager = new DropBoxManager(service);
}
}
return mDropBox;
return mDropBoxManager;
}
@Override

View File

@@ -1324,7 +1324,6 @@ public abstract class Context {
* 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";

View File

@@ -16,4 +16,4 @@
package android.os;
parcelable DropBox.Entry;
parcelable DropBoxManager.Entry;

View File

@@ -18,7 +18,7 @@ package android.os;
import android.util.Log;
import com.android.internal.os.IDropBoxService;
import com.android.internal.os.IDropBoxManagerService;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -37,14 +37,12 @@ import java.util.zip.GZIPInputStream;
* {@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}
* <p>DropBoxManager entries are not sent anywhere directly, but other system
* services and debugging tools may scan and upload entries for processing.
*/
public class DropBox {
private static final String TAG = "DropBox";
private final IDropBoxService mService;
public class DropBoxManager {
private static final String TAG = "DropBoxManager";
private final IDropBoxManagerService mService;
/** Flag value: Entry's content was deleted to save space. */
public static final int IS_EMPTY = 1;
@@ -198,14 +196,14 @@ public class DropBox {
}
/** {@hide} */
public DropBox(IDropBoxService service) { mService = service; }
public DropBoxManager(IDropBoxManagerService 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; }
protected DropBoxManager() { mService = null; }
/**
* Stores human-readable text. The data may be discarded eventually (or even

View File

@@ -16,27 +16,27 @@
package com.android.internal.os;
import android.os.DropBox;
import android.os.DropBoxManager;
import android.os.ParcelFileDescriptor;
/**
* "Backend" interface used by {@link android.os.DropBox} to talk to the
* DropBoxService that actually implements the drop box functionality.
* "Backend" interface used by {@link android.os.DropBoxManager} to talk to the
* DropBoxManagerService that actually implements the drop box functionality.
*
* @see DropBox
* @see DropBoxManager
* @hide
*/
interface IDropBoxService {
interface IDropBoxManagerService {
/**
* @see DropBox#addText
* @see DropBox#addData
* @see DropBox#addFile
* @see DropBoxManager#addText
* @see DropBoxManager#addData
* @see DropBoxManager#addFile
*/
void add(in DropBox.Entry entry);
void add(in DropBoxManager.Entry entry);
/** @see DropBox#getNextEntry */
/** @see DropBoxManager#getNextEntry */
boolean isTagEnabled(String tag);
/** @see DropBox#getNextEntry */
DropBox.Entry getNextEntry(String tag, long millis);
/** @see DropBoxManager#getNextEntry */
DropBoxManager.Entry getNextEntry(String tag, long millis);
}

View File

@@ -23,7 +23,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.DropBox;
import android.os.DropBoxManager;
import android.os.ParcelFileDescriptor;
import android.os.StatFs;
import android.os.SystemClock;
@@ -31,7 +31,7 @@ import android.provider.Settings;
import android.text.format.DateFormat;
import android.util.Log;
import com.android.internal.os.IDropBoxService;
import com.android.internal.os.IDropBoxManagerService;
import java.io.File;
import java.io.FileDescriptor;
@@ -54,13 +54,13 @@ import java.util.TreeSet;
import java.util.zip.GZIPOutputStream;
/**
* Implementation of {@link IDropBoxService} using the filesystem.
* Clients use {@link DropBox} to access this service.
* Implementation of {@link IDropBoxManagerService} using the filesystem.
* Clients use {@link DropBoxManager} to access this service.
*
* {@hide}
*/
public final class DropBoxService extends IDropBoxService.Stub {
private static final String TAG = "DropBoxService";
public final class DropBoxManagerService extends IDropBoxManagerService.Stub {
private static final String TAG = "DropBoxManagerService";
private static final int DEFAULT_RESERVE_PERCENT = 10;
private static final int DEFAULT_QUOTA_PERCENT = 10;
private static final int DEFAULT_QUOTA_KB = 5 * 1024;
@@ -113,7 +113,7 @@ public final class DropBoxService extends IDropBoxService.Stub {
* @param context to use for receiving free space & gservices intents
* @param path to store drop box entries in
*/
public DropBoxService(Context context, File path) {
public DropBoxManagerService(Context context, File path) {
mDropBoxDir = path;
// Set up intent receivers
@@ -131,13 +131,13 @@ public final class DropBoxService extends IDropBoxService.Stub {
mContext.unregisterReceiver(mReceiver);
}
public void add(DropBox.Entry entry) {
public void add(DropBoxManager.Entry entry) {
File temp = null;
OutputStream output = null;
final String tag = entry.getTag();
try {
int flags = entry.getFlags();
if ((flags & DropBox.IS_EMPTY) != 0) throw new IllegalArgumentException();
if ((flags & DropBoxManager.IS_EMPTY) != 0) throw new IllegalArgumentException();
init();
if (!isTagEnabled(tag)) return;
@@ -162,9 +162,9 @@ public final class DropBoxService extends IDropBoxService.Stub {
temp = new File(mDropBoxDir, "drop" + Thread.currentThread().getId() + ".tmp");
output = new FileOutputStream(temp);
if (read == buffer.length && ((flags & DropBox.IS_GZIPPED) == 0)) {
if (read == buffer.length && ((flags & DropBoxManager.IS_GZIPPED) == 0)) {
output = new GZIPOutputStream(output);
flags = flags | DropBox.IS_GZIPPED;
flags = flags | DropBoxManager.IS_GZIPPED;
}
do {
@@ -209,7 +209,7 @@ public final class DropBoxService extends IDropBoxService.Stub {
mContentResolver, Settings.Gservices.DROPBOX_TAG_PREFIX + tag));
}
public synchronized DropBox.Entry getNextEntry(String tag, long millis) {
public synchronized DropBoxManager.Entry getNextEntry(String tag, long millis) {
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.READ_LOGS)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("READ_LOGS permission required");
@@ -227,11 +227,12 @@ public final class DropBoxService extends IDropBoxService.Stub {
for (EntryFile entry : list.contents.tailSet(new EntryFile(millis + 1))) {
if (entry.tag == null) continue;
if ((entry.flags & DropBox.IS_EMPTY) != 0) {
return new DropBox.Entry(entry.tag, entry.timestampMillis);
if ((entry.flags & DropBoxManager.IS_EMPTY) != 0) {
return new DropBoxManager.Entry(entry.tag, entry.timestampMillis);
}
try {
return new DropBox.Entry(entry.tag, entry.timestampMillis, entry.file, entry.flags);
return new DropBoxManager.Entry(
entry.tag, entry.timestampMillis, entry.file, entry.flags);
} catch (IOException e) {
Log.e(TAG, "Can't read: " + entry.file, e);
// Continue to next file
@@ -244,7 +245,7 @@ public final class DropBoxService extends IDropBoxService.Stub {
public synchronized void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
!= PackageManager.PERMISSION_GRANTED) {
pw.println("Permission Denial: Can't dump DropBoxService");
pw.println("Permission Denial: Can't dump DropBoxManagerService");
return;
}
@@ -298,25 +299,25 @@ public final class DropBoxService extends IDropBoxService.Stub {
if (entry.file == null) {
pw.println(" (no file)");
continue;
} else if ((entry.flags & DropBox.IS_EMPTY) != 0) {
} else if ((entry.flags & DropBoxManager.IS_EMPTY) != 0) {
pw.println(" (contents lost)");
continue;
} else {
pw.print((entry.flags & DropBox.IS_GZIPPED) != 0 ? " (comopressed " : " (");
pw.print((entry.flags & DropBox.IS_TEXT) != 0 ? "text" : "data");
pw.print((entry.flags & DropBoxManager.IS_GZIPPED) != 0 ? " (comopressed " : " (");
pw.print((entry.flags & DropBoxManager.IS_TEXT) != 0 ? "text" : "data");
pw.format(", %d bytes)", entry.file.length());
pw.println();
}
if (doFile || (doPrint && (entry.flags & DropBox.IS_TEXT) == 0)) {
if (doFile || (doPrint && (entry.flags & DropBoxManager.IS_TEXT) == 0)) {
if (!doPrint) pw.print(" ");
pw.println(entry.file.getPath());
}
if ((entry.flags & DropBox.IS_TEXT) != 0 && (doPrint || !doFile)) {
DropBox.Entry dbe = null;
if ((entry.flags & DropBoxManager.IS_TEXT) != 0 && (doPrint || !doFile)) {
DropBoxManager.Entry dbe = null;
try {
dbe = new DropBox.Entry(
dbe = new DropBoxManager.Entry(
entry.tag, entry.timestampMillis, entry.file, entry.flags);
if (doPrint) {
@@ -408,14 +409,14 @@ public final class DropBoxService extends IDropBoxService.Stub {
*/
public EntryFile(File temp, File dir, String tag,long timestampMillis,
int flags, int blockSize) throws IOException {
if ((flags & DropBox.IS_EMPTY) != 0) throw new IllegalArgumentException();
if ((flags & DropBoxManager.IS_EMPTY) != 0) throw new IllegalArgumentException();
this.tag = tag;
this.timestampMillis = timestampMillis;
this.flags = flags;
this.file = new File(dir, Uri.encode(tag) + "@" + timestampMillis +
((flags & DropBox.IS_TEXT) != 0 ? ".txt" : ".dat") +
((flags & DropBox.IS_GZIPPED) != 0 ? ".gz" : ""));
((flags & DropBoxManager.IS_TEXT) != 0 ? ".txt" : ".dat") +
((flags & DropBoxManager.IS_GZIPPED) != 0 ? ".gz" : ""));
if (!temp.renameTo(this.file)) {
throw new IOException("Can't rename " + temp + " to " + this.file);
@@ -433,7 +434,7 @@ public final class DropBoxService extends IDropBoxService.Stub {
public EntryFile(File dir, String tag, long timestampMillis) throws IOException {
this.tag = tag;
this.timestampMillis = timestampMillis;
this.flags = DropBox.IS_EMPTY;
this.flags = DropBoxManager.IS_EMPTY;
this.file = new File(dir, Uri.encode(tag) + "@" + timestampMillis + ".lost");
this.blocks = 0;
new FileOutputStream(this.file).close();
@@ -453,26 +454,26 @@ public final class DropBoxService extends IDropBoxService.Stub {
if (at < 0) {
this.tag = null;
this.timestampMillis = 0;
this.flags = DropBox.IS_EMPTY;
this.flags = DropBoxManager.IS_EMPTY;
return;
}
int flags = 0;
this.tag = Uri.decode(name.substring(0, at));
if (name.endsWith(".gz")) {
flags |= DropBox.IS_GZIPPED;
flags |= DropBoxManager.IS_GZIPPED;
name = name.substring(0, name.length() - 3);
}
if (name.endsWith(".lost")) {
flags |= DropBox.IS_EMPTY;
flags |= DropBoxManager.IS_EMPTY;
name = name.substring(at + 1, name.length() - 5);
} else if (name.endsWith(".txt")) {
flags |= DropBox.IS_TEXT;
flags |= DropBoxManager.IS_TEXT;
name = name.substring(at + 1, name.length() - 4);
} else if (name.endsWith(".dat")) {
name = name.substring(at + 1, name.length() - 4);
} else {
this.flags = DropBox.IS_EMPTY;
this.flags = DropBoxManager.IS_EMPTY;
this.timestampMillis = 0;
return;
}
@@ -490,7 +491,7 @@ public final class DropBoxService extends IDropBoxService.Stub {
public EntryFile(long millis) {
this.tag = null;
this.timestampMillis = millis;
this.flags = DropBox.IS_EMPTY;
this.flags = DropBoxManager.IS_EMPTY;
this.file = null;
this.blocks = 0;
}
@@ -585,7 +586,7 @@ public final class DropBoxService extends IDropBoxService.Stub {
mAllFiles.blocks -= late.blocks;
FileList tagFiles = mFilesByTag.get(late.tag);
if (tagFiles.contents.remove(late)) tagFiles.blocks -= late.blocks;
if ((late.flags & DropBox.IS_EMPTY) == 0) {
if ((late.flags & DropBoxManager.IS_EMPTY) == 0) {
enrollEntry(new EntryFile(
late.file, mDropBoxDir, late.tag, t++, late.flags, mBlockSize));
} else {

View File

@@ -297,9 +297,9 @@ class ServerThread extends Thread {
try {
Log.i(TAG, "DropBox Service");
ServiceManager.addService(Context.DROPBOX_SERVICE,
new DropBoxService(context, new File("/data/system/dropbox")));
new DropBoxManagerService(context, new File("/data/system/dropbox")));
} catch (Throwable e) {
Log.e(TAG, "Failure starting DropBox Service", e);
Log.e(TAG, "Failure starting DropBoxManagerService", e);
}
try {

View File

@@ -19,14 +19,14 @@ package com.android.unit_tests;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.DropBox;
import android.os.DropBoxManager;
import android.os.ParcelFileDescriptor;
import android.os.ServiceManager;
import android.os.StatFs;
import android.provider.Settings;
import android.test.AndroidTestCase;
import com.android.server.DropBoxService;
import com.android.server.DropBoxManagerService;
import java.io.File;
import java.io.FileOutputStream;
@@ -35,7 +35,7 @@ import java.io.InputStream;
import java.util.Random;
import java.util.zip.GZIPOutputStream;
/** Test {@link DropBox} functionality. */
/** Test {@link DropBoxManager} functionality. */
public class DropBoxTest extends AndroidTestCase {
public void tearDown() throws Exception {
Intent override = new Intent(Settings.Gservices.OVERRIDE_ACTION);
@@ -46,7 +46,8 @@ public class DropBoxTest extends AndroidTestCase {
}
public void testAddText() throws Exception {
DropBox dropbox = (DropBox) getContext().getSystemService(Context.DROPBOX_SERVICE);
DropBoxManager dropbox = (DropBoxManager) getContext().getSystemService(
Context.DROPBOX_SERVICE);
long before = System.currentTimeMillis();
Thread.sleep(5);
dropbox.addText("DropBoxTest", "TEST0");
@@ -58,9 +59,9 @@ public class DropBoxTest extends AndroidTestCase {
Thread.sleep(5);
long after = System.currentTimeMillis();
DropBox.Entry e0 = dropbox.getNextEntry("DropBoxTest", before);
DropBox.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
DropBox.Entry e2 = dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis());
DropBoxManager.Entry e0 = dropbox.getNextEntry("DropBoxTest", before);
DropBoxManager.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
DropBoxManager.Entry e2 = dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis());
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e2.getTimeMillis()));
assertTrue(e0.getTimeMillis() > before);
@@ -79,12 +80,13 @@ public class DropBoxTest extends AndroidTestCase {
}
public void testAddData() throws Exception {
DropBox dropbox = (DropBox) getContext().getSystemService(Context.DROPBOX_SERVICE);
DropBoxManager dropbox = (DropBoxManager) getContext().getSystemService(
Context.DROPBOX_SERVICE);
long before = System.currentTimeMillis();
dropbox.addData("DropBoxTest", "TEST".getBytes(), 0);
long after = System.currentTimeMillis();
DropBox.Entry e = dropbox.getNextEntry("DropBoxTest", before);
DropBoxManager.Entry e = dropbox.getNextEntry("DropBoxTest", before);
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e.getTimeMillis()));
assertEquals("DropBoxTest", e.getTag());
@@ -122,7 +124,8 @@ public class DropBoxTest extends AndroidTestCase {
os2.close();
gz3.close();
DropBox dropbox = (DropBox) getContext().getSystemService(Context.DROPBOX_SERVICE);
DropBoxManager dropbox = (DropBoxManager) getContext().getSystemService(
Context.DROPBOX_SERVICE);
int mode = ParcelFileDescriptor.MODE_READ_ONLY;
ParcelFileDescriptor pfd0 = ParcelFileDescriptor.open(f0, mode);
@@ -130,20 +133,20 @@ public class DropBoxTest extends AndroidTestCase {
ParcelFileDescriptor pfd2 = ParcelFileDescriptor.open(f2, mode);
ParcelFileDescriptor pfd3 = ParcelFileDescriptor.open(f3, mode);
dropbox.addFile("DropBoxTest", pfd0, DropBox.IS_TEXT);
dropbox.addFile("DropBoxTest", pfd1, DropBox.IS_TEXT | DropBox.IS_GZIPPED);
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, DropBox.IS_GZIPPED);
dropbox.addFile("DropBoxTest", pfd3, DropBoxManager.IS_GZIPPED);
pfd0.close();
pfd1.close();
pfd2.close();
pfd3.close();
DropBox.Entry e0 = dropbox.getNextEntry("DropBoxTest", before);
DropBox.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
DropBox.Entry e2 = dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis());
DropBox.Entry e3 = dropbox.getNextEntry("DropBoxTest", e2.getTimeMillis());
DropBoxManager.Entry e0 = dropbox.getNextEntry("DropBoxTest", before);
DropBoxManager.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
DropBoxManager.Entry e2 = dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis());
DropBoxManager.Entry e3 = dropbox.getNextEntry("DropBoxTest", e2.getTimeMillis());
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e3.getTimeMillis()));
assertTrue(e0.getTimeMillis() > before);
@@ -151,8 +154,8 @@ public class DropBoxTest extends AndroidTestCase {
assertTrue(e2.getTimeMillis() > e1.getTimeMillis());
assertTrue(e3.getTimeMillis() > e2.getTimeMillis());
assertEquals(DropBox.IS_TEXT, e0.getFlags());
assertEquals(DropBox.IS_TEXT, e1.getFlags());
assertEquals(DropBoxManager.IS_TEXT, e0.getFlags());
assertEquals(DropBoxManager.IS_TEXT, e1.getFlags());
assertEquals(0, e2.getFlags());
assertEquals(0, e3.getFlags());
@@ -198,14 +201,14 @@ public class DropBoxTest extends AndroidTestCase {
// Tombstone in the far future
new FileOutputStream(new File(dir, "DropBoxTest@" + (before + 100002) + ".lost")).close();
DropBoxService service = new DropBoxService(getContext(), dir);
DropBox dropbox = new DropBox(service);
DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
DropBoxManager dropbox = new DropBoxManager(service);
// Until a write, the timestamps are taken at face value
DropBox.Entry e0 = dropbox.getNextEntry(null, before);
DropBox.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
DropBox.Entry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
DropBox.Entry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
DropBoxManager.Entry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
DropBoxManager.Entry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
assertTrue(null == dropbox.getNextEntry(null, e3.getTimeMillis()));
assertEquals("FUTURE0", e0.getText(80));
@@ -249,7 +252,8 @@ public class DropBoxTest extends AndroidTestCase {
}
public void testIsTagEnabled() throws Exception {
DropBox dropbox = (DropBox) getContext().getSystemService(Context.DROPBOX_SERVICE);
DropBoxManager dropbox = (DropBoxManager) getContext().getSystemService(
Context.DROPBOX_SERVICE);
long before = System.currentTimeMillis();
dropbox.addText("DropBoxTest", "TEST-ENABLED");
assertTrue(dropbox.isTagEnabled("DropBoxTest"));
@@ -268,8 +272,8 @@ public class DropBoxTest extends AndroidTestCase {
dropbox.addText("DropBoxTest", "TEST-ENABLED-AGAIN");
assertTrue(dropbox.isTagEnabled("DropBoxTest"));
DropBox.Entry e0 = dropbox.getNextEntry("DropBoxTest", before);
DropBox.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
DropBoxManager.Entry e0 = dropbox.getNextEntry("DropBoxTest", before);
DropBoxManager.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis()));
assertEquals("TEST-ENABLED", e0.getText(80));
@@ -281,24 +285,24 @@ public class DropBoxTest extends AndroidTestCase {
public void testGetNextEntry() throws Exception {
File dir = getEmptyDir("testGetNextEntry");
DropBoxService service = new DropBoxService(getContext(), dir);
DropBox dropbox = new DropBox(service);
DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
DropBoxManager dropbox = new DropBoxManager(service);
long before = System.currentTimeMillis();
dropbox.addText("DropBoxTest.A", "A0");
dropbox.addText("DropBoxTest.B", "B0");
dropbox.addText("DropBoxTest.A", "A1");
DropBox.Entry a0 = dropbox.getNextEntry("DropBoxTest.A", before);
DropBox.Entry a1 = dropbox.getNextEntry("DropBoxTest.A", a0.getTimeMillis());
DropBoxManager.Entry a0 = dropbox.getNextEntry("DropBoxTest.A", before);
DropBoxManager.Entry a1 = dropbox.getNextEntry("DropBoxTest.A", a0.getTimeMillis());
assertTrue(null == dropbox.getNextEntry("DropBoxTest.A", a1.getTimeMillis()));
DropBox.Entry b0 = dropbox.getNextEntry("DropBoxTest.B", before);
DropBoxManager.Entry b0 = dropbox.getNextEntry("DropBoxTest.B", before);
assertTrue(null == dropbox.getNextEntry("DropBoxTest.B", b0.getTimeMillis()));
DropBox.Entry x0 = dropbox.getNextEntry(null, before);
DropBox.Entry x1 = dropbox.getNextEntry(null, x0.getTimeMillis());
DropBox.Entry x2 = dropbox.getNextEntry(null, x1.getTimeMillis());
DropBoxManager.Entry x0 = dropbox.getNextEntry(null, before);
DropBoxManager.Entry x1 = dropbox.getNextEntry(null, x0.getTimeMillis());
DropBoxManager.Entry x2 = dropbox.getNextEntry(null, x1.getTimeMillis());
assertTrue(null == dropbox.getNextEntry(null, x2.getTimeMillis()));
assertEquals("DropBoxTest.A", a0.getTag());
@@ -345,8 +349,8 @@ public class DropBoxTest extends AndroidTestCase {
final int overhead = 64;
long before = System.currentTimeMillis();
DropBoxService service = new DropBoxService(getContext(), dir);
DropBox dropbox = new DropBox(service);
DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
DropBoxManager dropbox = new DropBoxManager(service);
addRandomEntry(dropbox, "DropBoxTest0", blockSize - overhead);
addRandomEntry(dropbox, "DropBoxTest0", blockSize - overhead);
@@ -361,16 +365,16 @@ public class DropBoxTest extends AndroidTestCase {
addRandomEntry(dropbox, "DropBoxTest2", blockSize - overhead);
addRandomEntry(dropbox, "DropBoxTest2", blockSize - overhead);
DropBox.Entry e0 = dropbox.getNextEntry(null, before);
DropBox.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
DropBox.Entry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
DropBox.Entry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
DropBox.Entry e4 = dropbox.getNextEntry(null, e3.getTimeMillis());
DropBox.Entry e5 = dropbox.getNextEntry(null, e4.getTimeMillis());
DropBox.Entry e6 = dropbox.getNextEntry(null, e5.getTimeMillis());
DropBox.Entry e7 = dropbox.getNextEntry(null, e6.getTimeMillis());
DropBox.Entry e8 = dropbox.getNextEntry(null, e7.getTimeMillis());
DropBox.Entry e9 = dropbox.getNextEntry(null, e8.getTimeMillis());
DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
DropBoxManager.Entry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
DropBoxManager.Entry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
DropBoxManager.Entry e4 = dropbox.getNextEntry(null, e3.getTimeMillis());
DropBoxManager.Entry e5 = dropbox.getNextEntry(null, e4.getTimeMillis());
DropBoxManager.Entry e6 = dropbox.getNextEntry(null, e5.getTimeMillis());
DropBoxManager.Entry e7 = dropbox.getNextEntry(null, e6.getTimeMillis());
DropBoxManager.Entry e8 = dropbox.getNextEntry(null, e7.getTimeMillis());
DropBoxManager.Entry e9 = dropbox.getNextEntry(null, e8.getTimeMillis());
assertTrue(null == dropbox.getNextEntry(null, e9.getTimeMillis()));
assertEquals("DropBoxTest0", e0.getTag());
@@ -409,9 +413,9 @@ public class DropBoxTest extends AndroidTestCase {
// Specifying a tag name skips tombstone records.
DropBox.Entry t0 = dropbox.getNextEntry("DropBoxTest1", before);
DropBox.Entry t1 = dropbox.getNextEntry("DropBoxTest1", t0.getTimeMillis());
DropBox.Entry t2 = dropbox.getNextEntry("DropBoxTest1", t1.getTimeMillis());
DropBoxManager.Entry t0 = dropbox.getNextEntry("DropBoxTest1", before);
DropBoxManager.Entry t1 = dropbox.getNextEntry("DropBoxTest1", t0.getTimeMillis());
DropBoxManager.Entry t2 = dropbox.getNextEntry("DropBoxTest1", t1.getTimeMillis());
assertTrue(null == dropbox.getNextEntry("DropBoxTest1", t2.getTimeMillis()));
assertEquals("DropBoxTest1", t0.getTag());
@@ -441,15 +445,15 @@ public class DropBoxTest extends AndroidTestCase {
// Write one normal entry and another so big that it is instantly tombstoned
long before = System.currentTimeMillis();
DropBoxService service = new DropBoxService(getContext(), dir);
DropBox dropbox = new DropBox(service);
DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
DropBoxManager dropbox = new DropBoxManager(service);
dropbox.addText("DropBoxTest", "TEST");
addRandomEntry(dropbox, "DropBoxTest", blockSize * 20);
// Verify that things are as expected
DropBox.Entry e0 = dropbox.getNextEntry(null, before);
DropBox.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
assertTrue(null == dropbox.getNextEntry(null, e1.getTimeMillis()));
assertEquals("TEST", e0.getText(80));
@@ -469,15 +473,15 @@ public class DropBoxTest extends AndroidTestCase {
e0.close();
}
public void testCreateDropBoxWithInvalidDirectory() throws Exception {
// If created with an invalid directory, the DropBox should suffer quietly
public void testCreateDropBoxManagerWithInvalidDirectory() throws Exception {
// If created with an invalid directory, the DropBoxManager should suffer quietly
// and fail all operations (this is how it survives a full disk).
// Once the directory becomes possible to create, it will start working.
File dir = new File(getEmptyDir("testCreateDropBoxWith"), "InvalidDirectory");
File dir = new File(getEmptyDir("testCreateDropBoxManagerWith"), "InvalidDirectory");
new FileOutputStream(dir).close(); // Create an empty file
DropBoxService service = new DropBoxService(getContext(), dir);
DropBox dropbox = new DropBox(service);
DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
DropBoxManager dropbox = new DropBoxManager(service);
dropbox.addText("DropBoxTest", "should be ignored");
dropbox.addData("DropBoxTest", "should be ignored".getBytes(), 0);
@@ -485,7 +489,7 @@ public class DropBoxTest extends AndroidTestCase {
dir.delete(); // Remove the file so a directory can be created
dropbox.addText("DropBoxTest", "TEST");
DropBox.Entry e = dropbox.getNextEntry("DropBoxTest", 0);
DropBoxManager.Entry e = dropbox.getNextEntry("DropBoxTest", 0);
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e.getTimeMillis()));
assertEquals("DropBoxTest", e.getTag());
assertEquals("TEST", e.getText(80));
@@ -493,7 +497,7 @@ public class DropBoxTest extends AndroidTestCase {
service.stop();
}
private void addRandomEntry(DropBox dropbox, String tag, int size) throws Exception {
private void addRandomEntry(DropBoxManager dropbox, String tag, int size) throws Exception {
byte[] bytes = new byte[size];
new Random(System.currentTimeMillis()).nextBytes(bytes);
@@ -507,7 +511,7 @@ public class DropBoxTest extends AndroidTestCase {
fd.close();
}
private int getEntrySize(DropBox.Entry e) throws Exception {
private int getEntrySize(DropBoxManager.Entry e) throws Exception {
InputStream is = e.getInputStream();
if (is == null) return -1;
int length = 0;