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

Commit e5961d5

Browse files
author
Michael Farb
committed
improved incoming introduction ux
- Cold launch should convert queued to draft, and delete specials, do the work that did not get done on the async task - Fixed #35 auto-download critical introduction attachments (stored for better reuse) - Corrected feedback method when storage is unmounted
1 parent 7c5b1d5 commit e5961d5

8 files changed

Lines changed: 180 additions & 36 deletions

File tree

safeslinger-messenger/src/edu/cmu/cylab/starslinger/SafeSlinger.java

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ public void onCreate() {
138138
PRNGFixes.apply();
139139
}
140140

141+
// failed message cleanup
142+
CleanupFailedMessagesTask cleanFailedMsgs = new CleanupFailedMessagesTask();
143+
cleanFailedMsgs.execute(new String());
144+
141145
// alert for pending messages
142146
checkForPendingMessages();
143147

@@ -316,10 +320,13 @@ public void showDebugEmail(Activity act, String debugData) {
316320

317321
output.append(debugData);
318322

319-
String filePath = SSUtil.makeDebugLoggingDir(this) + File.separator
320-
+ SafeSlingerConfig.FEEDBACK_TXT;
321-
322-
sendEmail(output.toString(), filePath);
323+
if (SSUtil.isExternalStorageWritable()) {
324+
String filePath = SSUtil.makeDebugLoggingDir(this) + File.separator
325+
+ SafeSlingerConfig.FEEDBACK_TXT;
326+
sendEmail(output.toString(), filePath);
327+
} else {
328+
sendEmail(output.toString(), null);
329+
}
323330
}
324331

325332
public void showFeedbackEmail(Activity act) {
@@ -334,10 +341,13 @@ public void showFeedbackEmail(Activity act) {
334341
}
335342
SafeSlinger.listThreads(rootGroup, "", output);
336343

337-
String filePath = SSUtil.makeDebugLoggingDir(this) + File.separator
338-
+ SafeSlingerConfig.FEEDBACK_TXT;
339-
340-
sendEmail(output.toString(), filePath);
344+
if (SSUtil.isExternalStorageWritable()) {
345+
String filePath = SSUtil.makeDebugLoggingDir(this) + File.separator
346+
+ SafeSlingerConfig.FEEDBACK_TXT;
347+
sendEmail(output.toString(), filePath);
348+
} else {
349+
sendEmail(output.toString(), null);
350+
}
341351
}
342352

343353
public void sendEmail(String feedback, String filePath) {
@@ -352,12 +362,16 @@ public void sendEmail(String feedback, String filePath) {
352362
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
353363

354364
try {
355-
BufferedWriter bos = new BufferedWriter(new FileWriter(filePath));
356-
bos.write(feedback);
357-
bos.flush();
358-
bos.close();
359-
Uri uri = Uri.fromFile(new File(filePath));
360-
intent.putExtra(Intent.EXTRA_STREAM, uri);
365+
if (!TextUtils.isEmpty(filePath)) {
366+
BufferedWriter bos = new BufferedWriter(new FileWriter(filePath));
367+
bos.write(feedback);
368+
bos.flush();
369+
bos.close();
370+
Uri uri = Uri.fromFile(new File(filePath));
371+
intent.putExtra(Intent.EXTRA_STREAM, uri);
372+
} else {
373+
intent.putExtra(Intent.EXTRA_TEXT, feedback);
374+
}
361375
} catch (IOException e) {
362376
e.printStackTrace();
363377
}
@@ -668,6 +682,38 @@ protected String doInBackground(String... arg0) {
668682
}
669683
}
670684

685+
private class CleanupFailedMessagesTask extends AsyncTask<String, String, String> {
686+
687+
@Override
688+
protected String doInBackground(String... arg0) {
689+
MessageDbAdapter dbMessage = MessageDbAdapter.openInstance(getApplicationContext());
690+
Cursor c = dbMessage.fetchAllMessagesQueued();
691+
if (c != null) {
692+
while (c.moveToNext()) {
693+
try {
694+
MessageData sendMsg = new MessageRow(c, true);
695+
696+
// we can remove failed introductions, it is better if
697+
// the user starts over
698+
String[] types = sendMsg.getFileType().split("/");
699+
if (types.length == 2) {
700+
if (types[1]
701+
.compareToIgnoreCase(SafeSlingerConfig.MIMETYPE_FUNC_SECINTRO) == 0) {
702+
703+
// queued draft should be removed
704+
dbMessage.deleteMessage(sendMsg.getRowId());
705+
}
706+
}
707+
} catch (OutOfMemoryError e) {
708+
e.printStackTrace();
709+
}
710+
}
711+
c.close();
712+
}
713+
return null;
714+
}
715+
}
716+
671717
public void updateLanguage(String language) {
672718
Configuration config = getBaseContext().getResources().getConfiguration();
673719

safeslinger-messenger/src/edu/cmu/cylab/starslinger/model/InboxDatabaseHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class InboxDatabaseHelper extends SQLiteOpenHelper {
5959
+ MessageDbAdapter.KEY_FILETYPE + " text, " //
6060
+ MessageDbAdapter.KEY_FILEDIR + " text, " //
6161
+ MessageDbAdapter.KEY_TEXT + " text, " //
62-
+ MessageDbAdapter.KEY_ENCFILE + " blob, " //
62+
+ MessageDbAdapter.KEY_RAWFILE + " blob, " //
6363
+ MessageDbAdapter.KEY_KEYID + " text, " //
6464
+ MessageDbAdapter.KEY_MSGHASH + " text, " //
6565
+ MessageDbAdapter.KEY_RETNOTIFY + " integer, " //

safeslinger-messenger/src/edu/cmu/cylab/starslinger/model/MessageDatabaseHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class MessageDatabaseHelper extends SQLiteOpenHelper {
6363
+ MessageDbAdapter.KEY_FILETYPE + " text, " //
6464
+ MessageDbAdapter.KEY_FILEDIR + " text, " //
6565
+ MessageDbAdapter.KEY_TEXT + " text, " //
66-
+ MessageDbAdapter.KEY_ENCFILE + " blob, " //
66+
+ MessageDbAdapter.KEY_RAWFILE + " blob, " //
6767
+ MessageDbAdapter.KEY_KEYID + " text, " //
6868
+ MessageDbAdapter.KEY_MSGHASH + " text, " //
6969
+ MessageDbAdapter.KEY_RETNOTIFY + " integer, " //

safeslinger-messenger/src/edu/cmu/cylab/starslinger/model/MessageDbAdapter.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ public class MessageDbAdapter {
6565
public static final String KEY_FILETYPE = "filetype"; // file mime type
6666
public static final String KEY_FILEDIR = "filedir"; // location file saved
6767
public static final String KEY_TEXT = "text"; // text message
68+
public static final String KEY_RAWFILE = "file"; // special files (was enc)
6869
public static final String KEY_MSGHASH = "fileid_str"; // file retrieval id
6970
public static final String KEY_RETNOTIFY = "ret_notify"; // return notify
7071
public static final String KEY_RETPUSHTOKEN = "ret_pushtoken"; // ret. token
7172
public static final String KEY_RETRECEIPT = "ret_receipt"; // ret. receipt
7273

73-
@Deprecated
74-
public static final String KEY_ENCFILE = "file";
7574
@Deprecated
7675
public static final String KEY_KEYIDLONG = "keyid";
7776
@Deprecated
@@ -355,6 +354,15 @@ public boolean updateFileDecrypted(long rowId) {
355354
}
356355
}
357356

357+
public boolean updateRawSafeSlingerFile(long rowId, byte[] rawFile) {
358+
synchronized (SafeSlinger.sDataLock) {
359+
ContentValues values = new ContentValues();
360+
values.put(KEY_RAWFILE, rawFile);
361+
362+
return update(DATABASE_TABLE, values, KEY_ROWID + "=" + rowId, null) > 0;
363+
}
364+
}
365+
358366
public boolean updateMessageFileLocation(long rowId, String filename, String filedir) {
359367
synchronized (SafeSlinger.sDataLock) {
360368
ContentValues values = new ContentValues();
@@ -424,6 +432,24 @@ public Cursor fetchAllMessagesUpgradeTo6() {
424432
}
425433
}
426434

435+
public Cursor fetchAllMessagesQueued() {
436+
synchronized (SafeSlinger.sDataLock) {
437+
String where = KEY_STATUS + "=" + MESSAGE_STATUS_QUEUED;
438+
Cursor c = query(true, DATABASE_TABLE, new String[] {
439+
KEY_ROWID, KEY_DATE_RECV, KEY_DATE_SENT, KEY_ENCBODY, KEY_FILEDIR,
440+
KEY_MSGHASH_BLOB, KEY_FILELEN, KEY_FILENAME, KEY_FILETYPE, KEY_KEYIDLONG,
441+
KEY_PERSON, KEY_READ, KEY_SEEN, KEY_STATUS, KEY_TEXT, KEY_TYPE, KEY_KEYID,
442+
KEY_MSGHASH, KEY_RETNOTIFY, KEY_RETPUSHTOKEN, KEY_RETRECEIPT
443+
}, where, null, null, null, null, null);
444+
if (c != null) {
445+
if (c.moveToFirst()) {
446+
return c;
447+
}
448+
}
449+
return null;
450+
}
451+
}
452+
427453
public Cursor fetchMessageSmall(long rowId) throws SQLException {
428454
synchronized (SafeSlinger.sDataLock) {
429455
String where = KEY_ROWID + "=" + rowId;
@@ -594,6 +620,23 @@ public int getAllMessageCount() throws SQLException {
594620
}
595621
}
596622

623+
public byte[] getRawFile(long rowId) {
624+
synchronized (SafeSlinger.sDataLock) {
625+
byte[] rawFile = null;
626+
String where = KEY_ROWID + "=" + rowId;
627+
Cursor c = query(true, DATABASE_TABLE, new String[] {
628+
KEY_ROWID, KEY_RAWFILE
629+
}, where, null, null, null, null, null);
630+
if (c != null) {
631+
if (c.moveToFirst()) {
632+
rawFile = c.getBlob(c.getColumnIndexOrThrow(KEY_RAWFILE));
633+
}
634+
c.close();
635+
}
636+
return rawFile;
637+
}
638+
}
639+
597640
public int getActionRequiredMessageCountByThread(String keyId) throws SQLException {
598641
synchronized (SafeSlinger.sDataLock) {
599642
StringBuilder where = new StringBuilder();
@@ -722,4 +765,5 @@ public static String getStatusCode(int stat) {
722765
}
723766
return status;
724767
}
768+
725769
}

safeslinger-messenger/src/edu/cmu/cylab/starslinger/model/MessageRow.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,18 @@ public boolean isFileDownloadable() {
111111
}
112112

113113
public boolean isFileOpenable() {
114+
if (!TextUtils.isEmpty(mFileType)) {
114115

115-
if (!TextUtils.isEmpty(mFileType)
116-
&& !mFileType.startsWith(SafeSlingerConfig.MIMETYPE_CLASS + "/")) {
116+
// incoming safeslinger files may be in database encoded
117+
if (mFileType.startsWith(SafeSlingerConfig.MIMETYPE_CLASS + "/")) {
118+
if (mInbox && mStatus == MessageDbAdapter.MESSAGE_STATUS_FILE_DECRYPTED) {
119+
return true;
120+
} else {
121+
return false;
122+
}
123+
}
117124

125+
// real files on storage media
118126
if (!TextUtils.isEmpty(mFileDir)) {
119127
File f = new File(mFileDir);
120128
return f.exists() && f.length() > 0;

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

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,8 +1051,8 @@ private void doSendMessageStart(MessageTransport... mts) {
10511051
sendIntent.putExtra(extra.RECIPIENT_ROW_ID, mts[0].getRecipient().getRowId());
10521052
} else {
10531053
// multiple should show all threads
1054-
sendIntent.putExtra(extra.MESSAGE_ROW_ID, -1);
1055-
sendIntent.putExtra(extra.RECIPIENT_ROW_ID, -1);
1054+
sendIntent.putExtra(extra.MESSAGE_ROW_ID, -1L);
1055+
sendIntent.putExtra(extra.RECIPIENT_ROW_ID, -1L);
10561056
}
10571057
getApplicationContext().sendBroadcast(sendIntent);
10581058

@@ -1269,7 +1269,7 @@ public void onComposeResultListener(Bundle data) {
12691269
String text = null;
12701270
if (data != null) {
12711271
text = data.getString(extra.TEXT_MESSAGE);
1272-
long rowIdRecipient = data.getLong(extra.RECIPIENT_ROW_ID, -1);
1272+
long rowIdRecipient = data.getLong(extra.RECIPIENT_ROW_ID, -1L);
12731273
if (rowIdRecipient > -1) {
12741274
RecipientDbAdapter dbRecipient = RecipientDbAdapter
12751275
.openInstance(getApplicationContext());
@@ -1383,9 +1383,9 @@ public void onMessageResultListener(Bundle data) {
13831383
long rowIdInbox = -1;
13841384
if (data != null) {
13851385
text = data.getString(extra.TEXT_MESSAGE);
1386-
rowIdMessage = data.getLong(extra.MESSAGE_ROW_ID, -1);
1387-
rowIdInbox = data.getLong(extra.INBOX_ROW_ID, -1);
1388-
long rowIdRecipient = data.getLong(extra.RECIPIENT_ROW_ID, -1);
1386+
rowIdMessage = data.getLong(extra.MESSAGE_ROW_ID, -1L);
1387+
rowIdInbox = data.getLong(extra.INBOX_ROW_ID, -1L);
1388+
long rowIdRecipient = data.getLong(extra.RECIPIENT_ROW_ID, -1L);
13891389
if (rowIdRecipient > -1) {
13901390
RecipientDbAdapter dbRecipient = RecipientDbAdapter
13911391
.openInstance(getApplicationContext());
@@ -1552,6 +1552,32 @@ public void onMessageResultListener(Bundle data) {
15521552
refreshView();
15531553
}
15541554
break;
1555+
case MessagesFragment.RESULT_PROCESS_SSMIME:
1556+
MessageData ssFile = new MessageData();
1557+
ssFile.setRowId(rowIdMessage);
1558+
ssFile.setMsgHash(data.getString(extra.PUSH_MSG_HASH));
1559+
ssFile.setFileName(data.getString(extra.PUSH_FILE_NAME));
1560+
ssFile.setFileType(data.getString(extra.PUSH_FILE_TYPE));
1561+
ssFile.setFileSize(data.getInt(extra.PUSH_FILE_SIZE, 0));
1562+
1563+
byte[] rawFile = dbMessage.getRawFile(rowIdMessage);
1564+
if (rawFile != null) {
1565+
// new ss-mime way: do separate file load
1566+
ssFile.setFileData(rawFile);
1567+
doProcessSafeSlingerMimeType(ssFile);
1568+
} else {
1569+
// old ss-mime way: complete re-download
1570+
ssFile.setFileData(null);
1571+
1572+
if (ssFile.getMsgHash() != null && ssFile.getFileName() != null) {
1573+
GetFileTask getFileTask = new GetFileTask();
1574+
getFileTask.execute(ssFile);
1575+
} else {
1576+
showNote(R.string.error_InvalidIncomingMessage);
1577+
refreshView();
1578+
}
1579+
}
1580+
break;
15551581
}
15561582
}
15571583

@@ -1888,7 +1914,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
18881914
case PickRecipientsActivity.RESULT_RECIPSEL:
18891915
RecipientDbAdapter dbRecipient = RecipientDbAdapter
18901916
.openInstance(getApplicationContext());
1891-
long rowIdRecipient = data.getLongExtra(extra.RECIPIENT_ROW_ID, -1);
1917+
long rowIdRecipient = data.getLongExtra(extra.RECIPIENT_ROW_ID, -1L);
18921918
Cursor c = dbRecipient.fetchRecipient(rowIdRecipient);
18931919
if (c != null) {
18941920
d.setRecip(new RecipientRow(c));
@@ -1994,7 +2020,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
19942020
// TODO: find better update for <= 2.3
19952021
// startActivity(getIntent());
19962022
// finish();
1997-
refreshView();
19982023
}
19992024

20002025
switch (resultCode) {
@@ -2407,6 +2432,7 @@ private void doProcessSafeSlingerMimeType(MessageData recvMsg) {
24072432
String[] types = recvMsg.getFileType().split("/");
24082433
if (types.length == 2) {
24092434
if (types[1].compareToIgnoreCase(SafeSlingerConfig.MIMETYPE_FUNC_SECINTRO) == 0) {
2435+
MessageDbAdapter dbMessage = MessageDbAdapter.openInstance(getApplicationContext());
24102436

24112437
byte[] vcard = recvMsg.getFileData();
24122438

@@ -2455,7 +2481,6 @@ private void doProcessSafeSlingerMimeType(MessageData recvMsg) {
24552481
RecipientRow exchRecip = null;
24562482
MessageRow inviteMsg = null;
24572483

2458-
MessageDbAdapter dbMessage = MessageDbAdapter.openInstance(getApplicationContext());
24592484
Cursor c = dbMessage.fetchMessageSmall(recvMsg.getRowId());
24602485
if (c != null) {
24612486
inviteMsg = new MessageRow(c, false);
@@ -2550,8 +2575,11 @@ protected void onPostExecute(String result) {
25502575
showNote(String
25512576
.format(getString(R.string.state_SomeContactsImported), imported));
25522577
}
2553-
// doSelectRecipientPostExchange(args, recipSource);
2554-
sendAutomaticMessage(args, recipSource);
2578+
2579+
// auto verify message only for direct slings, not introductions
2580+
if (recipSource == RecipientDbAdapter.RECIP_SOURCE_EXCHANGE) {
2581+
sendAutomaticMessage(args, recipSource);
2582+
}
25552583
} else {
25562584
showNote(result);
25572585
}
@@ -2888,6 +2916,13 @@ protected String doInBackground(MessageData... mds) {
28882916
return getString(R.string.error_UnableToUpdateMessageInDB);
28892917
}
28902918

2919+
// special attachments can be saved in db since they
2920+
// are occasional and small, not like large attachments
2921+
if (mRecvMsg.getFileType().startsWith(SafeSlingerConfig.MIMETYPE_CLASS + "/")) {
2922+
if (!dbMessage.updateRawSafeSlingerFile(mRowId, rawFile)) {
2923+
return getString(R.string.error_UnableToUpdateMessageInDB);
2924+
}
2925+
}
28912926
}
28922927

28932928
} catch (OutOfMemoryError e) {

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public class MessagesFragment extends Fragment {
9696
public static final int RESULT_FWDMESSAGE = 7127;
9797
public static final int RESULT_SEND = 7128;
9898
public static final int RESULT_SAVE = 7129;
99+
public static final int RESULT_PROCESS_SSMIME = 7130;
99100

100101
private List<ThreadData> mThreadList = new ArrayList<ThreadData>();
101102
private List<MessageRow> mMessageList = new ArrayList<MessageRow>();
@@ -145,8 +146,8 @@ public void updateValues(Bundle extras) {
145146
long recipRowId = 1;
146147

147148
if (extras != null) {
148-
msgRowId = extras.getLong(extra.MESSAGE_ROW_ID, -1);
149-
recipRowId = extras.getLong(extra.RECIPIENT_ROW_ID, -1);
149+
msgRowId = extras.getLong(extra.MESSAGE_ROW_ID, -1L);
150+
recipRowId = extras.getLong(extra.RECIPIENT_ROW_ID, -1L);
150151

151152
// set position to top when incoming message in
152153
// background...
@@ -831,7 +832,16 @@ private void doDecryptMessage(String pass, MessageRow inRow) {
831832
}
832833

833834
public void doOpenFile(MessageRow msg) {
834-
if (SSUtil.isExternalStorageReadable()) {
835+
836+
if (msg.getFileType().startsWith(SafeSlingerConfig.MIMETYPE_CLASS + "/")) {
837+
Intent intent = new Intent();
838+
intent.putExtra(extra.PUSH_MSG_HASH, msg.getMsgHash());
839+
intent.putExtra(extra.PUSH_FILE_NAME, msg.getFileName());
840+
intent.putExtra(extra.PUSH_FILE_TYPE, msg.getFileType());
841+
intent.putExtra(extra.PUSH_FILE_SIZE, msg.getFileSize());
842+
intent.putExtra(extra.MESSAGE_ROW_ID, msg.getRowId());
843+
sendResultToHost(RESULT_PROCESS_SSMIME, intent.getExtras());
844+
} else if (SSUtil.isExternalStorageReadable()) {
835845
File f;
836846
if (!TextUtils.isEmpty(msg.getFileDir())) {
837847
f = new File(msg.getFileDir());

0 commit comments

Comments
 (0)