Update List of apps on device string,

remove "XX apps" string.

Bug: 32692748
Test: m RunSettingsRoboTests
Change-Id: I64f833497b5362f95cfc56a1057d97d9539ff029
This commit is contained in:
Denis Kuznetsov
2017-03-22 15:41:38 +01:00
parent 6edba87daa
commit 0c88ff4ed9
14 changed files with 51 additions and 235 deletions

View File

@@ -30,22 +30,13 @@ 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;
/**
* Calculates the total number of apps installed on the device, across all users and managed
* profiles.
* Calculates the total number of apps installed on the device via policy across all users
* and managed profiles.
*
* @param installReason Only consider apps with this install reason; may be any install reason
* defined in {@link android.content.pm.PackageManager} or
* {@link #IGNORE_INSTALL_REASON} to count all apps, irrespective of install reason.
* @param async Whether to count asynchronously in a background thread
* @param callback The callback to invoke with the result
*/
void calculateNumberOfInstalledApps(int installReason, boolean async,
NumberOfAppsCallback callback);
void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback);
/**
* Asynchronously calculates the total number of apps installed on the device, across all users

View File

@@ -20,6 +20,7 @@ import android.app.Fragment;
import android.content.Context;
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;
@@ -56,10 +57,9 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
}
@Override
public void calculateNumberOfInstalledApps(int installReason, boolean async,
NumberOfAppsCallback callback) {
final AllUserInstalledAppCounter counter = new AllUserInstalledAppCounter(mContext,
installReason, mPm, callback);
public void calculateNumberOfPolicyInstalledApps(boolean async, NumberOfAppsCallback callback) {
final AllUserPolicyInstalledAppCounter counter =
new AllUserPolicyInstalledAppCounter(mContext, mPm, callback);
if (async) {
counter.execute();
} else {
@@ -113,12 +113,12 @@ public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvide
return activities;
}
private static class AllUserInstalledAppCounter extends InstalledAppCounter {
private static class AllUserPolicyInstalledAppCounter extends InstalledAppCounter {
private NumberOfAppsCallback mCallback;
AllUserInstalledAppCounter(Context context, int installReason,
PackageManagerWrapper packageManager, NumberOfAppsCallback callback) {
super(context, installReason, packageManager);
AllUserPolicyInstalledAppCounter(Context context, PackageManagerWrapper packageManager,
NumberOfAppsCallback callback) {
super(context, PackageManager.INSTALL_REASON_POLICY, packageManager);
mCallback = callback;
}

View File

@@ -25,6 +25,11 @@ import java.util.List;
public abstract class InstalledAppCounter extends AppCounter {
/**
* Count all installed packages, irrespective of install reason.
*/
public static final int IGNORE_INSTALL_REASON = -1;
private final int mInstallReason;
private final PackageManagerWrapper mPackageManager;
@@ -38,7 +43,7 @@ public abstract class InstalledAppCounter extends AppCounter {
@Override
protected boolean includeInCount(ApplicationInfo info) {
final int userId = UserHandle.getUserId(info.uid);
if (mInstallReason != ApplicationFeatureProvider.IGNORE_INSTALL_REASON
if (mInstallReason != IGNORE_INSTALL_REASON
&& mPackageManager.getInstallReason(info.packageName,
new UserHandle(userId)) != mInstallReason) {
return false;

View File

@@ -69,7 +69,6 @@ import com.android.settings.Settings.WriteSettingsActivity;
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
import com.android.settings.applications.AppStateInstallAppsBridge.InstallAppsState;
import com.android.settings.applications.AppStateUsageBridge.UsageState;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.dashboard.SummaryLoader;
@@ -1398,7 +1397,7 @@ public class ManageApplications extends InstrumentedPreferenceFragment
@Override
public void setListening(boolean listening) {
if (listening) {
new InstalledAppCounter(mContext, ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
new InstalledAppCounter(mContext, InstalledAppCounter.IGNORE_INSTALL_REASON,
new PackageManagerWrapperImpl(mContext.getPackageManager())) {
@Override
protected void onCountComplete(int num) {

View File

@@ -14,8 +14,6 @@
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;
@@ -42,8 +40,7 @@ public class EnterpriseInstalledPackagesPreferenceController
@Override
public void updateState(Preference preference) {
mFeatureProvider.calculateNumberOfInstalledApps(
PackageManager.INSTALL_REASON_POLICY, true /* async */,
mFeatureProvider.calculateNumberOfPolicyInstalledApps(true /* async */,
(num) -> {
if (num == 0) {
preference.setVisible(false);
@@ -69,8 +66,8 @@ public class EnterpriseInstalledPackagesPreferenceController
// changes to the pref's visibility made in updateState() would not be seen by the indexer.
// We block and return synchronously whether there are enterprise-installed apps or not.
final Boolean[] haveEnterpriseInstalledPackages = { null };
mFeatureProvider.calculateNumberOfInstalledApps(PackageManager.INSTALL_REASON_POLICY,
false /* async */, (num) -> haveEnterpriseInstalledPackages[0] = num > 0);
mFeatureProvider.calculateNumberOfPolicyInstalledApps(false /* async */,
(num) -> haveEnterpriseInstalledPackages[0] = num > 0);
return haveEnterpriseInstalledPackages[0];
}

View File

@@ -58,7 +58,6 @@ public class EnterprisePrivacySettings extends DashboardFragment {
private static List<PreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle, boolean async) {
final List controllers = new ArrayList<PreferenceController>();
controllers.add(new InstalledPackagesPreferenceController(context));
controllers.add(new NetworkLogsPreferenceController(context));
controllers.add(new BugReportsPreferenceController(context));
controllers.add(new SecurityLogsPreferenceController(context));

View File

@@ -1,59 +0,0 @@
/*
* Copyright (C) 2016 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.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 InstalledPackagesPreferenceController extends PreferenceController {
private static final String KEY_INSTALLED_PACKAGES = "installed_packages";
private final ApplicationFeatureProvider mFeatureProvider;
public InstalledPackagesPreferenceController(Context context) {
super(context);
mFeatureProvider = FeatureFactory.getFactory(context)
.getApplicationFeatureProvider(context);
}
@Override
public void updateState(Preference preference) {
mFeatureProvider.calculateNumberOfInstalledApps(
ApplicationFeatureProvider.IGNORE_INSTALL_REASON, true /* async */,
(num) -> {
if (num == 0) {
preference.setSummary("");
} else {
preference.setSummary(mContext.getResources().getQuantityString(
R.plurals.enterprise_privacy_number_packages, num, num));
}
});
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public String getPreferenceKey() {
return KEY_INSTALLED_PACKAGES;
}
}