Merge "Add number of enterprise-installed apps to Privacy Settings page"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c3fdc3e813
@@ -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.
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the
|
||||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
public class EnterpriseInstalledPackagesPreferenceController extends PreferenceController {
|
||||
|
||||
private static final String KEY_NUMBER_ENTERPRISE_INSTALLED_PACKAGES
|
||||
= "number_enterprise_installed_packages";
|
||||
private final ApplicationFeatureProvider mFeatureProvider;
|
||||
|
||||
public EnterpriseInstalledPackagesPreferenceController(Context context) {
|
||||
super(context);
|
||||
mFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getApplicationFeatureProvider(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
mFeatureProvider.calculateNumberOfInstalledApps(
|
||||
PackageManager.INSTALL_REASON_POLICY,
|
||||
(num) -> {
|
||||
if (num == 0) {
|
||||
preference.setVisible(false);
|
||||
} else {
|
||||
preference.setVisible(true);
|
||||
preference.setTitle(mContext.getResources().getQuantityString(
|
||||
R.plurals.enterprise_privacy_number_enterprise_installed_packages,
|
||||
num, num));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_NUMBER_ENTERPRISE_INSTALLED_PACKAGES;
|
||||
}
|
||||
}
|
@@ -64,6 +64,7 @@ public class EnterprisePrivacySettings extends DashboardFragment {
|
||||
controllers.add(new AlwaysOnVpnPrimaryUserPreferenceController(context));
|
||||
controllers.add(new AlwaysOnVpnManagedProfilePreferenceController(context));
|
||||
controllers.add(new GlobalHttpProxyPreferenceController(context));
|
||||
controllers.add(new EnterpriseInstalledPackagesPreferenceController(context));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
|
@@ -36,12 +36,10 @@ public class InstalledPackagesPreferenceController extends PreferenceController
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
mFeatureProvider.calculateNumberOfInstalledApps(
|
||||
new ApplicationFeatureProvider.NumberOfInstalledAppsCallback() {
|
||||
@Override
|
||||
public void onNumberOfInstalledAppsResult(int num) {
|
||||
preference.setTitle(mContext.getResources().getQuantityString(
|
||||
R.plurals.enterprise_privacy_number_installed_packages, num, num));
|
||||
}
|
||||
ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
|
||||
(num) -> {
|
||||
preference.setTitle(mContext.getResources().getQuantityString(
|
||||
R.plurals.enterprise_privacy_number_installed_packages, num, num));
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user