blob: eee8b75106e80048249f3e2bf6589e97a19ba278 [file] [log] [blame]
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -07001
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
19package com.android.settings;
20
21import com.android.settings.R;
22import android.app.Activity;
23import android.app.ActivityManager;
24import android.app.AlertDialog;
25import android.content.Context;
26import android.content.DialogInterface;
27import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.pm.ApplicationInfo;
30import android.content.pm.IPackageDataObserver;
31import android.content.pm.IPackageStatsObserver;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070032import android.content.pm.PackageManager;
33import android.content.pm.PackageStats;
34import android.content.pm.PackageManager.NameNotFoundException;
35import android.net.Uri;
36import android.os.Bundle;
37import android.os.Handler;
38import android.os.Message;
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080039import android.text.format.Formatter;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070040import android.util.Config;
41import android.util.Log;
42import java.util.ArrayList;
43import java.util.List;
44import android.content.ComponentName;
45import android.view.View;
46import android.widget.AppSecurityPermissions;
47import android.widget.Button;
48import android.widget.ImageView;
49import android.widget.LinearLayout;
50import android.widget.TextView;
51
52/**
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080053 * 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 Projectde2d9f52008-10-21 07:00:00 -070060 */
61public 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 Projectde2d9f52008-10-21 07:00:00 -070064 private ApplicationInfo mAppInfo;
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080065 private Button mAppButton;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070066 private Button mActivitiesButton;
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080067 private boolean mCanUninstall;
68 private boolean localLOGV=Config.LOGV || false;
The Android Open Source Project1feaa852009-02-10 15:44:05 -080069 private TextView mAppSnippetSize;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070070 private TextView mTotalSize;
71 private TextView mAppSize;
72 private TextView mDataSize;
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080073 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 Project1feaa852009-02-10 15:44:05 -080080 private Button mForceStopButton;
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080081
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070082 PackageStats mSizeInfo;
83 private Button mManageSpaceButton;
84 private PackageManager mPm;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070085
86 //internal constants used in Handler
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070087 private static final int OP_SUCCESSFUL = 1;
88 private static final int OP_FAILED = 2;
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080089 private static final int CLEAR_USER_DATA = 1;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070090 private static final int GET_PKG_SIZE = 2;
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080091 private static final int CLEAR_CACHE = 3;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070092 private static final String ATTR_PACKAGE_STATS="PackageStats";
93
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080094 // 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 Projectde2d9f52008-10-21 07:00:00 -0700111 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 Projectabc48f82008-12-17 18:06:01 -0800120 case CLEAR_CACHE:
121 // Refresh size info
122 mPm.getPackageSizeInfo(mAppInfo.packageName, mSizeObserver);
123 break;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700124 default:
125 break;
126 }
127 }
128 };
129
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800130 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 Projectde2d9f52008-10-21 07:00:00 -0700134 }
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800135 return true;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700136 }
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 Projectabc48f82008-12-17 18:06:01 -0800158 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 Projectde2d9f52008-10-21 07:00:00 -0700166 private String getSizeStr(long size) {
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800167 if (size == SIZE_INVALID) {
168 return mInvalidSizeStr.toString();
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700169 }
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800170 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 Projectde2d9f52008-10-21 07:00:00 -0700186 }
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800187 } else {
188 visible = true;
189 mAppButtonState = AppButtonStates.UNINSTALL;
190 mAppButtonText = getText(R.string.uninstall_text);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700191 }
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800192 if(visible) {
193 mAppButton.setText(mAppButtonText);
194 mAppButton.setVisibility(View.VISIBLE);
195 } else {
196 mAppButton.setVisibility(View.GONE);
197 }
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700198 }
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 Projectabc48f82008-12-17 18:06:01 -0800209 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 Projectde2d9f52008-10-21 07:00:00 -0700217 try {
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800218 mAppInfo = mPm.getApplicationInfo(packageName,
219 PackageManager.GET_UNINSTALLED_PACKAGES);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700220 } catch (NameNotFoundException e) {
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700221 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 Projectabc48f82008-12-17 18:06:01 -0800224 setContentView(R.layout.installed_app_details);
225 ((ImageView)findViewById(R.id.app_icon)).setImageDrawable(mAppInfo.loadIcon(mPm));
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700226 //set application name TODO version
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800227 CharSequence appName = mAppInfo.loadLabel(mPm);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700228 if(appName == null) {
229 appName = getString(_UNKNOWN_APP);
230 }
231 ((TextView)findViewById(R.id.app_name)).setText(appName);
The Android Open Source Project1feaa852009-02-10 15:44:05 -0800232 mAppSnippetSize = ((TextView)findViewById(R.id.app_size));
233 mAppSnippetSize.setText(totalSizeStr);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700234 //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 Projectabc48f82008-12-17 18:06:01 -0800243 mAppButton = ((Button)findViewById(R.id.uninstall_button));
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700244 //determine if app is a system app
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800245 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 Projectde2d9f52008-10-21 07:00:00 -0700252 }
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800253
254 // Cache section
255 mCachePanel = findViewById(R.id.cache_panel);
256 mCacheSize = (TextView) findViewById(R.id.cache_size_text);
The Android Open Source Project47729682009-02-19 10:57:36 -0800257 mCacheSize.setText(mComputingStr);
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800258 mClearCacheButton = (Button) findViewById(R.id.clear_cache_button);
The Android Open Source Project1feaa852009-02-10 15:44:05 -0800259 mForceStopButton = (Button) findViewById(R.id.force_stop_button);
260 mForceStopButton.setOnClickListener(this);
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800261
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700262 //clear activities
263 mActivitiesButton = (Button)findViewById(R.id.clear_activities_button);
264 List<ComponentName> prefActList = new ArrayList<ComponentName>();
265 //intent list cannot be null. so pass empty list
266 List<IntentFilter> intentList = new ArrayList<IntentFilter>();
267 mPm.getPreferredActivities(intentList, prefActList, packageName);
268 if(localLOGV) Log.i(TAG, "Have "+prefActList.size()+" number of activities in prefered list");
269 TextView autoLaunchView = (TextView)findViewById(R.id.auto_launch);
270 if(prefActList.size() <= 0) {
271 //disable clear activities button
272 autoLaunchView.setText(R.string.auto_launch_disable_text);
273 mActivitiesButton.setEnabled(false);
274 } else {
275 autoLaunchView.setText(R.string.auto_launch_enable_text);
276 mActivitiesButton.setOnClickListener(this);
277 }
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800278
279 // security permissions section
280 LinearLayout permsView = (LinearLayout) findViewById(R.id.permissions_section);
281 AppSecurityPermissions asp = new AppSecurityPermissions(this, packageName);
282 if(asp.getPermissionCount() > 0) {
283 permsView.setVisibility(View.VISIBLE);
284 // Make the security sections header visible
285 LinearLayout securityList = (LinearLayout) permsView.findViewById(
286 R.id.security_settings_list);
287 securityList.addView(asp.getPermissionsView());
288 } else {
289 permsView.setVisibility(View.GONE);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700290 }
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700291 }
292
293 private void displayErrorDialog(int msgId, final boolean finish, final boolean changed) {
294 //display confirmation dialog
295 new AlertDialog.Builder(this)
296 .setTitle(getString(R.string.app_not_found_dlg_title))
The Android Open Source Project5962e182009-01-09 17:51:25 -0800297 .setIcon(android.R.drawable.ic_dialog_alert)
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700298 .setMessage(getString(msgId))
299 .setNeutralButton(getString(R.string.dlg_ok),
300 new DialogInterface.OnClickListener() {
301 public void onClick(DialogInterface dialog, int which) {
302 //force to recompute changed value
303 setIntentAndFinish(finish, changed);
304 }
305 }
306 )
307 .show();
308 }
309
310 private void setIntentAndFinish(boolean finish, boolean appChanged) {
311 if(localLOGV) Log.i(TAG, "appChanged="+appChanged);
312 Intent intent = new Intent();
313 intent.putExtra(ManageApplications.APP_CHG, appChanged);
314 setResult(ManageApplications.RESULT_OK, intent);
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800315 mAppButton.setEnabled(false);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700316 if(finish) {
317 finish();
318 }
319 }
320
321 /*
322 * Private method to handle get size info notification from observer when
323 * the async operation from PackageManager is complete. The current user data
324 * info has to be refreshed in the manage applications screen as well as the current screen.
325 */
326 private void refreshSizeInfo(Message msg) {
327 boolean changed = false;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700328 PackageStats newPs = msg.getData().getParcelable(ATTR_PACKAGE_STATS);
329 long newTot = newPs.cacheSize+newPs.codeSize+newPs.dataSize;
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800330 if(mSizeInfo == null) {
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700331 mSizeInfo = newPs;
The Android Open Source Project1feaa852009-02-10 15:44:05 -0800332 String str = getSizeStr(newTot);
333 mTotalSize.setText(str);
334 mAppSnippetSize.setText(str);
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800335 mAppSize.setText(getSizeStr(newPs.codeSize));
The Android Open Source Project47729682009-02-19 10:57:36 -0800336 mDataSize.setText(getSizeStr(newPs.dataSize));
337 mCacheSize.setText(getSizeStr(newPs.cacheSize));
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800338 } else {
339 long oldTot = mSizeInfo.cacheSize+mSizeInfo.codeSize+mSizeInfo.dataSize;
340 if(newTot != oldTot) {
The Android Open Source Project1feaa852009-02-10 15:44:05 -0800341 String str = getSizeStr(newTot);
342 mTotalSize.setText(str);
343 mAppSnippetSize.setText(str);
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800344 changed = true;
345 }
346 if(newPs.codeSize != mSizeInfo.codeSize) {
347 mAppSize.setText(getSizeStr(newPs.codeSize));
348 changed = true;
349 }
The Android Open Source Project47729682009-02-19 10:57:36 -0800350 if(newPs.dataSize != mSizeInfo.dataSize) {
351 mDataSize.setText(getSizeStr(newPs.dataSize));
352 changed = true;
353 }
354 if(newPs.cacheSize != mSizeInfo.cacheSize) {
355 mCacheSize.setText(getSizeStr(newPs.cacheSize));
356 changed = true;
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800357 }
358 if(changed) {
359 mSizeInfo = newPs;
360 }
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700361 }
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800362
The Android Open Source Project47729682009-02-19 10:57:36 -0800363 long data = mSizeInfo.dataSize;
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800364 // Disable button if data is 0
365 if(mAppButtonState != AppButtonStates.NONE){
366 mAppButton.setText(mAppButtonText);
367 if((mAppButtonState == AppButtonStates.CLEAR_DATA) && (data == 0)) {
368 mAppButton.setEnabled(false);
369 } else {
370 mAppButton.setEnabled(true);
371 mAppButton.setOnClickListener(this);
372 }
373 }
374 refreshCacheInfo(newPs.cacheSize);
375 }
376
377 private void refreshCacheInfo(long cacheSize) {
378 // Set cache info
379 mCacheSize.setText(getSizeStr(cacheSize));
380 if (cacheSize <= 0) {
381 mClearCacheButton.setEnabled(false);
382 } else {
383 mClearCacheButton.setOnClickListener(this);
384 }
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700385 }
386
387 /*
388 * Private method to handle clear message notification from observer when
389 * the async operation from PackageManager is complete
390 */
391 private void processClearMsg(Message msg) {
392 int result = msg.arg1;
393 String packageName = mAppInfo.packageName;
394 if(result == OP_SUCCESSFUL) {
395 Log.i(TAG, "Cleared user data for system package:"+packageName);
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800396 mPm.getPackageSizeInfo(packageName, mSizeObserver);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700397 } else {
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800398 mAppButton.setText(R.string.clear_user_data_text);
399 mAppButton.setEnabled(true);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700400 }
401 }
402
403 /*
404 * Private method to initiate clearing user data when the user clicks the clear data
405 * button for a system package
406 */
407 private void initiateClearUserDataForSysPkg() {
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800408 mAppButton.setEnabled(false);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700409 //invoke uninstall or clear user data based on sysPackage
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700410 String packageName = mAppInfo.packageName;
411 Log.i(TAG, "Clearing user data for system package");
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800412 if(mClearDataObserver == null) {
413 mClearDataObserver = new ClearUserDataObserver();
414 }
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700415 ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800416 boolean res = am.clearApplicationUserData(packageName, mClearDataObserver);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700417 if(!res) {
418 //doesnt initiate clear. some error. should not happen but just log error for now
419 Log.i(TAG, "Couldnt clear application user data for package:"+packageName);
420 displayErrorDialog(R.string.clear_data_failed, false, false);
421 } else {
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800422 mAppButton.setText(R.string.recompute_size);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700423 }
424 }
425
426 /*
427 * Method implementing functionality of buttons clicked
428 * @see android.view.View.OnClickListener#onClick(android.view.View)
429 */
430 public void onClick(View v) {
431 String packageName = mAppInfo.packageName;
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800432 if(v == mAppButton) {
433 if(mCanUninstall) {
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700434 //display confirmation dialog
435 new AlertDialog.Builder(this)
436 .setTitle(getString(R.string.clear_data_dlg_title))
The Android Open Source Project5962e182009-01-09 17:51:25 -0800437 .setIcon(android.R.drawable.ic_dialog_alert)
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700438 .setMessage(getString(R.string.clear_data_dlg_text))
439 .setPositiveButton(R.string.dlg_ok, this)
440 .setNegativeButton(R.string.dlg_cancel, this)
441 .show();
442 } else {
443 //create new intent to launch Uninstaller activity
444 Uri packageURI = Uri.parse("package:"+packageName);
445 Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
446 startActivity(uninstallIntent);
The Android Open Source Projecta578a6c2009-03-03 14:04:35 -0800447 setIntentAndFinish(true, false);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700448 }
449 } else if(v == mActivitiesButton) {
450 mPm.clearPackagePreferredActivities(packageName);
451 mActivitiesButton.setEnabled(false);
452 } else if(v == mManageSpaceButton) {
453 Intent intent = new Intent(Intent.ACTION_DEFAULT);
454 intent.setClassName(mAppInfo.packageName, mAppInfo.manageSpaceActivityName);
455 startActivityForResult(intent, -1);
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800456 } else if (v == mClearCacheButton) {
457 // Lazy initialization of observer
458 if (mClearCacheObserver == null) {
459 mClearCacheObserver = new ClearCacheObserver();
460 }
461 mPm.deleteApplicationCacheFiles(packageName, mClearCacheObserver);
The Android Open Source Project1feaa852009-02-10 15:44:05 -0800462 } else if (v == mForceStopButton) {
463 ActivityManager am = (ActivityManager)getSystemService(
464 Context.ACTIVITY_SERVICE);
465 am.restartPackage(packageName);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700466 }
467 }
468
469 public void onClick(DialogInterface dialog, int which) {
The Android Open Source Projectabc48f82008-12-17 18:06:01 -0800470 if(which == AlertDialog.BUTTON_POSITIVE) {
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700471 //invoke uninstall or clear user data based on sysPackage
472 initiateClearUserDataForSysPkg();
473 } else {
474 //cancel do nothing just retain existing screen
475 }
476 }
477}
478