Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d4db41ad authored by Siim Sammul's avatar Siim Sammul Committed by Android (Google) Code Review
Browse files

Merge "Log the reason and tag for dropbox dropped entries." into tm-dev

parents 244a90bf d9249c2b
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.IDropBoxManagerService;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.ObjectUtils;
import com.android.server.DropBoxManagerInternal.EntrySource;

@@ -501,12 +502,20 @@ public final class DropBoxManagerService extends SystemService {
            }
        } catch (IOException e) {
            Slog.e(TAG, "Can't write: " + tag, e);
            logDropboxDropped(
                    FrameworkStatsLog.DROPBOX_ENTRY_DROPPED__DROP_REASON__WRITE_FAILURE,
                    tag,
                    0);
        } finally {
            IoUtils.closeQuietly(entry);
            if (temp != null) temp.delete();
        }
    }

    private void logDropboxDropped(int reason, String tag, long entryAge) {
        FrameworkStatsLog.write(FrameworkStatsLog.DROPBOX_ENTRY_DROPPED, reason, tag, entryAge);
    }

    public boolean isTagEnabled(String tag) {
        final long token = Binder.clearCallingIdentity();
        try {
@@ -1119,13 +1128,19 @@ public final class DropBoxManagerService extends SystemService {
                Settings.Global.DROPBOX_MAX_FILES,
                (ActivityManager.isLowRamDeviceStatic()
                        ?  DEFAULT_MAX_FILES_LOWRAM : DEFAULT_MAX_FILES));
        long cutoffMillis = System.currentTimeMillis() - ageSeconds * 1000;
        long curTimeMillis = System.currentTimeMillis();
        long cutoffMillis = curTimeMillis - ageSeconds * 1000;
        while (!mAllFiles.contents.isEmpty()) {
            EntryFile entry = mAllFiles.contents.first();
            if (entry.timestampMillis > cutoffMillis && mAllFiles.contents.size() < mMaxFiles) {
                break;
            }

            logDropboxDropped(
                    FrameworkStatsLog.DROPBOX_ENTRY_DROPPED__DROP_REASON__AGED,
                    entry.tag,
                    curTimeMillis - entry.timestampMillis);

            FileList tag = mFilesByTag.get(entry.tag);
            if (tag != null && tag.contents.remove(entry)) tag.blocks -= entry.blocks;
            if (mAllFiles.contents.remove(entry)) mAllFiles.blocks -= entry.blocks;
@@ -1194,6 +1209,11 @@ public final class DropBoxManagerService extends SystemService {
                if (mAllFiles.blocks < mCachedQuotaBlocks) break;
                while (tag.blocks > tagQuota && !tag.contents.isEmpty()) {
                    EntryFile entry = tag.contents.first();
                    logDropboxDropped(
                            FrameworkStatsLog.DROPBOX_ENTRY_DROPPED__DROP_REASON__CLEARING_DATA,
                            entry.tag,
                            curTimeMillis - entry.timestampMillis);

                    if (tag.contents.remove(entry)) tag.blocks -= entry.blocks;
                    if (mAllFiles.contents.remove(entry)) mAllFiles.blocks -= entry.blocks;