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

Commit f41a76e8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove extra null-check on IntervalStats.events."

parents e06f9da4 f6118b3d
Loading
Loading
Loading
Loading
+4 −20
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import static junit.framework.TestCase.fail;

import static org.testng.Assert.assertEquals;

import android.app.usage.EventList;
import android.app.usage.TimeSparseArray;
import android.app.usage.UsageEvents.Event;
import android.app.usage.UsageStats;
@@ -130,10 +129,6 @@ public class UsageStatsDatabaseTest {
        mIntervalStats.keyguardHiddenTracker.count = 5;
        mIntervalStats.keyguardHiddenTracker.duration = 4444444;

        if (mIntervalStats.events == null) {
            mIntervalStats.events = new EventList();
        }

        for (int i = 0; i < numberOfEvents; i++) {
            Event event = new Event();
            final int packageInt = ((i / 3) % 7); //clusters of 3 events from 7 "apps"
@@ -320,22 +315,11 @@ public class UsageStatsDatabaseTest {
            }
        }
        assertEquals(stats1.activeConfiguration, stats2.activeConfiguration);

        if (stats1.events == null) {
            // If stats1 events are null, stats2 should be null or empty
            if (stats2.events != null) {
                assertEquals(stats2.events.size(), 0);
            }
        } else if (stats2.events == null) {
            // If stats2 events are null, stats1 should be null or empty
            assertEquals(stats1.events.size(), 0);
        } else {
        assertEquals(stats1.events.size(), stats2.events.size());
        for (int i = 0; i < stats1.events.size(); i++) {
            compareUsageEvent(stats1.events.get(i), stats2.events.get(i), i, minVersion);
        }
    }
    }

    /**
     * Runs the Write Read test.
@@ -421,7 +405,7 @@ public class UsageStatsDatabaseTest {
        // Clear non backed up data from expected IntervalStats
        mIntervalStats.activeConfiguration = null;
        mIntervalStats.configurations.clear();
        if (mIntervalStats.events != null) mIntervalStats.events.clear();
        mIntervalStats.events.clear();

        // The written and read IntervalStats should match
        compareIntervalStats(mIntervalStats, stats.get(0), version);
+29 −31
Original line number Diff line number Diff line
@@ -930,7 +930,6 @@ public class UsageStatsDatabase {
            }
        }

        if (statsOut.events != null) {
        final int eventSize = statsOut.events.size();
        for (int i = 0; i < eventSize; i++) {
            final UsageEvents.Event event = statsOut.events.get(i);
@@ -965,7 +964,6 @@ public class UsageStatsDatabase {
                }
            }
        }
        }

        if (failures != 0) {
            if (failures > failureLogLimit) {
@@ -1198,7 +1196,7 @@ public class UsageStatsDatabase {
        if (stats == null) return;
        stats.activeConfiguration = null;
        stats.configurations.clear();
        if (stats.events != null) stats.events.clear();
        stats.events.clear();
    }

    private byte[] serializeIntervalStats(IntervalStats stats, int version) {
+2 −10
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
package com.android.server.usage;

import android.app.usage.ConfigurationStats;
import android.app.usage.EventList;
import android.app.usage.UsageEvents;
import android.app.usage.UsageStats;
import android.content.res.Configuration;
@@ -303,10 +302,6 @@ final class UsageStatsProto {
        if (event.mPackage == null) {
            throw new ProtocolException("no package field present");
        }

        if (statsOut.events == null) {
            statsOut.events = new EventList();
        }
        statsOut.events.insert(event);
    }

@@ -514,10 +509,7 @@ final class UsageStatsProto {
        statsOut.packageStats.clear();
        statsOut.configurations.clear();
        statsOut.activeConfiguration = null;

        if (statsOut.events != null) {
        statsOut.events.clear();
        }

        while (true) {
            switch (proto.nextField()) {
@@ -607,7 +599,7 @@ final class UsageStatsProto {
            writeConfigStats(proto, IntervalStatsProto.CONFIGURATIONS, stats,
                    stats.configurations.valueAt(i), active);
        }
        final int eventCount = stats.events != null ? stats.events.size() : 0;
        final int eventCount = stats.events.size();
        for (int i = 0; i < eventCount; i++) {
            writeEvent(proto, IntervalStatsProto.EVENT_LOG, stats, stats.events.get(i));
        }
+2 −5
Original line number Diff line number Diff line
@@ -384,10 +384,7 @@ final class UsageStatsXmlV1 {
        statsOut.packageStats.clear();
        statsOut.configurations.clear();
        statsOut.activeConfiguration = null;

        if (statsOut.events != null) {
        statsOut.events.clear();
        }

        statsOut.endTime = statsOut.beginTime + XmlUtils.readLongAttribute(parser, END_TIME_ATTR);
        try {
@@ -481,7 +478,7 @@ final class UsageStatsXmlV1 {
        xml.endTag(null, CONFIGURATIONS_TAG);

        xml.startTag(null, EVENT_LOG_TAG);
        final int eventCount = stats.events != null ? stats.events.size() : 0;
        final int eventCount = stats.events.size();
        for (int i = 0; i < eventCount; i++) {
            writeEvent(xml, stats, stats.events.get(i));
        }
+0 −4
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.frameworks.perftests.usage.tests;

import static junit.framework.Assert.assertEquals;

import android.app.usage.EventList;
import android.app.usage.UsageEvents;
import android.app.usage.UsageStatsManager;
import android.content.Context;
@@ -84,9 +83,6 @@ public class UsageStatsDatabasePerfTest {

    private static void populateIntervalStats(IntervalStats intervalStats, int packageCount,
            int eventsPerPackage) {
        if (intervalStats.events == null) {
            intervalStats.events = new EventList();
        }
        for (int pkg = 0; pkg < packageCount; pkg++) {
            UsageEvents.Event event = new UsageEvents.Event();
            event.mPackage = "fake.package.name" + pkg;