use of com.android.server.storage.DiskStatsLoggingService.LogRunnable in project android_frameworks_base by ResurrectionRemix.
the class DiskStatsLoggingServiceTest method testEmptyLog.
@Test
public void testEmptyLog() throws Exception {
LogRunnable task = new LogRunnable();
task.setAppCollector(mCollector);
task.setDownloadsDirectory(mDownloads.getRoot());
task.setRootDirectory(mRootDirectory.getRoot());
task.setLogOutputFile(mInputFile);
task.setSystemSize(0L);
task.run();
JSONObject json = getJsonOutput();
assertThat(json.getLong(DiskStatsFileLogger.PHOTOS_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.VIDEOS_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.AUDIO_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.DOWNLOADS_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.SYSTEM_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.MISC_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.APP_SIZE_AGG_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.APP_CACHE_AGG_KEY)).isEqualTo(0L);
assertThat(json.getJSONArray(DiskStatsFileLogger.PACKAGE_NAMES_KEY).length()).isEqualTo(0L);
assertThat(json.getJSONArray(DiskStatsFileLogger.APP_SIZES_KEY).length()).isEqualTo(0L);
assertThat(json.getJSONArray(DiskStatsFileLogger.APP_CACHES_KEY).length()).isEqualTo(0L);
}
use of com.android.server.storage.DiskStatsLoggingService.LogRunnable in project android_frameworks_base by ResurrectionRemix.
the class DiskStatsLoggingServiceTest method testPopulatedLogTask.
@Test
public void testPopulatedLogTask() throws Exception {
// Write data to directories.
writeDataToFile(mDownloads.newFile(), "lol");
writeDataToFile(mRootDirectory.newFile("test.jpg"), "1234");
writeDataToFile(mRootDirectory.newFile("test.mp4"), "12345");
writeDataToFile(mRootDirectory.newFile("test.mp3"), "123456");
writeDataToFile(mRootDirectory.newFile("test.whatever"), "1234567");
// Write apps.
ArrayList<PackageStats> apps = new ArrayList<>();
PackageStats testApp = new PackageStats("com.test.app");
testApp.dataSize = 5L;
testApp.cacheSize = 55L;
testApp.codeSize = 10L;
apps.add(testApp);
when(mCollector.getPackageStats(anyInt())).thenReturn(apps);
LogRunnable task = new LogRunnable();
task.setAppCollector(mCollector);
task.setDownloadsDirectory(mDownloads.getRoot());
task.setRootDirectory(mRootDirectory.getRoot());
task.setLogOutputFile(mInputFile);
task.setSystemSize(10L);
task.run();
JSONObject json = getJsonOutput();
assertThat(json.getLong(DiskStatsFileLogger.PHOTOS_KEY)).isEqualTo(4L);
assertThat(json.getLong(DiskStatsFileLogger.VIDEOS_KEY)).isEqualTo(5L);
assertThat(json.getLong(DiskStatsFileLogger.AUDIO_KEY)).isEqualTo(6L);
assertThat(json.getLong(DiskStatsFileLogger.DOWNLOADS_KEY)).isEqualTo(3L);
assertThat(json.getLong(DiskStatsFileLogger.SYSTEM_KEY)).isEqualTo(10L);
assertThat(json.getLong(DiskStatsFileLogger.MISC_KEY)).isEqualTo(7L);
assertThat(json.getLong(DiskStatsFileLogger.APP_SIZE_AGG_KEY)).isEqualTo(15L);
assertThat(json.getLong(DiskStatsFileLogger.APP_CACHE_AGG_KEY)).isEqualTo(55L);
assertThat(json.getJSONArray(DiskStatsFileLogger.PACKAGE_NAMES_KEY).length()).isEqualTo(1L);
assertThat(json.getJSONArray(DiskStatsFileLogger.APP_SIZES_KEY).length()).isEqualTo(1L);
assertThat(json.getJSONArray(DiskStatsFileLogger.APP_CACHES_KEY).length()).isEqualTo(1L);
}
use of com.android.server.storage.DiskStatsLoggingService.LogRunnable in project android_frameworks_base by DirtyUnicorns.
the class DiskStatsLoggingServiceTest method testDontCrashOnPackageStatsTimeout.
@Test
public void testDontCrashOnPackageStatsTimeout() throws Exception {
when(mCollector.getPackageStats(anyInt())).thenReturn(null);
LogRunnable task = new LogRunnable();
task.setAppCollector(mCollector);
task.setDownloadsDirectory(mDownloads.getRoot());
task.setRootDirectory(mRootDirectory.getRoot());
task.setLogOutputFile(mInputFile);
task.setSystemSize(10L);
task.run();
// No exception should be thrown.
}
use of com.android.server.storage.DiskStatsLoggingService.LogRunnable in project android_frameworks_base by DirtyUnicorns.
the class DiskStatsLoggingServiceTest method testPopulatedLogTask.
@Test
public void testPopulatedLogTask() throws Exception {
// Write data to directories.
writeDataToFile(mDownloads.newFile(), "lol");
writeDataToFile(mRootDirectory.newFile("test.jpg"), "1234");
writeDataToFile(mRootDirectory.newFile("test.mp4"), "12345");
writeDataToFile(mRootDirectory.newFile("test.mp3"), "123456");
writeDataToFile(mRootDirectory.newFile("test.whatever"), "1234567");
// Write apps.
ArrayList<PackageStats> apps = new ArrayList<>();
PackageStats testApp = new PackageStats("com.test.app");
testApp.dataSize = 5L;
testApp.cacheSize = 55L;
testApp.codeSize = 10L;
apps.add(testApp);
when(mCollector.getPackageStats(anyInt())).thenReturn(apps);
LogRunnable task = new LogRunnable();
task.setAppCollector(mCollector);
task.setDownloadsDirectory(mDownloads.getRoot());
task.setRootDirectory(mRootDirectory.getRoot());
task.setLogOutputFile(mInputFile);
task.setSystemSize(10L);
task.run();
JSONObject json = getJsonOutput();
assertThat(json.getLong(DiskStatsFileLogger.PHOTOS_KEY)).isEqualTo(4L);
assertThat(json.getLong(DiskStatsFileLogger.VIDEOS_KEY)).isEqualTo(5L);
assertThat(json.getLong(DiskStatsFileLogger.AUDIO_KEY)).isEqualTo(6L);
assertThat(json.getLong(DiskStatsFileLogger.DOWNLOADS_KEY)).isEqualTo(3L);
assertThat(json.getLong(DiskStatsFileLogger.SYSTEM_KEY)).isEqualTo(10L);
assertThat(json.getLong(DiskStatsFileLogger.MISC_KEY)).isEqualTo(7L);
assertThat(json.getLong(DiskStatsFileLogger.APP_SIZE_AGG_KEY)).isEqualTo(15L);
assertThat(json.getLong(DiskStatsFileLogger.APP_CACHE_AGG_KEY)).isEqualTo(55L);
assertThat(json.getJSONArray(DiskStatsFileLogger.PACKAGE_NAMES_KEY).length()).isEqualTo(1L);
assertThat(json.getJSONArray(DiskStatsFileLogger.APP_SIZES_KEY).length()).isEqualTo(1L);
assertThat(json.getJSONArray(DiskStatsFileLogger.APP_CACHES_KEY).length()).isEqualTo(1L);
}
use of com.android.server.storage.DiskStatsLoggingService.LogRunnable in project android_frameworks_base by DirtyUnicorns.
the class DiskStatsLoggingServiceTest method testEmptyLog.
@Test
public void testEmptyLog() throws Exception {
LogRunnable task = new LogRunnable();
task.setAppCollector(mCollector);
task.setDownloadsDirectory(mDownloads.getRoot());
task.setRootDirectory(mRootDirectory.getRoot());
task.setLogOutputFile(mInputFile);
task.setSystemSize(0L);
task.run();
JSONObject json = getJsonOutput();
assertThat(json.getLong(DiskStatsFileLogger.PHOTOS_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.VIDEOS_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.AUDIO_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.DOWNLOADS_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.SYSTEM_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.MISC_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.APP_SIZE_AGG_KEY)).isEqualTo(0L);
assertThat(json.getLong(DiskStatsFileLogger.APP_CACHE_AGG_KEY)).isEqualTo(0L);
assertThat(json.getJSONArray(DiskStatsFileLogger.PACKAGE_NAMES_KEY).length()).isEqualTo(0L);
assertThat(json.getJSONArray(DiskStatsFileLogger.APP_SIZES_KEY).length()).isEqualTo(0L);
assertThat(json.getJSONArray(DiskStatsFileLogger.APP_CACHES_KEY).length()).isEqualTo(0L);
}
Aggregations