Messaging: Remove unused or not required classes and methods

Change-Id: I28ebaecc503ee58c74fc8081162777f861dd4516
This commit is contained in:
Michael W
2025-05-18 09:18:48 +00:00
parent f0b25f0760
commit 2f9b1386f8
20 changed files with 10 additions and 475 deletions
-140
View File
@@ -52,19 +52,16 @@ import android.text.TextUtils;
import com.android.messaging.Factory;
import com.android.messaging.R;
import com.android.messaging.datamodel.MediaScratchFileProvider;
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.mmslib.SqliteWrapper;
import com.android.messaging.mmslib.pdu.PduComposer;
import com.android.messaging.mmslib.pdu.PduPersister;
import com.android.messaging.sms.SmsSender.SendResult;
import com.android.messaging.util.Assert;
import com.android.messaging.util.BugleGservicesKeys;
import com.android.messaging.util.BuglePrefs;
import com.android.messaging.util.DebugUtils;
import com.android.messaging.util.EmailAddress;
import com.android.messaging.util.ImageUtils;
import com.android.messaging.util.ImageUtils.ImageResizer;
@@ -73,10 +70,7 @@ import com.android.messaging.util.MediaMetadataRetrieverWrapper;
import com.android.messaging.util.PhoneUtils;
import com.google.common.base.Joiner;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@@ -87,7 +81,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
/**
* Utils for sending sms/mms messages.
@@ -277,10 +270,6 @@ public class MmsUtils {
private static final String sSmilNonVisualAttachmentsWithText = sSmilTextOnly;
public static final String MMS_DUMP_PREFIX = "mmsdump-";
public static final String SMS_DUMP_PREFIX = "smsdump-";
public static final int MIN_VIDEO_BYTES_PER_SECOND = 4 * 1024;
public static final int MIN_IMAGE_BYTE_SIZE = 16 * 1024;
public static final int MAX_VIDEO_ATTACHMENT_COUNT = 1;
@@ -1396,43 +1385,6 @@ public class MmsUtils {
return sHasSmsDateSentColumn;
}
private static final String[] TEST_CARRIERS_PROJECTION =
new String[] { Telephony.Carriers.MMSC };
private static Boolean sUseSystemApn = null;
/**
* Check if we can access the APN data in the Telephony provider. Access was restricted in
* JB MR1 (and some JB MR2) devices. If we can't access the APN, we have to fall back and use
* a private table in our own app.
*
* @return Whether we can access the system APN table
*/
public static boolean useSystemApnTable() {
if (sUseSystemApn == null) {
Cursor cursor = null;
try {
final Context context = Factory.get().getApplicationContext();
final ContentResolver resolver = context.getContentResolver();
cursor = SqliteWrapper.query(
context,
resolver,
Telephony.Carriers.CONTENT_URI,
TEST_CARRIERS_PROJECTION,
null/*selection*/,
null/*selectionArgs*/,
null);
sUseSystemApn = true;
} catch (final SecurityException e) {
LogUtil.w(TAG, "Can't access system APN, using internal table", e);
sUseSystemApn = false;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
return sUseSystemApn;
}
public static final Uri MMS_PART_CONTENT_URI = Uri.parse("content://mms/part");
/**
@@ -1818,15 +1770,6 @@ public class MmsUtils {
return pdu;
}
private static RetrieveConf receiveFromDumpFile(final byte[] data) throws MmsFailureException {
final GenericPdu pdu = parsePduForAnyCarrier(data);
if (pdu == null || !(pdu instanceof RetrieveConf)) {
LogUtil.e(TAG, "receiveFromDumpFile: Parsing retrieved PDU failure");
throw new MmsFailureException(MMS_REQUEST_MANUAL_RETRY, "Failed reading dump file");
}
return (RetrieveConf) pdu;
}
public static StatusPlusUri sendMmsMessage(final Context context, final int subId,
final Uri messageUri, final Bundle extras) {
int status = MMS_REQUEST_MANUAL_RETRY;
@@ -2241,40 +2184,6 @@ public class MmsUtils {
return resolver.delete(messageUri, null /* selection */, null /* selectionArgs */);
}
public static byte[] createDebugNotificationInd(final String fileName) {
byte[] pduData = null;
try {
final Context context = Factory.get().getApplicationContext();
// Load the message file
final byte[] data = DebugUtils.receiveFromDumpFile(fileName);
final RetrieveConf retrieveConf = receiveFromDumpFile(data);
// Create the notification
final NotificationInd notification = new NotificationInd();
final long expiry = System.currentTimeMillis() / 1000 + 600;
notification.setTransactionId(fileName.getBytes());
notification.setMmsVersion(retrieveConf.getMmsVersion());
notification.setFrom(retrieveConf.getFrom());
notification.setSubject(retrieveConf.getSubject());
notification.setExpiry(expiry);
notification.setMessageSize(data.length);
notification.setMessageClass(retrieveConf.getMessageClass());
final Uri.Builder builder = MediaScratchFileProvider.getUriBuilder();
builder.appendPath(fileName);
final Uri contentLocation = builder.build();
notification.setContentLocation(contentLocation.toString().getBytes());
// Serialize
pduData = new PduComposer(context, notification).make();
if (pduData == null || pduData.length < 1) {
throw new IllegalArgumentException("Empty or zero length PDU data");
}
} catch (final MmsFailureException | InvalidHeaderValueException e) {
// Nothing to do
}
return pduData;
}
public static int mapRawStatusToErrorResourceId(final int bugleStatus, final int rawStatus) {
int stringResId = R.string.message_status_send_failed;
switch (rawStatus) {
@@ -2304,53 +2213,4 @@ public class MmsUtils {
}
return stringResId;
}
/**
* Dump the raw MMS data into a file
*
* @param rawPdu The raw pdu data
* @param pdu The parsed pdu, used to construct a dump file name
*/
public static void dumpPdu(final byte[] rawPdu, final GenericPdu pdu) {
if (rawPdu == null || rawPdu.length < 1) {
return;
}
final String dumpFileName = MmsUtils.MMS_DUMP_PREFIX + getDumpFileId(pdu);
final File dumpFile = DebugUtils.getDebugFile(dumpFileName, true);
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);
}
}
/**
* Get the dump file id based on the parsed PDU
* 1. Use message id if not empty
* 2. Use transaction id if message id is empty
* 3. If all above is empty, use random UUID
*
* @param pdu the parsed PDU
* @return the id of the dump file
*/
private static String getDumpFileId(final GenericPdu pdu) {
String fileId = null;
if (pdu != null && pdu instanceof RetrieveConf) {
final RetrieveConf retrieveConf = (RetrieveConf) pdu;
if (retrieveConf.getMessageId() != null) {
fileId = new String(retrieveConf.getMessageId());
} else if (retrieveConf.getTransactionId() != null) {
fileId = new String(retrieveConf.getTransactionId());
}
}
if (TextUtils.isEmpty(fileId)) {
fileId = UUID.randomUUID().toString();
}
return fileId;
}
}
@@ -1,50 +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.sms;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Hacky way to call the hidden SystemProperties class API
*/
class SystemProperties {
private static Method sSystemPropertiesGetMethod = null;
public static String get(final String name) {
if (sSystemPropertiesGetMethod == null) {
try {
final Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
if (systemPropertiesClass != null) {
sSystemPropertiesGetMethod =
systemPropertiesClass.getMethod("get", String.class);
}
} catch (final ClassNotFoundException | NoSuchMethodException e) {
// Nothing to do
}
}
if (sSystemPropertiesGetMethod != null) {
try {
return (String) sSystemPropertiesGetMethod.invoke(null, name);
} catch (final IllegalArgumentException | InvocationTargetException |
IllegalAccessException e) {
// Nothing to do
}
}
return null;
}
}