Extract counting of installed apps into helper class

This CL extracts the code that counts the number of installed apps
for a set of users from ManageApplications to a helper class,
InstalledAppCounter. The new helper is designed to be unit-testable
(PackageManager dependencies are injected via a new PackageManagerWrapper
abstraction) and customizable (the set of users for which to count is
specified by subclasses).

The CL adds a unit test for the InstalledAppCounter as well.

Test: make RunSettingsRoboTests
Bug: 32692748
Change-Id: Ie7fbd40d9dd998b27f1f9de227b6a187b5c9d315
This commit is contained in:
Bartosz Fabianowski
2016-11-17 21:04:34 +01:00
parent 10dd465969
commit 3d83300deb
9 changed files with 433 additions and 42 deletions

View File

@@ -17,10 +17,17 @@ package com.android.settings.applications;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManager;
import com.android.settings.R;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.notification.NotificationBackend;
import java.util.List;
/**
* Extension of ManageApplications with no changes other than having its own
* SummaryProvider.
@@ -42,12 +49,18 @@ public class NotificationApps extends ManageApplications {
@Override
public void setListening(boolean listening) {
if (listening) {
new AppCounter(mContext) {
new AppCounter(mContext,
new PackageManagerWrapperImpl(mContext.getPackageManager())) {
@Override
protected void onCountComplete(int num) {
updateSummary(num);
}
@Override
protected List<UserInfo> getUsersToCount() {
return mUm.getProfiles(UserHandle.myUserId());
}
@Override
protected boolean includeInCount(ApplicationInfo info) {
return mNotificationBackend.getNotificationsBanned(info.packageName,