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

Commit be1c422a authored by Suchi Amalapurapu's avatar Suchi Amalapurapu
Browse files

If the usage stats file doesn't exist in the first place there is no need to

backup and short return.
parent 48a65d99
Loading
Loading
Loading
Loading
+11 −13
Original line number Diff line number Diff line
@@ -380,11 +380,15 @@ public final class UsageStatsService extends IUsageStats.Stub {
            // Get the most recent file
            mFileLeaf = getCurrentDateStr(FILE_PREFIX);
            // Copy current file to back up
            File backupFile =  new File(mFile.getPath() + ".bak");
            File backupFile = null;
            if (mFile != null && mFile.exists()) {
                backupFile = new File(mFile.getPath() + ".bak");
                if (!mFile.renameTo(backupFile)) {
                    Log.w(TAG, "Failed to persist new stats");
                    return;
                }
            }

            try {
                // Write mStats to file
                writeStatsFLOCK();
@@ -468,16 +472,10 @@ public final class UsageStatsService extends IUsageStats.Stub {
            
            final boolean samePackage = pkgName.equals(mLastResumedPkg);
            if (mIsResumed) {
                if (samePackage) {
                    Log.w(TAG, "Something wrong here, didn't expect "
                            + pkgName + " to be resumed");
                    return;
                }
                
                if (mLastResumedPkg != null) {
                    // We last resumed some other package...  just pause it now
                    // to recover.
                    Log.w(TAG, "Unexpected resume of " + pkgName
                    Log.i(TAG, "Unexpected resume of " + pkgName
                            + " while already resumed in " + mLastResumedPkg);
                    PkgUsageStatsExtended pus = mStats.get(mLastResumedPkg);
                    if (pus != null) {
@@ -516,7 +514,7 @@ public final class UsageStatsService extends IUsageStats.Stub {
                return;
            }
            if (!mIsResumed) {
                Log.w(TAG, "Something wrong here, didn't expect "
                Log.i(TAG, "Something wrong here, didn't expect "
                        + pkgName + " to be paused");
                return;
            }
@@ -527,7 +525,7 @@ public final class UsageStatsService extends IUsageStats.Stub {
            PkgUsageStatsExtended pus = mStats.get(pkgName);
            if (pus == null) {
                // Weird some error here
                Log.w(TAG, "No package stats for pkg:"+pkgName);
                Log.i(TAG, "No package stats for pkg:"+pkgName);
                return;
            }
            pus.updatePause();