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

Commit 3f963cb7 authored by Varun Shah's avatar Varun Shah Committed by Automerger Merge Worker
Browse files

Merge "Fixed to prevent usagestats file corruption when writing" am:...

Merge "Fixed to prevent usagestats file corruption when writing" am: 98fc96fc am: acb36aad am: 9d58180b am: b47c4631 am: 492a5c18

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1550659

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I7889baa5e77b15f2cb8c6d517f7d895b161f1697
parents a324cf81 492a5c18
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -1026,6 +1026,8 @@ public class UsageStatsDatabase {
            writeLocked(fos, stats, version, packagesTokenData);
            file.finishWrite(fos);
            fos = null;
        } catch (Exception e) {
            // Do nothing. Exception has already been handled.
        } finally {
            // When fos is null (successful write), this will no-op
            file.failWrite(fos);
@@ -1033,7 +1035,7 @@ public class UsageStatsDatabase {
    }

    private static void writeLocked(OutputStream out, IntervalStats stats, int version,
            PackagesTokenData packagesTokenData) throws RuntimeException {
            PackagesTokenData packagesTokenData) throws Exception {
        switch (version) {
            case 1:
            case 2:
@@ -1045,6 +1047,7 @@ public class UsageStatsDatabase {
                    UsageStatsProto.write(out, stats);
                } catch (Exception e) {
                    Slog.e(TAG, "Unable to write interval stats to proto.", e);
                    throw e;
                }
                break;
            case 5:
@@ -1053,6 +1056,7 @@ public class UsageStatsDatabase {
                    UsageStatsProtoV2.write(out, stats);
                } catch (Exception e) {
                    Slog.e(TAG, "Unable to write interval stats to proto.", e);
                    throw e;
                }
                break;
            default: