1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.messaging.ui.conversation;
import android.app.AlertDialog;
import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import android.text.TextUtils;
import android.text.format.Formatter;
import com.android.messaging.Factory;
import com.android.messaging.R;
import com.android.messaging.datamodel.BugleDatabaseOperations;
import com.android.messaging.datamodel.DataModel;
import com.android.messaging.datamodel.data.ConversationMessageData;
import com.android.messaging.datamodel.data.ConversationParticipantsData;
import com.android.messaging.datamodel.data.ParticipantData;
import com.android.messaging.mmslib.pdu.PduHeaders;
import com.android.messaging.sms.DatabaseMessages.MmsMessage;
import com.android.messaging.sms.MmsUtils;
import com.android.messaging.util.Assert;
import com.android.messaging.util.Assert.DoesNotRunOnMainThread;
import com.android.messaging.util.Dates;
import com.android.messaging.util.DebugUtils;
import com.android.messaging.util.OsUtil;
import com.android.messaging.util.PhoneUtils;
import com.android.messaging.util.SafeAsyncTask;
import java.util.List;
public class MessageDetailsDialog {
private static final String RECIPIENT_SEPARATOR = ", ";
// All methods are static, no creating this class
private MessageDetailsDialog() {
}
public static void show(final Context context, final ConversationMessageData data,
final ConversationParticipantsData participants, final ParticipantData self) {
if (DebugUtils.isDebugEnabled()) {
new SafeAsyncTask<Void, Void, String>() {
@Override
protected String doInBackgroundTimed(Void... params) {
return getMessageDetails(context, data, participants, self);
}
@Override
protected void onPostExecute(String messageDetails) {
showDialog(context, messageDetails);
}
}.executeOnThreadPool(null, null, null);
} else {
String messageDetails = getMessageDetails(context, data, participants, self);
showDialog(context, messageDetails);
}
}
private static String getMessageDetails(final Context context,
final ConversationMessageData data,
final ConversationParticipantsData participants, final ParticipantData self) {
String messageDetails = null;
if (data.getIsSms()) {
messageDetails = getSmsMessageDetails(data, participants, self);
} else {
// TODO: Handle SMS_TYPE_MMS_PUSH_NOTIFICATION type differently?
messageDetails = getMmsMessageDetails(context, data, participants, self);
}
return messageDetails;
}
private static void showDialog(final Context context, String messageDetails) {
if (!TextUtils.isEmpty(messageDetails)) {
new AlertDialog.Builder(context)
.setTitle(R.string.message_details_title)
.setMessage(messageDetails)
.setCancelable(true)
.show();
}
}
/**
* Return a string, separated by newlines, that contains a number of labels and values
* for this sms message. The string will be displayed in a modal dialog.
* @return string list of various message properties
*/
private static String getSmsMessageDetails(final ConversationMessageData data,
final ConversationParticipantsData participants, final ParticipantData self) {
final Resources res = Factory.get().getApplicationContext().getResources();
final StringBuilder details = new StringBuilder();
// Type: Text message
details.append(res.getString(R.string.message_type_label));
details.append(res.getString(R.string.text_message));
// From: +1425xxxxxxx
// or To: +1425xxxxxxx
final String rawSender = data.getSenderNormalizedDestination();
if (!TextUtils.isEmpty(rawSender)) {
details.append('\n');
details.append(res.getString(R.string.from_label));
details.append(rawSender);
}
final String rawRecipients = getRecipientParticipantString(participants,
data.getParticipantId(), data.getIsIncoming(), data.getSelfParticipantId());
if (!TextUtils.isEmpty(rawRecipients)) {
details.append('\n');
details.append(res.getString(R.string.to_address_label));
details.append(rawRecipients);
}
// Sent: Mon 11:42AM
if (data.getIsIncoming()) {
if (data.getSentTimeStamp() != MmsUtils.INVALID_TIMESTAMP) {
details.append('\n');
details.append(res.getString(R.string.sent_label));
details.append(
Dates.getMessageDetailsTimeString(data.getSentTimeStamp()).toString());
}
}
// Sent: Mon 11:43AM
// or Received: Mon 11:43AM
appendSentOrReceivedTimestamp(res, details, data);
appendSimInfo(res, self, details);
if (DebugUtils.isDebugEnabled()) {
appendDebugInfo(details, data);
}
return details.toString();
}
/**
* Return a string, separated by newlines, that contains a number of labels and values
* for this mms message. The string will be displayed in a modal dialog.
* @return string list of various message properties
*/
private static String getMmsMessageDetails(Context context, final ConversationMessageData data,
final ConversationParticipantsData participants, final ParticipantData self) {
final Resources res = Factory.get().getApplicationContext().getResources();
// TODO: when we support non-auto-download of mms messages, we'll have to handle
// the case when the message is a PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND and display
// something different. See the Messaging app's MessageUtils.getNotificationIndDetails()
final StringBuilder details = new StringBuilder();
// Type: Multimedia message.
details.append(res.getString(R.string.message_type_label));
details.append(res.getString(R.string.multimedia_message));
// From: +1425xxxxxxx
final String rawSender = data.getSenderNormalizedDestination();
details.append('\n');
details.append(res.getString(R.string.from_label));
details.append(!TextUtils.isEmpty(rawSender) ? rawSender :
res.getString(R.string.hidden_sender_address));
// To: +1425xxxxxxx
final String rawRecipients = getRecipientParticipantString(participants,
data.getParticipantId(), data.getIsIncoming(), data.getSelfParticipantId());
if (!TextUtils.isEmpty(rawRecipients)) {
details.append('\n');
details.append(res.getString(R.string.to_address_label));
details.append(rawRecipients);
}
// Sent: Tue 3:05PM
// or Received: Tue 3:05PM
appendSentOrReceivedTimestamp(res, details, data);
// Subject: You're awesome
details.append('\n');
details.append(res.getString(R.string.subject_label));
if (!TextUtils.isEmpty(MmsUtils.cleanseMmsSubject(res, data.getMmsSubject()))) {
details.append(data.getMmsSubject());
}
// Priority: High/Normal/Low
details.append('\n');
details.append(res.getString(R.string.priority_label));
details.append(getPriorityDescription(res, data.getSmsPriority()));
// Message size: 30 KB
if (data.getSmsMessageSize() > 0) {
details.append('\n');
details.append(res.getString(R.string.message_size_label));
details.append(Formatter.formatFileSize(context, data.getSmsMessageSize()));
}
appendSimInfo(res, self, details);
if (DebugUtils.isDebugEnabled()) {
appendDebugInfo(details, data);
}
return details.toString();
}
private static void appendSentOrReceivedTimestamp(Resources res, StringBuilder details,
ConversationMessageData data) {
int labelId = -1;
if (data.getIsIncoming()) {
labelId = R.string.received_label;
} else if (data.getIsSendComplete()) {
labelId = R.string.sent_label;
}
if (labelId >= 0) {
details.append('\n');
details.append(res.getString(labelId));
details.append(
Dates.getMessageDetailsTimeString(data.getReceivedTimeStamp()).toString());
}
}
@DoesNotRunOnMainThread
private static void appendDebugInfo(StringBuilder details, ConversationMessageData data) {
// We grab the thread id from the database, so this needs to run in the background
Assert.isNotMainThread();
details.append("\n\n");
details.append("DEBUG");
details.append('\n');
details.append("Message id: ");
details.append(data.getMessageId());
final String telephonyUri = data.getSmsMessageUri();
details.append('\n');
details.append("Telephony uri: ");
details.append(telephonyUri);
final String conversationId = data.getConversationId();
if (conversationId == null) {
return;
}
details.append('\n');
details.append("Conversation id: ");
details.append(conversationId);
final long threadId = BugleDatabaseOperations.getThreadId(DataModel.get().getDatabase(),
conversationId);
details.append('\n');
details.append("Conversation telephony thread id: ");
details.append(threadId);
MmsMessage mms = null;
if (data.getIsMms()) {
if (telephonyUri == null) {
return;
}
mms = MmsUtils.loadMms(Uri.parse(telephonyUri));
if (mms == null) {
return;
}
// We log the thread id again to check that they are internally consistent
final long mmsThreadId = mms.mThreadId;
details.append('\n');
details.append("Telephony thread id: ");
details.append(mmsThreadId);
// Log the MMS content location
final String mmsContentLocation = mms.mContentLocation;
details.append('\n');
details.append("Content location URL: ");
details.append(mmsContentLocation);
}
final String recipientsString = MmsUtils.getRawRecipientIdsForThread(threadId);
if (recipientsString != null) {
details.append('\n');
details.append("Thread recipient ids: ");
details.append(recipientsString);
}
final List<String> recipients = MmsUtils.getRecipientsByThread(threadId);
if (recipients != null) {
details.append('\n');
details.append("Thread recipients: ");
details.append(recipients.toString());
if (mms != null) {
final String from = MmsUtils.getMmsSender(recipients, mms.getUri());
details.append('\n');
details.append("Sender: ");
details.append(from);
}
}
}
private static String getRecipientParticipantString(
final ConversationParticipantsData participants, final String senderId,
final boolean addSelf, final String selfId) {
final StringBuilder recipients = new StringBuilder();
for (final ParticipantData participant : participants) {
if (TextUtils.equals(participant.getId(), senderId)) {
// Don't add sender
continue;
}
if (participant.isSelf() &&
(!participant.getId().equals(selfId) || !addSelf)) {
// For self participants, don't add the one that's not relevant to this message
// or if we are asked not to add self
continue;
}
final String phoneNumber = participant.getNormalizedDestination();
// Don't add empty number. This should not happen. But if that happens
// we should not add it.
if (!TextUtils.isEmpty(phoneNumber)) {
if (recipients.length() > 0) {
recipients.append(RECIPIENT_SEPARATOR);
}
recipients.append(phoneNumber);
}
}
return recipients.toString();
}
/**
* Convert the numeric mms priority into a human-readable string
* @param res
* @param priorityValue coded PduHeader priority
* @return string representation of the priority
*/
private static String getPriorityDescription(final Resources res, final int priorityValue) {
switch(priorityValue) {
case PduHeaders.PRIORITY_HIGH:
return res.getString(R.string.priority_high);
case PduHeaders.PRIORITY_LOW:
return res.getString(R.string.priority_low);
case PduHeaders.PRIORITY_NORMAL:
default:
return res.getString(R.string.priority_normal);
}
}
private static void appendSimInfo(final Resources res,
final ParticipantData self, final StringBuilder outString) {
if (!OsUtil.isAtLeastL_MR1()
|| self == null
|| PhoneUtils.getDefault().getActiveSubscriptionCount() < 2) {
return;
}
// The appended SIM info would look like:
// SIM: SUB 01
// or SIM: SIM 1
// or SIM: Unknown
Assert.isTrue(self.isSelf());
outString.append('\n');
outString.append(res.getString(R.string.sim_label));
if (self.isActiveSubscription() && !self.isDefaultSelf()) {
final String subscriptionName = self.getSubscriptionName();
if (TextUtils.isEmpty(subscriptionName)) {
outString.append(res.getString(R.string.sim_slot_identifier,
self.getDisplaySlotId()));
} else {
outString.append(subscriptionName);
}
}
}
}
|