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 | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 69 | private TextView mTotalSize; |
| 70 | private TextView mAppSize; |
| 71 | private TextView mDataSize; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 72 | private PkgSizeObserver mSizeObserver; |
| 73 | private ClearUserDataObserver mClearDataObserver; |
| 74 | // Views related to cache info |
| 75 | private View mCachePanel; |
| 76 | private TextView mCacheSize; |
| 77 | private Button mClearCacheButton; |
| 78 | private ClearCacheObserver mClearCacheObserver; |
| 79 | |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 80 | PackageStats mSizeInfo; |
| 81 | private Button mManageSpaceButton; |
| 82 | private PackageManager mPm; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 83 | |
| 84 | //internal constants used in Handler |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 85 | private static final int OP_SUCCESSFUL = 1; |
| 86 | private static final int OP_FAILED = 2; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 87 | private static final int CLEAR_USER_DATA = 1; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 88 | private static final int GET_PKG_SIZE = 2; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 89 | private static final int CLEAR_CACHE = 3; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 90 | private static final String ATTR_PACKAGE_STATS="PackageStats"; |
| 91 | |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 92 | // invalid size value used initially and also when size retrieval through PackageManager |
| 93 | // fails for whatever reason |
| 94 | private static final int SIZE_INVALID = -1; |
| 95 | |
| 96 | // Resource strings |
| 97 | private CharSequence mInvalidSizeStr; |
| 98 | private CharSequence mComputingStr; |
| 99 | private CharSequence mAppButtonText; |
| 100 | |
| 101 | // Possible btn states |
| 102 | private enum AppButtonStates { |
| 103 | CLEAR_DATA, |
| 104 | UNINSTALL, |
| 105 | NONE |
| 106 | } |
| 107 | private AppButtonStates mAppButtonState; |
| 108 | |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 109 | private Handler mHandler = new Handler() { |
| 110 | public void handleMessage(Message msg) { |
| 111 | switch (msg.what) { |
| 112 | case CLEAR_USER_DATA: |
| 113 | processClearMsg(msg); |
| 114 | break; |
| 115 | case GET_PKG_SIZE: |
| 116 | refreshSizeInfo(msg); |
| 117 | break; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 118 | case CLEAR_CACHE: |
| 119 | // Refresh size info |
| 120 | mPm.getPackageSizeInfo(mAppInfo.packageName, mSizeObserver); |
| 121 | break; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 122 | default: |
| 123 | break; |
| 124 | } |
| 125 | } |
| 126 | }; |
| 127 | |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 128 | private boolean isUninstallable() { |
| 129 | if (((mAppInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) && |
| 130 | ((mAppInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0)) { |
| 131 | return false; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 132 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 133 | return true; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | class ClearUserDataObserver extends IPackageDataObserver.Stub { |
| 137 | public void onRemoveCompleted(final String packageName, final boolean succeeded) { |
| 138 | final Message msg = mHandler.obtainMessage(CLEAR_USER_DATA); |
| 139 | msg.arg1 = succeeded?OP_SUCCESSFUL:OP_FAILED; |
| 140 | mHandler.sendMessage(msg); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | class PkgSizeObserver extends IPackageStatsObserver.Stub { |
| 145 | public int idx; |
| 146 | public void onGetStatsCompleted(PackageStats pStats, boolean succeeded) { |
| 147 | Message msg = mHandler.obtainMessage(GET_PKG_SIZE); |
| 148 | Bundle data = new Bundle(); |
| 149 | data.putParcelable(ATTR_PACKAGE_STATS, pStats); |
| 150 | msg.setData(data); |
| 151 | mHandler.sendMessage(msg); |
| 152 | |
| 153 | } |
| 154 | } |
| 155 | |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 156 | class ClearCacheObserver extends IPackageDataObserver.Stub { |
| 157 | public void onRemoveCompleted(final String packageName, final boolean succeeded) { |
| 158 | final Message msg = mHandler.obtainMessage(CLEAR_CACHE); |
| 159 | msg.arg1 = succeeded?OP_SUCCESSFUL:OP_FAILED; |
| 160 | mHandler.sendMessage(msg); |
| 161 | } |
| 162 | } |
| 163 | |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 164 | private String getSizeStr(long size) { |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 165 | if (size == SIZE_INVALID) { |
| 166 | return mInvalidSizeStr.toString(); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 167 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 168 | return Formatter.formatFileSize(this, size); |
| 169 | } |
| 170 | |
| 171 | private void setAppBtnState() { |
| 172 | boolean visible = false; |
| 173 | if(mCanUninstall) { |
| 174 | //app can clear user data |
| 175 | if((mAppInfo.flags & ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA) |
| 176 | == ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA) { |
| 177 | mAppButtonText = getText(R.string.clear_user_data_text); |
| 178 | mAppButtonState = AppButtonStates.CLEAR_DATA; |
| 179 | visible = true; |
| 180 | } else { |
| 181 | //hide button if diableClearUserData is set |
| 182 | visible = false; |
| 183 | mAppButtonState = AppButtonStates.NONE; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 184 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 185 | } else { |
| 186 | visible = true; |
| 187 | mAppButtonState = AppButtonStates.UNINSTALL; |
| 188 | mAppButtonText = getText(R.string.uninstall_text); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 189 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 190 | if(visible) { |
| 191 | mAppButton.setText(mAppButtonText); |
| 192 | mAppButton.setVisibility(View.VISIBLE); |
| 193 | } else { |
| 194 | mAppButton.setVisibility(View.GONE); |
| 195 | } |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /** Called when the activity is first created. */ |
| 199 | @Override |
| 200 | protected void onCreate(Bundle icicle) { |
| 201 | super.onCreate(icicle); |
| 202 | //get package manager |
| 203 | mPm = getPackageManager(); |
| 204 | //get application's name from intent |
| 205 | Intent intent = getIntent(); |
| 206 | final String packageName = intent.getStringExtra(ManageApplications.APP_PKG_NAME); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 207 | mComputingStr = getText(R.string.computing_size); |
| 208 | // Try retrieving package stats again |
| 209 | CharSequence totalSizeStr, appSizeStr, dataSizeStr; |
| 210 | totalSizeStr = appSizeStr = dataSizeStr = mComputingStr; |
| 211 | if(localLOGV) Log.i(TAG, "Have to compute package sizes"); |
| 212 | mSizeObserver = new PkgSizeObserver(); |
| 213 | mPm.getPackageSizeInfo(packageName, mSizeObserver); |
| 214 | |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 215 | try { |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 216 | mAppInfo = mPm.getApplicationInfo(packageName, |
| 217 | PackageManager.GET_UNINSTALLED_PACKAGES); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 218 | } catch (NameNotFoundException e) { |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 219 | Log.e(TAG, "Exception when retrieving package:"+packageName, e); |
| 220 | displayErrorDialog(R.string.app_not_found_dlg_text, true, true); |
| 221 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 222 | setContentView(R.layout.installed_app_details); |
| 223 | ((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] | 224 | //set application name TODO version |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 225 | CharSequence appName = mAppInfo.loadLabel(mPm); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 226 | if(appName == null) { |
| 227 | appName = getString(_UNKNOWN_APP); |
| 228 | } |
| 229 | ((TextView)findViewById(R.id.app_name)).setText(appName); |
| 230 | CharSequence appDesc = mAppInfo.loadDescription(mPm); |
| 231 | if(appDesc != null) { |
| 232 | ((TextView)findViewById(R.id.app_description)).setText(appDesc); |
| 233 | } |
| 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); |
| 258 | |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 259 | //clear activities |
| 260 | mActivitiesButton = (Button)findViewById(R.id.clear_activities_button); |
| 261 | List<ComponentName> prefActList = new ArrayList<ComponentName>(); |
| 262 | //intent list cannot be null. so pass empty list |
| 263 | List<IntentFilter> intentList = new ArrayList<IntentFilter>(); |
| 264 | mPm.getPreferredActivities(intentList, prefActList, packageName); |
| 265 | if(localLOGV) Log.i(TAG, "Have "+prefActList.size()+" number of activities in prefered list"); |
| 266 | TextView autoLaunchView = (TextView)findViewById(R.id.auto_launch); |
| 267 | if(prefActList.size() <= 0) { |
| 268 | //disable clear activities button |
| 269 | autoLaunchView.setText(R.string.auto_launch_disable_text); |
| 270 | mActivitiesButton.setEnabled(false); |
| 271 | } else { |
| 272 | autoLaunchView.setText(R.string.auto_launch_enable_text); |
| 273 | mActivitiesButton.setOnClickListener(this); |
| 274 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 275 | |
| 276 | // security permissions section |
| 277 | LinearLayout permsView = (LinearLayout) findViewById(R.id.permissions_section); |
| 278 | AppSecurityPermissions asp = new AppSecurityPermissions(this, packageName); |
| 279 | if(asp.getPermissionCount() > 0) { |
| 280 | permsView.setVisibility(View.VISIBLE); |
| 281 | // Make the security sections header visible |
| 282 | LinearLayout securityList = (LinearLayout) permsView.findViewById( |
| 283 | R.id.security_settings_list); |
| 284 | securityList.addView(asp.getPermissionsView()); |
| 285 | } else { |
| 286 | permsView.setVisibility(View.GONE); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 287 | } |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | private void displayErrorDialog(int msgId, final boolean finish, final boolean changed) { |
| 291 | //display confirmation dialog |
| 292 | new AlertDialog.Builder(this) |
| 293 | .setTitle(getString(R.string.app_not_found_dlg_title)) |
The Android Open Source Project | 5962e18 | 2009-01-09 17:51:25 -0800 | [diff] [blame] | 294 | .setIcon(android.R.drawable.ic_dialog_alert) |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 295 | .setMessage(getString(msgId)) |
| 296 | .setNeutralButton(getString(R.string.dlg_ok), |
| 297 | new DialogInterface.OnClickListener() { |
| 298 | public void onClick(DialogInterface dialog, int which) { |
| 299 | //force to recompute changed value |
| 300 | setIntentAndFinish(finish, changed); |
| 301 | } |
| 302 | } |
| 303 | ) |
| 304 | .show(); |
| 305 | } |
| 306 | |
| 307 | private void setIntentAndFinish(boolean finish, boolean appChanged) { |
| 308 | if(localLOGV) Log.i(TAG, "appChanged="+appChanged); |
| 309 | Intent intent = new Intent(); |
| 310 | intent.putExtra(ManageApplications.APP_CHG, appChanged); |
| 311 | setResult(ManageApplications.RESULT_OK, intent); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 312 | mAppButton.setEnabled(false); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 313 | if(finish) { |
| 314 | finish(); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | /* |
| 319 | * Private method to handle get size info notification from observer when |
| 320 | * the async operation from PackageManager is complete. The current user data |
| 321 | * info has to be refreshed in the manage applications screen as well as the current screen. |
| 322 | */ |
| 323 | private void refreshSizeInfo(Message msg) { |
| 324 | boolean changed = false; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 325 | PackageStats newPs = msg.getData().getParcelable(ATTR_PACKAGE_STATS); |
| 326 | long newTot = newPs.cacheSize+newPs.codeSize+newPs.dataSize; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 327 | if(mSizeInfo == null) { |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 328 | mSizeInfo = newPs; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 329 | mTotalSize.setText(getSizeStr(newTot)); |
| 330 | mAppSize.setText(getSizeStr(newPs.codeSize)); |
| 331 | mDataSize.setText(getSizeStr(newPs.dataSize+newPs.cacheSize)); |
| 332 | } else { |
| 333 | long oldTot = mSizeInfo.cacheSize+mSizeInfo.codeSize+mSizeInfo.dataSize; |
| 334 | if(newTot != oldTot) { |
| 335 | mTotalSize.setText(getSizeStr(newTot)); |
| 336 | changed = true; |
| 337 | } |
| 338 | if(newPs.codeSize != mSizeInfo.codeSize) { |
| 339 | mAppSize.setText(getSizeStr(newPs.codeSize)); |
| 340 | changed = true; |
| 341 | } |
| 342 | if((newPs.dataSize != mSizeInfo.dataSize) || (newPs.cacheSize != mSizeInfo.cacheSize)) { |
| 343 | mDataSize.setText(getSizeStr(newPs.dataSize+newPs.cacheSize)); |
| 344 | } |
| 345 | if(changed) { |
| 346 | mSizeInfo = newPs; |
| 347 | } |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 348 | } |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 349 | |
| 350 | long data = mSizeInfo.dataSize+mSizeInfo.cacheSize; |
| 351 | // Disable button if data is 0 |
| 352 | if(mAppButtonState != AppButtonStates.NONE){ |
| 353 | mAppButton.setText(mAppButtonText); |
| 354 | if((mAppButtonState == AppButtonStates.CLEAR_DATA) && (data == 0)) { |
| 355 | mAppButton.setEnabled(false); |
| 356 | } else { |
| 357 | mAppButton.setEnabled(true); |
| 358 | mAppButton.setOnClickListener(this); |
| 359 | } |
| 360 | } |
| 361 | refreshCacheInfo(newPs.cacheSize); |
| 362 | } |
| 363 | |
| 364 | private void refreshCacheInfo(long cacheSize) { |
| 365 | // Set cache info |
| 366 | mCacheSize.setText(getSizeStr(cacheSize)); |
| 367 | if (cacheSize <= 0) { |
| 368 | mClearCacheButton.setEnabled(false); |
| 369 | } else { |
| 370 | mClearCacheButton.setOnClickListener(this); |
| 371 | } |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /* |
| 375 | * Private method to handle clear message notification from observer when |
| 376 | * the async operation from PackageManager is complete |
| 377 | */ |
| 378 | private void processClearMsg(Message msg) { |
| 379 | int result = msg.arg1; |
| 380 | String packageName = mAppInfo.packageName; |
| 381 | if(result == OP_SUCCESSFUL) { |
| 382 | 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] | 383 | mPm.getPackageSizeInfo(packageName, mSizeObserver); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 384 | } else { |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 385 | mAppButton.setText(R.string.clear_user_data_text); |
| 386 | mAppButton.setEnabled(true); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | * Private method to initiate clearing user data when the user clicks the clear data |
| 392 | * button for a system package |
| 393 | */ |
| 394 | private void initiateClearUserDataForSysPkg() { |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 395 | mAppButton.setEnabled(false); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 396 | //invoke uninstall or clear user data based on sysPackage |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 397 | String packageName = mAppInfo.packageName; |
| 398 | Log.i(TAG, "Clearing user data for system package"); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 399 | if(mClearDataObserver == null) { |
| 400 | mClearDataObserver = new ClearUserDataObserver(); |
| 401 | } |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 402 | ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 403 | boolean res = am.clearApplicationUserData(packageName, mClearDataObserver); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 404 | if(!res) { |
| 405 | //doesnt initiate clear. some error. should not happen but just log error for now |
| 406 | Log.i(TAG, "Couldnt clear application user data for package:"+packageName); |
| 407 | displayErrorDialog(R.string.clear_data_failed, false, false); |
| 408 | } else { |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 409 | mAppButton.setText(R.string.recompute_size); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * Method implementing functionality of buttons clicked |
| 415 | * @see android.view.View.OnClickListener#onClick(android.view.View) |
| 416 | */ |
| 417 | public void onClick(View v) { |
| 418 | String packageName = mAppInfo.packageName; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 419 | if(v == mAppButton) { |
| 420 | if(mCanUninstall) { |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 421 | //display confirmation dialog |
| 422 | new AlertDialog.Builder(this) |
| 423 | .setTitle(getString(R.string.clear_data_dlg_title)) |
The Android Open Source Project | 5962e18 | 2009-01-09 17:51:25 -0800 | [diff] [blame] | 424 | .setIcon(android.R.drawable.ic_dialog_alert) |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 425 | .setMessage(getString(R.string.clear_data_dlg_text)) |
| 426 | .setPositiveButton(R.string.dlg_ok, this) |
| 427 | .setNegativeButton(R.string.dlg_cancel, this) |
| 428 | .show(); |
| 429 | } else { |
| 430 | //create new intent to launch Uninstaller activity |
| 431 | Uri packageURI = Uri.parse("package:"+packageName); |
| 432 | Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI); |
| 433 | startActivity(uninstallIntent); |
| 434 | setIntentAndFinish(true, false); |
| 435 | } |
| 436 | } else if(v == mActivitiesButton) { |
| 437 | mPm.clearPackagePreferredActivities(packageName); |
| 438 | mActivitiesButton.setEnabled(false); |
| 439 | } else if(v == mManageSpaceButton) { |
| 440 | Intent intent = new Intent(Intent.ACTION_DEFAULT); |
| 441 | intent.setClassName(mAppInfo.packageName, mAppInfo.manageSpaceActivityName); |
| 442 | startActivityForResult(intent, -1); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 443 | } else if (v == mClearCacheButton) { |
| 444 | // Lazy initialization of observer |
| 445 | if (mClearCacheObserver == null) { |
| 446 | mClearCacheObserver = new ClearCacheObserver(); |
| 447 | } |
| 448 | mPm.deleteApplicationCacheFiles(packageName, mClearCacheObserver); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
| 452 | public void onClick(DialogInterface dialog, int which) { |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 453 | if(which == AlertDialog.BUTTON_POSITIVE) { |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 454 | //invoke uninstall or clear user data based on sysPackage |
| 455 | initiateClearUserDataForSysPkg(); |
| 456 | } else { |
| 457 | //cancel do nothing just retain existing screen |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |