mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 09:12:19 +00:00
apntool and ApnDatabase
// FREEBIE
This commit is contained in:
committed by
Moxie Marlinspike
parent
40495a2261
commit
7f51f9fd5b
36
src/org/thoughtcrime/securesms/util/TelephonyUtil.java
Normal file
36
src/org/thoughtcrime/securesms/util/TelephonyUtil.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class TelephonyUtil {
|
||||
private static final String TAG = TelephonyUtil.class.getSimpleName();
|
||||
|
||||
public static String getMccMnc(final Context context) {
|
||||
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
final int configMcc = context.getResources().getConfiguration().mcc;
|
||||
final int configMnc = context.getResources().getConfiguration().mnc;
|
||||
if (tm.getSimState() == TelephonyManager.SIM_STATE_READY) {
|
||||
Log.w(TAG, "Choosing MCC+MNC info from TelephonyManager.getSimOperator()");
|
||||
return tm.getSimOperator();
|
||||
} else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) {
|
||||
Log.w(TAG, "Choosing MCC+MNC info from TelephonyManager.getNetworkOperator()");
|
||||
return tm.getNetworkOperator();
|
||||
} else if (configMcc != 0 && configMnc != 0) {
|
||||
Log.w(TAG, "Choosing MCC+MNC info from current context's Configuration");
|
||||
return String.format("%03d%d",
|
||||
configMcc,
|
||||
configMnc == Configuration.MNC_ZERO ? 0 : configMnc);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getApn(final Context context) {
|
||||
final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
return cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS).getExtraInfo();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user