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.Intent;
19 import android.content.pm.ApplicationInfo;
20 import android.os.Bundle;
21 import android.preference.Preference;
23 import com.android.internal.logging.MetricsLogger;
24 import com.android.settings.R;
25 import com.android.settings.SettingsPreferenceFragment;
26 import com.android.settings.applications.PermissionsSummaryHelper.PermissionsResultCallback;
27 import com.android.settings.fuelgauge.PowerWhitelistBackend;
28 import com.android.settingslib.applications.ApplicationsState;
29 import com.android.settingslib.applications.ApplicationsState.AppEntry;
30 import com.android.settingslib.applications.ApplicationsState.Session;
32 import java.util.ArrayList;
34 public class AdvancedAppSettings extends SettingsPreferenceFragment implements
35 ApplicationsState.Callbacks {
37 static final String TAG = "AdvancedAppSettings";
39 private static final String KEY_APP_PERM = "manage_perms";
40 private static final String KEY_APP_DOMAIN_URLS = "domain_urls";
41 private static final String KEY_HIGH_POWER_APPS = "high_power_apps";
43 private Session mSession;
44 private Preference mAppPermsPreference;
45 private Preference mAppDomainURLsPreference;
46 private Preference mHighPowerPreference;
49 public void onCreate(Bundle icicle) {
50 super.onCreate(icicle);
51 addPreferencesFromResource(R.xml.advanced_apps);
53 Preference permissions = getPreferenceScreen().findPreference(KEY_APP_PERM);
54 permissions.setIntent(new Intent(Intent.ACTION_MANAGE_PERMISSIONS));
56 ApplicationsState applicationsState = ApplicationsState.getInstance(
57 getActivity().getApplication());
58 mSession = applicationsState.newSession(this);
60 mAppPermsPreference = findPreference(KEY_APP_PERM);
61 mAppDomainURLsPreference = findPreference(KEY_APP_DOMAIN_URLS);
62 mHighPowerPreference = findPreference(KEY_HIGH_POWER_APPS);
66 private void updateUI() {
67 ArrayList<AppEntry> allApps = mSession.getAllApps();
69 int countAppWithDomainURLs = 0;
70 for (AppEntry entry : allApps) {
71 boolean hasDomainURLs =
72 (entry.info.privateFlags & ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS) != 0;
73 if (hasDomainURLs) countAppWithDomainURLs++;
75 String summary = getResources().getQuantityString(
76 R.plurals.domain_urls_apps_summary, countAppWithDomainURLs, countAppWithDomainURLs);
77 mAppDomainURLsPreference.setSummary(summary);
79 int highPowerCount = PowerWhitelistBackend.getInstance().getWhitelistSize();
80 mHighPowerPreference.setSummary(getResources().getQuantityString(R.plurals.high_power_count,
81 highPowerCount, highPowerCount));
82 PermissionsSummaryHelper.getAppWithPermissionsCounts(getContext(), mPermissionCallback);
86 protected int getMetricsCategory() {
87 return MetricsLogger.APPLICATIONS_ADVANCED;
91 public void onRunningStateChanged(boolean running) {
96 public void onPackageListChanged() {
101 public void onRebuildComplete(ArrayList<AppEntry> apps) {
106 public void onPackageIconChanged() {
111 public void onPackageSizeChanged(String packageName) {
116 public void onAllSizesComputed() {
121 public void onLauncherInfoChanged() {
126 public void onLoadEntriesCompleted() {
130 private final PermissionsResultCallback mPermissionCallback = new PermissionsResultCallback() {
132 public void onPermissionSummaryResult(int[] counts, CharSequence[] groupLabels) {
133 if (getActivity() == null) {
136 if (counts != null) {
137 mAppPermsPreference.setSummary(getContext().getString(
138 R.string.app_permissions_summary, counts[0], counts[1]));
140 mAppPermsPreference.setSummary(null);