2 * Copyright (C) 2015 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.android.settings.applications;
18 import android.content.BroadcastReceiver;
19 import android.content.Intent;
20 import android.content.pm.ApplicationInfo;
21 import android.os.Bundle;
22 import android.preference.Preference;
24 import com.android.internal.logging.MetricsLogger;
25 import com.android.settings.R;
26 import com.android.settings.SettingsPreferenceFragment;
27 import com.android.settings.applications.PermissionsSummaryHelper.PermissionsResultCallback;
28 import com.android.settings.fuelgauge.PowerWhitelistBackend;
29 import com.android.settingslib.applications.ApplicationsState;
30 import com.android.settingslib.applications.ApplicationsState.AppEntry;
31 import com.android.settingslib.applications.ApplicationsState.Session;
33 import java.util.ArrayList;
35 public class AdvancedAppSettings extends SettingsPreferenceFragment implements
36 ApplicationsState.Callbacks {
38 static final String TAG = "AdvancedAppSettings";
40 private static final String KEY_APP_PERM = "manage_perms";
41 private static final String KEY_APP_DOMAIN_URLS = "domain_urls";
42 private static final String KEY_HIGH_POWER_APPS = "high_power_apps";
44 private Session mSession;
45 private Preference mAppPermsPreference;
46 private Preference mAppDomainURLsPreference;
47 private Preference mHighPowerPreference;
49 private BroadcastReceiver mPermissionReceiver;
52 public void onCreate(Bundle icicle) {
53 super.onCreate(icicle);
54 addPreferencesFromResource(R.xml.advanced_apps);
56 Preference permissions = getPreferenceScreen().findPreference(KEY_APP_PERM);
57 permissions.setIntent(new Intent(Intent.ACTION_MANAGE_PERMISSIONS));
59 ApplicationsState applicationsState = ApplicationsState.getInstance(
60 getActivity().getApplication());
61 mSession = applicationsState.newSession(this);
63 mAppPermsPreference = findPreference(KEY_APP_PERM);
64 mAppDomainURLsPreference = findPreference(KEY_APP_DOMAIN_URLS);
65 mHighPowerPreference = findPreference(KEY_HIGH_POWER_APPS);
70 public void onDestroy() {
72 if (mPermissionReceiver != null) {
73 getContext().unregisterReceiver(mPermissionReceiver);
74 mPermissionReceiver = null;
78 private void updateUI() {
79 ArrayList<AppEntry> allApps = mSession.getAllApps();
81 int countAppWithDomainURLs = 0;
82 for (AppEntry entry : allApps) {
83 boolean hasDomainURLs =
84 (entry.info.privateFlags & ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS) != 0;
85 if (hasDomainURLs) countAppWithDomainURLs++;
87 String summary = getResources().getQuantityString(
88 R.plurals.domain_urls_apps_summary, countAppWithDomainURLs, countAppWithDomainURLs);
89 mAppDomainURLsPreference.setSummary(summary);
91 int highPowerCount = PowerWhitelistBackend.getInstance().getWhitelistSize();
92 mHighPowerPreference.setSummary(getResources().getQuantityString(R.plurals.high_power_count,
93 highPowerCount, highPowerCount));
95 if (mPermissionReceiver != null) {
96 getContext().unregisterReceiver(mPermissionReceiver);
98 mPermissionReceiver = PermissionsSummaryHelper.getAppWithPermissionsCounts(getContext(),
103 protected int getMetricsCategory() {
104 return MetricsLogger.APPLICATIONS_ADVANCED;
108 public void onRunningStateChanged(boolean running) {
113 public void onPackageListChanged() {
118 public void onRebuildComplete(ArrayList<AppEntry> apps) {
123 public void onPackageIconChanged() {
128 public void onPackageSizeChanged(String packageName) {
133 public void onAllSizesComputed() {
138 public void onLauncherInfoChanged() {
143 public void onLoadEntriesCompleted() {
147 private final PermissionsResultCallback mPermissionCallback = new PermissionsResultCallback() {
149 public void onPermissionSummaryResult(int[] counts, CharSequence[] groupLabels) {
150 if (getActivity() == null) {
153 mPermissionReceiver = null;
154 if (counts != null) {
155 mAppPermsPreference.setSummary(getContext().getString(
156 R.string.app_permissions_summary, counts[0], counts[1]));
158 mAppPermsPreference.setSummary(null);