2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy
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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
17 package com.android.settings.applications;
19 import android.app.Activity;
20 import android.app.ActivityManager;
21 import android.app.AlertDialog;
22 import android.app.LoaderManager.LoaderCallbacks;
23 import android.content.ActivityNotFoundException;
24 import android.content.BroadcastReceiver;
25 import android.content.ComponentName;
26 import android.content.Context;
27 import android.content.DialogInterface;
28 import android.content.Intent;
29 import android.content.Loader;
30 import android.content.pm.ApplicationInfo;
31 import android.content.pm.PackageInfo;
32 import android.content.pm.PackageManager;
33 import android.content.pm.PackageManager.NameNotFoundException;
34 import android.content.pm.ResolveInfo;
35 import android.net.INetworkStatsService;
36 import android.net.INetworkStatsSession;
37 import android.net.NetworkTemplate;
38 import android.net.TrafficStats;
39 import android.net.Uri;
40 import android.os.AsyncTask;
41 import android.os.BatteryStats;
42 import android.os.Bundle;
43 import android.os.RemoteException;
44 import android.os.ServiceManager;
45 import android.os.UserHandle;
46 import android.preference.Preference;
47 import android.preference.Preference.OnPreferenceClickListener;
48 import android.text.format.DateUtils;
49 import android.text.format.Formatter;
50 import android.util.Log;
51 import android.view.Menu;
52 import android.view.MenuInflater;
53 import android.view.MenuItem;
54 import android.view.View;
55 import android.widget.Button;
56 import android.widget.ImageView;
57 import android.widget.TextView;
59 import com.android.internal.logging.MetricsLogger;
60 import com.android.internal.os.BatterySipper;
61 import com.android.internal.os.BatteryStatsHelper;
62 import com.android.settings.DataUsageSummary;
63 import com.android.settings.DataUsageSummary.AppItem;
64 import com.android.settings.R;
65 import com.android.settings.SettingsActivity;
66 import com.android.settings.Utils;
67 import com.android.settings.applications.ApplicationsState.AppEntry;
68 import com.android.settings.applications.PermissionsSummaryHelper.PermissionsResultCallback;
69 import com.android.settings.fuelgauge.BatteryEntry;
70 import com.android.settings.fuelgauge.PowerUsageDetail;
71 import com.android.settings.net.ChartData;
72 import com.android.settings.net.ChartDataLoader;
73 import com.android.settings.notification.AppNotificationSettings;
74 import com.android.settings.notification.NotificationBackend;
75 import com.android.settings.notification.NotificationBackend.AppRow;
77 import java.lang.ref.WeakReference;
78 import java.util.ArrayList;
79 import java.util.HashSet;
80 import java.util.List;
83 * Activity to display application information from Settings. This activity presents
84 * extended information associated with a package like code, data, total size, permissions
85 * used by the application and also the set of default launchable activities.
86 * For system applications, an option to clear user data is displayed only if data size is > 0.
87 * System applications that do not want clear user data do not have this option.
88 * For non-system applications, there is no option to clear data. Instead there is an option to
89 * uninstall the application.
91 public class InstalledAppDetails extends AppInfoBase
92 implements View.OnClickListener, OnPreferenceClickListener {
94 private static final String LOG_TAG = "InstalledAppDetails";
97 public static final int UNINSTALL_ALL_USERS_MENU = 1;
98 public static final int UNINSTALL_UPDATES = 2;
100 // Result code identifiers
101 public static final int REQUEST_UNINSTALL = 0;
102 private static final int SUB_INFO_FRAGMENT = 1;
104 private static final int LOADER_CHART_DATA = 2;
106 private static final int DLG_FORCE_STOP = DLG_BASE + 1;
107 private static final int DLG_DISABLE = DLG_BASE + 2;
108 private static final int DLG_SPECIAL_DISABLE = DLG_BASE + 3;
109 private static final int DLG_FACTORY_RESET = DLG_BASE + 4;
111 private static final String KEY_HEADER = "header_view";
112 private static final String KEY_NOTIFICATION = "notification_settings";
113 private static final String KEY_STORAGE = "storage_settings";
114 private static final String KEY_PERMISSION = "permission_settings";
115 private static final String KEY_DATA = "data_settings";
116 private static final String KEY_LAUNCH = "preferred_settings";
117 private static final String KEY_BATTERY = "battery";
119 private final HashSet<String> mHomePackages = new HashSet<String>();
121 private boolean mInitialized;
122 private boolean mShowUninstalled;
123 private LayoutPreference mHeader;
124 private Button mUninstallButton;
125 private boolean mUpdatedSysApp = false;
126 private TextView mAppVersion;
127 private Button mForceStopButton;
128 private Preference mNotificationPreference;
129 private Preference mStoragePreference;
130 private Preference mPermissionsPreference;
131 private Preference mLaunchPreference;
132 private Preference mDataPreference;
134 private boolean mDisableAfterUninstall;
135 // Used for updating notification preference.
136 private final NotificationBackend mBackend = new NotificationBackend();
138 private ChartData mChartData;
139 private INetworkStatsSession mStatsSession;
141 private Preference mBatteryPreference;
143 private BatteryStatsHelper mBatteryHelper;
144 private BatterySipper mSipper;
146 private boolean handleDisableable(Button button) {
147 boolean disableable = false;
148 // Try to prevent the user from bricking their phone
149 // by not allowing disabling of apps signed with the
150 // system cert and any launcher app in the system.
151 if (mHomePackages.contains(mAppEntry.info.packageName)
152 || Utils.isSystemPackage(mPm, mPackageInfo)) {
153 // Disable button for core system applications.
154 button.setText(R.string.disable_text);
155 } else if (mAppEntry.info.enabled) {
156 button.setText(R.string.disable_text);
159 button.setText(R.string.enable_text);
166 private void initUninstallButtons() {
167 final boolean isBundled = (mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
168 boolean enabled = true;
170 enabled = handleDisableable(mUninstallButton);
172 if ((mPackageInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0
173 && mUserManager.getUsers().size() >= 2) {
174 // When we have multiple users, there is a separate menu
175 // to uninstall for all users.
178 mUninstallButton.setText(R.string.uninstall_text);
180 // If this is a device admin, it can't be uninstalled or disabled.
181 // We do this here so the text of the button is still set correctly.
182 if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
186 // Home apps need special handling. Bundled ones we don't risk downgrading
187 // because that can interfere with home-key resolution. Furthermore, we
188 // can't allow uninstallation of the only home app, and we don't want to
189 // allow uninstallation of an explicitly preferred one -- the user can go
190 // to Home settings and pick a different one, after which we'll permit
191 // uninstallation of the now-not-default one.
192 if (enabled && mHomePackages.contains(mPackageInfo.packageName)) {
196 ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
197 ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities);
198 if (currentDefaultHome == null) {
199 // No preferred default, so permit uninstall only when
200 // there is more than one candidate
201 enabled = (mHomePackages.size() > 1);
203 // There is an explicit default home app -- forbid uninstall of
204 // that one, but permit it for installed-but-inactive ones.
205 enabled = !mPackageInfo.packageName.equals(currentDefaultHome.getPackageName());
210 if (mAppControlRestricted) {
214 mUninstallButton.setEnabled(enabled);
217 mUninstallButton.setOnClickListener(this);
221 /** Called when the activity is first created. */
223 public void onCreate(Bundle icicle) {
224 super.onCreate(icicle);
226 setHasOptionsMenu(true);
227 addPreferencesFromResource(R.xml.installed_app_details);
229 if (Utils.isBandwidthControlEnabled()) {
230 INetworkStatsService statsService = INetworkStatsService.Stub.asInterface(
231 ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
233 mStatsSession = statsService.openSession();
234 } catch (RemoteException e) {
235 throw new RuntimeException(e);
238 removePreference(KEY_DATA);
240 mBatteryHelper = new BatteryStatsHelper(getActivity(), true);
244 protected int getMetricsCategory() {
245 return MetricsLogger.APPLICATIONS_INSTALLED_APP_DETAILS;
249 public void onResume() {
254 mState.requestSize(mPackageName, mUserId);
255 AppItem app = new AppItem(mAppEntry.info.uid);
256 app.addUid(mAppEntry.info.uid);
257 if (mStatsSession != null) {
258 getLoaderManager().restartLoader(LOADER_CHART_DATA,
259 ChartDataLoader.buildArgs(getTemplate(getContext()), app),
262 new BatteryUpdater().execute();
266 public void onPause() {
267 getLoaderManager().destroyLoader(LOADER_CHART_DATA);
272 public void onDestroy() {
273 TrafficStats.closeQuietly(mStatsSession);
278 public void onActivityCreated(Bundle savedInstanceState) {
279 super.onActivityCreated(savedInstanceState);
285 mNotificationPreference = findPreference(KEY_NOTIFICATION);
286 mNotificationPreference.setOnPreferenceClickListener(this);
287 mStoragePreference = findPreference(KEY_STORAGE);
288 mStoragePreference.setOnPreferenceClickListener(this);
289 mPermissionsPreference = findPreference(KEY_PERMISSION);
290 mPermissionsPreference.setOnPreferenceClickListener(this);
291 mDataPreference = findPreference(KEY_DATA);
292 if (mDataPreference != null) {
293 mDataPreference.setOnPreferenceClickListener(this);
295 mBatteryPreference = findPreference(KEY_BATTERY);
296 mBatteryPreference.setEnabled(false);
297 mBatteryPreference.setOnPreferenceClickListener(this);
299 mLaunchPreference = findPreference(KEY_LAUNCH);
300 if (mAppEntry.info != null) {
301 if ((mAppEntry.info.flags&ApplicationInfo.FLAG_INSTALLED) == 0 ||
302 !mAppEntry.info.enabled) {
303 mLaunchPreference.setEnabled(false);
305 mLaunchPreference.setOnPreferenceClickListener(this);
308 mLaunchPreference.setEnabled(false);
312 private void handleHeader() {
313 mHeader = (LayoutPreference) findPreference(KEY_HEADER);
315 // Get Control button panel
316 View btnPanel = mHeader.findViewById(R.id.control_buttons_panel);
317 mForceStopButton = (Button) btnPanel.findViewById(R.id.right_button);
318 mForceStopButton.setText(R.string.force_stop);
319 mUninstallButton = (Button) btnPanel.findViewById(R.id.left_button);
320 mForceStopButton.setEnabled(false);
324 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
325 menu.add(0, UNINSTALL_UPDATES, 0, R.string.app_factory_reset)
326 .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
327 menu.add(0, UNINSTALL_ALL_USERS_MENU, 1, R.string.uninstall_all_users_text)
328 .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
332 public void onPrepareOptionsMenu(Menu menu) {
333 boolean showIt = true;
334 if (mUpdatedSysApp) {
336 } else if (mAppEntry == null) {
338 } else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
340 } else if (mPackageInfo == null || mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
342 } else if (UserHandle.myUserId() != 0) {
344 } else if (mUserManager.getUsers().size() < 2) {
347 menu.findItem(UNINSTALL_ALL_USERS_MENU).setVisible(showIt);
348 mUpdatedSysApp = (mAppEntry.info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
349 menu.findItem(UNINSTALL_UPDATES).setVisible(mUpdatedSysApp && !mAppControlRestricted);
353 public boolean onOptionsItemSelected(MenuItem item) {
354 switch (item.getItemId()) {
355 case UNINSTALL_ALL_USERS_MENU:
356 uninstallPkg(mAppEntry.info.packageName, true, false);
358 case UNINSTALL_UPDATES:
359 showDialogInner(DLG_FACTORY_RESET, 0);
366 public void onActivityResult(int requestCode, int resultCode, Intent data) {
367 super.onActivityResult(requestCode, resultCode, data);
368 if (requestCode == REQUEST_UNINSTALL) {
369 if (mDisableAfterUninstall) {
370 mDisableAfterUninstall = false;
372 ApplicationInfo ainfo = getActivity().getPackageManager().getApplicationInfo(
373 mAppEntry.info.packageName, PackageManager.GET_UNINSTALLED_PACKAGES
374 | PackageManager.GET_DISABLED_COMPONENTS);
375 if ((ainfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0) {
376 new DisableChanger(this, mAppEntry.info,
377 PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER)
378 .execute((Object)null);
380 } catch (NameNotFoundException e) {
384 setIntentAndFinish(true, true);
389 // Utility method to set application label and icon.
390 private void setAppLabelAndIcon(PackageInfo pkgInfo) {
391 final View appSnippet = mHeader.findViewById(R.id.app_snippet);
392 appSnippet.setPaddingRelative(0, appSnippet.getPaddingTop(), 0,
393 appSnippet.getPaddingBottom());
395 ImageView icon = (ImageView) appSnippet.findViewById(R.id.app_icon);
396 mState.ensureIcon(mAppEntry);
397 icon.setImageDrawable(mAppEntry.icon);
398 // Set application name.
399 TextView label = (TextView) appSnippet.findViewById(R.id.app_name);
400 label.setText(mAppEntry.label);
401 // Version number of application
402 mAppVersion = (TextView) appSnippet.findViewById(R.id.app_summary);
404 if (pkgInfo != null && pkgInfo.versionName != null) {
405 mAppVersion.setVisibility(View.VISIBLE);
406 mAppVersion.setText(getActivity().getString(R.string.version_text,
407 String.valueOf(pkgInfo.versionName)));
409 mAppVersion.setVisibility(View.INVISIBLE);
413 private boolean signaturesMatch(String pkg1, String pkg2) {
414 if (pkg1 != null && pkg2 != null) {
416 final int match = mPm.checkSignatures(pkg1, pkg2);
417 if (match >= PackageManager.SIGNATURE_MATCH) {
420 } catch (Exception e) {
421 // e.g. named alternate package not found during lookup;
422 // this is an expected case sometimes
429 protected boolean refreshUi() {
431 if (mAppEntry == null) {
432 return false; // onCreate must have failed, make sure to exit
435 if (mPackageInfo == null) {
436 return false; // onCreate must have failed, make sure to exit
439 // Get list of "home" apps and trace through any meta-data references
440 List<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
441 mPm.getHomeActivities(homeActivities);
442 mHomePackages.clear();
443 for (int i = 0; i< homeActivities.size(); i++) {
444 ResolveInfo ri = homeActivities.get(i);
445 final String activityPkg = ri.activityInfo.packageName;
446 mHomePackages.add(activityPkg);
448 // Also make sure to include anything proxying for the home app
449 final Bundle metadata = ri.activityInfo.metaData;
450 if (metadata != null) {
451 final String metaPkg = metadata.getString(ActivityManager.META_HOME_ALTERNATE);
452 if (signaturesMatch(metaPkg, activityPkg)) {
453 mHomePackages.add(metaPkg);
459 setAppLabelAndIcon(mPackageInfo);
460 initUninstallButtons();
462 // Update the preference summaries.
463 Activity context = getActivity();
464 mStoragePreference.setSummary(AppStorageSettings.getSummary(mAppEntry, context));
465 PermissionsSummaryHelper.getPermissionCounts(getContext(), mPackageName,
466 mPermissionCallback);
467 mLaunchPreference.setSummary(Utils.getLaunchByDeafaultSummary(mAppEntry, mUsbManager,
469 mNotificationPreference.setSummary(getNotificationSummary(mAppEntry, context,
471 if (mDataPreference != null) {
472 mDataPreference.setSummary(getDataSummary());
478 // First time init: are we displaying an uninstalled app?
480 mShowUninstalled = (mAppEntry.info.flags&ApplicationInfo.FLAG_INSTALLED) == 0;
482 // All other times: if the app no longer exists then we want
485 ApplicationInfo ainfo = context.getPackageManager().getApplicationInfo(
486 mAppEntry.info.packageName, PackageManager.GET_UNINSTALLED_PACKAGES
487 | PackageManager.GET_DISABLED_COMPONENTS);
488 if (!mShowUninstalled) {
489 // If we did not start out with the app uninstalled, then
490 // it transitioning to the uninstalled state for the current
491 // user means we should go away as well.
492 return (ainfo.flags&ApplicationInfo.FLAG_INSTALLED) != 0;
494 } catch (NameNotFoundException e) {
502 private void updateBattery() {
503 if (mSipper != null) {
504 mBatteryPreference.setEnabled(true);
505 int dischargeAmount = mBatteryHelper.getStats().getDischargeAmount(
506 BatteryStats.STATS_SINCE_CHARGED);
507 final int percentOfMax = (int) ((mSipper.totalPowerMah)
508 / mBatteryHelper.getTotalPower() * dischargeAmount + .5f);
509 mBatteryPreference.setSummary(getString(R.string.battery_summary, percentOfMax));
511 mBatteryPreference.setEnabled(false);
512 mBatteryPreference.setSummary(getString(R.string.no_battery_summary));
516 private CharSequence getDataSummary() {
517 if (mChartData != null) {
518 long totalBytes = mChartData.detail.getTotalBytes();
519 if (totalBytes == 0) {
520 return getString(R.string.no_data_usage);
522 Context context = getActivity();
523 return getString(R.string.data_summary_format,
524 Formatter.formatFileSize(context, totalBytes),
525 DateUtils.formatDateTime(context, mChartData.detail.getStart(),
526 DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH));
528 return getString(R.string.computing_size);
532 protected AlertDialog createDialog(int id, int errorCode) {
535 return new AlertDialog.Builder(getActivity())
536 .setTitle(getActivity().getText(R.string.app_disable_dlg_title))
537 .setMessage(getActivity().getText(R.string.app_disable_dlg_text))
538 .setPositiveButton(R.string.dlg_ok, new DialogInterface.OnClickListener() {
539 public void onClick(DialogInterface dialog, int which) {
541 new DisableChanger(InstalledAppDetails.this, mAppEntry.info,
542 PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER)
543 .execute((Object)null);
546 .setNegativeButton(R.string.dlg_cancel, null)
548 case DLG_SPECIAL_DISABLE:
549 return new AlertDialog.Builder(getActivity())
550 .setTitle(getActivity().getText(R.string.app_special_disable_dlg_title))
551 .setMessage(getActivity().getText(R.string.app_special_disable_dlg_text))
552 .setPositiveButton(R.string.dlg_ok, new DialogInterface.OnClickListener() {
553 public void onClick(DialogInterface dialog, int which) {
554 // Clear user data here
555 uninstallPkg(mAppEntry.info.packageName,
559 .setNegativeButton(R.string.dlg_cancel, null)
562 return new AlertDialog.Builder(getActivity())
563 .setTitle(getActivity().getText(R.string.force_stop_dlg_title))
564 .setMessage(getActivity().getText(R.string.force_stop_dlg_text))
565 .setPositiveButton(R.string.dlg_ok, new DialogInterface.OnClickListener() {
566 public void onClick(DialogInterface dialog, int which) {
568 forceStopPackage(mAppEntry.info.packageName);
571 .setNegativeButton(R.string.dlg_cancel, null)
573 case DLG_FACTORY_RESET:
574 return new AlertDialog.Builder(getActivity())
575 .setTitle(getActivity().getText(R.string.app_factory_reset_dlg_title))
576 .setMessage(getActivity().getText(R.string.app_factory_reset_dlg_text))
577 .setPositiveButton(R.string.dlg_ok, new DialogInterface.OnClickListener() {
578 public void onClick(DialogInterface dialog, int which) {
579 // Clear user data here
580 uninstallPkg(mAppEntry.info.packageName,
584 .setNegativeButton(R.string.dlg_cancel, null)
590 private void uninstallPkg(String packageName, boolean allUsers, boolean andDisable) {
591 // Create new intent to launch Uninstaller activity
592 Uri packageURI = Uri.parse("package:"+packageName);
593 Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
594 uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, allUsers);
595 startActivityForResult(uninstallIntent, REQUEST_UNINSTALL);
596 mDisableAfterUninstall = andDisable;
599 private void forceStopPackage(String pkgName) {
600 ActivityManager am = (ActivityManager)getActivity().getSystemService(
601 Context.ACTIVITY_SERVICE);
602 am.forceStopPackage(pkgName);
603 int userId = UserHandle.getUserId(mAppEntry.info.uid);
604 mState.invalidatePackage(pkgName, userId);
605 ApplicationsState.AppEntry newEnt = mState.getEntry(pkgName, userId);
606 if (newEnt != null) {
612 private void updateForceStopButton(boolean enabled) {
613 if (mAppControlRestricted) {
614 mForceStopButton.setEnabled(false);
616 mForceStopButton.setEnabled(enabled);
617 mForceStopButton.setOnClickListener(InstalledAppDetails.this);
621 private void checkForceStop() {
622 if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
623 // User can't force stop device admin.
624 updateForceStopButton(false);
625 } else if ((mAppEntry.info.flags&ApplicationInfo.FLAG_STOPPED) == 0) {
626 // If the app isn't explicitly stopped, then always show the
627 // force stop button.
628 updateForceStopButton(true);
630 Intent intent = new Intent(Intent.ACTION_QUERY_PACKAGE_RESTART,
631 Uri.fromParts("package", mAppEntry.info.packageName, null));
632 intent.putExtra(Intent.EXTRA_PACKAGES, new String[] { mAppEntry.info.packageName });
633 intent.putExtra(Intent.EXTRA_UID, mAppEntry.info.uid);
634 intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(mAppEntry.info.uid));
635 getActivity().sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null,
636 mCheckKillProcessesReceiver, null, Activity.RESULT_CANCELED, null, null);
640 private void startManagePermissionsActivity() {
641 // start new activity to manage app permissions
642 Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS);
643 intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mAppEntry.info.packageName);
644 intent.putExtra(AppInfoWithHeader.EXTRA_HIDE_INFO_BUTTON, true);
646 startActivity(intent);
647 } catch (ActivityNotFoundException e) {
648 Log.w(LOG_TAG, "No app can handle android.intent.action.MANAGE_APP_PERMISSIONS");
652 private void startAppInfoFragment(Class<?> fragment, CharSequence title) {
653 // start new fragment to display extended information
654 Bundle args = new Bundle();
655 args.putString(ARG_PACKAGE_NAME, mAppEntry.info.packageName);
656 args.putInt(ARG_PACKAGE_UID, mAppEntry.info.uid);
657 args.putBoolean(AppInfoWithHeader.EXTRA_HIDE_INFO_BUTTON, true);
659 SettingsActivity sa = (SettingsActivity) getActivity();
660 sa.startPreferencePanel(fragment.getName(), args, -1, title, this, SUB_INFO_FRAGMENT);
664 * Method implementing functionality of buttons clicked
665 * @see android.view.View.OnClickListener#onClick(android.view.View)
667 public void onClick(View v) {
668 String packageName = mAppEntry.info.packageName;
669 if(v == mUninstallButton) {
670 if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
671 if (mAppEntry.info.enabled) {
672 if (mUpdatedSysApp) {
673 showDialogInner(DLG_SPECIAL_DISABLE, 0);
675 showDialogInner(DLG_DISABLE, 0);
678 new DisableChanger(this, mAppEntry.info,
679 PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
680 .execute((Object) null);
682 } else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
683 uninstallPkg(packageName, true, false);
685 uninstallPkg(packageName, false, false);
687 } else if (v == mForceStopButton) {
688 showDialogInner(DLG_FORCE_STOP, 0);
689 //forceStopPackage(mAppInfo.packageName);
694 public boolean onPreferenceClick(Preference preference) {
695 if (preference == mStoragePreference) {
696 startAppInfoFragment(AppStorageSettings.class, mStoragePreference.getTitle());
697 } else if (preference == mNotificationPreference) {
698 startAppInfoFragment(AppNotificationSettings.class,
699 getString(R.string.app_notifications_title));
700 } else if (preference == mPermissionsPreference) {
701 startManagePermissionsActivity();
702 } else if (preference == mLaunchPreference) {
703 startAppInfoFragment(AppLaunchSettings.class, mLaunchPreference.getTitle());
704 } else if (preference == mDataPreference) {
705 Bundle args = new Bundle();
706 args.putString(DataUsageSummary.EXTRA_SHOW_APP_IMMEDIATE_PKG,
707 mAppEntry.info.packageName);
709 SettingsActivity sa = (SettingsActivity) getActivity();
710 sa.startPreferencePanel(DataUsageSummary.class.getName(), args, -1,
711 getString(R.string.app_data_usage), this, SUB_INFO_FRAGMENT);
712 } else if (preference == mBatteryPreference) {
713 BatteryEntry entry = new BatteryEntry(getActivity(), null, mUserManager, mSipper);
714 PowerUsageDetail.startBatteryDetailPage((SettingsActivity) getActivity(),
715 mBatteryHelper, BatteryStats.STATS_SINCE_CHARGED, entry, true);
722 private static NetworkTemplate getTemplate(Context context) {
723 if (DataUsageSummary.hasReadyMobileRadio(context)) {
724 return NetworkTemplate.buildTemplateMobileWildcard();
726 if (DataUsageSummary.hasWifiRadio(context)) {
727 return NetworkTemplate.buildTemplateWifiWildcard();
729 return NetworkTemplate.buildTemplateEthernet();
732 public static CharSequence getNotificationSummary(AppEntry appEntry, Context context) {
733 return getNotificationSummary(appEntry, context, new NotificationBackend());
736 public static CharSequence getNotificationSummary(AppEntry appEntry, Context context,
737 NotificationBackend backend) {
738 AppRow appRow = backend.loadAppRow(context.getPackageManager(), appEntry.info);
739 return getNotificationSummary(appRow, context);
742 public static CharSequence getNotificationSummary(AppRow appRow, Context context) {
744 return context.getString(R.string.notifications_disabled);
746 ArrayList<CharSequence> notifSummary = new ArrayList<>();
747 if (appRow.priority) {
748 notifSummary.add(context.getString(R.string.notifications_priority));
750 if (appRow.sensitive) {
751 notifSummary.add(context.getString(R.string.notifications_sensitive));
753 if (!appRow.peekable) {
754 notifSummary.add(context.getString(R.string.notifications_no_peeking));
756 switch (notifSummary.size()) {
758 return context.getString(R.string.notifications_three_items,
759 notifSummary.get(0), notifSummary.get(1), notifSummary.get(2));
761 return context.getString(R.string.notifications_two_items,
762 notifSummary.get(0), notifSummary.get(1));
764 return notifSummary.get(0);
766 return context.getString(R.string.notifications_enabled);
770 private class BatteryUpdater extends AsyncTask<Void, Void, Void> {
772 protected Void doInBackground(Void... params) {
773 mBatteryHelper.create((Bundle) null);
774 mBatteryHelper.refreshStats(BatteryStats.STATS_SINCE_CHARGED,
775 mUserManager.getUserProfiles());
776 List<BatterySipper> usageList = mBatteryHelper.getUsageList();
777 final int N = usageList.size();
778 for (int i = 0; i < N; i++) {
779 BatterySipper sipper = usageList.get(i);
780 if (sipper.getUid() == mPackageInfo.applicationInfo.uid) {
789 protected void onPostExecute(Void result) {
794 private static class DisableChanger extends AsyncTask<Object, Object, Object> {
795 final PackageManager mPm;
796 final WeakReference<InstalledAppDetails> mActivity;
797 final ApplicationInfo mInfo;
800 DisableChanger(InstalledAppDetails activity, ApplicationInfo info, int state) {
802 mActivity = new WeakReference<InstalledAppDetails>(activity);
808 protected Object doInBackground(Object... params) {
809 mPm.setApplicationEnabledSetting(mInfo.packageName, mState, 0);
814 private final LoaderCallbacks<ChartData> mDataCallbacks = new LoaderCallbacks<ChartData>() {
817 public Loader<ChartData> onCreateLoader(int id, Bundle args) {
818 return new ChartDataLoader(getActivity(), mStatsSession, args);
822 public void onLoadFinished(Loader<ChartData> loader, ChartData data) {
824 mDataPreference.setSummary(getDataSummary());
828 public void onLoaderReset(Loader<ChartData> loader) {
830 mDataPreference.setSummary(getDataSummary());
834 private final BroadcastReceiver mCheckKillProcessesReceiver = new BroadcastReceiver() {
836 public void onReceive(Context context, Intent intent) {
837 updateForceStopButton(getResultCode() != Activity.RESULT_CANCELED);
841 private final PermissionsResultCallback mPermissionCallback = new PermissionsResultCallback() {
843 public void onPermissionCountResult(int[] result) {
844 if (getActivity() == null) {
847 if (result != null) {
848 mPermissionsPreference.setSummary(getResources().getQuantityString(
849 R.plurals.runtime_permissions_summary, result[1], result[0], result[1]));
851 mPermissionsPreference.setSummary(null);