Add number of enterprise-installed apps to Privacy Settings page

This CL adds information about the number of apps that were installed
by the admin to the Enterprise Privacy Settings page.

Test: make RunSettingsRoboTests
Bug: 32692748

Change-Id: Ib710a1249db6d285da962122fd3dfb35a43752a1
This commit is contained in:
Bartosz Fabianowski
2017-01-13 17:41:38 +01:00
parent 0d22680807
commit 13f569ebd6
16 changed files with 314 additions and 40 deletions

View File

@@ -26,11 +26,21 @@ public interface ApplicationFeatureProvider {
*/
AppHeaderController newAppHeaderController(Fragment fragment, View appHeader);
/**
* Count all installed packages, irrespective of install reason.
*/
public static final int IGNORE_INSTALL_REASON = -1;
/**
* Asynchronously calculates the total number of apps installed on the device, across all users
* and managed profiles.
*
* @param installReason Only consider packages with this install reason; may be any install
* reason defined in {@link android.content.pm.PackageManager} or
* {@link #IGNORE_INSTALL_REASON} to count all packages, irrespective of install reason.
* @param callback The callback to invoke with the result
*/
void calculateNumberOfInstalledApps(NumberOfInstalledAppsCallback callback);
void calculateNumberOfInstalledApps(int installReason, NumberOfInstalledAppsCallback callback);
/**
* Callback that receives the total number of packages installed on the device.

View File

@@ -42,15 +42,16 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
}
@Override
public void calculateNumberOfInstalledApps(NumberOfInstalledAppsCallback callback) {
new AllUserInstalledAppCounter(callback).execute();
public void calculateNumberOfInstalledApps(int installReason,
NumberOfInstalledAppsCallback callback) {
new AllUserInstalledAppCounter(installReason, callback).execute();
}
private class AllUserInstalledAppCounter extends InstalledAppCounter {
private NumberOfInstalledAppsCallback mCallback;
AllUserInstalledAppCounter(NumberOfInstalledAppsCallback callback) {
super(mContext, ApplicationFeatureProviderImpl.this.mPm);
AllUserInstalledAppCounter(int installReason, NumberOfInstalledAppsCallback callback) {
super(mContext, installReason, ApplicationFeatureProviderImpl.this.mPm);
mCallback = callback;
}

View File

@@ -25,12 +25,24 @@ import java.util.List;
public abstract class InstalledAppCounter extends AppCounter {
public InstalledAppCounter(Context context, PackageManagerWrapper packageManager) {
private final int mInstallReason;
private final PackageManagerWrapper mPackageManager;
public InstalledAppCounter(Context context, int installReason,
PackageManagerWrapper packageManager) {
super(context, packageManager);
mInstallReason = installReason;
mPackageManager = packageManager;
}
@Override
protected boolean includeInCount(ApplicationInfo info) {
final int userId = UserHandle.getUserId(info.uid);
if (mInstallReason != ApplicationFeatureProvider.IGNORE_INSTALL_REASON
&& mPackageManager.getInstallReason(info.packageName,
new UserHandle(userId)) != mInstallReason) {
return false;
}
if ((info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
return true;
}
@@ -40,7 +52,6 @@ public abstract class InstalledAppCounter extends AppCounter {
Intent launchIntent = new Intent(Intent.ACTION_MAIN, null)
.addCategory(Intent.CATEGORY_LAUNCHER)
.setPackage(info.packageName);
int userId = UserHandle.getUserId(info.uid);
List<ResolveInfo> intents = mPm.queryIntentActivitiesAsUser(
launchIntent,
PackageManager.GET_DISABLED_COMPONENTS

View File

@@ -1252,7 +1252,7 @@ public class ManageApplications extends InstrumentedPreferenceFragment
@Override
public void setListening(boolean listening) {
if (listening) {
new InstalledAppCounter(mContext,
new InstalledAppCounter(mContext, ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
new PackageManagerWrapperImpl(mContext.getPackageManager())) {
@Override
protected void onCountComplete(int num) {

View File

@@ -20,6 +20,7 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.UserHandle;
import java.util.List;
@@ -56,4 +57,12 @@ public interface PackageManagerWrapper {
* @see android.content.pm.PackageManager#queryIntentActivitiesAsUser
*/
List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent, int flags, int userId);
/**
* Calls {@code PackageManager.getInstallReason()}.
*
* @see android.content.pm.PackageManager#getInstallReason
*/
int getInstallReason(String packageName, UserHandle user);
}

View File

@@ -20,6 +20,7 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.UserHandle;
import java.util.List;
@@ -50,4 +51,9 @@ public class PackageManagerWrapperImpl implements PackageManagerWrapper {
public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent, int flags, int userId) {
return mPm.queryIntentActivitiesAsUser(intent, flags, userId);
}
@Override
public int getInstallReason(String packageName, UserHandle user) {
return mPm.getInstallReason(packageName, user);
}
}