OSDN Git Service

47a0098b0adad7106fecd23830fea3efdc3d30aa
[android-x86/packages-apps-Settings.git] / src / com / android / settings / applications / AdvancedAppSettings.java
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package com.android.settings.applications;
17
18 import android.content.Intent;
19 import android.content.pm.ApplicationInfo;
20 import android.os.Bundle;
21 import android.preference.Preference;
22
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;
31
32 import java.util.ArrayList;
33
34 public class AdvancedAppSettings extends SettingsPreferenceFragment implements
35         ApplicationsState.Callbacks {
36
37     static final String TAG = "AdvancedAppSettings";
38
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";
42
43     private Session mSession;
44     private Preference mAppPermsPreference;
45     private Preference mAppDomainURLsPreference;
46     private Preference mHighPowerPreference;
47
48     @Override
49     public void onCreate(Bundle icicle) {
50         super.onCreate(icicle);
51         addPreferencesFromResource(R.xml.advanced_apps);
52
53         Preference permissions = getPreferenceScreen().findPreference(KEY_APP_PERM);
54         permissions.setIntent(new Intent(Intent.ACTION_MANAGE_PERMISSIONS));
55
56         ApplicationsState applicationsState = ApplicationsState.getInstance(
57                 getActivity().getApplication());
58         mSession = applicationsState.newSession(this);
59
60         mAppPermsPreference = findPreference(KEY_APP_PERM);
61         mAppDomainURLsPreference = findPreference(KEY_APP_DOMAIN_URLS);
62         mHighPowerPreference = findPreference(KEY_HIGH_POWER_APPS);
63         updateUI();
64     }
65
66     private void updateUI() {
67         ArrayList<AppEntry> allApps = mSession.getAllApps();
68
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++;
74         }
75         String summary = getResources().getQuantityString(
76                 R.plurals.domain_urls_apps_summary, countAppWithDomainURLs, countAppWithDomainURLs);
77         mAppDomainURLsPreference.setSummary(summary);
78
79         int highPowerCount = PowerWhitelistBackend.getInstance().getWhitelistSize();
80         mHighPowerPreference.setSummary(getResources().getQuantityString(R.plurals.high_power_count,
81                 highPowerCount, highPowerCount));
82         PermissionsSummaryHelper.getAppWithPermissionsCounts(getContext(), mPermissionCallback);
83     }
84
85     @Override
86     protected int getMetricsCategory() {
87         return MetricsLogger.APPLICATIONS_ADVANCED;
88     }
89
90     @Override
91     public void onRunningStateChanged(boolean running) {
92         // No-op.
93     }
94
95     @Override
96     public void onPackageListChanged() {
97         updateUI();
98     }
99
100     @Override
101     public void onRebuildComplete(ArrayList<AppEntry> apps) {
102         // No-op.
103     }
104
105     @Override
106     public void onPackageIconChanged() {
107         // No-op.
108     }
109
110     @Override
111     public void onPackageSizeChanged(String packageName) {
112         // No-op.
113     }
114
115     @Override
116     public void onAllSizesComputed() {
117         // No-op.
118     }
119
120     @Override
121     public void onLauncherInfoChanged() {
122         // No-op.
123     }
124
125     @Override
126     public void onLoadEntriesCompleted() {
127         // No-op.
128     }
129
130     private final PermissionsResultCallback mPermissionCallback = new PermissionsResultCallback() {
131         @Override
132         public void onPermissionSummaryResult(int[] counts, CharSequence[] groupLabels) {
133             if (getActivity() == null) {
134                 return;
135             }
136             if (counts != null) {
137                 mAppPermsPreference.setSummary(getContext().getString(
138                         R.string.app_permissions_summary, counts[0], counts[1]));
139             } else {
140                 mAppPermsPreference.setSummary(null);
141             }
142         }
143     };
144 }