Messaging: Language cleanup

No unnecessary boxing, enhanced for loops, redundant checks and throws,
imports (removal, reordering), possible void returns

Change-Id: I7a8e1b2007e3b0906e01b41785c518d02c2f3fab
This commit is contained in:
Michael W
2024-12-26 15:54:37 +01:00
parent e335f6bec8
commit e128bff457
77 changed files with 202 additions and 334 deletions
@@ -359,7 +359,7 @@ public class BugleApnSettingsLoader implements ApnSettingsLoader {
} else {
uri = Telephony.Carriers.CONTENT_URI;
}
Cursor cursor = null;
Cursor cursor;
try {
for (; ; ) {
// Try different combinations of queries. Some would work on some platforms.
@@ -556,7 +556,7 @@ public class BugleApnSettingsLoader implements ApnSettingsLoader {
return addr;
}
final StringBuilder builder = new StringBuilder(16);
String result = null;
String result;
for (int i = 0; i < 4; i++) {
try {
if (octets[i].length() > 3) {
@@ -107,9 +107,7 @@ public class BugleCarrierConfigValuesLoader implements CarrierConfigValuesLoader
try {
final Bundle systemValues =
PhoneUtils.get(subId).getSmsManager().getCarrierConfigValues();
if (systemValues != null) {
values.putAll(systemValues);
}
values.putAll(systemValues);
} catch (final Exception e) {
LogUtil.w(LogUtil.BUGLE_TAG, "Calling system getCarrierConfigValues exception", e);
}
@@ -35,7 +35,6 @@ import android.webkit.MimeTypeMap;
import com.android.messaging.Factory;
import com.android.messaging.datamodel.data.MessageData;
import com.android.messaging.datamodel.media.VideoThumbnailRequest;
import com.android.messaging.mmslib.pdu.CharacterSets;
import com.android.messaging.util.ContentType;
import com.android.messaging.util.LogUtil;
@@ -65,7 +64,7 @@ public class DatabaseMessages {
@Override
public boolean equals(final Object other) {
if (other == null || !(other instanceof DatabaseMessage)) {
if (!(other instanceof DatabaseMessage)) {
return false;
}
final DatabaseMessage otherDbMsg = (DatabaseMessage) other;
@@ -155,8 +154,8 @@ public class DatabaseMessages {
mType = cursor.getInt(INDEX_TYPE);
mThreadId = cursor.getLong(INDEX_THREAD_ID);
mStatus = cursor.getInt(INDEX_STATUS);
mRead = cursor.getInt(INDEX_READ) == 0 ? false : true;
mSeen = cursor.getInt(INDEX_SEEN) == 0 ? false : true;
mRead = cursor.getInt(INDEX_READ) != 0;
mSeen = cursor.getInt(INDEX_SEEN) != 0;
mUri = ContentUris.withAppendedId(Sms.CONTENT_URI, mRowId).toString();
mSubId = PhoneUtils.getDefault().getSubIdFromTelephony(cursor, INDEX_SUB_ID);
}
@@ -351,8 +350,8 @@ public class DatabaseMessages {
mThreadId = cursor.getLong(INDEX_THREAD_ID);
mPriority = cursor.getInt(INDEX_PRIORITY);
mStatus = cursor.getInt(INDEX_STATUS);
mRead = cursor.getInt(INDEX_READ) == 0 ? false : true;
mSeen = cursor.getInt(INDEX_SEEN) == 0 ? false : true;
mRead = cursor.getInt(INDEX_READ) != 0;
mSeen = cursor.getInt(INDEX_SEEN) != 0;
mContentLocation = cursor.getString(INDEX_CONTENT_LOCATION);
mTransactionId = cursor.getString(INDEX_TRANSACTION_ID);
mMmsMessageType = cursor.getInt(INDEX_MESSAGE_TYPE);
@@ -731,6 +730,7 @@ public class DatabaseMessages {
/**
* Get an instance of the MMS part from the part table cursor
*
* @param loadMedia Whether to load the media file of the part
*/
public static MmsPart get(final Cursor cursor, final boolean loadMedia) {
final MmsPart part = new MmsPart();
+19 -42
View File
@@ -29,12 +29,10 @@ import android.database.sqlite.SQLiteException;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.provider.Telephony;
import android.provider.Telephony.Mms;
import android.provider.Telephony.Sms;
import android.provider.Telephony.Threads;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.text.TextUtils;
@@ -45,7 +43,6 @@ import com.android.messaging.datamodel.action.DownloadMmsAction;
import com.android.messaging.datamodel.action.SendMessageAction;
import com.android.messaging.datamodel.data.MessageData;
import com.android.messaging.datamodel.data.MessagePartData;
import com.android.messaging.datamodel.data.ParticipantData;
import com.android.messaging.mmslib.InvalidHeaderValueException;
import com.android.messaging.mmslib.MmsException;
import com.android.messaging.mmslib.SqliteWrapper;
@@ -122,7 +119,7 @@ public class MmsUtils {
*/
public static final int MMS_REQUEST_NO_RETRY = 3;
public static final String getRequestStatusDescription(final int status) {
public static String getRequestStatusDescription(final int status) {
switch (status) {
case MMS_REQUEST_SUCCEEDED:
return "SUCCEEDED";
@@ -889,9 +886,7 @@ public class MmsUtils {
LogUtil.d(TAG, "Mmsutils: Inserted SMS message into telephony (type = " + type + ")"
+ ", uri: " + response);
}
} catch (final SQLiteException e) {
LogUtil.e(TAG, "MmsUtils: persist sms message failure " + e, e);
} catch (final IllegalArgumentException e) {
} catch (final SQLiteException | IllegalArgumentException e) {
LogUtil.e(TAG, "MmsUtils: persist sms message failure " + e, e);
}
return response;
@@ -914,9 +909,7 @@ public class MmsUtils {
}
return true;
}
} catch (final SQLiteException e) {
LogUtil.e(TAG, "MmsUtils: update sms message failure " + e, e);
} catch (final IllegalArgumentException e) {
} catch (final SQLiteException | IllegalArgumentException e) {
LogUtil.e(TAG, "MmsUtils: update sms message failure " + e, e);
}
return false;
@@ -999,9 +992,7 @@ public class MmsUtils {
}
return true;
}
} catch (final SQLiteException e) {
LogUtil.e(TAG, "MmsUtils: update mms message failure " + e, e);
} catch (final IllegalArgumentException e) {
} catch (final SQLiteException | IllegalArgumentException e) {
LogUtil.e(TAG, "MmsUtils: update mms message failure " + e, e);
}
return false;
@@ -1135,9 +1126,7 @@ public class MmsUtils {
if (messageUri != null) {
return ContentUris.parseId(messageUri);
}
} catch (final UnsupportedOperationException e) {
// Nothing to do
} catch (final NumberFormatException e) {
} catch (final UnsupportedOperationException | NumberFormatException e) {
// Nothing to do
}
return -1;
@@ -1785,9 +1774,7 @@ public class MmsUtils {
}
MmsSender.sendNotifyResponseForMmsDownload(
context, subId, transactionId, contentLocation, status);
} catch (final MmsFailureException e) {
LogUtil.e(TAG, "sendNotifyResponseForMmsDownload: failed to retrieve message " + e, e);
} catch (final InvalidHeaderValueException e) {
} catch (final MmsFailureException | InvalidHeaderValueException e) {
LogUtil.e(TAG, "sendNotifyResponseForMmsDownload: failed to retrieve message " + e, e);
}
}
@@ -1810,9 +1797,7 @@ public class MmsUtils {
return;
}
MmsSender.sendAcknowledgeForMmsDownload(context, subId, transactionId, contentLocation);
} catch (final MmsFailureException e) {
LogUtil.e(TAG, "sendAcknowledgeForMmsDownload: failed to retrieve message " + e, e);
} catch (final InvalidHeaderValueException e) {
} catch (final MmsFailureException | InvalidHeaderValueException e) {
LogUtil.e(TAG, "sendAcknowledgeForMmsDownload: failed to retrieve message " + e, e);
}
}
@@ -1875,12 +1860,10 @@ public class MmsUtils {
status = e.retryHint;
rawStatus = e.rawStatus;
LogUtil.e(TAG, "MmsUtils: failed to send message " + e, e);
} catch (final InvalidHeaderValueException e) {
} catch (final MmsException e) {
LogUtil.e(TAG, "MmsUtils: failed to send message " + e, e);
} catch (final IllegalArgumentException e) {
LogUtil.e(TAG, "MmsUtils: invalid message to send " + e, e);
} catch (final MmsException e) {
LogUtil.e(TAG, "MmsUtils: failed to send message " + e, e);
}
// If we get here, some exception occurred
return new StatusPlusUri(status, rawStatus, messageUri);
@@ -1939,8 +1922,6 @@ public class MmsUtils {
private static String[] getDupNotifications(final Context context, final NotificationInd nInd) {
final byte[] rawTransactionId = nInd.getTransactionId();
if (rawTransactionId != null) {
// dedup algorithm
String selection = DUP_NOTIFICATION_QUERY_SELECTION;
final long nowSecs = System.currentTimeMillis() / 1000;
String[] selectionArgs = new String[] {
Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND),
@@ -1952,7 +1933,7 @@ public class MmsUtils {
try (Cursor cursor = SqliteWrapper.query(
context, context.getContentResolver(),
Mms.CONTENT_URI, new String[]{Mms._ID},
selection, selectionArgs, null)) {
DUP_NOTIFICATION_QUERY_SELECTION, selectionArgs, null)) {
final int dupCount = cursor.getCount();
if (dupCount > 0) {
// We already received the same notification before.
@@ -2015,7 +1996,7 @@ public class MmsUtils {
}
final String[] dups = getDupNotifications(context, nInd);
if (dups == null) {
Uri inboxUri = null;
Uri inboxUri;
try {
inboxUri = p.persist(pdu, Mms.Inbox.CONTENT_URI, subId, subPhoneNumber,
null);
@@ -2299,9 +2280,7 @@ public class MmsUtils {
if (pduData == null || pduData.length < 1) {
throw new IllegalArgumentException("Empty or zero length PDU data");
}
} catch (final MmsFailureException e) {
// Nothing to do
} catch (final InvalidHeaderValueException e) {
} catch (final MmsFailureException | InvalidHeaderValueException e) {
// Nothing to do
}
return pduData;
@@ -2349,17 +2328,15 @@ public class MmsUtils {
}
final String dumpFileName = MmsUtils.MMS_DUMP_PREFIX + getDumpFileId(pdu);
final File dumpFile = DebugUtils.getDebugFile(dumpFileName, true);
if (dumpFile != null) {
try {
final FileOutputStream fos = new FileOutputStream(dumpFile);
try (BufferedOutputStream bos = new BufferedOutputStream(fos)) {
bos.write(rawPdu);
bos.flush();
}
DebugUtils.ensureReadable(dumpFile);
} catch (final IOException e) {
LogUtil.e(TAG, "dumpPdu: " + e, e);
try {
final FileOutputStream fos = new FileOutputStream(dumpFile);
try (BufferedOutputStream bos = new BufferedOutputStream(fos)) {
bos.write(rawPdu);
bos.flush();
}
DebugUtils.ensureReadable(dumpFile);
} catch (final IOException e) {
LogUtil.e(TAG, "dumpPdu: " + e, e);
}
}
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,20 +33,15 @@ class SystemProperties {
sSystemPropertiesGetMethod =
systemPropertiesClass.getMethod("get", String.class);
}
} catch (final ClassNotFoundException e) {
// Nothing to do
} catch (final NoSuchMethodException e) {
} catch (final ClassNotFoundException | NoSuchMethodException e) {
// Nothing to do
}
}
if (sSystemPropertiesGetMethod != null) {
try {
return (String) sSystemPropertiesGetMethod.invoke(null, name);
} catch (final IllegalArgumentException e) {
// Nothing to do
} catch (final IllegalAccessException e) {
// Nothing to do
} catch (final InvocationTargetException e) {
} catch (final IllegalArgumentException | InvocationTargetException |
IllegalAccessException e) {
// Nothing to do
}
}