The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | |
| 2 | |
| 3 | /** |
| 4 | * Copyright (C) 2007 The Android Open Source Project |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 7 | * use this file except in compliance with the License. You may obtain a copy |
| 8 | * of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | * License for the specific language governing permissions and limitations |
| 16 | * under the License. |
| 17 | */ |
| 18 | |
| 19 | package com.android.settings; |
| 20 | |
| 21 | import com.android.settings.R; |
| 22 | import android.app.Activity; |
| 23 | import android.app.ActivityManager; |
| 24 | import android.app.AlertDialog; |
| 25 | import android.content.Context; |
| 26 | import android.content.DialogInterface; |
| 27 | import android.content.Intent; |
| 28 | import android.content.IntentFilter; |
| 29 | import android.content.pm.ApplicationInfo; |
| 30 | import android.content.pm.IPackageDataObserver; |
| 31 | import android.content.pm.IPackageStatsObserver; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 32 | import android.content.pm.PackageManager; |
| 33 | import android.content.pm.PackageStats; |
| 34 | import android.content.pm.PackageManager.NameNotFoundException; |
| 35 | import android.net.Uri; |
| 36 | import android.os.Bundle; |
| 37 | import android.os.Handler; |
| 38 | import android.os.Message; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 39 | import android.text.format.Formatter; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 40 | import android.util.Config; |
| 41 | import android.util.Log; |
| 42 | import java.util.ArrayList; |
| 43 | import java.util.List; |
| 44 | import android.content.ComponentName; |
| 45 | import android.view.View; |
| 46 | import android.widget.AppSecurityPermissions; |
| 47 | import android.widget.Button; |
| 48 | import android.widget.ImageView; |
| 49 | import android.widget.LinearLayout; |
| 50 | import android.widget.TextView; |
| 51 | |
| 52 | /** |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 53 | * Activity to display application information from Settings. This activity presents |
| 54 | * extended information associated with a package like code, data, total size, permissions |
| 55 | * used by the application and also the set of default launchable activities. |
| 56 | * For system applications, an option to clear user data is displayed only if data size is > 0. |
| 57 | * System applications that do not want clear user data do not have this option. |
| 58 | * For non-system applications, there is no option to clear data. Instead there is an option to |
| 59 | * uninstall the application. |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 60 | */ |
| 61 | public class InstalledAppDetails extends Activity implements View.OnClickListener, DialogInterface.OnClickListener { |
| 62 | private static final String TAG="InstalledAppDetails"; |
| 63 | private static final int _UNKNOWN_APP=R.string.unknown; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 64 | private ApplicationInfo mAppInfo; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 65 | private Button mAppButton; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 66 | private Button mActivitiesButton; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 67 | private boolean mCanUninstall; |
| 68 | private boolean localLOGV=Config.LOGV || false; |
The Android Open Source Project | 1feaa85 | 2009-02-10 15:44:05 -0800 | [diff] [blame^] | 69 | private TextView mAppSnippetSize; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 70 | private TextView mTotalSize; |
| 71 | private TextView mAppSize; |
| 72 | private TextView mDataSize; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 73 | private PkgSizeObserver mSizeObserver; |
| 74 | private ClearUserDataObserver mClearDataObserver; |
| 75 | // Views related to cache info |
| 76 | private View mCachePanel; |
| 77 | private TextView mCacheSize; |
| 78 | private Button mClearCacheButton; |
| 79 | private ClearCacheObserver mClearCacheObserver; |
The Android Open Source Project | 1feaa85 | 2009-02-10 15:44:05 -0800 | [diff] [blame^] | 80 | private Button mForceStopButton; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 81 | |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 82 | PackageStats mSizeInfo; |
| 83 | private Button mManageSpaceButton; |
| 84 | private PackageManager mPm; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 85 | |
| 86 | //internal constants used in Handler |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 87 | private static final int OP_SUCCESSFUL = 1; |
| 88 | private static final int OP_FAILED = 2; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 89 | private static final int CLEAR_USER_DATA = 1; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 90 | private static final int GET_PKG_SIZE = 2; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 91 | private static final int CLEAR_CACHE = 3; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 92 | private static final String ATTR_PACKAGE_STATS="PackageStats"; |
| 93 | |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 94 | // invalid size value used initially and also when size retrieval through PackageManager |
| 95 | // fails for whatever reason |
| 96 | private static final int SIZE_INVALID = -1; |
| 97 | |
| 98 | // Resource strings |
| 99 | private CharSequence mInvalidSizeStr; |
| 100 | private CharSequence mComputingStr; |
| 101 | private CharSequence mAppButtonText; |
| 102 | |
| 103 | // Possible btn states |
| 104 | private enum AppButtonStates { |
| 105 | CLEAR_DATA, |
| 106 | UNINSTALL, |
| 107 | NONE |
| 108 | } |
| 109 | private AppButtonStates mAppButtonState; |
| 110 | |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 111 | private Handler mHandler = new Handler() { |
| 112 | public void handleMessage(Message msg) { |
| 113 | switch (msg.what) { |
| 114 | case CLEAR_USER_DATA: |
| 115 | processClearMsg(msg); |
| 116 | break; |
| 117 | case GET_PKG_SIZE: |
| 118 | refreshSizeInfo(msg); |
| 119 | break; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 120 | case CLEAR_CACHE: |
| 121 | // Refresh size info |
| 122 | mPm.getPackageSizeInfo(mAppInfo.packageName, mSizeObserver); |
| 123 | break; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 124 | default: |
| 125 | break; |
| 126 | } |
| 127 | } |
| 128 | }; |
| 129 | |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 130 | private boolean isUninstallable() { |
| 131 | if (((mAppInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) && |
| 132 | ((mAppInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0)) { |
| 133 | return false; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 134 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 135 | return true; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | class ClearUserDataObserver extends IPackageDataObserver.Stub { |
| 139 | public void onRemoveCompleted(final String packageName, final boolean succeeded) { |
| 140 | final Message msg = mHandler.obtainMessage(CLEAR_USER_DATA); |
| 141 | msg.arg1 = succeeded?OP_SUCCESSFUL:OP_FAILED; |
| 142 | mHandler.sendMessage(msg); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | class PkgSizeObserver extends IPackageStatsObserver.Stub { |
| 147 | public int idx; |
| 148 | public void onGetStatsCompleted(PackageStats pStats, boolean succeeded) { |
| 149 | Message msg = mHandler.obtainMessage(GET_PKG_SIZE); |
| 150 | Bundle data = new Bundle(); |
| 151 | data.putParcelable(ATTR_PACKAGE_STATS, pStats); |
| 152 | msg.setData(data); |
| 153 | mHandler.sendMessage(msg); |
| 154 | |
| 155 | } |
| 156 | } |
| 157 | |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 158 | class ClearCacheObserver extends IPackageDataObserver.Stub { |
| 159 | public void onRemoveCompleted(final String packageName, final boolean succeeded) { |
| 160 | final Message msg = mHandler.obtainMessage(CLEAR_CACHE); |
| 161 | msg.arg1 = succeeded?OP_SUCCESSFUL:OP_FAILED; |
| 162 | mHandler.sendMessage(msg); |
| 163 | } |
| 164 | } |
| 165 | |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 166 | private String getSizeStr(long size) { |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 167 | if (size == SIZE_INVALID) { |
| 168 | return mInvalidSizeStr.toString(); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 169 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 170 | return Formatter.formatFileSize(this, size); |
| 171 | } |
| 172 | |
| 173 | private void setAppBtnState() { |
| 174 | boolean visible = false; |
| 175 | if(mCanUninstall) { |
| 176 | //app can clear user data |
| 177 | if((mAppInfo.flags & ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA) |
| 178 | == ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA) { |
| 179 | mAppButtonText = getText(R.string.clear_user_data_text); |
| 180 | mAppButtonState = AppButtonStates.CLEAR_DATA; |
| 181 | visible = true; |
| 182 | } else { |
| 183 | //hide button if diableClearUserData is set |
| 184 | visible = false; |
| 185 | mAppButtonState = AppButtonStates.NONE; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 186 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 187 | } else { |
| 188 | visible = true; |
| 189 | mAppButtonState = AppButtonStates.UNINSTALL; |
| 190 | mAppButtonText = getText(R.string.uninstall_text); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 191 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 192 | if(visible) { |
| 193 | mAppButton.setText(mAppButtonText); |
| 194 | mAppButton.setVisibility(View.VISIBLE); |
| 195 | } else { |
| 196 | mAppButton.setVisibility(View.GONE); |
| 197 | } |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /** Called when the activity is first created. */ |
| 201 | @Override |
| 202 | protected void onCreate(Bundle icicle) { |
| 203 | super.onCreate(icicle); |
| 204 | //get package manager |
| 205 | mPm = getPackageManager(); |
| 206 | //get application's name from intent |
| 207 | Intent intent = getIntent(); |
| 208 | final String packageName = intent.getStringExtra(ManageApplications.APP_PKG_NAME); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 209 | mComputingStr = getText(R.string.computing_size); |
| 210 | // Try retrieving package stats again |
| 211 | CharSequence totalSizeStr, appSizeStr, dataSizeStr; |
| 212 | totalSizeStr = appSizeStr = dataSizeStr = mComputingStr; |
| 213 | if(localLOGV) Log.i(TAG, "Have to compute package sizes"); |
| 214 | mSizeObserver = new PkgSizeObserver(); |
| 215 | mPm.getPackageSizeInfo(packageName, mSizeObserver); |
| 216 | |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 217 | try { |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 218 | mAppInfo = mPm.getApplicationInfo(packageName, |
| 219 | PackageManager.GET_UNINSTALLED_PACKAGES); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 220 | } catch (NameNotFoundException e) { |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 221 | Log.e(TAG, "Exception when retrieving package:"+packageName, e); |
| 222 | displayErrorDialog(R.string.app_not_found_dlg_text, true, true); |
| 223 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 224 | setContentView(R.layout.installed_app_details); |
| 225 | ((ImageView)findViewById(R.id.app_icon)).setImageDrawable(mAppInfo.loadIcon(mPm)); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 226 | //set application name TODO version |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 227 | CharSequence appName = mAppInfo.loadLabel(mPm); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 228 | if(appName == null) { |
| 229 | appName = getString(_UNKNOWN_APP); |
| 230 | } |
| 231 | ((TextView)findViewById(R.id.app_name)).setText(appName); |
The Android Open Source Project | 1feaa85 | 2009-02-10 15:44:05 -0800 | [diff] [blame^] | 232 | mAppSnippetSize = ((TextView)findViewById(R.id.app_size)); |
| 233 | mAppSnippetSize.setText(totalSizeStr); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 234 | //TODO download str and download url |
| 235 | //set values on views |
| 236 | mTotalSize = (TextView)findViewById(R.id.total_size_text); |
| 237 | mTotalSize.setText(totalSizeStr); |
| 238 | mAppSize = (TextView)findViewById(R.id.application_size_text); |
| 239 | mAppSize.setText(appSizeStr); |
| 240 | mDataSize = (TextView)findViewById(R.id.data_size_text); |
| 241 | mDataSize.setText(dataSizeStr); |
| 242 | |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 243 | mAppButton = ((Button)findViewById(R.id.uninstall_button)); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 244 | //determine if app is a system app |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 245 | mCanUninstall = !isUninstallable(); |
| 246 | if(localLOGV) Log.i(TAG, "Is systemPackage "+mCanUninstall); |
| 247 | setAppBtnState(); |
| 248 | mManageSpaceButton = (Button)findViewById(R.id.manage_space_button); |
| 249 | if(mAppInfo.manageSpaceActivityName != null) { |
| 250 | mManageSpaceButton.setVisibility(View.VISIBLE); |
| 251 | mManageSpaceButton.setOnClickListener(this); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 252 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 253 | |
| 254 | // Cache section |
| 255 | mCachePanel = findViewById(R.id.cache_panel); |
| 256 | mCacheSize = (TextView) findViewById(R.id.cache_size_text); |
| 257 | mClearCacheButton = (Button) findViewById(R.id.clear_cache_button); |
The Android Open Source Project | 1feaa85 | 2009-02-10 15:44:05 -0800 | [diff] [blame^] | 258 | mForceStopButton = (Button) findViewById(R.id.force_stop_button); |
| 259 | mForceStopButton.setOnClickListener(this); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 260 | |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 261 | //clear activities |
| 262 | mActivitiesButton = (Button)findViewById(R.id.clear_activities_button); |
| 263 | List<ComponentName> prefActList = new ArrayList<ComponentName>(); |
| 264 | //intent list cannot be null. so pass empty list |
| 265 | List<IntentFilter> intentList = new ArrayList<IntentFilter>(); |
| 266 | mPm.getPreferredActivities(intentList, prefActList, packageName); |
| 267 | if(localLOGV) Log.i(TAG, "Have "+prefActList.size()+" number of activities in prefered list"); |
| 268 | TextView autoLaunchView = (TextView)findViewById(R.id.auto_launch); |
| 269 | if(prefActList.size() <= 0) { |
| 270 | //disable clear activities button |
| 271 | autoLaunchView.setText(R.string.auto_launch_disable_text); |
| 272 | mActivitiesButton.setEnabled(false); |
| 273 | } else { |
| 274 | autoLaunchView.setText(R.string.auto_launch_enable_text); |
| 275 | mActivitiesButton.setOnClickListener(this); |
| 276 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 277 | |
| 278 | // security permissions section |
| 279 | LinearLayout permsView = (LinearLayout) findViewById(R.id.permissions_section); |
| 280 | AppSecurityPermissions asp = new AppSecurityPermissions(this, packageName); |
| 281 | if(asp.getPermissionCount() > 0) { |
| 282 | permsView.setVisibility(View.VISIBLE); |
| 283 | // Make the security sections header visible |
| 284 | LinearLayout securityList = (LinearLayout) permsView.findViewById( |
| 285 | R.id.security_settings_list); |
| 286 | securityList.addView(asp.getPermissionsView()); |
| 287 | } else { |
| 288 | permsView.setVisibility(View.GONE); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 289 | } |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | private void displayErrorDialog(int msgId, final boolean finish, final boolean changed) { |
| 293 | //display confirmation dialog |
| 294 | new AlertDialog.Builder(this) |
| 295 | .setTitle(getString(R.string.app_not_found_dlg_title)) |
The Android Open Source Project | 5962e18 | 2009-01-09 17:51:25 -0800 | [diff] [blame] | 296 | .setIcon(android.R.drawable.ic_dialog_alert) |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 297 | .setMessage(getString(msgId)) |
| 298 | .setNeutralButton(getString(R.string.dlg_ok), |
| 299 | new DialogInterface.OnClickListener() { |
| 300 | public void onClick(DialogInterface dialog, int which) { |
| 301 | //force to recompute changed value |
| 302 | setIntentAndFinish(finish, changed); |
| 303 | } |
| 304 | } |
| 305 | ) |
| 306 | .show(); |
| 307 | } |
| 308 | |
| 309 | private void setIntentAndFinish(boolean finish, boolean appChanged) { |
| 310 | if(localLOGV) Log.i(TAG, "appChanged="+appChanged); |
| 311 | Intent intent = new Intent(); |
| 312 | intent.putExtra(ManageApplications.APP_CHG, appChanged); |
| 313 | setResult(ManageApplications.RESULT_OK, intent); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 314 | mAppButton.setEnabled(false); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 315 | if(finish) { |
| 316 | finish(); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | * Private method to handle get size info notification from observer when |
| 322 | * the async operation from PackageManager is complete. The current user data |
| 323 | * info has to be refreshed in the manage applications screen as well as the current screen. |
| 324 | */ |
| 325 | private void refreshSizeInfo(Message msg) { |
| 326 | boolean changed = false; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 327 | PackageStats newPs = msg.getData().getParcelable(ATTR_PACKAGE_STATS); |
| 328 | long newTot = newPs.cacheSize+newPs.codeSize+newPs.dataSize; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 329 | if(mSizeInfo == null) { |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 330 | mSizeInfo = newPs; |
The Android Open Source Project | 1feaa85 | 2009-02-10 15:44:05 -0800 | [diff] [blame^] | 331 | String str = getSizeStr(newTot); |
| 332 | mTotalSize.setText(str); |
| 333 | mAppSnippetSize.setText(str); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 334 | mAppSize.setText(getSizeStr(newPs.codeSize)); |
| 335 | mDataSize.setText(getSizeStr(newPs.dataSize+newPs.cacheSize)); |
| 336 | } else { |
| 337 | long oldTot = mSizeInfo.cacheSize+mSizeInfo.codeSize+mSizeInfo.dataSize; |
| 338 | if(newTot != oldTot) { |
The Android Open Source Project | 1feaa85 | 2009-02-10 15:44:05 -0800 | [diff] [blame^] | 339 | String str = getSizeStr(newTot); |
| 340 | mTotalSize.setText(str); |
| 341 | mAppSnippetSize.setText(str); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 342 | changed = true; |
| 343 | } |
| 344 | if(newPs.codeSize != mSizeInfo.codeSize) { |
| 345 | mAppSize.setText(getSizeStr(newPs.codeSize)); |
| 346 | changed = true; |
| 347 | } |
| 348 | if((newPs.dataSize != mSizeInfo.dataSize) || (newPs.cacheSize != mSizeInfo.cacheSize)) { |
| 349 | mDataSize.setText(getSizeStr(newPs.dataSize+newPs.cacheSize)); |
| 350 | } |
| 351 | if(changed) { |
| 352 | mSizeInfo = newPs; |
| 353 | } |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 354 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 355 | |
| 356 | long data = mSizeInfo.dataSize+mSizeInfo.cacheSize; |
| 357 | // Disable button if data is 0 |
| 358 | if(mAppButtonState != AppButtonStates.NONE){ |
| 359 | mAppButton.setText(mAppButtonText); |
| 360 | if((mAppButtonState == AppButtonStates.CLEAR_DATA) && (data == 0)) { |
| 361 | mAppButton.setEnabled(false); |
| 362 | } else { |
| 363 | mAppButton.setEnabled(true); |
| 364 | mAppButton.setOnClickListener(this); |
| 365 | } |
| 366 | } |
| 367 | refreshCacheInfo(newPs.cacheSize); |
| 368 | } |
| 369 | |
| 370 | private void refreshCacheInfo(long cacheSize) { |
| 371 | // Set cache info |
| 372 | mCacheSize.setText(getSizeStr(cacheSize)); |
| 373 | if (cacheSize <= 0) { |
| 374 | mClearCacheButton.setEnabled(false); |
| 375 | } else { |
| 376 | mClearCacheButton.setOnClickListener(this); |
| 377 | } |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | /* |
| 381 | * Private method to handle clear message notification from observer when |
| 382 | * the async operation from PackageManager is complete |
| 383 | */ |
| 384 | private void processClearMsg(Message msg) { |
| 385 | int result = msg.arg1; |
| 386 | String packageName = mAppInfo.packageName; |
| 387 | if(result == OP_SUCCESSFUL) { |
| 388 | Log.i(TAG, "Cleared user data for system package:"+packageName); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 389 | mPm.getPackageSizeInfo(packageName, mSizeObserver); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 390 | } else { |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 391 | mAppButton.setText(R.string.clear_user_data_text); |
| 392 | mAppButton.setEnabled(true); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | |
| 396 | /* |
| 397 | * Private method to initiate clearing user data when the user clicks the clear data |
| 398 | * button for a system package |
| 399 | */ |
| 400 | private void initiateClearUserDataForSysPkg() { |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 401 | mAppButton.setEnabled(false); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 402 | //invoke uninstall or clear user data based on sysPackage |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 403 | String packageName = mAppInfo.packageName; |
| 404 | Log.i(TAG, "Clearing user data for system package"); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 405 | if(mClearDataObserver == null) { |
| 406 | mClearDataObserver = new ClearUserDataObserver(); |
| 407 | } |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 408 | ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 409 | boolean res = am.clearApplicationUserData(packageName, mClearDataObserver); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 410 | if(!res) { |
| 411 | //doesnt initiate clear. some error. should not happen but just log error for now |
| 412 | Log.i(TAG, "Couldnt clear application user data for package:"+packageName); |
| 413 | displayErrorDialog(R.string.clear_data_failed, false, false); |
| 414 | } else { |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 415 | mAppButton.setText(R.string.recompute_size); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
| 419 | /* |
| 420 | * Method implementing functionality of buttons clicked |
| 421 | * @see android.view.View.OnClickListener#onClick(android.view.View) |
| 422 | */ |
| 423 | public void onClick(View v) { |
| 424 | String packageName = mAppInfo.packageName; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 425 | if(v == mAppButton) { |
| 426 | if(mCanUninstall) { |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 427 | //display confirmation dialog |
| 428 | new AlertDialog.Builder(this) |
| 429 | .setTitle(getString(R.string.clear_data_dlg_title)) |
The Android Open Source Project | 5962e18 | 2009-01-09 17:51:25 -0800 | [diff] [blame] | 430 | .setIcon(android.R.drawable.ic_dialog_alert) |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 431 | .setMessage(getString(R.string.clear_data_dlg_text)) |
| 432 | .setPositiveButton(R.string.dlg_ok, this) |
| 433 | .setNegativeButton(R.string.dlg_cancel, this) |
| 434 | .show(); |
| 435 | } else { |
| 436 | //create new intent to launch Uninstaller activity |
| 437 | Uri packageURI = Uri.parse("package:"+packageName); |
| 438 | Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI); |
| 439 | startActivity(uninstallIntent); |
| 440 | setIntentAndFinish(true, false); |
| 441 | } |
| 442 | } else if(v == mActivitiesButton) { |
| 443 | mPm.clearPackagePreferredActivities(packageName); |
| 444 | mActivitiesButton.setEnabled(false); |
| 445 | } else if(v == mManageSpaceButton) { |
| 446 | Intent intent = new Intent(Intent.ACTION_DEFAULT); |
| 447 | intent.setClassName(mAppInfo.packageName, mAppInfo.manageSpaceActivityName); |
| 448 | startActivityForResult(intent, -1); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 449 | } else if (v == mClearCacheButton) { |
| 450 | // Lazy initialization of observer |
| 451 | if (mClearCacheObserver == null) { |
| 452 | mClearCacheObserver = new ClearCacheObserver(); |
| 453 | } |
| 454 | mPm.deleteApplicationCacheFiles(packageName, mClearCacheObserver); |
The Android Open Source Project | 1feaa85 | 2009-02-10 15:44:05 -0800 | [diff] [blame^] | 455 | } else if (v == mForceStopButton) { |
| 456 | ActivityManager am = (ActivityManager)getSystemService( |
| 457 | Context.ACTIVITY_SERVICE); |
| 458 | am.restartPackage(packageName); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
| 462 | public void onClick(DialogInterface dialog, int which) { |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 463 | if(which == AlertDialog.BUTTON_POSITIVE) { |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 464 | //invoke uninstall or clear user data based on sysPackage |
| 465 | initiateClearUserDataForSysPkg(); |
| 466 | } else { |
| 467 | //cancel do nothing just retain existing screen |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |