Don't use ApplicationsState for summaries
Since it grabs a lock that can be slow on the main thread, don't use ApplicationsState in any of the summaries, instead load the information directly from the PM. Change-Id: Ibefe867810d2a9926177a8de4e23a7faea4b1c3b Fixes: 28435146
This commit is contained in:
70
src/com/android/settings/applications/AppCounter.java
Normal file
70
src/com/android/settings/applications/AppCounter.java
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.applications;
|
||||||
|
|
||||||
|
import android.app.AppGlobals;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.IPackageManager;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ParceledListSlice;
|
||||||
|
import android.content.pm.UserInfo;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
public abstract class AppCounter extends AsyncTask<Void, Void, Integer> {
|
||||||
|
|
||||||
|
protected final PackageManager mPm;
|
||||||
|
protected final IPackageManager mIpm;
|
||||||
|
protected final UserManager mUm;
|
||||||
|
|
||||||
|
public AppCounter(Context context) {
|
||||||
|
mPm = context.getPackageManager();
|
||||||
|
mIpm = AppGlobals.getPackageManager();
|
||||||
|
mUm = UserManager.get(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Integer doInBackground(Void... params) {
|
||||||
|
int count = 0;
|
||||||
|
for (UserInfo user : mUm.getProfiles(UserHandle.myUserId())) {
|
||||||
|
try {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
ParceledListSlice<ApplicationInfo> list =
|
||||||
|
mIpm.getInstalledApplications(PackageManager.GET_DISABLED_COMPONENTS
|
||||||
|
| PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS
|
||||||
|
| (user.isAdmin() ? PackageManager.GET_UNINSTALLED_PACKAGES : 0),
|
||||||
|
user.id);
|
||||||
|
for (ApplicationInfo info : list.getList()) {
|
||||||
|
if (includeInCount(info)) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Integer count) {
|
||||||
|
onCountComplete(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void onCountComplete(int num);
|
||||||
|
protected abstract boolean includeInCount(ApplicationInfo info);
|
||||||
|
}
|
@@ -17,14 +17,18 @@
|
|||||||
package com.android.settings.applications;
|
package com.android.settings.applications;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Application;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageItemInfo;
|
import android.content.pm.PackageItemInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
import android.icu.text.AlphabeticIndex;
|
import android.icu.text.AlphabeticIndex;
|
||||||
import android.os.*;
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.os.LocaleList;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.preference.PreferenceFrameLayout;
|
import android.preference.PreferenceFrameLayout;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
@@ -49,7 +53,6 @@ import android.widget.SectionIndexer;
|
|||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.AppHeader;
|
import com.android.settings.AppHeader;
|
||||||
import com.android.settingslib.HelpUtils;
|
|
||||||
import com.android.settings.InstrumentedFragment;
|
import com.android.settings.InstrumentedFragment;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Settings.AllApplicationsActivity;
|
import com.android.settings.Settings.AllApplicationsActivity;
|
||||||
@@ -71,6 +74,7 @@ import com.android.settings.notification.AppNotificationSettings;
|
|||||||
import com.android.settings.notification.ConfigureNotificationSettings;
|
import com.android.settings.notification.ConfigureNotificationSettings;
|
||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
import com.android.settings.notification.NotificationBackend.AppRow;
|
import com.android.settings.notification.NotificationBackend.AppRow;
|
||||||
|
import com.android.settingslib.HelpUtils;
|
||||||
import com.android.settingslib.applications.ApplicationsState;
|
import com.android.settingslib.applications.ApplicationsState;
|
||||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||||
import com.android.settingslib.applications.ApplicationsState.AppFilter;
|
import com.android.settingslib.applications.ApplicationsState.AppFilter;
|
||||||
@@ -80,6 +84,7 @@ import com.android.settingslib.applications.ApplicationsState.VolumeFilter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1248,84 +1253,48 @@ public class ManageApplications extends InstrumentedFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SummaryProvider implements SummaryLoader.SummaryProvider,
|
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
|
||||||
ApplicationsState.Callbacks {
|
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final SummaryLoader mLoader;
|
private final SummaryLoader mLoader;
|
||||||
// TODO: Can probably hack together with less than full app state.
|
|
||||||
private final ApplicationsState mAppState;
|
|
||||||
private final Handler mHandler;
|
|
||||||
private ApplicationsState.Session mSession;
|
private ApplicationsState.Session mSession;
|
||||||
|
|
||||||
private SummaryProvider(Context context, SummaryLoader loader) {
|
private SummaryProvider(Context context, SummaryLoader loader) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mLoader = loader;
|
mLoader = loader;
|
||||||
mAppState =
|
|
||||||
ApplicationsState.getInstance((Application) context.getApplicationContext());
|
|
||||||
mHandler = new Handler(mAppState.getBackgroundLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setListening(boolean listening) {
|
public void setListening(boolean listening) {
|
||||||
if (listening) {
|
if (listening) {
|
||||||
mSession = mAppState.newSession(this);
|
new AppCounter(mContext) {
|
||||||
mSession.resume();
|
|
||||||
} else {
|
|
||||||
mSession.pause();
|
|
||||||
mSession.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateSummary(ArrayList<AppEntry> apps) {
|
|
||||||
if (apps == null) return;
|
|
||||||
mLoader.setSummary(this, mContext.getString(R.string.apps_summary, apps.size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void postRebuild() {
|
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
protected void onCountComplete(int num) {
|
||||||
updateSummary(mSession.rebuild(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER,
|
mLoader.setSummary(SummaryProvider.this,
|
||||||
null, false));
|
mContext.getString(R.string.apps_summary, num));
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRebuildComplete(ArrayList<AppEntry> apps) {
|
protected boolean includeInCount(ApplicationInfo info) {
|
||||||
updateSummary(apps);
|
if ((info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
|
||||||
|
return true;
|
||||||
|
} else if ((info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
Intent launchIntent = new Intent(Intent.ACTION_MAIN, null)
|
||||||
@Override
|
.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
public void onPackageListChanged() {
|
.setPackage(info.packageName);
|
||||||
postRebuild();
|
int userId = UserHandle.getUserId(info.uid);
|
||||||
|
List<ResolveInfo> intents = mPm.queryIntentActivitiesAsUser(
|
||||||
|
launchIntent,
|
||||||
|
PackageManager.GET_DISABLED_COMPONENTS
|
||||||
|
| PackageManager.MATCH_DIRECT_BOOT_AWARE
|
||||||
|
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
|
||||||
|
userId);
|
||||||
|
return intents != null && intents.size() != 0;
|
||||||
}
|
}
|
||||||
|
}.execute();
|
||||||
@Override
|
|
||||||
public void onLauncherInfoChanged() {
|
|
||||||
postRebuild();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadEntriesCompleted() {
|
|
||||||
postRebuild();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRunningStateChanged(boolean running) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPackageIconChanged() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPackageSizeChanged(String packageName) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAllSizesComputed() {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,19 +15,11 @@
|
|||||||
package com.android.settings.applications;
|
package com.android.settings.applications;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Application;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Handler;
|
import android.content.pm.ApplicationInfo;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.applications.AppStateBaseBridge.Callback;
|
|
||||||
import com.android.settings.dashboard.SummaryLoader;
|
import com.android.settings.dashboard.SummaryLoader;
|
||||||
import com.android.settings.dashboard.SummaryLoader.SummaryProvider;
|
|
||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
import com.android.settingslib.applications.ApplicationsState;
|
|
||||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
|
||||||
import com.android.settingslib.applications.ApplicationsState.Callbacks;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension of ManageApplications with no changes other than having its own
|
* Extension of ManageApplications with no changes other than having its own
|
||||||
@@ -35,97 +27,44 @@ import java.util.ArrayList;
|
|||||||
*/
|
*/
|
||||||
public class NotificationApps extends ManageApplications {
|
public class NotificationApps extends ManageApplications {
|
||||||
|
|
||||||
private static class SummaryProvider implements SummaryLoader.SummaryProvider,
|
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
|
||||||
Callbacks, Callback {
|
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final SummaryLoader mLoader;
|
private final SummaryLoader mLoader;
|
||||||
|
private final NotificationBackend mNotificationBackend;
|
||||||
private final ApplicationsState mAppState;
|
|
||||||
private final NotificationBackend mNotifBackend;
|
|
||||||
private final Handler mHandler;
|
|
||||||
private AppStateNotificationBridge mExtraInfoBridge;
|
|
||||||
private ApplicationsState.Session mSession;
|
|
||||||
|
|
||||||
private SummaryProvider(Context context, SummaryLoader loader) {
|
private SummaryProvider(Context context, SummaryLoader loader) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mLoader = loader;
|
mLoader = loader;
|
||||||
mAppState =
|
mNotificationBackend = new NotificationBackend();
|
||||||
ApplicationsState.getInstance((Application) context.getApplicationContext());
|
|
||||||
mNotifBackend = new NotificationBackend();
|
|
||||||
mHandler = new Handler(mAppState.getBackgroundLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setListening(boolean listening) {
|
public void setListening(boolean listening) {
|
||||||
if (listening) {
|
if (listening) {
|
||||||
mSession = mAppState.newSession(this);
|
new AppCounter(mContext) {
|
||||||
mExtraInfoBridge = new AppStateNotificationBridge(mContext,
|
@Override
|
||||||
mAppState, this, mNotifBackend);
|
protected void onCountComplete(int num) {
|
||||||
mSession.resume();
|
updateSummary(num);
|
||||||
mExtraInfoBridge.resume();
|
}
|
||||||
} else {
|
|
||||||
mSession.pause();
|
@Override
|
||||||
mExtraInfoBridge.pause();
|
protected boolean includeInCount(ApplicationInfo info) {
|
||||||
mSession.release();
|
return mNotificationBackend.getNotificationsBanned(info.packageName,
|
||||||
mExtraInfoBridge.release();
|
info.uid);
|
||||||
|
}
|
||||||
|
}.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSummary(ArrayList<AppEntry> apps) {
|
private void updateSummary(int count) {
|
||||||
if (apps == null) return;
|
if (count == 0) {
|
||||||
if (apps.size() == 0) {
|
|
||||||
mLoader.setSummary(this, mContext.getString(R.string.notification_summary_none));
|
mLoader.setSummary(this, mContext.getString(R.string.notification_summary_none));
|
||||||
} else {
|
} else {
|
||||||
mLoader.setSummary(this, mContext.getResources().getQuantityString(
|
mLoader.setSummary(this, mContext.getResources().getQuantityString(
|
||||||
R.plurals.notification_summary, apps.size(), apps.size()));
|
R.plurals.notification_summary, count, count));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRebuildComplete(ArrayList<AppEntry> apps) {
|
|
||||||
updateSummary(apps);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExtraInfoUpdated() {
|
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateSummary(mSession.rebuild(
|
|
||||||
AppStateNotificationBridge.FILTER_APP_NOTIFICATION_BLOCKED,
|
|
||||||
null, false));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPackageListChanged() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLauncherInfoChanged() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadEntriesCompleted() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRunningStateChanged(boolean running) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPackageIconChanged() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPackageSizeChanged(String packageName) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAllSizesComputed() {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
|
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
|
||||||
|
Reference in New Issue
Block a user