• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 **
3 ** Copyright 2007, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 package com.android.packageinstaller;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.content.pm.ApplicationInfo;
22 import android.content.pm.IPackageDeleteObserver;
23 import android.os.Bundle;
24 import android.os.Handler;
25 import android.os.Message;
26 import android.util.Log;
27 import android.view.KeyEvent;
28 import android.view.View;
29 import android.view.Window;
30 import android.view.View.OnClickListener;
31 import android.widget.Button;
32 import android.widget.ProgressBar;
33 import android.widget.TextView;
34 
35 /**
36  * This activity corresponds to a download progress screen that is displayed
37  * when an application is uninstalled. The result of the application uninstall
38  * is indicated in the result code that gets set to 0 or 1. The application gets launched
39  * by an intent with the intent's class name explicitly set to UninstallAppProgress and expects
40  * the application object of the application to uninstall.
41  */
42 public class UninstallAppProgress extends Activity implements OnClickListener {
43     private final String TAG="UninstallAppProgress";
44     private boolean localLOGV = false;
45     private ApplicationInfo mAppInfo;
46     private TextView mStatusTextView;
47     private Button mOkButton;
48     private ProgressBar mProgressBar;
49     private View mOkPanel;
50     private volatile int mResultCode = -1;
51     private final int UNINSTALL_COMPLETE = 1;
52     public final static int SUCCEEDED=1;
53     public final static int FAILED=0;
54     private Handler mHandler = new Handler() {
55         public void handleMessage(Message msg) {
56             switch (msg.what) {
57                 case UNINSTALL_COMPLETE:
58                     mResultCode = msg.arg1;
59                     // Update the status text
60                     if (msg.arg1 == SUCCEEDED) {
61                         mStatusTextView.setText(R.string.uninstall_done);
62                     } else {
63                         mStatusTextView.setText(R.string.uninstall_failed);
64                     }
65                     mProgressBar.setVisibility(View.INVISIBLE);
66                     // Show the ok button
67                     mOkPanel.setVisibility(View.VISIBLE);
68                     break;
69                 default:
70                     break;
71             }
72         }
73     };
74 
75     @Override
onCreate(Bundle icicle)76     public void onCreate(Bundle icicle) {
77         super.onCreate(icicle);
78         Intent intent = getIntent();
79         mAppInfo = intent.getParcelableExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO);
80         initView();
81     }
82 
83     class PackageDeleteObserver extends IPackageDeleteObserver.Stub {
packageDeleted(boolean succeeded)84         public void packageDeleted(boolean succeeded) {
85             Message msg = mHandler.obtainMessage(UNINSTALL_COMPLETE);
86             msg.arg1 = succeeded?SUCCEEDED:FAILED;
87             mHandler.sendMessage(msg);
88         }
89     }
90 
setResultAndFinish(int retCode)91     void setResultAndFinish(int retCode) {
92         setResult(retCode);
93         finish();
94     }
95 
initView()96     public void initView() {
97         requestWindowFeature(Window.FEATURE_NO_TITLE);
98         setContentView(R.layout.uninstall_progress);
99         // Initialize views
100         PackageUtil.initSnippetForInstalledApp(this, mAppInfo, R.id.app_snippet);
101         mStatusTextView = (TextView)findViewById(R.id.center_text);
102         mStatusTextView.setText(R.string.uninstalling);
103         mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
104         mProgressBar.setIndeterminate(true);
105         // Hide button till progress is being displayed
106         mOkPanel = (View)findViewById(R.id.ok_panel);
107         mOkButton = (Button)findViewById(R.id.ok_button);
108         mOkButton.setOnClickListener(this);
109         mOkPanel.setVisibility(View.INVISIBLE);
110         PackageDeleteObserver observer = new PackageDeleteObserver();
111         getPackageManager().deletePackage(mAppInfo.packageName, observer, 0);
112     }
113 
onClick(View v)114     public void onClick(View v) {
115         if(v == mOkButton) {
116             Log.i(TAG, "Finished uninstalling pkg: " + mAppInfo.packageName);
117             setResultAndFinish(mResultCode);
118         }
119     }
120 
121     @Override
dispatchKeyEvent(KeyEvent ev)122     public boolean dispatchKeyEvent(KeyEvent ev) {
123         if (ev.getKeyCode() == KeyEvent.KEYCODE_BACK) {
124             if (mResultCode == -1) {
125                 // Ignore back key when installation is in progress
126                 return true;
127             } else {
128                 // If installation is done, just set the result code
129                 setResult(mResultCode);
130             }
131         }
132         return super.dispatchKeyEvent(ev);
133     }
134 }
135