forked from upstream-mirrors/quik
Remove obsolete checks for API 23
This commit is contained in:
@@ -551,15 +551,11 @@ public class MmsConfig {
|
||||
final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(
|
||||
Context.TELEPHONY_SERVICE);
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
try {
|
||||
Method method = telephonyManager.getClass().getMethod("getLine1NumberForSubscriber", int.class);
|
||||
return (String) method.invoke(telephonyManager, subId);
|
||||
} catch (Exception e) {
|
||||
return telephonyManager.getLine1Number();
|
||||
} else {
|
||||
try {
|
||||
Method method = telephonyManager.getClass().getMethod("getLine1NumberForSubscriber", int.class);
|
||||
return (String) method.invoke(telephonyManager, subId);
|
||||
} catch (Exception e) {
|
||||
return telephonyManager.getLine1Number();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,16 +577,12 @@ public class MmsConfig {
|
||||
|
||||
String nai = "";
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
try {
|
||||
Method method = telephonyManager.getClass().getMethod("getNai", int.class);
|
||||
Method getSlotId = SubscriptionManager.class.getMethod("getSlotId", int.class);
|
||||
nai = (String) method.invoke(telephonyManager, getSlotId.invoke(null, subId));
|
||||
} catch (Exception e) {
|
||||
nai = SystemPropertiesProxy.get(context, "persist.radio.cdma.nai");
|
||||
} else {
|
||||
try {
|
||||
Method method = telephonyManager.getClass().getMethod("getNai", int.class);
|
||||
Method getSlotId = SubscriptionManager.class.getMethod("getSlotId", int.class);
|
||||
nai = (String) method.invoke(telephonyManager, getSlotId.invoke(null, subId));
|
||||
} catch (Exception e) {
|
||||
nai = SystemPropertiesProxy.get(context, "persist.radio.cdma.nai");
|
||||
}
|
||||
}
|
||||
|
||||
Timber.v("MmsConfig.getNai: nai=" + nai);
|
||||
|
||||
@@ -73,24 +73,19 @@ public class MmsConfigManager {
|
||||
public void init(final Context context) {
|
||||
mContext = context;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
mSubscriptionManager = SubscriptionManager.from(context);
|
||||
mSubscriptionManager = SubscriptionManager.from(context);
|
||||
|
||||
// TODO: When this object "finishes" we should unregister.
|
||||
IntentFilter intentFilterLoaded =
|
||||
new IntentFilter("LOADED");
|
||||
// TODO: When this object "finishes" we should unregister.
|
||||
IntentFilter intentFilterLoaded = new IntentFilter("LOADED");
|
||||
|
||||
try {
|
||||
context.registerReceiver(mReceiver, intentFilterLoaded);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
context.registerReceiver(mReceiver, intentFilterLoaded);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
load(context);
|
||||
} else {
|
||||
load(context);
|
||||
}
|
||||
|
||||
load(context);
|
||||
|
||||
// TODO: When this object "finishes" we should unregister by invoking
|
||||
// SubscriptionManager.getInstance(mContext).unregister(mOnSubscriptionsChangedListener);
|
||||
// This is not strictly necessary because it will be unregistered if the
|
||||
@@ -151,39 +146,37 @@ public class MmsConfigManager {
|
||||
*
|
||||
*/
|
||||
private void load(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
List<SubscriptionInfo> subs = mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||
if (subs == null || subs.size() < 1) {
|
||||
Timber.e("MmsConfigManager.load -- empty getActiveSubInfoList");
|
||||
return;
|
||||
}
|
||||
// Load all the mms_config.xml files in a separate map and then swap with the
|
||||
// real map at the end so we don't block anyone sync'd on the real map.
|
||||
final Map<Integer, MmsConfig> newConfigMap = new ArrayMap<Integer, MmsConfig>();
|
||||
for (SubscriptionInfo sub : subs) {
|
||||
Configuration configuration = new Configuration();
|
||||
if (sub.getMcc() == 0 && sub.getMnc() == 0) {
|
||||
Configuration config = mContext.getResources().getConfiguration();
|
||||
configuration.mcc = config.mcc;
|
||||
configuration.mnc = config.mnc;
|
||||
Timber.i("MmsConfigManager.load -- no mcc/mnc for sub: " + sub +
|
||||
" using mcc/mnc from main context: " + configuration.mcc + "/" +
|
||||
configuration.mnc);
|
||||
} else {
|
||||
Timber.i("MmsConfigManager.load -- mcc/mnc for sub: " + sub);
|
||||
List<SubscriptionInfo> subs = mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||
if (subs == null || subs.size() < 1) {
|
||||
Timber.e("MmsConfigManager.load -- empty getActiveSubInfoList");
|
||||
return;
|
||||
}
|
||||
// Load all the mms_config.xml files in a separate map and then swap with the
|
||||
// real map at the end so we don't block anyone sync'd on the real map.
|
||||
final Map<Integer, MmsConfig> newConfigMap = new ArrayMap<Integer, MmsConfig>();
|
||||
for (SubscriptionInfo sub : subs) {
|
||||
Configuration configuration = new Configuration();
|
||||
if (sub.getMcc() == 0 && sub.getMnc() == 0) {
|
||||
Configuration config = mContext.getResources().getConfiguration();
|
||||
configuration.mcc = config.mcc;
|
||||
configuration.mnc = config.mnc;
|
||||
Timber.i("MmsConfigManager.load -- no mcc/mnc for sub: " + sub +
|
||||
" using mcc/mnc from main context: " + configuration.mcc + "/" +
|
||||
configuration.mnc);
|
||||
} else {
|
||||
Timber.i("MmsConfigManager.load -- mcc/mnc for sub: " + sub);
|
||||
|
||||
configuration.mcc = sub.getMcc();
|
||||
configuration.mnc = sub.getMnc();
|
||||
}
|
||||
Context subContext = context.createConfigurationContext(configuration);
|
||||
configuration.mcc = sub.getMcc();
|
||||
configuration.mnc = sub.getMnc();
|
||||
}
|
||||
Context subContext = context.createConfigurationContext(configuration);
|
||||
|
||||
int subId = sub.getSubscriptionId();
|
||||
newConfigMap.put(subId, new MmsConfig(subContext, subId));
|
||||
}
|
||||
synchronized (mSubIdConfigMap) {
|
||||
mSubIdConfigMap.clear();
|
||||
mSubIdConfigMap.putAll(newConfigMap);
|
||||
}
|
||||
int subId = sub.getSubscriptionId();
|
||||
newConfigMap.put(subId, new MmsConfig(subContext, subId));
|
||||
}
|
||||
synchronized (mSubIdConfigMap) {
|
||||
mSubIdConfigMap.clear();
|
||||
mSubIdConfigMap.putAll(newConfigMap);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,18 +87,11 @@ public class MmsNetworkManager implements com.squareup.okhttp.internal.Network {
|
||||
mSubId = subId;
|
||||
|
||||
if (!MmsRequest.useWifi(context)) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
mNetworkRequest = new NetworkRequest.Builder()
|
||||
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
|
||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_MMS)
|
||||
.setNetworkSpecifier(Integer.toString(mSubId))
|
||||
.build();
|
||||
} else {
|
||||
mNetworkRequest = new NetworkRequest.Builder()
|
||||
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
|
||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_MMS)
|
||||
.build();
|
||||
}
|
||||
mNetworkRequest = new NetworkRequest.Builder()
|
||||
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
|
||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_MMS)
|
||||
.setNetworkSpecifier(Integer.toString(mSubId))
|
||||
.build();
|
||||
} else {
|
||||
mNetworkRequest = new NetworkRequest.Builder()
|
||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||
|
||||
@@ -104,12 +104,8 @@ public abstract class MmsRequest {
|
||||
private boolean ensureMmsConfigLoaded() {
|
||||
if (mMmsConfig == null) {
|
||||
final MmsConfig config;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
// Not yet retrieved from mms config manager. Try getting it.
|
||||
config = MmsConfigManager.getInstance().getMmsConfigBySubId(mSubId);
|
||||
} else {
|
||||
config = MmsConfigManager.getInstance().getMmsConfig();
|
||||
}
|
||||
// Not yet retrieved from mms config manager. Try getting it.
|
||||
config = MmsConfigManager.getInstance().getMmsConfigBySubId(mSubId);
|
||||
|
||||
if (config != null) {
|
||||
mMmsConfig = new MmsConfig.Overridden(config, mMmsConfigOverrides);
|
||||
@@ -167,11 +163,7 @@ public abstract class MmsRequest {
|
||||
result = SmsManager.MMS_ERROR_IO_ERROR;
|
||||
} else if (!isDataNetworkAvailable(context, mSubId)) {
|
||||
Timber.e("MmsRequest: in airplane mode or mobile data disabled");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
result = SmsManager.MMS_ERROR_NO_DATA_NETWORK;
|
||||
} else {
|
||||
result = 8;
|
||||
}
|
||||
result = SmsManager.MMS_ERROR_NO_DATA_NETWORK;
|
||||
} else { // Execute
|
||||
long retryDelaySecs = 2;
|
||||
// Try multiple times of MMS HTTP request
|
||||
@@ -268,11 +260,7 @@ public abstract class MmsRequest {
|
||||
fillIn.putExtra("uri", messageUri.toString());
|
||||
}
|
||||
if (result == SmsManager.MMS_ERROR_HTTP_FAILURE && httpStatusCode != 0) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
fillIn.putExtra(SmsManager.EXTRA_MMS_HTTP_STATUS, httpStatusCode);
|
||||
} else {
|
||||
fillIn.putExtra("android.telephony.extra.MMS_HTTP_STATUS", httpStatusCode);
|
||||
}
|
||||
fillIn.putExtra(SmsManager.EXTRA_MMS_HTTP_STATUS, httpStatusCode);
|
||||
}
|
||||
try {
|
||||
if (!succeeded) {
|
||||
|
||||
+13
-15
@@ -16,21 +16,19 @@ class SubscriptionIdChecker {
|
||||
|
||||
// I met a device which does not have Telephony.Mms.SUBSCRIPTION_ID event if it's API Level is 22.
|
||||
private void check(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
Cursor c = null;
|
||||
try {
|
||||
c = SqliteWrapper.query(context, context.getContentResolver(),
|
||||
Telephony.Mms.CONTENT_URI,
|
||||
new String[]{Telephony.Mms.SUBSCRIPTION_ID}, null, null, null);
|
||||
if (c != null) {
|
||||
mCanUseSubscriptionId = true;
|
||||
}
|
||||
} catch (SQLiteException e) {
|
||||
Timber.e("SubscriptionIdChecker.check() fail");
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
Cursor c = null;
|
||||
try {
|
||||
c = SqliteWrapper.query(context, context.getContentResolver(),
|
||||
Telephony.Mms.CONTENT_URI,
|
||||
new String[]{Telephony.Mms.SUBSCRIPTION_ID}, null, null, null);
|
||||
if (c != null) {
|
||||
mCanUseSubscriptionId = true;
|
||||
}
|
||||
} catch (SQLiteException e) {
|
||||
Timber.e("SubscriptionIdChecker.check() fail");
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -539,11 +539,6 @@ public class TransactionService extends Service implements Observer {
|
||||
|
||||
// cancel timer for renewal of lease
|
||||
mServiceHandler.removeMessages(EVENT_CONTINUE_MMS_CONNECTIVITY);
|
||||
if (mConnMgr != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
mConnMgr.stopUsingNetworkFeature(
|
||||
ConnectivityManager.TYPE_MOBILE,
|
||||
"enableMMS");
|
||||
}
|
||||
} finally {
|
||||
releaseWakeLock();
|
||||
}
|
||||
|
||||
@@ -1604,8 +1604,6 @@ public class PduPersister {
|
||||
* Check if read permissions for SMS have been granted
|
||||
*/
|
||||
private boolean checkReadSmsPermissions() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||
|
||||
mContext.checkSelfPermission(Manifest.permission.READ_SMS) ==
|
||||
PackageManager.PERMISSION_GRANTED;
|
||||
return mContext.checkSelfPermission(Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ object SmsManagerFactory {
|
||||
fun createSmsManager(subscriptionId: Int): SmsManager {
|
||||
var manager: SmsManager? = null
|
||||
|
||||
if (subscriptionId != -1 && Build.VERSION.SDK_INT >= 22) {
|
||||
if (subscriptionId != -1) {
|
||||
try {
|
||||
manager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId)
|
||||
} catch (e: Exception) {
|
||||
|
||||
@@ -59,14 +59,9 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static <T> T ensureRouteToMmsNetwork(Context context, String url, String proxy, Task<T> task) throws IOException {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
return ensureRouteToMmsNetworkMarshmallow(context, task);
|
||||
} else {
|
||||
return ensureRouteToMmsNetworkLollipop(context, task);
|
||||
}
|
||||
return ensureRouteToMmsNetworkMarshmallow(context, task);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
private static <T> T ensureRouteToMmsNetworkMarshmallow(Context context, Task<T> task) throws IOException {
|
||||
final MmsNetworkManager networkManager = new MmsNetworkManager(context.getApplicationContext(), Utils.getDefaultSubscriptionId());
|
||||
final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
@@ -85,24 +80,6 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private static <T> T ensureRouteToMmsNetworkLollipop(Context context, Task<T> task) throws IOException {
|
||||
final MmsNetworkManager networkManager = new MmsNetworkManager(context.getApplicationContext(), Utils.getDefaultSubscriptionId());
|
||||
Network network = null;
|
||||
try {
|
||||
network = networkManager.acquireNetwork();
|
||||
ConnectivityManager.setProcessDefaultNetwork(network);
|
||||
return task.run();
|
||||
} catch (MmsNetworkException e) {
|
||||
throw new IOException(e);
|
||||
} finally {
|
||||
if (network != null) {
|
||||
ConnectivityManager.setProcessDefaultNetwork(null);
|
||||
}
|
||||
networkManager.releaseNetwork();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the host MMSC is reachable
|
||||
*
|
||||
@@ -381,10 +358,6 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static int getDefaultSubscriptionId() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
return SmsManager.getDefaultSmsSubscriptionId();
|
||||
} else {
|
||||
return DEFAULT_SUBSCRIPTION_ID;
|
||||
}
|
||||
return SmsManager.getDefaultSmsSubscriptionId();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user