Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f2f63a17 authored by Qiang Chen's avatar Qiang Chen
Browse files

SystemUI: Add 2G/3G/4G RAT on the SystemUI

 - Add 2G/3G/4G after carrier strings on status bar
 - Add one bool config to control the RAT display
 - Add strings config to add 2G/3G/4G RAT

CRs-fixed: 652834

Change-Id: Ic497ea288a16ba4bcb7cdf93d0f35ce36270d219
parent 85d0f004
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1453,4 +1453,8 @@
    <!-- Should the device show AM/PM in unlock screen -->
    <bool name="config_show_ampm_in_unlock_screen">false</bool>

    <!-- config 2G/3G/4G RAT strings for carriers -->
    <string name="config_rat_2g" translatable="false">2G</string>
    <string name="config_rat_3g" translatable="false">3G</string>
    <string name="config_rat_4g" translatable="false">4G</string>
</resources>
+4 −0
Original line number Diff line number Diff line
@@ -1826,4 +1826,8 @@
  <!-- From keyguard for showing am/pm in unlock screen -->
  <java-symbol type="bool" name="config_show_ampm_in_unlock_screen" />

  <!-- config 2G/3G/4G RAT strings for carriers -->
  <java-symbol type="string" name="config_rat_2g" />
  <java-symbol type="string" name="config_rat_3g" />
  <java-symbol type="string" name="config_rat_4g" />
</resources>
+6 −0
Original line number Diff line number Diff line
@@ -100,6 +100,9 @@
        <item>中国移动</item>
        <item>中国联通</item>
        <item>中国电信</item>
        <item>中國移動</item>
        <item>中國聯通</item>
        <item>中國電信</item>
        <item>Searching for Service</item>
    </string-array>

@@ -112,6 +115,9 @@
        <item>China_Mobile</item>
        <item>China_Unicom</item>
        <item>China_Telecom</item>
        <item>China_Mobile</item>
        <item>China_Unicom</item>
        <item>China_Telecom</item>
        <item>roamingTextSearching</item>
    </string-array>
</resources>
+61 −53
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ public class KeyguardUpdateMonitor {
    private CharSequence []mTelephonySpn;
    private CharSequence []mOriginalTelephonyPlmn;
    private CharSequence []mOriginalTelephonySpn;
    private ServiceState []mServiceState;
    private int mRingMode;
    private int mPhoneState;
    private boolean mKeyguardIsVisible;
@@ -286,8 +287,8 @@ public class KeyguardUpdateMonitor {
                // Update PLMN and SPN for corresponding subscriptions.
                mTelephonyPlmn[subscription] = getTelephonyPlmnFrom(intent);
                mTelephonySpn[subscription] = getTelephonySpnFrom(intent);
                mOriginalTelephonyPlmn[subscription] = getTelephonyPlmnFrom(intent);
                mOriginalTelephonySpn[subscription] = getTelephonySpnFrom(intent);
                mOriginalTelephonyPlmn[subscription] = mTelephonyPlmn[subscription];
                mOriginalTelephonySpn[subscription] = mTelephonySpn[subscription];
                mShowSpn[subscription] = intent.getBooleanExtra(
                        TelephonyIntents.EXTRA_SHOW_SPN, false);
                mShowPlmn[subscription] = intent.getBooleanExtra(
@@ -328,20 +329,30 @@ public class KeyguardUpdateMonitor {
            } else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
                dispatchBootCompleted();
            } else if (TelephonyIntents.ACTION_SERVICE_STATE_CHANGED.equals(action)) {
                ServiceState state = ServiceState.newFromBundle(intent.getExtras());
                int sub = intent.getIntExtra(MSimConstants.SUBSCRIPTION_KEY, MSimConstants.SUB1);
                mServiceState[sub] = ServiceState.newFromBundle(intent.getExtras());
                Log.d(TAG, "ACTION_SERVICE_STATE_CHANGED on sub: " + sub + " showSpn:" +
                        mShowSpn[sub] + " showPlmn:" + mShowPlmn[sub]);
                //display 2G/3G/4G if operator ask for showing radio tech
                if (mContext.getResources().getBoolean(R.bool.config_display_RAT)
                        && (ServiceState.STATE_IN_SERVICE == state.getDataRegState()
                        || ServiceState.STATE_IN_SERVICE == state.getVoiceRegState())) {
                    concatenate(mShowSpn[sub], mShowPlmn[sub], sub, state);
                        mShowSpn[sub] + " showPlmn:" + mShowPlmn[sub] + " mServiceState: "
                        + mServiceState[sub]);

                //display 2G/3G/4G if operator ask for showing radio tech
                if ((mServiceState[sub] != null) && (mServiceState[sub].getDataRegState() ==
                        ServiceState.STATE_IN_SERVICE || mServiceState[sub].getVoiceRegState()
                        == ServiceState.STATE_IN_SERVICE) && mContext.getResources().getBoolean
                        (R.bool.config_display_RAT)) {
                    final Message msg = mHandler.obtainMessage(MSG_CARRIER_INFO_UPDATE);
                    msg.arg1 = sub;
                    mHandler.sendMessage(msg);
                }
            } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
                Log.d(TAG, "Received CONFIGURATION_CHANGED intent");
                if (mContext.getResources().getBoolean(R.bool.config_monitor_locale_change)) {
                    for (int i = 0; i < MSimTelephonyManager.getDefault().getPhoneCount(); i++) {
                        final Message msg = mHandler.obtainMessage(MSG_CARRIER_INFO_UPDATE);
                        msg.arg1 = i;
                        mHandler.sendMessage(msg);
                    }
                }
            }
        }
    };
@@ -349,10 +360,11 @@ public class KeyguardUpdateMonitor {
    private void concatenate(boolean showSpn, boolean showPlmn, int sub, ServiceState state) {
        String rat = getRadioTech(state, sub);
        if (showSpn) {
            mTelephonySpn[sub] = new StringBuilder().append(mOriginalTelephonySpn[sub]).append(rat)
            mTelephonySpn[sub] = new StringBuilder().append(mTelephonySpn[sub]).append(rat)
                    .toString();
        } else if (showPlmn) {
            mTelephonyPlmn[sub] = new StringBuilder().append(mOriginalTelephonyPlmn[sub]).append
        }
        if (showPlmn) {
            mTelephonyPlmn[sub] = new StringBuilder().append(mTelephonyPlmn[sub]).append
                    (rat).toString();
        }
    }
@@ -362,53 +374,19 @@ public class KeyguardUpdateMonitor {
        int networkType = 0;
        Log.d(TAG, "dataRegState = " + serviceState.getDataRegState() + " voiceRegState = "
                + serviceState.getVoiceRegState() + " sub = " + sub);
        if (ServiceState.STATE_IN_SERVICE == serviceState.getDataRegState()
                && ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN
                != serviceState.getRadioTechnology()) {
        if (serviceState.getRilDataRadioTechnology() != ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN) {
            networkType = serviceState.getDataNetworkType();
            radioTech = new StringBuilder().append(" ").append(networkTypeToString(networkType))
                    .toString();
        } else if (ServiceState.STATE_IN_SERVICE == serviceState.getVoiceRegState()
                && ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN
                != serviceState.getRilVoiceRadioTechnology()) {
            radioTech = new StringBuilder().append(" ").append(TelephonyManager.from(mContext).
                    networkTypeToString(networkType)).toString();
        } else if (serviceState.getRilVoiceRadioTechnology() != ServiceState.
                RIL_RADIO_TECHNOLOGY_UNKNOWN) {
            networkType = serviceState.getVoiceNetworkType();
            radioTech = new StringBuilder().append(" ").append(networkTypeToString(networkType))
                    .toString();
            radioTech = new StringBuilder().append(" ").append(TelephonyManager.from(mContext).
                    networkTypeToString(networkType)).toString();
        }
        return radioTech;
    }

    /**
     * Convert network type to String
     *
     * @param networkType
     * @return String representation of the NetworkType
     *
     */
    private String networkTypeToString(int networkType) {
        String ratClassName = "";
        int networkClass = TelephonyManager.getNetworkClass(networkType);
        Log.d(TAG, "networkType = " + networkType + " networkClass = " + networkClass);
        switch (networkClass) {
            case TelephonyManager.NETWORK_CLASS_UNKNOWN:
                ratClassName = "";
                break;
            case TelephonyManager.NETWORK_CLASS_2_G:
                ratClassName = "2G";
                break;
            case TelephonyManager.NETWORK_CLASS_3_G:
                ratClassName = "3G";
                break;
            case TelephonyManager.NETWORK_CLASS_4_G:
                ratClassName = "4G";
                break;
            default:
                ratClassName = "";
                break;
        }
        return ratClassName;
    }

    private final BroadcastReceiver mBroadcastAllReceiver = new BroadcastReceiver() {

        public void onReceive(Context context, Intent intent) {
@@ -641,6 +619,7 @@ public class KeyguardUpdateMonitor {
        mTelephonySpn = new CharSequence[numPhones];
        mOriginalTelephonyPlmn = new CharSequence[numPhones];
        mOriginalTelephonySpn = new CharSequence[numPhones];
        mServiceState = new ServiceState[numPhones];
        mSimState = new IccCardConstants.State[numPhones];
        for (int i = 0; i < numPhones; i++) {
            mTelephonyPlmn[i] = getDefaultPlmn();
@@ -657,6 +636,7 @@ public class KeyguardUpdateMonitor {
        filter.addAction(Intent.ACTION_TIME_CHANGED);
        filter.addAction(Intent.ACTION_BATTERY_CHANGED);
        filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
        filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
        filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
        filter.addAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
@@ -902,6 +882,26 @@ public class KeyguardUpdateMonitor {
     * Handle {@link #MSG_CARRIER_INFO_UPDATE}
     */
    private void handleCarrierInfoUpdate(int subscription) {
        if (mContext.getResources().getBoolean(R.bool.config_monitor_locale_change)) {
            if (mOriginalTelephonyPlmn[subscription] != null) {
                mTelephonyPlmn[subscription] = getLocaleString(
                        mOriginalTelephonyPlmn[subscription].toString());
            }
            if (mOriginalTelephonySpn[subscription] != null) {
                mTelephonySpn[subscription] = getLocaleString(
                        mOriginalTelephonySpn[subscription].toString());
            }
        }

        //display 2G/3G/4G if operator ask for showing radio tech
        if ((mServiceState[subscription] != null) && (mServiceState[subscription].getDataRegState()
                == ServiceState.STATE_IN_SERVICE || mServiceState[subscription].getVoiceRegState()
                == ServiceState.STATE_IN_SERVICE) && mContext.getResources().getBoolean(
                        R.bool.config_display_RAT)) {
            concatenate(mShowSpn[subscription], mShowPlmn[subscription], subscription,
                    mServiceState[subscription]);
        }

        if (DEBUG) Log.d(TAG, "handleCarrierInfoUpdate: plmn = " + mTelephonyPlmn[subscription]
                + ", spn = " + mTelephonySpn[subscription] + ", subscription = " + subscription);
        for (int i = 0; i < mCallbacks.size(); i++) {
@@ -918,6 +918,14 @@ public class KeyguardUpdateMonitor {
        }
    }

    private String getLocaleString(String networkName) {
        networkName = android.util.NativeTextHelper.getInternalLocalString(mContext,
                networkName,
                R.array.origin_carrier_names,
                R.array.locale_carrier_names);
        return networkName;
    }

    /**
     * Handle {@link #MSG_SIM_STATE_CHANGE}
     */
+5 −0
Original line number Diff line number Diff line
@@ -202,4 +202,9 @@
    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"亮度"</string>
    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"自動"</string>
    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"網絡可能會\n受到監控"</string>

    <string name="China_Mobile">中國移動</string>
    <string name="China_Unicom">中國聯通</string>
    <string name="China_Telecom">中國電信</string>
    <string name="roamingTextSearching">"正在搜索服務"</string>
</resources>
Loading