Skip to content

Commit c7f8b6f

Browse files
committed
Managed dialogs should run on the same thread as their activity.
Bug: 3418998 Change-Id: I9b1cf73f9d6f8a5594f405546fcaa3cfd6f03c45
1 parent 8444023 commit c7f8b6f

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

packages/SystemUI/src/com/android/systemui/usb/UsbStorageActivity.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class UsbStorageActivity extends Activity
7171
private static final int DLG_CONFIRM_KILL_STORAGE_USERS = 1;
7272
private static final int DLG_ERROR_SHARING = 2;
7373
static final boolean localLOGV = false;
74+
private boolean mDestroyed;
7475

7576
// UI thread
7677
private Handler mUIHandler;
@@ -136,6 +137,12 @@ protected void onCreate(Bundle savedInstanceState) {
136137
mProgressBar = (ProgressBar) findViewById(com.android.internal.R.id.progress);
137138
}
138139

140+
@Override
141+
protected void onDestroy() {
142+
super.onDestroy();
143+
mDestroyed = true;
144+
}
145+
139146
private void switchDisplay(final boolean usbStorageInUse) {
140147
mUIHandler.post(new Runnable() {
141148
@Override
@@ -232,9 +239,16 @@ public void onClick(DialogInterface dialog, int which) {
232239
return null;
233240
}
234241

235-
private void showDialogInner(int id) {
236-
removeDialog(id);
237-
showDialog(id);
242+
private void scheduleShowDialog(final int id) {
243+
mUIHandler.post(new Runnable() {
244+
@Override
245+
public void run() {
246+
if (!mDestroyed) {
247+
removeDialog(id);
248+
showDialog(id);
249+
}
250+
}
251+
});
238252
}
239253

240254
private void switchUsbMassStorage(final boolean on) {
@@ -276,7 +290,7 @@ private void checkStorageUsersAsync() {
276290
IMountService ims = getMountService();
277291
if (ims == null) {
278292
// Display error dialog
279-
showDialogInner(DLG_ERROR_SHARING);
293+
scheduleShowDialog(DLG_ERROR_SHARING);
280294
}
281295
String extStoragePath = Environment.getExternalStorageDirectory().toString();
282296
boolean showDialog = false;
@@ -294,11 +308,11 @@ private void checkStorageUsersAsync() {
294308
}
295309
} catch (RemoteException e) {
296310
// Display error dialog
297-
showDialogInner(DLG_ERROR_SHARING);
311+
scheduleShowDialog(DLG_ERROR_SHARING);
298312
}
299313
if (showDialog) {
300314
// Display dialog to user
301-
showDialogInner(DLG_CONFIRM_KILL_STORAGE_USERS);
315+
scheduleShowDialog(DLG_CONFIRM_KILL_STORAGE_USERS);
302316
} else {
303317
if (localLOGV) Log.i(TAG, "Enabling UMS");
304318
switchUsbMassStorage(true);

0 commit comments

Comments
 (0)