Java Code Examples for android.os.DropBoxManager#IS_EMPTY

The following examples show how to use android.os.DropBoxManager#IS_EMPTY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DropBoxManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Moves an existing temporary file to a new log filename.
 *
 * @param temp file to rename
 * @param dir to store file in
 * @param tag to use for new log file name
 * @param timestampMillis of log entry
 * @param flags for the entry data
 * @param blockSize to use for space accounting
 * @throws IOException if the file can't be moved
 */
public EntryFile(File temp, File dir, String tag,long timestampMillis,
                 int flags, int blockSize) throws IOException {
    if ((flags & DropBoxManager.IS_EMPTY) != 0) throw new IllegalArgumentException();

    this.tag = TextUtils.safeIntern(tag);
    this.timestampMillis = timestampMillis;
    this.flags = flags;

    final File file = this.getFile(dir);
    if (!temp.renameTo(file)) {
        throw new IOException("Can't rename " + temp + " to " + file);
    }
    this.blocks = (int) ((file.length() + blockSize - 1) / blockSize);
}
 
Example 2
Source File: DropBoxManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a EntryFile object with only a timestamp for comparison purposes.
 * @param millis to compare with.
 */
public EntryFile(long millis) {
    this.tag = null;
    this.timestampMillis = millis;
    this.flags = DropBoxManager.IS_EMPTY;
    this.blocks = 0;
}
 
Example 3
Source File: DropBoxManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @return File extension for the flags. */
private String getExtension() {
    if ((flags &  DropBoxManager.IS_EMPTY) != 0) {
        return ".lost";
    }
    return ((flags & DropBoxManager.IS_TEXT) != 0 ? ".txt" : ".dat") +
            ((flags & DropBoxManager.IS_GZIPPED) != 0 ? ".gz" : "");
}
 
Example 4
Source File: DropBoxManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts metadata from an existing on-disk log filename.
 *
 * Note when a filename is not recognizable, it will create an instance that
 * {@link #hasFile()} would return false on, and also remove the file.
 *
 * @param file name of existing log file
 * @param blockSize to use for space accounting
 */
public EntryFile(File file, int blockSize) {

    boolean parseFailure = false;

    String name = file.getName();
    int flags = 0;
    String tag = null;
    long millis = 0;

    final int at = name.lastIndexOf('@');
    if (at < 0) {
        parseFailure = true;
    } else {
        tag = Uri.decode(name.substring(0, at));
        if (name.endsWith(".gz")) {
            flags |= DropBoxManager.IS_GZIPPED;
            name = name.substring(0, name.length() - 3);
        }
        if (name.endsWith(".lost")) {
            flags |= DropBoxManager.IS_EMPTY;
            name = name.substring(at + 1, name.length() - 5);
        } else if (name.endsWith(".txt")) {
            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 {
            parseFailure = true;
        }
        if (!parseFailure) {
            try {
                millis = Long.parseLong(name);
            } catch (NumberFormatException e) {
                parseFailure = true;
            }
        }
    }
    if (parseFailure) {
        Slog.wtf(TAG, "Invalid filename: " + file);

        // Remove the file and return an empty instance.
        file.delete();
        this.tag = null;
        this.flags = DropBoxManager.IS_EMPTY;
        this.timestampMillis = 0;
        this.blocks = 0;
        return;
    }

    this.blocks = (int) ((file.length() + blockSize - 1) / blockSize);
    this.tag = TextUtils.safeIntern(tag);
    this.flags = flags;
    this.timestampMillis = millis;
}
 
Example 5
Source File: DropBoxManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/** Moves a temporary file to a final log filename and enrolls it. */
private synchronized long createEntry(File temp, String tag, int flags) throws IOException {
    long t = System.currentTimeMillis();

    // Require each entry to have a unique timestamp; if there are entries
    // >10sec in the future (due to clock skew), drag them back to avoid
    // keeping them around forever.

    SortedSet<EntryFile> tail = mAllFiles.contents.tailSet(new EntryFile(t + 10000));
    EntryFile[] future = null;
    if (!tail.isEmpty()) {
        future = tail.toArray(new EntryFile[tail.size()]);
        tail.clear();  // Remove from mAllFiles
    }

    if (!mAllFiles.contents.isEmpty()) {
        t = Math.max(t, mAllFiles.contents.last().timestampMillis + 1);
    }

    if (future != null) {
        for (EntryFile late : future) {
            mAllFiles.blocks -= late.blocks;
            FileList tagFiles = mFilesByTag.get(late.tag);
            if (tagFiles != null && tagFiles.contents.remove(late)) {
                tagFiles.blocks -= late.blocks;
            }
            if ((late.flags & DropBoxManager.IS_EMPTY) == 0) {
                enrollEntry(new EntryFile(late.getFile(mDropBoxDir), mDropBoxDir,
                        late.tag, t++, late.flags, mBlockSize));
            } else {
                enrollEntry(new EntryFile(mDropBoxDir, late.tag, t++));
            }
        }
    }

    if (temp == null) {
        enrollEntry(new EntryFile(mDropBoxDir, tag, t));
    } else {
        enrollEntry(new EntryFile(temp, mDropBoxDir, tag, t, flags, mBlockSize));
    }
    return t;
}
 
Example 6
Source File: DropBoxManagerService.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a zero-length tombstone for a file whose contents were lost.
 *
 * @param dir to store file in
 * @param tag to use for new log file name
 * @param timestampMillis of log entry
 * @throws IOException if the file can't be created.
 */
public EntryFile(File dir, String tag, long timestampMillis) throws IOException {
    this.tag = TextUtils.safeIntern(tag);
    this.timestampMillis = timestampMillis;
    this.flags = DropBoxManager.IS_EMPTY;
    this.blocks = 0;
    new FileOutputStream(getFile(dir)).close();
}