Example usage for android.telephony SubscriptionManager from

List of usage examples for android.telephony SubscriptionManager from

Introduction

In this page you can find the example usage for android.telephony SubscriptionManager from.

Prototype

@Deprecated
public static SubscriptionManager from(Context context) 

Source Link

Usage

From source file:com.android.mms.ui.MessageUtils.java

public static boolean isLocalNumber(String number) {
    if (number == null) {
        return false;
    }/*from  w w  w .  ja v a2s  .  c  o m*/

    // we don't use Mms.isEmailAddress() because it is too strict for comparing addresses like
    // "foo+caf_=6505551212=tmomail.net@gmail.com",
    // which is the 'from' address from a forwarded email
    // message from Gmail. We don't want to treat "foo+caf
    // =6505551212=tmomail.net@gmail.com" and
    // "6505551212" to be the same.
    if (number.indexOf('@') >= 0) {
        return false;
    }

    List<SubscriptionInfo> subInfoList;
    subInfoList = SubscriptionManager.from(MmsApp.getApplication()).getActiveSubscriptionInfoList();
    if (subInfoList == null || subInfoList.size() == 0) {
        MmsLog.d(TAG, "isLocalNumber SIM not insert");
        return false;
    }
    for (SubscriptionInfo subInfoRecord : subInfoList) {
        // modify BUG_ID:JWYYL-16 chenweihua 20141216 (start)
        /*
        if (PhoneNumberUtils.compare(number, getLocalNumber(subInfoRecord.getSubscriptionId()))) {
           return true;
        }
        */
        if (android.os.SystemProperties.getInt("ro.rgk_brazil_number_match", 0) == 1) {
            if (PhoneNumberUtils.compareWithAreaCode(number,
                    getLocalNumber(subInfoRecord.getSubscriptionId()))) {
                return true;
            }
        } else {
            if (PhoneNumberUtils.compare(number, getLocalNumber(subInfoRecord.getSubscriptionId()))) {
                return true;
            }
        }
        // modify BUG_ID:JWYYL-16 chenweihua 20141216 (end)
    }
    return false;
}

From source file:com.android.mms.ui.MessageUtils.java

public static void setSubIconAndLabel(int subId, String subName, TextView subView) {
    Log.i(TAG, "setSubIconAndLabel subId=" + subId);
    int textColor = 0;
    if (subView == null) {
        return;//from  ww  w  . ja  va 2  s. c  om
    }
    int activeSubCount = SubscriptionManager.from(MmsApp.getApplication()).getActiveSubscriptionInfoCount();

    if (subName == null && activeSubCount > 1) {
        SubscriptionInfo subInfo = SubscriptionManager.from(MmsApp.getApplication())
                .getActiveSubscriptionInfo(subId);
        Log.d(TAG, "subInfo=" + subInfo);
        if (null != subInfo) {
            if ((subInfo.getSimSlotIndex() == SubscriptionManager.SIM_NOT_INSERTED)
                    || (subInfo.getSimSlotIndex() == SubscriptionManager.INVALID_SUBSCRIPTION_ID)) {
                Log.i(TAG, "current not insert sim card");
            } else {
                subName = subInfo.getDisplayName().toString();
                textColor = subInfo.getIconTint();
            }
        } else {
            Log.i(TAG, "subInfo is null ");
        }
    }

    if (subName == null || activeSubCount <= 1) {
        subView.setVisibility(View.GONE);
    } else {
        subView.setVisibility(View.VISIBLE);
        subView.setTextColor(textColor);
        subView.setText(subName);
    }
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

@Override
public void onDestroy() {
    Log.i(TAG, "Destroy");

    commandLooper.quit();/*from w w w  . j a v  a  2  s  . c o m*/
    logLooper.quit();
    statsLooper.quit();

    unregisterReceiver(interactiveStateReceiver);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        unregisterReceiver(powerSaveReceiver);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
        unregisterReceiver(userReceiver);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        unregisterReceiver(idleStateReceiver);
    unregisterReceiver(connectivityChangedReceiver);
    unregisterReceiver(packageAddedReceiver);

    if (phone_state) {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (tm != null) {
            tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
            phone_state = false;
        }
    }

    if (subscriptionsChangedListener != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager sm = SubscriptionManager.from(this);
        sm.removeOnSubscriptionsChangedListener(
                (SubscriptionManager.OnSubscriptionsChangedListener) subscriptionsChangedListener);
        subscriptionsChangedListener = null;
    }

    try {
        if (vpn != null) {
            stopNative(vpn, true, true);
            stopVPN(vpn);
            vpn = null;
            unprepare();
        }
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    jni_done();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);

    super.onDestroy();
}

From source file:com.master.metehan.filtereagle.ServiceSinkhole.java

@Override
public void onDestroy() {
    Log.i(TAG, "Destroy");

    commandLooper.quit();//from ww w  .  ja  v  a2s  .  c o m
    logLooper.quit();
    statsLooper.quit();

    if (registeredInteractiveState) {
        unregisterReceiver(interactiveStateReceiver);
        registeredInteractiveState = false;
    }
    if (registeredPowerSave) {
        unregisterReceiver(powerSaveReceiver);
        registeredPowerSave = false;
    }
    if (registeredUser) {
        unregisterReceiver(userReceiver);
        registeredUser = false;
    }
    if (registeredIdleState) {
        unregisterReceiver(idleStateReceiver);
        registeredIdleState = false;
    }
    if (registeredConnectivityChanged) {
        unregisterReceiver(connectivityChangedReceiver);
        registeredConnectivityChanged = false;
    }
    if (registeredPackageAdded) {
        unregisterReceiver(packageAddedReceiver);
        registeredPackageAdded = false;
    }

    if (phone_state) {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (tm != null) {
            tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
            phone_state = false;
        }
    }

    if (subscriptionsChangedListener != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager sm = SubscriptionManager.from(this);
        sm.removeOnSubscriptionsChangedListener(
                (SubscriptionManager.OnSubscriptionsChangedListener) subscriptionsChangedListener);
        subscriptionsChangedListener = null;
    }

    try {
        if (vpn != null) {
            stopNative(vpn, true, true);
            stopVPN(vpn);
            vpn = null;
            unprepare();
        }
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    jni_done();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);

    super.onDestroy();
}

From source file:com.zhengde163.netguard.ServiceSinkhole.java

@Override
public void onDestroy() {
    Log.i(TAG, "Destroy");

    commandLooper.quit();//from   w w w .  j  a v  a  2s.c  om
    logLooper.quit();
    statsLooper.quit();

    if (registeredInteractiveState) {
        unregisterReceiver(interactiveStateReceiver);
        registeredInteractiveState = false;
    }
    if (registeredPowerSave) {
        unregisterReceiver(powerSaveReceiver);
        registeredPowerSave = false;
    }
    if (registeredUser) {
        unregisterReceiver(userReceiver);
        registeredUser = false;
    }
    if (registeredIdleState) {
        unregisterReceiver(idleStateReceiver);
        registeredIdleState = false;
    }
    if (registeredConnectivityChanged) {
        unregisterReceiver(connectivityChangedReceiver);
        registeredConnectivityChanged = false;
    }
    if (registeredPackageAdded) {
        unregisterReceiver(packageAddedReceiver);
        registeredPackageAdded = false;
    }

    if (phone_state) {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (tm != null) {
            tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
            phone_state = false;
        }
    }

    if (subscriptionsChangedListener != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager sm = SubscriptionManager.from(this);
        sm.removeOnSubscriptionsChangedListener(
                (SubscriptionManager.OnSubscriptionsChangedListener) subscriptionsChangedListener);
        subscriptionsChangedListener = null;
    }

    try {
        if (vpn != null) {
            stopNative(vpn, true, true);
            stopVPN(vpn);
            vpn = null;
            unprepare();
        }
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    jni_done();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);
    Intent localIntent = new Intent();
    localIntent.setClass(this, ServiceSinkhole.class); //???Service
    this.startService(localIntent);
    super.onDestroy();
}

From source file:android_network.hetnet.vpn_service.ServiceSinkhole.java

@Override
public void onDestroy() {
    Log.i(TAG, "Destroy");

    commandLooper.quit();//from   w w w .j a  va2s  . c om
    logLooper.quit();
    statsLooper.quit();

    if (registeredInteractiveState) {
        unregisterReceiver(interactiveStateReceiver);
        registeredInteractiveState = false;
    }
    if (registeredPowerSave) {
        unregisterReceiver(powerSaveReceiver);
        registeredPowerSave = false;
    }
    if (registeredUser) {
        unregisterReceiver(userReceiver);
        registeredUser = false;
    }
    if (registeredIdleState) {
        unregisterReceiver(idleStateReceiver);
        registeredIdleState = false;
    }
    if (registeredConnectivityChanged) {
        unregisterReceiver(connectivityChangedReceiver);
        registeredConnectivityChanged = false;
    }
    if (registeredPackageAdded) {
        unregisterReceiver(packageAddedReceiver);
        registeredPackageAdded = false;
    }

    if (phone_state) {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (tm != null) {
            tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
            phone_state = false;
        }
    }

    if (subscriptionsChangedListener != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager sm = SubscriptionManager.from(this);
        sm.removeOnSubscriptionsChangedListener(
                (SubscriptionManager.OnSubscriptionsChangedListener) subscriptionsChangedListener);
        subscriptionsChangedListener = null;
    }

    try {
        if (vpn != null) {
            stopNative(vpn, true);
            stopVPN(vpn);
            vpn = null;
            unprepare();
        }
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    jni_done();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);

    super.onDestroy();
}

From source file:eu.faircode.netguard.ServiceSinkhole.java

@Override
public void onDestroy() {
    Log.i(TAG, "Destroy");

    commandLooper.quit();//from w  ww .j  av a2  s .co m
    logLooper.quit();
    statsLooper.quit();

    if (registeredInteractiveState) {
        unregisterReceiver(interactiveStateReceiver);
        registeredInteractiveState = false;
    }
    if (registeredPowerSave) {
        unregisterReceiver(powerSaveReceiver);
        registeredPowerSave = false;
    }
    if (registeredUser) {
        unregisterReceiver(userReceiver);
        registeredUser = false;
    }
    if (registeredIdleState) {
        unregisterReceiver(idleStateReceiver);
        registeredIdleState = false;
    }
    if (registeredConnectivityChanged) {
        unregisterReceiver(connectivityChangedReceiver);
        registeredConnectivityChanged = false;
    }
    if (registeredPackageChanged) {
        unregisterReceiver(packageChangedReceiver);
        registeredPackageChanged = false;
    }

    if (phone_state) {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (tm != null) {
            tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
            phone_state = false;
        }
    }

    if (subscriptionsChangedListener != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager sm = SubscriptionManager.from(this);
        sm.removeOnSubscriptionsChangedListener(
                (SubscriptionManager.OnSubscriptionsChangedListener) subscriptionsChangedListener);
        subscriptionsChangedListener = null;
    }

    try {
        if (vpn != null) {
            stopNative(vpn, true);
            stopVPN(vpn);
            vpn = null;
            unprepare();
        }
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    jni_done();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);

    super.onDestroy();
}

From source file:com.android.mms.ui.MessageUtils.java

public static String getMainCardDisplayName() {
    String mainSubDisplayName = "";
    Context ct = MmsApp.getApplication();
    int mainSubId = (int) Settings.System.getLong(ct.getContentResolver(), Settings.System.SMS_SIM_SETTING,
            Settings.System.DEFAULT_SIM_NOT_SET);
    if (mainSubId != Settings.System.DEFAULT_SIM_SETTING_ALWAYS_ASK
            && mainSubId != Settings.System.DEFAULT_SIM_NOT_SET) {
        SubscriptionInfo info = SubscriptionManager.from(MmsApp.getApplication())
                .getActiveSubscriptionInfo(mainSubId);
        mainSubDisplayName = info.getDisplayName().toString();
    } else {//w  w  w.j a v a2  s .  c o m
        SubscriptionInfo info = SubscriptionManager.from(MmsApp.getApplication())
                .getActiveSubscriptionInfo(mainSubId);
        if (info != null && info.getSubscriptionId() > 0) {
            mainSubDisplayName = info.getDisplayName().toString();
        } else {
            info = SubscriptionManager.from(MmsApp.getApplication()).getActiveSubscriptionInfo(mainSubId);
            if (info != null && info.getSubscriptionId() > 0) {
                mainSubDisplayName = info.getDisplayName().toString();
            } else {
                MmsLog.e(TAG, "error to get main sub display name");
            }
        }
    }
    return mainSubDisplayName;
}

From source file:com.android.mms.ui.MessageUtils.java

public static boolean isSimMessageAccessable(Context context, int... subId) {
    // First, forbid to access SIM message if this is not default MMS.
    boolean isSmsEnable = MmsConfig.isSmsEnabled(context);
    if (!isSmsEnable) {
        MmsLog.d(TAG, "isSimMessageAccessable Sms not enabled");
        return false;
    }//from w  w w  .  j  a va 2 s .c  o m

    // Second, check airplane mode
    boolean airplaneOn = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,
            0) == 1;
    if (airplaneOn) {
        MmsLog.d(TAG, "isSimMessageAccessable airplane is On");
        return false;
    }

    // Third, check whether has inserted SIM
    List<SubscriptionInfo> subInfoList = SubscriptionManager.from(MmsApp.getApplication())
            .getActiveSubscriptionInfoList();
    if (subInfoList == null || subInfoList.size() == 0) {
        MmsLog.d(TAG, "isSimMessageAccessable SIM not insert");
        return false;
    }

    // Forth, check sms ready
    ISms mSmsManager = ISms.Stub.asInterface(ServiceManager.getService("isms"));
    if (mSmsManager == null) {
        MmsLog.d(TAG, "isSimMessageAccessable mSmsManager is null");
        return false;
    }
    boolean isSimReady = false;
    try {
        if (subId.length == 1) {
            isSimReady = mSmsManager.isSmsReadyForSubscriber(subId[0]);
        } else {
            for (SubscriptionInfo subInfoRecord : subInfoList) {
                isSimReady = mSmsManager.isSmsReadyForSubscriber(subInfoRecord.getSubscriptionId());
                if (isSimReady) {
                    break;
                }
            }
        }
    } catch (RemoteException e) {
        MmsLog.e(TAG, "isSimMessageAccessable failed to get sms state");
        isSimReady = false;
    }

    MmsLog.d(TAG, "isSimMessageAccessable" + isSimReady);
    return isSimReady;
}

From source file:com.android.mms.ui.MessageUtils.java

public static boolean isSimPresent(Context context) {
    int[] subs = SubscriptionManager.from(context).getActiveSubscriptionIdList();
    if (subs.length == 0) {
        MmsLog.d(TAG, "Sim not present");
        return false;
    } else {/*from w w  w.j av a 2  s .  co  m*/
        MmsLog.d(TAG, "Sim present");
        return true;
    }
}