Messaging: Remove unused code

Change-Id: I8093bb3e305ae323f7069bf42f9e83f8c8647cc7
This commit is contained in:
Michael W
2024-12-26 15:54:37 +01:00
parent 0069df879a
commit e29b158fba
69 changed files with 42 additions and 3228 deletions
@@ -1,365 +0,0 @@
/*
* 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.
* 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.datamodel;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import androidx.annotation.NonNull;
import android.text.TextUtils;
import android.util.SparseArray;
import com.android.messaging.datamodel.MemoryCacheManager.MemoryCache;
import com.android.messaging.util.Assert;
import com.android.messaging.util.LogUtil;
import java.io.InputStream;
/**
* Class for creating / loading / reusing bitmaps. This class allow the user to create a new bitmap,
* reuse an bitmap from the pool and to return a bitmap for future reuse. The pool of bitmaps
* allows for faster decode and more efficient memory usage.
* Note: consumers should not create BitmapPool directly, but instead get the pool they want from
* the BitmapPoolManager.
*/
public class BitmapPool implements MemoryCache {
public static final int MAX_SUPPORTED_IMAGE_DIMENSION = 0xFFFF;
protected static final boolean VERBOSE = false;
/**
* Number of reuse failures to skip before reporting.
*/
private static final int FAILED_REPORTING_FREQUENCY = 100;
/**
* Count of reuse failures which have occurred.
*/
private static volatile int sFailedBitmapReuseCount = 0;
/**
* Overall pool data structure which currently only supports rectangular bitmaps. The size of
* one of the sides is used to index into the SparseArray.
*/
private final SparseArray<SingleSizePool> mPool;
private final Object mPoolLock = new Object();
private final String mPoolName;
private final int mMaxSize;
/**
* Inner structure which holds a pool of bitmaps all the same size (i.e. all have the same
* width as each other and height as each other, but not necessarily the same).
*/
private class SingleSizePool {
int mNumItems;
final Bitmap[] mBitmaps;
SingleSizePool(final int maxPoolSize) {
mNumItems = 0;
mBitmaps = new Bitmap[maxPoolSize];
}
}
/**
* Creates a pool of reused bitmaps with helper decode methods which will attempt to use the
* reclaimed bitmaps. This will help speed up the creation of bitmaps by using already allocated
* bitmaps.
* @param maxSize The overall max size of the pool. When the pool exceeds this size, all calls
* to reclaimBitmap(Bitmap) will result in recycling the bitmap.
* @param name Name of the bitmap pool and only used for logging. Can not be null.
*/
BitmapPool(final int maxSize, @NonNull final String name) {
Assert.isTrue(maxSize > 0);
Assert.isTrue(!TextUtils.isEmpty(name));
mPoolName = name;
mMaxSize = maxSize;
mPool = new SparseArray<>();
}
@Override
public void reclaim() {
synchronized (mPoolLock) {
for (int p = 0; p < mPool.size(); p++) {
final SingleSizePool singleSizePool = mPool.valueAt(p);
for (int i = 0; i < singleSizePool.mNumItems; i++) {
singleSizePool.mBitmaps[i].recycle();
singleSizePool.mBitmaps[i] = null;
}
singleSizePool.mNumItems = 0;
}
mPool.clear();
}
}
/**
* Creates a new BitmapFactory.Options.
*/
public static BitmapFactory.Options getBitmapOptionsForPool(final boolean scaled,
final int inputDensity, final int targetDensity) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = scaled;
options.inDensity = inputDensity;
options.inTargetDensity = targetDensity;
options.inSampleSize = 1;
options.inJustDecodeBounds = false;
options.inMutable = true;
return options;
}
/**
* @return The pool key for the provided image dimensions or 0 if either width or height is
* greater than the max supported image dimension.
*/
private int getPoolKey(final int width, final int height) {
if (width > MAX_SUPPORTED_IMAGE_DIMENSION || height > MAX_SUPPORTED_IMAGE_DIMENSION) {
return 0;
}
return (width << 16) | height;
}
/**
*
* @return A bitmap in the pool with the specified dimensions or null if no bitmap with the
* specified dimension is available.
*/
private Bitmap findPoolBitmap(final int width, final int height) {
final int poolKey = getPoolKey(width, height);
if (poolKey != 0) {
synchronized (mPoolLock) {
// Take a bitmap from the pool if one is available
final SingleSizePool singlePool = mPool.get(poolKey);
if (singlePool != null && singlePool.mNumItems > 0) {
singlePool.mNumItems--;
final Bitmap foundBitmap = singlePool.mBitmaps[singlePool.mNumItems];
singlePool.mBitmaps[singlePool.mNumItems] = null;
return foundBitmap;
}
}
}
return null;
}
/**
* Internal function to try and find a bitmap in the pool which matches the desired width and
* height and then set that in the bitmap options properly.
*
* TODO: Why do we take a width/height? Shouldn't this already be in the
* BitmapFactory.Options instance? Can we assert that they match?
* @param optionsTmp The BitmapFactory.Options to update with the bitmap for the system to try
* to reuse.
* @param width The width of the reusable bitmap.
* @param height The height of the reusable bitmap.
*/
private void assignPoolBitmap(final BitmapFactory.Options optionsTmp, final int width,
final int height) {
if (optionsTmp.inJustDecodeBounds) {
return;
}
optionsTmp.inBitmap = findPoolBitmap(width, height);
}
/**
* Load a resource into a bitmap. Uses a bitmap from the pool if possible to reduce memory
* turnover.
* @param resourceId Resource id to load.
* @param resources Application resources. Cannot be null.
* @param optionsTmp Should be the same options returned from getBitmapOptionsForPool(). Cannot
* be null.
* @param width The width of the bitmap.
* @param height The height of the bitmap.
* @return The decoded Bitmap with the resource drawn in it.
*/
public Bitmap decodeSampledBitmapFromResource(final int resourceId,
@NonNull final Resources resources, @NonNull final BitmapFactory.Options optionsTmp,
final int width, final int height) {
Assert.notNull(resources);
Assert.notNull(optionsTmp);
Assert.isTrue(width > 0);
Assert.isTrue(height > 0);
assignPoolBitmap(optionsTmp, width, height);
Bitmap b = null;
try {
b = BitmapFactory.decodeResource(resources, resourceId, optionsTmp);
} catch (final IllegalArgumentException e) {
// BitmapFactory couldn't decode the file, try again without an inputBufferBitmap.
if (optionsTmp.inBitmap != null) {
optionsTmp.inBitmap = null;
b = BitmapFactory.decodeResource(resources, resourceId, optionsTmp);
sFailedBitmapReuseCount++;
if (sFailedBitmapReuseCount % FAILED_REPORTING_FREQUENCY == 0) {
LogUtil.w(LogUtil.BUGLE_TAG,
"Pooled bitmap consistently not being reused count = " +
sFailedBitmapReuseCount);
}
}
} catch (final OutOfMemoryError e) {
LogUtil.w(LogUtil.BUGLE_TAG, "Oom decoding resource " + resourceId);
reclaim();
}
return b;
}
/**
* Load an input stream into a bitmap. Uses a bitmap from the pool if possible to reduce memory
* turnover.
* @param inputStream InputStream load. Cannot be null.
* @param optionsTmp Should be the same options returned from getBitmapOptionsForPool(). Cannot
* be null.
* @param width The width of the bitmap.
* @param height The height of the bitmap.
* @return The decoded Bitmap with the resource drawn in it.
*/
public Bitmap decodeSampledBitmapFromInputStream(@NonNull final InputStream inputStream,
@NonNull final BitmapFactory.Options optionsTmp,
final int width, final int height) {
Assert.notNull(inputStream);
Assert.isTrue(width > 0);
Assert.isTrue(height > 0);
assignPoolBitmap(optionsTmp, width, height);
Bitmap b = null;
try {
b = BitmapFactory.decodeStream(inputStream, null, optionsTmp);
} catch (final IllegalArgumentException e) {
// BitmapFactory couldn't decode the file, try again without an inputBufferBitmap.
if (optionsTmp.inBitmap != null) {
optionsTmp.inBitmap = null;
b = BitmapFactory.decodeStream(inputStream, null, optionsTmp);
sFailedBitmapReuseCount++;
if (sFailedBitmapReuseCount % FAILED_REPORTING_FREQUENCY == 0) {
LogUtil.w(LogUtil.BUGLE_TAG,
"Pooled bitmap consistently not being reused count = " +
sFailedBitmapReuseCount);
}
}
} catch (final OutOfMemoryError e) {
LogUtil.w(LogUtil.BUGLE_TAG, "Oom decoding inputStream");
reclaim();
}
return b;
}
/**
* Turn encoded bytes into a bitmap. Uses a bitmap from the pool if possible to reduce memory
* turnover.
* @param bytes Encoded bytes to draw on the bitmap. Cannot be null.
* @param optionsTmp The bitmap will set here and the input should be generated from
* getBitmapOptionsForPool(). Cannot be null.
* @param width The width of the bitmap.
* @param height The height of the bitmap.
* @return A Bitmap with the encoded bytes drawn in it.
*/
public Bitmap decodeByteArray(@NonNull final byte[] bytes,
@NonNull final BitmapFactory.Options optionsTmp, final int width,
final int height) throws OutOfMemoryError {
Assert.notNull(bytes);
Assert.notNull(optionsTmp);
Assert.isTrue(width > 0);
Assert.isTrue(height > 0);
assignPoolBitmap(optionsTmp, width, height);
Bitmap b = null;
try {
b = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, optionsTmp);
} catch (final IllegalArgumentException e) {
if (VERBOSE) {
LogUtil.v(LogUtil.BUGLE_TAG, "BitmapPool(" + mPoolName +
") Unable to use pool bitmap");
}
// BitmapFactory couldn't decode the file, try again without an inputBufferBitmap.
// (i.e. without the bitmap from the pool)
if (optionsTmp.inBitmap != null) {
optionsTmp.inBitmap = null;
b = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, optionsTmp);
sFailedBitmapReuseCount++;
if (sFailedBitmapReuseCount % FAILED_REPORTING_FREQUENCY == 0) {
LogUtil.w(LogUtil.BUGLE_TAG,
"Pooled bitmap consistently not being reused count = " +
sFailedBitmapReuseCount);
}
}
}
return b;
}
/**
* Creates a bitmap with the given size, this will reuse a bitmap in the pool, if one is
* available, otherwise this will create a new one.
* @param width The desired width of the bitmap.
* @param height The desired height of the bitmap.
* @return A bitmap with the desired width and height, this maybe a reused bitmap from the pool.
*/
public Bitmap createOrReuseBitmap(final int width, final int height) {
Bitmap b = findPoolBitmap(width, height);
if (b == null) {
b = createBitmap(width, height);
}
return b;
}
/**
* This will create a new bitmap regardless of pool state.
* @param width The desired width of the bitmap.
* @param height The desired height of the bitmap.
* @return A bitmap with the desired width and height.
*/
private Bitmap createBitmap(final int width, final int height) {
return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
/**
* Called when a bitmap is finished being used so that it can be used for another bitmap in the
* future or recycled. Any bitmaps returned should not be used by the caller again.
* @param b The bitmap to return to the pool for future usage or recycled. This cannot be null.
*/
public void reclaimBitmap(@NonNull final Bitmap b) {
Assert.notNull(b);
final int poolKey = getPoolKey(b.getWidth(), b.getHeight());
if (poolKey == 0 || !b.isMutable()) {
// Unsupported image dimensions or a immutable bitmap.
b.recycle();
return;
}
synchronized (mPoolLock) {
SingleSizePool singleSizePool = mPool.get(poolKey);
if (singleSizePool == null) {
singleSizePool = new SingleSizePool(mMaxSize);
mPool.append(poolKey, singleSizePool);
}
if (singleSizePool.mNumItems < singleSizePool.mBitmaps.length) {
singleSizePool.mBitmaps[singleSizePool.mNumItems] = b;
singleSizePool.mNumItems++;
} else {
b.recycle();
}
}
}
/**
* @return whether the pool is full for a given width and height.
*/
public boolean isFull(final int width, final int height) {
final int poolKey = getPoolKey(width, height);
synchronized (mPoolLock) {
final SingleSizePool singleSizePool = mPool.get(poolKey);
if (singleSizePool != null &&
singleSizePool.mNumItems >= singleSizePool.mBitmaps.length) {
return true;
}
return false;
}
}
}
@@ -835,17 +835,6 @@ public class BugleDatabaseOperations {
return null;
}
/**
* Frees up memory associated with phone number to participant id matching.
*/
@DoesNotRunOnMainThread
public static void clearParticipantIdCache() {
Assert.isNotMainThread();
synchronized (sNormalizedPhoneNumberToParticipantIdCache) {
sNormalizedPhoneNumberToParticipantIdCache.clear();
}
}
@DoesNotRunOnMainThread
public static ArrayList<String> getRecipientsForConversation(final DatabaseWrapper dbWrapper,
final String conversationId) {
@@ -940,21 +929,6 @@ public class BugleDatabaseOperations {
return message;
}
@VisibleForTesting
static MessagePartData readMessagePartData(final DatabaseWrapper dbWrapper,
final String partId) {
MessagePartData messagePartData = null;
try (Cursor cursor = dbWrapper.query(DatabaseHelper.PARTS_TABLE,
MessagePartData.getProjection(), PartColumns._ID + "=?",
new String[]{partId}, null, null, null)) {
Assert.inRange(cursor.getCount(), 0, 1);
if (cursor.moveToFirst()) {
messagePartData = MessagePartData.createFromCursor(cursor);
}
}
return messagePartData;
}
@DoesNotRunOnMainThread
public static MessageData readMessageData(final DatabaseWrapper dbWrapper,
final Uri smsMessageUri) {
@@ -1726,17 +1700,6 @@ public class BugleDatabaseOperations {
}
}
/**
* Refresh conversation names/avatars based on a changed participant.
*/
@DoesNotRunOnMainThread
public static void refreshConversationsForParticipant(final String participantId) {
Assert.isNotMainThread();
final ArrayList<String> participantList = new ArrayList<>(1);
participantList.add(participantId);
refreshConversationsForParticipants(participantList);
}
/**
* Refresh one conversation.
*/
@@ -1,101 +0,0 @@
/*
* 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.datamodel;
public class DataModelException extends Exception {
private static final long serialVersionUID = 1L;
private static final int FIRST = 100;
// ERRORS GENERATED INTERNALLY BY DATA MODEL.
// ERRORS RELATED WITH SMS.
public static final int ERROR_SMS_TEMPORARY_FAILURE = 116;
public static final int ERROR_SMS_PERMANENT_FAILURE = 117;
public static final int ERROR_MMS_TEMPORARY_FAILURE = 118;
public static final int ERROR_MMS_PERMANENT_UNKNOWN_FAILURE = 119;
// Request expired.
public static final int ERROR_EXPIRED = 120;
// Request canceled by user.
public static final int ERROR_CANCELED = 121;
public static final int ERROR_MOBILE_DATA_DISABLED = 123;
public static final int ERROR_MMS_SERVICE_BLOCKED = 124;
public static final int ERROR_MMS_INVALID_ADDRESS = 125;
public static final int ERROR_MMS_NETWORK_PROBLEM = 126;
public static final int ERROR_MMS_MESSAGE_NOT_FOUND = 127;
public static final int ERROR_MMS_MESSAGE_FORMAT_CORRUPT = 128;
public static final int ERROR_MMS_CONTENT_NOT_ACCEPTED = 129;
public static final int ERROR_MMS_MESSAGE_NOT_SUPPORTED = 130;
public static final int ERROR_MMS_REPLY_CHARGING_ERROR = 131;
public static final int ERROR_MMS_ADDRESS_HIDING_NOT_SUPPORTED = 132;
public static final int ERROR_MMS_LACK_OF_PREPAID = 133;
public static final int ERROR_MMS_CAN_NOT_PERSIST = 134;
public static final int ERROR_MMS_NO_AVAILABLE_APN = 135;
public static final int ERROR_MMS_INVALID_MESSAGE_TO_SEND = 136;
public static final int ERROR_MMS_INVALID_MESSAGE_RECEIVED = 137;
public static final int ERROR_MMS_NO_CONFIGURATION = 138;
private static final int LAST = 138;
private final boolean mIsInjection;
private final int mErrorCode;
private final String mMessage;
private final long mBackoff;
public DataModelException(final int errorCode, final Exception innerException,
final long backoff, final boolean injection, final String message) {
// Since some of the exceptions passed in may not be serializable, only record message
// instead of setting inner exception for Exception class. Otherwise, we will get
// serialization issues when we pass ServerRequestException as intent extra later.
if (errorCode < FIRST || errorCode > LAST) {
throw new IllegalArgumentException("error code out of range: " + errorCode);
}
mIsInjection = injection;
mErrorCode = errorCode;
if (innerException != null) {
mMessage = innerException.getMessage() + " -- " +
(mIsInjection ? "[INJECTED] -- " : "") + message;
} else {
mMessage = (mIsInjection ? "[INJECTED] -- " : "") + message;
}
mBackoff = backoff;
}
public DataModelException(final int errorCode) {
this(errorCode, null, 0, false, null);
}
public DataModelException(final int errorCode, final Exception innerException) {
this(errorCode, innerException, 0, false, null);
}
public DataModelException(final int errorCode, final String message) {
this(errorCode, null, 0, false, message);
}
@Override
public String getMessage() {
return mMessage;
}
public int getErrorCode() {
return mErrorCode;
}
}
@@ -1102,29 +1102,6 @@ public abstract class MessageNotificationState extends NotificationState {
}
}
/*
private static void updateAlertStatusMessages(final long thresholdDeltaMs) {
// TODO may need this when supporting error notifications
final EsDatabaseHelper helper = EsDatabaseHelper.getDatabaseHelper();
final ContentValues values = new ContentValues();
final long nowMicros = System.currentTimeMillis() * 1000;
values.put(MessageColumns.ALERT_STATUS, "1");
final String selection =
MessageColumns.ALERT_STATUS + "=0 AND (" +
MessageColumns.STATUS + "=" + EsProvider.MESSAGE_STATUS_FAILED_TO_SEND + " OR (" +
MessageColumns.STATUS + "!=" + EsProvider.MESSAGE_STATUS_ON_SERVER + " AND " +
MessageColumns.TIMESTAMP + "+" + thresholdDeltaMs*1000 + "<" + nowMicros + ")) ";
final int updateCount = helper.getWritableDatabaseWrapper().update(
EsProvider.MESSAGES_TABLE,
values,
selection,
null);
if (updateCount > 0) {
EsConversationsData.notifyConversationsChanged();
}
}*/
static CharSequence applyWarningTextColor(final Context context,
final CharSequence text) {
if (text == null) {
@@ -1166,7 +1143,6 @@ public abstract class MessageNotificationState extends NotificationState {
final ArrayList<Integer> failedMessages = new ArrayList<>();
int cursorPosition = -1;
final long when = 0;
messageDataCursor.moveToPosition(-1);
while (messageDataCursor.moveToNext()) {
@@ -1195,7 +1171,6 @@ public abstract class MessageNotificationState extends NotificationState {
CharSequence line1;
CharSequence line2;
final boolean isRichContent = false;
ConversationIdSet conversationIds = null;
PendingIntent destinationIntent;
if (failedMessages.size() == 1) {
@@ -1222,12 +1197,6 @@ public abstract class MessageNotificationState extends NotificationState {
}
line1 = resources.getString(failureStringId);
line2 = failedMessgeSnippet;
// Set rich text for non-SMS messages or MMS push notification messages
// which we generate locally with rich text
// TODO- fix this
// if (messageData.isMmsInd()) {
// isRichContent = true;
// }
} else {
// We have notifications for multiple conversation, go to the conversation
// list.
@@ -1265,29 +1234,18 @@ public abstract class MessageNotificationState extends NotificationState {
builder
.setContentTitle(line1)
.setTicker(line1)
.setWhen(when > 0 ? when : System.currentTimeMillis())
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_failed_light)
.setDeleteIntent(pendingIntentForDelete)
.setContentIntent(destinationIntent)
.setSound(UriUtil.getUriForResourceId(context, R.raw.message_failure));
if (isRichContent && !TextUtils.isEmpty(line2)) {
final NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle(builder);
if (line2 != null) {
inboxStyle.addLine(Html.fromHtml(line2.toString()));
}
builder.setStyle(inboxStyle);
} else {
builder.setContentText(line2);
}
builder.setContentText(line2);
if (builder != null) {
notificationManager.notify(
BugleNotifications.buildNotificationTag(
PendingIntentConstants.MSG_SEND_ERROR, null),
PendingIntentConstants.MSG_SEND_ERROR,
builder.build());
}
notificationManager.notify(
BugleNotifications.buildNotificationTag(
PendingIntentConstants.MSG_SEND_ERROR, null),
PendingIntentConstants.MSG_SEND_ERROR,
builder.build());
} else {
notificationManager.cancel(
BugleNotifications.buildNotificationTag(
@@ -254,15 +254,6 @@ public class MessagingContentProvider extends ContentProvider {
@Override
public Cursor query(@NonNull final Uri uri, final String[] projection, String selection,
final String[] selectionArgs, String sortOrder) {
// Processes other than self are allowed to temporarily access the media
// scratch space; we grant uri read access on a case-by-case basis. Dialer app and
// contacts app would doQuery() on the vCard uri before trying to open the inputStream.
// There's nothing that we need to return for this uri so just No-Op.
//if (isMediaScratchSpaceUri(uri)) {
// return null;
//}
final SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
String[] queryArgs = selectionArgs;
@@ -23,7 +23,6 @@ import android.os.Parcelable;
import android.text.TextUtils;
import com.android.messaging.datamodel.DataModel;
import com.android.messaging.datamodel.DataModelException;
import com.android.messaging.datamodel.action.ActionMonitor.ActionCompletedListener;
import com.android.messaging.datamodel.action.ActionMonitor.ActionExecutedListener;
import com.android.messaging.util.LogUtil;
@@ -96,11 +95,10 @@ public abstract class Action implements Parcelable {
/**
* Do work in a long running background worker thread.
* {@link #requestBackgroundWork} needs to be called for this method to
* be called. {@link #processBackgroundFailure} will be called on the Action service thread
* if this method throws {@link DataModelException}.
* be called.
* @return response that is to be passed to {@link #processBackgroundResponse}
*/
protected Bundle doBackgroundWork() throws DataModelException {
protected Bundle doBackgroundWork() {
return null;
}
@@ -26,7 +26,6 @@ import androidx.core.app.JobIntentService;
import com.android.messaging.Factory;
import com.android.messaging.datamodel.DataModel;
import com.android.messaging.datamodel.DataModelException;
import com.android.messaging.util.Assert;
import com.android.messaging.util.LogUtil;
import com.android.messaging.util.LoggingTimer;
@@ -140,18 +139,9 @@ public class BackgroundWorkerService extends JobIntentService {
} catch (final Exception exception) {
final boolean retry = false;
LogUtil.e(TAG, "Error in background worker", exception);
if (!(exception instanceof DataModelException)) {
// DataModelException is expected (sort-of) and handled in handleFailureFromWorker
// below, but other exceptions should crash ENG builds
Assert.fail("Unexpected error in background worker - abort");
}
if (retry) {
action.markBackgroundWorkQueued();
startServiceWithAction(action, attempt + 1);
} else {
action.markBackgroundCompletionQueued();
mHost.handleFailureFromBackgroundWorker(action, exception);
}
Assert.fail("Unexpected error in background worker - abort");
action.markBackgroundCompletionQueued();
mHost.handleFailureFromBackgroundWorker(action, exception);
}
}
}
@@ -114,9 +114,6 @@ public class BugleActionToasts {
}
}
public static void onConversationDeleted() {
}
private static void showToast(final int messageResId) {
ThreadUtil.getMainThreadHandler().post(() -> Toast.makeText(getApplicationContext(),
getApplicationContext().getString(messageResId), Toast.LENGTH_LONG).show());
@@ -30,7 +30,6 @@ import com.android.messaging.Factory;
import com.android.messaging.datamodel.BugleDatabaseOperations;
import com.android.messaging.datamodel.BugleNotifications;
import com.android.messaging.datamodel.DataModel;
import com.android.messaging.datamodel.DataModelException;
import com.android.messaging.datamodel.DatabaseHelper;
import com.android.messaging.datamodel.DatabaseHelper.MessageColumns;
import com.android.messaging.datamodel.DatabaseWrapper;
@@ -71,7 +70,7 @@ public class DeleteConversationAction extends Action implements Parcelable {
// telephony database can sometimes be quite slow to delete conversations, so we delete from
// the local DB first, notify the UI, and then delete from telephony.
@Override
protected Bundle doBackgroundWork() throws DataModelException {
protected Bundle doBackgroundWork() {
final DatabaseWrapper db = DataModel.get().getDatabase();
final String conversationId = actionParameters.getString(KEY_CONVERSATION_ID);
@@ -85,8 +84,6 @@ public class DeleteConversationAction extends Action implements Parcelable {
LogUtil.i(TAG, "DeleteConversationAction: Deleted local conversation "
+ conversationId);
BugleActionToasts.onConversationDeleted();
// Remove notifications if necessary
BugleNotifications.update(true /* silent */, null /* conversationId */,
BugleNotifications.UPDATE_MESSAGES);
@@ -34,7 +34,6 @@ import com.android.messaging.Factory;
import com.android.messaging.datamodel.BugleDatabaseOperations;
import com.android.messaging.datamodel.BugleNotifications;
import com.android.messaging.datamodel.DataModel;
import com.android.messaging.datamodel.DataModelException;
import com.android.messaging.datamodel.DatabaseWrapper;
import com.android.messaging.datamodel.MessagingContentProvider;
import com.android.messaging.datamodel.MmsFileProvider;
@@ -211,7 +210,7 @@ public class ProcessDownloadedMmsAction extends Action {
}
@Override
protected Bundle doBackgroundWork() throws DataModelException {
protected Bundle doBackgroundWork() {
final Context context = Factory.get().getApplicationContext();
final int subId = actionParameters.getInt(KEY_SUB_ID, ParticipantData.DEFAULT_SELF_SUB_ID);
final String messageId = actionParameters.getString(KEY_MESSAGE_ID);
@@ -28,7 +28,6 @@ import com.android.messaging.Factory;
import com.android.messaging.datamodel.BugleDatabaseOperations;
import com.android.messaging.datamodel.BugleNotifications;
import com.android.messaging.datamodel.DataModel;
import com.android.messaging.datamodel.DataModelException;
import com.android.messaging.datamodel.DatabaseWrapper;
import com.android.messaging.datamodel.MessagingContentProvider;
import com.android.messaging.datamodel.SyncManager;
@@ -161,7 +160,7 @@ public class ReceiveMmsMessageAction extends Action implements Parcelable {
}
@Override
protected Bundle doBackgroundWork() throws DataModelException {
protected Bundle doBackgroundWork() {
final Context context = Factory.get().getApplicationContext();
final int subId = actionParameters.getInt(KEY_SUB_ID, ParticipantData.DEFAULT_SELF_SUB_ID);
final String transactionId = actionParameters.getString(KEY_TRANSACTION_ID);
@@ -55,10 +55,7 @@ import com.android.messaging.util.PhoneUtils;
import com.android.messaging.widget.WidgetConversationProvider;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ConversationData extends BindableData {
@@ -67,40 +64,6 @@ public class ConversationData extends BindableData {
private static final long LAST_MESSAGE_TIMESTAMP_NaN = -1;
private static final int MESSAGE_COUNT_NaN = -1;
/**
* Takes a conversation id and a list of message ids and computes the positions
* for each message.
*/
public List<Integer> getPositions(final String conversationId, final List<Long> ids) {
final ArrayList<Integer> result = new ArrayList<>();
if (ids.isEmpty()) {
return result;
}
final Cursor c = new ConversationData.ReversedCursor(
DataModel.get().getDatabase().rawQuery(
ConversationMessageData.getConversationMessageIdsQuerySql(),
new String [] { conversationId }));
if (c != null) {
try {
final Set<Long> idsSet = new HashSet<>(ids);
if (c.moveToLast()) {
do {
final long messageId = c.getLong(0);
if (idsSet.contains(messageId)) {
result.add(c.getPosition());
}
} while (c.moveToPrevious());
}
} finally {
c.close();
}
}
Collections.sort(result);
return result;
}
public interface ConversationDataListener {
void onConversationMessagesCursorUpdated(ConversationData data, Cursor cursor,
@Nullable ConversationMessageData newestMessage, boolean isSync);
@@ -477,10 +477,6 @@ public class ConversationMessageData {
return mProtocol == (MessageData.PROTOCOL_SMS);
}
final int getProtocol() {
return mProtocol;
}
public final int getStatus() {
return mStatus;
}
@@ -639,14 +639,6 @@ public class MessageData implements Parcelable {
|| mProtocol == MessageData.PROTOCOL_MMS_PUSH_NOTIFICATION;
}
public static boolean getIsMmsNotification(final int protocol) {
return (protocol == MessageData.PROTOCOL_MMS_PUSH_NOTIFICATION);
}
public final boolean getIsMmsNotification() {
return getIsMmsNotification(mProtocol);
}
public static boolean getIsSms(final int protocol) {
return protocol == (MessageData.PROTOCOL_SMS);
}
@@ -801,10 +793,6 @@ public class MessageData implements Parcelable {
}
}
public final void setRetryStartTimestamp(final long timestamp) {
mRetryStartTimestamp = timestamp;
}
public final void setRawTelephonyStatus(final int rawStatus) {
mRawStatus = rawStatus;
}
@@ -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.
@@ -25,7 +26,6 @@ import com.android.messaging.util.ImageUtils;
import com.android.messaging.util.UriUtil;
public class AvatarRequestDescriptor extends UriImageRequestDescriptor {
final boolean isWearBackground;
public AvatarRequestDescriptor(final Uri uri, final int desiredWidth,
final int desiredHeight) {
@@ -45,7 +45,6 @@ public class AvatarRequestDescriptor extends UriImageRequestDescriptor {
ImageUtils.DEFAULT_CIRCLE_STROKE_COLOR /* circleStrokeColor */);
Assert.isTrue(uri == null || UriUtil.isLocalResourceUri(uri) ||
AvatarUriUtil.isAvatarUri(uri));
this.isWearBackground = isWearBackground;
}
@Override
@@ -79,12 +79,10 @@ public class NetworkUriImageRequest<D extends UriImageRequestDescriptor> extends
return false;
}
@SuppressWarnings("deprecation")
@Override
public Bitmap loadBitmapInternal() throws IOException {
public Bitmap loadBitmapInternal() {
Assert.isNotMainThread();
InputStream inputStream = null;
Bitmap bitmap = null;
HttpURLConnection connection = null;
try {
@@ -109,9 +107,6 @@ public class NetworkUriImageRequest<D extends UriImageRequestDescriptor> extends
"IOException trying to get inputStream for image with url: "
+ mDescriptor.uri, e);
} finally {
if (inputStream != null) {
inputStream.close();
}
if (connection != null) {
connection.disconnect();
}