Skip to content
This repository was archived by the owner on Aug 19, 2021. It is now read-only.

Commit 95bb2c4

Browse files
author
Michael Farb
committed
Closing out known crashes
- Better message tab refresh avoiding UI flicker. - Fixed #100 NetworkOnMainThreadException in ExchangeActivity - Fixed #86 IllegalStateException in RecipientDbAdapter - Fixed #96 WindowManager$BadTokenException in ExchangeActivity
1 parent c8ba846 commit 95bb2c4

13 files changed

Lines changed: 190 additions & 65 deletions

File tree

safeslinger-demo/src/edu/cmu/cylab/starslinger/demo/MainActivity.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import android.view.MenuItem;
4949
import android.view.View;
5050
import android.view.ViewGroup;
51+
import android.view.WindowManager.BadTokenException;
5152
import android.widget.Button;
5253
import android.widget.CompoundButton;
5354
import android.widget.EditText;
@@ -305,8 +306,12 @@ protected void showMessage(String title, String msg) {
305306
args.putString(EXTRA_TITLE, title);
306307
args.putString(EXTRA_MSG, msg);
307308
if (!isFinishing()) {
308-
removeDialog(MENU_MSG);
309-
showDialog(MENU_MSG, args);
309+
try {
310+
removeDialog(MENU_MSG);
311+
showDialog(MENU_MSG, args);
312+
} catch (BadTokenException e) {
313+
e.printStackTrace();
314+
}
310315
}
311316
}
312317

safeslinger-exchange/src/edu/cmu/cylab/starslinger/exchange/BaseActivity.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import android.os.Bundle;
3535
import android.text.TextUtils;
3636
import android.util.Log;
37+
import android.view.WindowManager.BadTokenException;
3738
import android.widget.Toast;
3839
import edu.cmu.cylab.starslinger.exchange.ExchangeConfig.extra;
3940

@@ -51,8 +52,12 @@ protected void showHelp(String title, String msg) {
5152
args.putString(extra.RESID_TITLE, title);
5253
args.putString(extra.RESID_MSG, msg);
5354
if (!isFinishing()) {
54-
removeDialog(DIALOG_HELP);
55-
showDialog(DIALOG_HELP, args);
55+
try {
56+
removeDialog(DIALOG_HELP);
57+
showDialog(DIALOG_HELP, args);
58+
} catch (BadTokenException e) {
59+
e.printStackTrace();
60+
}
5661
}
5762
}
5863

safeslinger-exchange/src/edu/cmu/cylab/starslinger/exchange/ExchangeActivity.java

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import android.os.Handler;
5353
import android.text.TextUtils;
5454
import android.util.Log;
55+
import android.view.WindowManager.BadTokenException;
5556
import edu.cmu.cylab.starslinger.exchange.ExchangeConfig.extra;
5657

5758
/***
@@ -542,8 +543,12 @@ private void showError(String msg) {
542543
Bundle args = new Bundle();
543544
args.putString(extra.RESID_MSG, msg);
544545
if (!isFinishing()) {
545-
removeDialog(DIALOG_ERROR);
546-
showDialog(DIALOG_ERROR, args);
546+
try {
547+
removeDialog(DIALOG_ERROR);
548+
showDialog(DIALOG_ERROR, args);
549+
} catch (BadTokenException e) {
550+
e.printStackTrace();
551+
}
547552
}
548553
}
549554

@@ -575,8 +580,12 @@ private void showLowestUserIdPrompt(int usrid) {
575580

576581
private void showGroupSizePicker() {
577582
if (!isFinishing()) {
578-
removeDialog(DIALOG_GRP_SIZE);
579-
showDialog(DIALOG_GRP_SIZE);
583+
try {
584+
removeDialog(DIALOG_GRP_SIZE);
585+
showDialog(DIALOG_GRP_SIZE);
586+
} catch (BadTokenException e) {
587+
e.printStackTrace();
588+
}
580589
}
581590
}
582591

@@ -673,8 +682,12 @@ private void showQuestion(String msg, final int requestCode) {
673682
args.putInt(extra.REQUEST_CODE, requestCode);
674683
args.putString(extra.RESID_MSG, msg);
675684
if (!isFinishing()) {
676-
removeDialog(DIALOG_QUESTION);
677-
showDialog(DIALOG_QUESTION, args);
685+
try {
686+
removeDialog(DIALOG_QUESTION);
687+
showDialog(DIALOG_QUESTION, args);
688+
} catch (BadTokenException e) {
689+
e.printStackTrace();
690+
}
678691
}
679692
}
680693

@@ -709,8 +722,16 @@ private void showProgress(String msg) {
709722
Bundle args = new Bundle();
710723
args.putString(extra.RESID_MSG, msg);
711724
if (!isFinishing()) {
712-
removeDialog(DIALOG_PROGRESS);
713-
showDialog(DIALOG_PROGRESS, args);
725+
try {
726+
try {
727+
removeDialog(DIALOG_PROGRESS);
728+
showDialog(DIALOG_PROGRESS, args);
729+
} catch (BadTokenException e) {
730+
e.printStackTrace();
731+
}
732+
} catch (BadTokenException e) {
733+
e.printStackTrace();
734+
}
714735
}
715736
}
716737

@@ -784,6 +805,5 @@ protected void onDestroy() {
784805
if (mHandler != null) {
785806
mHandler.removeCallbacks(mUpdateReceivedProg);
786807
}
787-
mProt.endProtocol();
788808
}
789809
}

safeslinger-messenger/res/layout/messagelist.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
android:layout_height="fill_parent"
3535
android:gravity="center"
3636
android:orientation="vertical"
37-
android:visibility="gone" >
37+
android:visibility="visible" >
3838

3939
<ProgressBar
4040
android:id="@+id/pbHeaderProgress"

safeslinger-messenger/src/edu/cmu/cylab/starslinger/view/BaseActivity.java

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import android.view.ContextThemeWrapper;
7777
import android.view.LayoutInflater;
7878
import android.view.View;
79+
import android.view.WindowManager.BadTokenException;
7980
import android.webkit.MimeTypeMap;
8081
import android.widget.CheckBox;
8182
import android.widget.SimpleAdapter;
@@ -625,8 +626,12 @@ protected void showHelp(String title, String msg) {
625626
args.putString(extra.RESID_TITLE, title);
626627
args.putString(extra.RESID_MSG, msg);
627628
if (!isFinishing()) {
628-
removeDialog(DIALOG_HELP);
629-
showDialog(DIALOG_HELP, args);
629+
try {
630+
removeDialog(DIALOG_HELP);
631+
showDialog(DIALOG_HELP, args);
632+
} catch (BadTokenException e) {
633+
e.printStackTrace();
634+
}
630635
}
631636
}
632637

@@ -700,8 +705,12 @@ private boolean doCleanupOldKeyData(String[] keyNames) {
700705

701706
protected void showAbout() {
702707
if (!isFinishing()) {
703-
removeDialog(DIALOG_ABOUT);
704-
showDialog(DIALOG_ABOUT);
708+
try {
709+
removeDialog(DIALOG_ABOUT);
710+
showDialog(DIALOG_ABOUT);
711+
} catch (BadTokenException e) {
712+
e.printStackTrace();
713+
}
705714
}
706715
}
707716

@@ -1281,8 +1290,12 @@ protected void onPause() {
12811290

12821291
protected void showBackupQuery() {
12831292
if (!isFinishing()) {
1284-
removeDialog(DIALOG_BACKUPQUERY);
1285-
showDialog(DIALOG_BACKUPQUERY);
1293+
try {
1294+
removeDialog(DIALOG_BACKUPQUERY);
1295+
showDialog(DIALOG_BACKUPQUERY);
1296+
} catch (BadTokenException e) {
1297+
e.printStackTrace();
1298+
}
12861299
}
12871300
}
12881301

@@ -1350,8 +1363,12 @@ public void onCancel(DialogInterface dialog) {
13501363

13511364
protected void showReference() {
13521365
if (!isFinishing()) {
1353-
removeDialog(DIALOG_REFERENCE);
1354-
showDialog(DIALOG_REFERENCE);
1366+
try {
1367+
removeDialog(DIALOG_REFERENCE);
1368+
showDialog(DIALOG_REFERENCE);
1369+
} catch (BadTokenException e) {
1370+
e.printStackTrace();
1371+
}
13551372
}
13561373
}
13571374

@@ -1408,8 +1425,12 @@ public void onCancel(DialogInterface dialog) {
14081425

14091426
protected void showAddContactInvite() {
14101427
if (!isFinishing()) {
1411-
removeDialog(DIALOG_CONTACTINVITE);
1412-
showDialog(DIALOG_CONTACTINVITE);
1428+
try {
1429+
removeDialog(DIALOG_CONTACTINVITE);
1430+
showDialog(DIALOG_CONTACTINVITE);
1431+
} catch (BadTokenException e) {
1432+
e.printStackTrace();
1433+
}
14131434
}
14141435
}
14151436

@@ -1572,8 +1593,12 @@ private void showCustomContactPicker(int resultCode) {
15721593
Bundle args = new Bundle();
15731594
args.putInt(extra.RESULT_CODE, resultCode);
15741595
if (!isFinishing()) {
1575-
removeDialog(DIALOG_CONTACTTYPE);
1576-
showDialog(DIALOG_CONTACTTYPE, args);
1596+
try {
1597+
removeDialog(DIALOG_CONTACTTYPE);
1598+
showDialog(DIALOG_CONTACTTYPE, args);
1599+
} catch (BadTokenException e) {
1600+
e.printStackTrace();
1601+
}
15771602
}
15781603
}
15791604

safeslinger-messenger/src/edu/cmu/cylab/starslinger/view/FilePickerActivity.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import android.view.View;
4242
import android.view.ViewGroup;
4343
import android.view.WindowManager;
44+
import android.view.WindowManager.BadTokenException;
4445
import android.widget.ArrayAdapter;
4546
import android.widget.ListAdapter;
4647
import android.widget.TextView;
@@ -158,8 +159,12 @@ public View getView(int position, View convertView, ViewGroup parent) {
158159
private void showFilePicker() {
159160
MyLog.d(TAG, mPath.getAbsolutePath());
160161
if (!isFinishing()) {
161-
removeDialog(DIALOG_LOAD_FILE);
162-
showDialog(DIALOG_LOAD_FILE);
162+
try {
163+
removeDialog(DIALOG_LOAD_FILE);
164+
showDialog(DIALOG_LOAD_FILE);
165+
} catch (BadTokenException e) {
166+
e.printStackTrace();
167+
}
163168
}
164169
}
165170

safeslinger-messenger/src/edu/cmu/cylab/starslinger/view/FileSaveActivity.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import android.view.View;
4444
import android.view.ViewGroup;
4545
import android.view.WindowManager;
46+
import android.view.WindowManager.BadTokenException;
4647
import android.widget.ArrayAdapter;
4748
import android.widget.EditText;
4849
import android.widget.ListAdapter;
@@ -155,8 +156,12 @@ public View getView(int position, View convertView, ViewGroup parent) {
155156
private void showFileLoader() {
156157
MyLog.d(TAG, mPath.getAbsolutePath());
157158
if (!isFinishing()) {
158-
removeDialog(DIALOG_LOAD_FILE);
159-
showDialog(DIALOG_LOAD_FILE);
159+
try {
160+
removeDialog(DIALOG_LOAD_FILE);
161+
showDialog(DIALOG_LOAD_FILE);
162+
} catch (BadTokenException e) {
163+
e.printStackTrace();
164+
}
160165
}
161166
}
162167

@@ -240,8 +245,12 @@ protected void showFileSaveAs() {
240245
Intent intent = getIntent();
241246
Bundle args = intent.getExtras();
242247
if (!isFinishing()) {
243-
removeDialog(DIALOG_TEXT_ENTRY);
244-
showDialog(DIALOG_TEXT_ENTRY, args);
248+
try {
249+
removeDialog(DIALOG_TEXT_ENTRY);
250+
showDialog(DIALOG_TEXT_ENTRY, args);
251+
} catch (BadTokenException e) {
252+
e.printStackTrace();
253+
}
245254
}
246255
}
247256

0 commit comments

Comments
 (0)