Messaging: Remove compatibility for old android versions

Change-Id: Id9065d60525a509271a0e64c0e349e857cb998e2
This commit is contained in:
Michael W
2024-12-26 14:55:12 +01:00
parent 9bbc7a8f99
commit 7c55a6d56a
104 changed files with 580 additions and 2306 deletions
@@ -34,7 +34,6 @@ import com.android.messaging.mmslib.SqliteWrapper;
import com.android.messaging.util.BugleGservices;
import com.android.messaging.util.BugleGservicesKeys;
import com.android.messaging.util.LogUtil;
import com.android.messaging.util.OsUtil;
import com.android.messaging.util.PhoneUtils;
import java.net.URI;
@@ -384,7 +383,7 @@ public class BugleApnSettingsLoader implements ApnSettingsLoader {
*/
private void loadFromSystem(final int subId, final String apnName, final List<Apn> apns) {
Uri uri;
if (OsUtil.isAtLeastL_MR1() && subId != MmsManager.DEFAULT_SUB_ID) {
if (subId != MmsManager.DEFAULT_SUB_ID) {
uri = Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "/subId/" + subId);
} else {
uri = Telephony.Carriers.CONTENT_URI;
@@ -27,7 +27,6 @@ import android.util.SparseArray;
import com.android.messaging.R;
import com.android.messaging.util.LogUtil;
import com.android.messaging.util.OsUtil;
import com.android.messaging.util.PhoneUtils;
/**
@@ -93,12 +92,9 @@ public class BugleCarrierConfigValuesLoader implements CarrierConfigValuesLoader
private String loadLocked(final int subId, final Bundle values) {
// Load from resources in earlier platform
loadFromResources(subId, values);
if (OsUtil.isAtLeastL()) {
// Load from system to override if system API exists
loadFromSystem(subId, values);
return "resources+system";
}
return "resources";
// Load from system to override if system API exists
loadFromSystem(subId, values);
return "resources+system";
}
/**
@@ -158,9 +154,6 @@ public class BugleCarrierConfigValuesLoader implements CarrierConfigValuesLoader
* @return the sub-dependent Context
*/
private static Context getSubDepContext(final Context context, final int subId) {
if (!OsUtil.isAtLeastL_MR1()) {
return context;
}
final int[] mccMnc = PhoneUtils.get(subId).getMccMnc();
final int mcc = mccMnc[0];
final int mnc = mccMnc[1];
@@ -25,7 +25,6 @@ import android.text.TextUtils;
import com.android.messaging.util.BugleGservices;
import com.android.messaging.util.BugleGservicesKeys;
import com.android.messaging.util.LogUtil;
import com.android.messaging.util.OsUtil;
import com.android.messaging.util.VersionUtil;
/**
@@ -75,13 +74,11 @@ public class BugleUserAgentInfoLoader implements UserAgentInfoLoader {
}
private void loadLocked() {
if (OsUtil.isAtLeastKLP()) {
// load the MMS User agent and UaProfUrl from TelephonyManager APIs
final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(
Context.TELEPHONY_SERVICE);
mUserAgent = telephonyManager.getMmsUserAgent();
mUAProfUrl = telephonyManager.getMmsUAProfUrl();
}
// load the MMS User agent and UaProfUrl from TelephonyManager APIs
final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(
Context.TELEPHONY_SERVICE);
mUserAgent = telephonyManager.getMmsUserAgent();
mUAProfUrl = telephonyManager.getMmsUAProfUrl();
// if user agent string isn't set, use the format "Bugle/<app_version>".
if (TextUtils.isEmpty(mUserAgent)) {
final String simpleVersionName = VersionUtil.getInstance(mContext).getSimpleName();
@@ -37,11 +37,9 @@ 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.Assert;
import com.android.messaging.util.ContentType;
import com.android.messaging.util.LogUtil;
import com.android.messaging.util.MediaMetadataRetrieverWrapper;
import com.android.messaging.util.OsUtil;
import com.android.messaging.util.PhoneUtils;
import com.google.common.collect.Lists;
@@ -120,12 +118,6 @@ public class DatabaseMessages {
if (!MmsUtils.hasSmsDateSentColumn()) {
projection[INDEX_DATE_SENT] = Sms.DATE;
}
if (!OsUtil.isAtLeastL_MR1()) {
Assert.equals(INDEX_SUB_ID, projection.length - 1);
String[] withoutSubId = new String[projection.length - 1];
System.arraycopy(projection, 0, withoutSubId, 0, withoutSubId.length);
projection = withoutSubId;
}
sProjection = projection;
}
@@ -307,13 +299,6 @@ public class DatabaseMessages {
Mms.SUBSCRIPTION_ID,
};
if (!OsUtil.isAtLeastL_MR1()) {
Assert.equals(INDEX_SUB_ID, projection.length - 1);
String[] withoutSubId = new String[projection.length - 1];
System.arraycopy(projection, 0, withoutSubId, 0, withoutSubId.length);
projection = withoutSubId;
}
sProjection = projection;
}
@@ -722,11 +707,6 @@ public class DatabaseMessages {
* Load video file of a video part and parse the dimensions and type
*/
private void loadVideo() {
// This is a coarse check, and should not be applied to outgoing messages. However,
// currently, this does not cause any problems.
if (!VideoThumbnailRequest.shouldShowIncomingVideoThumbnails()) {
return;
}
final Uri uri = getDataUri();
final MediaMetadataRetrieverWrapper retriever = new MediaMetadataRetrieverWrapper();
try {
+11 -18
View File
@@ -25,7 +25,6 @@ import com.android.messaging.Factory;
import com.android.messaging.datamodel.data.ParticipantData;
import com.android.messaging.util.Assert;
import com.android.messaging.util.LogUtil;
import com.android.messaging.util.OsUtil;
import com.android.messaging.util.PhoneUtils;
import com.android.messaging.util.SafeAsyncTask;
import com.google.common.collect.Maps;
@@ -151,27 +150,21 @@ public class MmsConfig {
// Rebuild the entire MmsConfig map.
sSubIdToMmsConfigMap.clear();
loader.reset();
if (OsUtil.isAtLeastL_MR1()) {
final List<SubscriptionInfo> subInfoRecords =
PhoneUtils.getDefault().toLMr1().getActiveSubscriptionInfoList();
if (subInfoRecords == null) {
LogUtil.w(TAG, "Loading mms config failed: no active SIM");
return;
}
for (SubscriptionInfo subInfoRecord : subInfoRecords) {
final int subId = subInfoRecord.getSubscriptionId();
final Bundle values = loader.get(subId);
addMmsConfig(new MmsConfig(subId, values));
}
} else {
final Bundle values = loader.get(ParticipantData.DEFAULT_SELF_SUB_ID);
addMmsConfig(new MmsConfig(ParticipantData.DEFAULT_SELF_SUB_ID, values));
final List<SubscriptionInfo> subInfoRecords =
PhoneUtils.getDefault().getActiveSubscriptionInfoList();
if (subInfoRecords == null) {
LogUtil.w(TAG, "Loading mms config failed: no active SIM");
return;
}
for (SubscriptionInfo subInfoRecord : subInfoRecords) {
final int subId = subInfoRecord.getSubscriptionId();
final Bundle values = loader.get(subId);
addMmsConfig(new MmsConfig(subId, values));
}
}
private static void addMmsConfig(MmsConfig mmsConfig) {
Assert.isTrue(OsUtil.isAtLeastL_MR1() !=
(mmsConfig.mSubId == ParticipantData.DEFAULT_SELF_SUB_ID));
Assert.isTrue(mmsConfig.mSubId != ParticipantData.DEFAULT_SELF_SUB_ID);
sSubIdToMmsConfigMap.put(mmsConfig.mSubId, mmsConfig);
}
+21 -80
View File
@@ -76,7 +76,6 @@ import com.android.messaging.util.ImageUtils;
import com.android.messaging.util.ImageUtils.ImageResizer;
import com.android.messaging.util.LogUtil;
import com.android.messaging.util.MediaMetadataRetrieverWrapper;
import com.android.messaging.util.OsUtil;
import com.android.messaging.util.PhoneUtils;
import com.google.common.base.Joiner;
@@ -869,9 +868,7 @@ public class MmsUtils {
values.put(Telephony.Sms.SEEN, seen ? 1 : 0);
values.put(Telephony.Sms.SUBJECT, subject);
values.put(Telephony.Sms.BODY, body);
if (OsUtil.isAtLeastL_MR1()) {
values.put(Telephony.Sms.SUBSCRIPTION_ID, subId);
}
values.put(Telephony.Sms.SUBSCRIPTION_ID, subId);
if (status != Telephony.Sms.STATUS_NONE) {
values.put(Telephony.Sms.STATUS, status);
}
@@ -1156,9 +1153,7 @@ public class MmsUtils {
public static SmsMessage getSmsMessageFromDeliveryReport(final Intent intent) {
final byte[] pdu = intent.getByteArrayExtra("pdu");
final String format = intent.getStringExtra("format");
return OsUtil.isAtLeastM()
? SmsMessage.createFromPdu(pdu, format)
: SmsMessage.createFromPdu(pdu);
return SmsMessage.createFromPdu(pdu, format);
}
/**
@@ -1520,27 +1515,22 @@ public class MmsUtils {
// For the internal debugger only
public static void setUseSystemApnTable(final boolean turnOn) {
if (!turnOn) {
// We're not turning on to the system table. Instead, we're using our internal table.
final int osVersion = OsUtil.getApiVersion();
if (osVersion != android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
// We're turning on local APNs on a device where we wouldn't normally have the
// local APN table. Build it here.
// We're turning on local APNs on a device where we wouldn't normally have the
// local APN table. Build it here.
final SQLiteDatabase database = ApnDatabase.getApnDatabase().getWritableDatabase();
final SQLiteDatabase database = ApnDatabase.getApnDatabase().getWritableDatabase();
// Do we already have the table?
Cursor cursor = null;
try {
cursor = database.query(ApnDatabase.APN_TABLE,
ApnDatabase.APN_PROJECTION,
null, null, null, null, null, null);
} catch (final Exception e) {
// Apparently there's no table, create it now.
ApnDatabase.forceBuildAndLoadApnTables();
} finally {
if (cursor != null) {
cursor.close();
}
// Do we already have the table?
Cursor cursor = null;
try {
cursor = database.query(ApnDatabase.APN_TABLE,
ApnDatabase.APN_PROJECTION,
null, null, null, null, null, null);
} catch (final Exception e) {
// Apparently there's no table, create it now.
ApnDatabase.forceBuildAndLoadApnTables();
} finally {
if (cursor != null) {
cursor.close();
}
}
}
@@ -1812,14 +1802,6 @@ public class MmsUtils {
return new StatusPlusUri(
MMS_REQUEST_NO_RETRY, MessageData.RAW_TELEPHONY_STATUS_UNDEFINED, null);
}
if (!isMmsDataAvailable(subId)) {
LogUtil.e(TAG,
"MmsUtils: failed to download message, no data available");
return new StatusPlusUri(MMS_REQUEST_MANUAL_RETRY,
MessageData.RAW_TELEPHONY_STATUS_UNDEFINED,
null,
SmsManager.MMS_ERROR_NO_DATA_NETWORK);
}
int status = MMS_REQUEST_MANUAL_RETRY;
try {
RetrieveConf retrieveConf = null;
@@ -1837,14 +1819,10 @@ public class MmsUtils {
LogUtil.d(TAG, "MmsUtils: Downloading MMS via MMS lib API; notification "
+ "message: " + notificationUri);
}
if (OsUtil.isAtLeastL_MR1()) {
if (subId < 0) {
LogUtil.e(TAG, "MmsUtils: Incoming MMS came from unknown SIM");
throw new MmsFailureException(MMS_REQUEST_NO_RETRY,
"Message from unknown SIM");
}
} else {
Assert.isTrue(subId == ParticipantData.DEFAULT_SELF_SUB_ID);
if (subId < 0) {
LogUtil.e(TAG, "MmsUtils: Incoming MMS came from unknown SIM");
throw new MmsFailureException(MMS_REQUEST_NO_RETRY,
"Message from unknown SIM");
}
if (extras == null) {
extras = new Bundle();
@@ -1943,10 +1921,6 @@ public class MmsUtils {
LogUtil.w(TAG, "MmsUtils: Can't send NotifyResp; transaction id is null");
return;
}
if (!isMmsDataAvailable(subId)) {
LogUtil.w(TAG, "MmsUtils: Can't send NotifyResp; no data available");
return;
}
MmsSender.sendNotifyResponseForMmsDownload(
context, subId, transactionId, contentLocation, status);
} catch (final MmsFailureException e) {
@@ -1973,10 +1947,6 @@ public class MmsUtils {
LogUtil.w(TAG, "MmsUtils: Can't send AckInd; transaction id is null");
return;
}
if (!isMmsDataAvailable(subId)) {
LogUtil.w(TAG, "MmsUtils: Can't send AckInd; no data available");
return;
}
MmsSender.sendAcknowledgeForMmsDownload(context, subId, transactionId, contentLocation);
} catch (final MmsFailureException e) {
LogUtil.e(TAG, "sendAcknowledgeForMmsDownload: failed to retrieve message " + e, e);
@@ -2021,35 +1991,10 @@ public class MmsUtils {
return (RetrieveConf) pdu;
}
private static boolean isMmsDataAvailable(final int subId) {
if (OsUtil.isAtLeastL_MR1()) {
// L_MR1 above may support sending mms via wifi
return true;
}
final PhoneUtils phoneUtils = PhoneUtils.get(subId);
return !phoneUtils.isAirplaneModeOn() && phoneUtils.isMobileDataEnabled();
}
private static boolean isSmsDataAvailable(final int subId) {
if (OsUtil.isAtLeastL_MR1()) {
// L_MR1 above may support sending sms via wifi
return true;
}
final PhoneUtils phoneUtils = PhoneUtils.get(subId);
return !phoneUtils.isAirplaneModeOn();
}
public static StatusPlusUri sendMmsMessage(final Context context, final int subId,
final Uri messageUri, final Bundle extras) {
int status = MMS_REQUEST_MANUAL_RETRY;
int rawStatus = MessageData.RAW_TELEPHONY_STATUS_UNDEFINED;
if (!isMmsDataAvailable(subId)) {
LogUtil.w(TAG, "MmsUtils: failed to send message, no data available");
return new StatusPlusUri(MMS_REQUEST_MANUAL_RETRY,
MessageData.RAW_TELEPHONY_STATUS_UNDEFINED,
messageUri,
SmsManager.MMS_ERROR_NO_DATA_NETWORK);
}
final PduPersister persister = PduPersister.getPduPersister(context);
try {
final SendReq sendReq = (SendReq) persister.load(messageUri);
@@ -2460,10 +2405,6 @@ public class MmsUtils {
public static int sendSmsMessage(final String recipient, final String messageText,
final Uri requestUri, final int subId,
final String smsServiceCenter, final boolean requireDeliveryReport) {
if (!isSmsDataAvailable(subId)) {
LogUtil.w(TAG, "MmsUtils: can't send SMS without radio");
return MMS_REQUEST_MANUAL_RETRY;
}
final Context context = Factory.get().getApplicationContext();
int status = MMS_REQUEST_MANUAL_RETRY;
try {