Merge "Device management info: Refer to current user, not primary user" into oc-dev

This commit is contained in:
TreeHugger Robot
2017-04-01 05:12:38 +00:00
committed by Android (Google) Code Review
20 changed files with 89 additions and 139 deletions

View File

@@ -20,6 +20,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.os.AsyncTask;
import android.os.UserHandle;
import android.os.UserManager;
import java.util.List;
@@ -37,7 +38,7 @@ public abstract class AppCounter extends AsyncTask<Void, Void, Integer> {
@Override
protected Integer doInBackground(Void... params) {
int count = 0;
for (UserInfo user : getUsersToCount()) {
for (UserInfo user : mUm.getProfiles(UserHandle.myUserId())) {
final List<ApplicationInfo> list =
mPm.getInstalledApplicationsAsUser(PackageManager.GET_DISABLED_COMPONENTS
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS
@@ -62,6 +63,5 @@ public abstract class AppCounter extends AsyncTask<Void, Void, Integer> {
}
protected abstract void onCountComplete(int num);
protected abstract List<UserInfo> getUsersToCount();
protected abstract boolean includeInCount(ApplicationInfo info);
}

View File

@@ -40,8 +40,8 @@ public interface ApplicationFeatureProvider {
View view);
/**
* Calculates the total number of apps installed on the device via policy across all users
* and managed profiles.
* Calculates the total number of apps installed on the device via policy in the current user
* and all its managed profiles.
*
* @param async Whether to count asynchronously in a background thread
* @param callback The callback to invoke with the result
@@ -49,9 +49,8 @@ public interface ApplicationFeatureProvider {
void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback);
/**
* Asynchronously calculates the total number of apps installed on the device, across all users
* and managed profiles, that have been granted one or more of the given permissions by the
* admin.
* Asynchronously calculates the total number of apps installed in the current user and all its
* managed profiles that have been granted one or more of the given permissions by the admin.
*
* @param permissions Only consider apps that have been granted one or more of these permissions
* by the admin, either at run-time or install-time

View File

@@ -22,7 +22,6 @@ import android.content.Intent;
import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
@@ -65,8 +64,8 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
@Override
public void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback) {
final AllUserPolicyInstalledAppCounter counter =
new AllUserPolicyInstalledAppCounter(mContext, mPm, callback);
final CurrentUserAndManagedProfilePolicyInstalledAppCounter counter =
new CurrentUserAndManagedProfilePolicyInstalledAppCounter(mContext, mPm, callback);
if (async) {
counter.execute();
} else {
@@ -77,9 +76,9 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
@Override
public void calculateNumberOfAppsWithAdminGrantedPermissions(String[] permissions,
boolean async, NumberOfAppsCallback callback) {
final AllUserAppWithAdminGrantedPermissionsCounter counter =
new AllUserAppWithAdminGrantedPermissionsCounter(mContext, permissions, mPm, mPms,
mDpm, callback);
final CurrentUserAndManagedProfileAppWithAdminGrantedPermissionsCounter counter =
new CurrentUserAndManagedProfileAppWithAdminGrantedPermissionsCounter(mContext,
permissions, mPm, mPms, mDpm, callback);
if (async) {
counter.execute();
} else {
@@ -120,11 +119,12 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
return activities;
}
private static class AllUserPolicyInstalledAppCounter extends InstalledAppCounter {
private static class CurrentUserAndManagedProfilePolicyInstalledAppCounter
extends InstalledAppCounter {
private NumberOfAppsCallback mCallback;
AllUserPolicyInstalledAppCounter(Context context, PackageManagerWrapper packageManager,
NumberOfAppsCallback callback) {
CurrentUserAndManagedProfilePolicyInstalledAppCounter(Context context,
PackageManagerWrapper packageManager, NumberOfAppsCallback callback) {
super(context, PackageManager.INSTALL_REASON_POLICY, packageManager);
mCallback = callback;
}
@@ -133,19 +133,15 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
protected void onCountComplete(int num) {
mCallback.onNumberOfAppsResult(num);
}
@Override
protected List<UserInfo> getUsersToCount() {
return mUm.getUsers(true /* excludeDying */);
}
}
private static class AllUserAppWithAdminGrantedPermissionsCounter extends
AppWithAdminGrantedPermissionsCounter {
private static class CurrentUserAndManagedProfileAppWithAdminGrantedPermissionsCounter
extends AppWithAdminGrantedPermissionsCounter {
private NumberOfAppsCallback mCallback;
AllUserAppWithAdminGrantedPermissionsCounter(Context context, String[] permissions,
PackageManagerWrapper packageManager, IPackageManagerWrapper packageManagerService,
CurrentUserAndManagedProfileAppWithAdminGrantedPermissionsCounter(Context context,
String[] permissions, PackageManagerWrapper packageManager,
IPackageManagerWrapper packageManagerService,
DevicePolicyManagerWrapper devicePolicyManager, NumberOfAppsCallback callback) {
super(context, permissions, packageManager, packageManagerService, devicePolicyManager);
mCallback = callback;
@@ -155,10 +151,5 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
protected void onCountComplete(int num) {
mCallback.onNumberOfAppsResult(num);
}
@Override
protected List<UserInfo> getUsersToCount() {
return mUm.getUsers(true /* excludeDying */);
}
}
}

View File

@@ -23,7 +23,6 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.icu.text.AlphabeticIndex;
import android.os.Bundle;
import android.os.Environment;
@@ -1404,11 +1403,6 @@ public class ManageApplications extends InstrumentedPreferenceFragment
mLoader.setSummary(SummaryProvider.this,
mContext.getString(R.string.apps_summary, num));
}
@Override
protected List<UserInfo> getUsersToCount() {
return mUm.getProfiles(UserHandle.myUserId());
}
}.execute();
}
}

View File

@@ -18,16 +18,11 @@ 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.
@@ -56,11 +51,6 @@ public class NotificationApps extends ManageApplications {
updateSummary(num);
}
@Override
protected List<UserInfo> getUsersToCount() {
return mUm.getProfiles(UserHandle.myUserId());
}
@Override
protected boolean includeInCount(ApplicationInfo info) {
return mNotificationBackend.getNotificationsBanned(info.packageName,