Source:
<code>private void writeStatsToFile(final boolean force, final boolean forceWriteHistoryStats) { int curDay; synchronized (mCal) { mCal.setTimeInMillis(System.currentTimeMillis()); curDay = mCal.get(Calendar.DAY_OF_YEAR); } final boolean dayChanged = curDay != mLastWriteDay.get(); final long currElapsedTime = SystemClock.elapsedRealtime(); if (!force) { if (!dayChanged && (currElapsedTime - mLastWriteElapsedTime.get()) < FILE_WRITE_INTERVAL <START> && !localLOGV) { <END> return; } if (mUnforcedDiskWriteRunning.compareAndSet(false, true)) { new Thread("UsageStatsService_DiskWriter") { public void run() { try { if (localLOGV) Slog.d(TAG, "Disk writer thread starting."); writeStatsToFile(true, false); } finally { mUnforcedDiskWriteRunning.set(false); if (localLOGV) Slog.d(TAG, "Disk writer thread ending."); } } }.start(); } return; } synchronized (mFileLock) { mFileLeaf = getCurrentDateStr(FILE_PREFIX); File backupFile = null; if (mFile != null && mFile.exists()) { backupFile = new File(mFile.getPath() + ".bak"); if (!backupFile.exists()) { if (!mFile.renameTo(backupFile)) { Slog.w(TAG, "Failed to persist new stats"); return; } } else { mFile.delete(); } } try { writeStatsFLOCK(mFile); mLastWriteElapsedTime.set(currElapsedTime); if (dayChanged) { mLastWriteDay.set(curDay); synchronized (mStats) { mStats.clear(); } mFile = new File(mDir, mFileLeaf); checkFileLimitFLOCK(); } if (dayChanged || forceWriteHistoryStats || localLOGV) { writeHistoryStatsFLOCK(); } if (backupFile != null) { backupFile.delete(); } } catch (IOException e) { Slog.w(TAG, "Failed writing stats to file:" + mFile); if (backupFile != null) { mFile.delete(); backupFile.renameTo(mFile); } } } if (localLOGV) Slog.d(TAG, "Dumped usage stats."); }</code><technical_language>this out</technical_language>

Target:
private void writeStatsToFile(final boolean force, final boolean forceWriteHistoryStats) { int curDay; synchronized (mCal) { mCal.setTimeInMillis(System.currentTimeMillis()); curDay = mCal.get(Calendar.DAY_OF_YEAR); } final boolean dayChanged = curDay != mLastWriteDay.get(); final long currElapsedTime = SystemClock.elapsedRealtime(); if (!force) { if (!dayChanged && (currElapsedTime - mLastWriteElapsedTime.get()) < FILE_WRITE_INTERVAL) { return; } if (mUnforcedDiskWriteRunning.compareAndSet(false, true)) { new Thread("UsageStatsService_DiskWriter") { public void run() { try { if (localLOGV) Slog.d(TAG, "Disk writer thread starting."); writeStatsToFile(true, false); } finally { mUnforcedDiskWriteRunning.set(false); if (localLOGV) Slog.d(TAG, "Disk writer thread ending."); } } }.start(); } return; } synchronized (mFileLock) { mFileLeaf = getCurrentDateStr(FILE_PREFIX); File backupFile = null; if (mFile != null && mFile.exists()) { backupFile = new File(mFile.getPath() + ".bak"); if (!backupFile.exists()) { if (!mFile.renameTo(backupFile)) { Slog.w(TAG, "Failed to persist new stats"); return; } } else { mFile.delete(); } } try { writeStatsFLOCK(mFile); mLastWriteElapsedTime.set(currElapsedTime); if (dayChanged) { mLastWriteDay.set(curDay); synchronized (mStats) { mStats.clear(); } mFile = new File(mDir, mFileLeaf); checkFileLimitFLOCK(); } if (dayChanged || forceWriteHistoryStats) { writeHistoryStatsFLOCK(); } if (backupFile != null) { backupFile.delete(); } } catch (IOException e) { Slog.w(TAG, "Failed writing stats to file:" + mFile); if (backupFile != null) { mFile.delete(); backupFile.renameTo(mFile); } } } if (localLOGV) Slog.d(TAG, "Dumped usage stats."); }