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

Commit af060eee authored by Pavel Zhamaitsiak's avatar Pavel Zhamaitsiak
Browse files

Don't use overlays for WFC error messages and SPN formats

- Error alert and notification messages are stored as string arrays in
  resources. CarrierConfig stores carrier-specific error codes and corresponding
  index which is used to get appropriate messages.
- Supported SPN formats are stored as string arrays in resources. CarrierConfig
  stores index used to get appropriate SPN format.

Bug: 27170754
Change-Id: I7f3635ec0ae73d6190b4b73b11ad13058fc25d54
parent d4e4c8b5
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -2214,10 +2214,29 @@ public class ServiceStateTracker extends Handler {
                    && mPhone.getImsPhone() != null
                    && mPhone.getImsPhone().isWifiCallingEnabled()) {
                // In Wi-Fi Calling mode show SPN+WiFi
                String formatVoice = mPhone.getContext().getText(
                        com.android.internal.R.string.wfcSpnFormat).toString();
                String formatData = mPhone.getContext().getText(
                        com.android.internal.R.string.wfcDataSpnFormat).toString();

                final String[] wfcSpnFormats =
                        mPhone.getContext().getResources().getStringArray(
                                com.android.internal.R.array.wfcSpnFormats);
                int voiceIdx = 0;
                int dataIdx = 0;
                CarrierConfigManager configLoader = (CarrierConfigManager)
                        mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
                if (configLoader != null) {
                    try {
                        PersistableBundle b = configLoader.getConfig(mPhone.getSubId());
                        if (b != null) {
                            voiceIdx = b.getInt(CarrierConfigManager.KEY_WFC_SPN_FORMAT_IDX_INT);
                            dataIdx = b.getInt(
                                    CarrierConfigManager.KEY_WFC_DATA_SPN_FORMAT_IDX_INT);
                        }
                    } catch (Exception e) {
                        loge("updateSpnDisplay: carrier config error: " + e);
                    }
                }

                String formatVoice = wfcSpnFormats[voiceIdx];
                String formatData = wfcSpnFormats[dataIdx];
                String originalSpn = spn.trim();
                spn = String.format(formatVoice, originalSpn);
                dataSpn = String.format(formatData, originalSpn);
+40 −9
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.AsyncResult;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.PowerManager;
import android.os.Registrant;
import android.os.RegistrantList;
@@ -36,6 +37,7 @@ import android.os.SystemProperties;
import android.os.UserHandle;

import android.provider.Telephony;
import android.telephony.CarrierConfigManager;
import android.telephony.PhoneNumberUtils;
import android.telephony.ServiceState;
import android.telephony.Rlog;
@@ -1445,9 +1447,25 @@ public class ImsPhone extends ImsPhoneBase {
        if (imsReasonInfo.mCode == imsReasonInfo.CODE_REGISTRATION_ERROR
                && imsReasonInfo.mExtraMessage != null) {

            CarrierConfigManager configManager =
                    (CarrierConfigManager)mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
            if (configManager == null) {
                Rlog.e(LOG_TAG, "processDisconnectReason: CarrierConfigManager is not ready");
                return;
            }
            PersistableBundle pb = configManager.getConfig(getSubId());
            if (pb == null) {
                Rlog.e(LOG_TAG, "processDisconnectReason: no config for subId " + getSubId());
                return;
            }
            final String[] wfcOperatorErrorCodes =
                    mContext.getResources().getStringArray(
                            com.android.internal.R.array.wfcOperatorErrorCodes);
                    pb.getStringArray(
                            CarrierConfigManager.KEY_WFC_OPERATOR_ERROR_CODES_STRING_ARRAY);
            if (wfcOperatorErrorCodes == null) {
                // no operator-specific error codes
                return;
            }

            final String[] wfcOperatorErrorAlertMessages =
                    mContext.getResources().getStringArray(
                            com.android.internal.R.array.wfcOperatorErrorAlertMessages);
@@ -1456,17 +1474,23 @@ public class ImsPhone extends ImsPhoneBase {
                            com.android.internal.R.array.wfcOperatorErrorNotificationMessages);

            for (int i = 0; i < wfcOperatorErrorCodes.length; i++) {
                String[] codes = wfcOperatorErrorCodes[i].split("|");
                if (codes.length != 2) {
                    Rlog.e(LOG_TAG, "Invalid carrier config: " + wfcOperatorErrorCodes[i]);
                    continue;
                }

                // Match error code.
                if (!imsReasonInfo.mExtraMessage.startsWith(
                        wfcOperatorErrorCodes[i])) {
                        codes[0])) {
                    continue;
                }
                // If there is no delimiter at the end of error code string
                // then we need to verify that we are not matching partial code.
                // EXAMPLE: "REG9" must not match "REG99".
                // NOTE: Error code must not be empty.
                int codeStringLength = wfcOperatorErrorCodes[i].length();
                char lastChar = wfcOperatorErrorCodes[i].charAt(codeStringLength-1);
                int codeStringLength = codes[0].length();
                char lastChar = codes[0].charAt(codeStringLength - 1);
                if (Character.isLetterOrDigit(lastChar)) {
                    if (imsReasonInfo.mExtraMessage.length() > codeStringLength) {
                        char nextChar = imsReasonInfo.mExtraMessage.charAt(codeStringLength);
@@ -1479,13 +1503,20 @@ public class ImsPhone extends ImsPhoneBase {
                final CharSequence title = mContext.getText(
                        com.android.internal.R.string.wfcRegErrorTitle);

                int idx = Integer.parseInt(codes[1]);
                if (idx < 0 ||
                        idx >= wfcOperatorErrorAlertMessages.length ||
                        idx >= wfcOperatorErrorNotificationMessages.length) {
                    Rlog.e(LOG_TAG, "Invalid index: " + wfcOperatorErrorCodes[i]);
                    continue;
                }
                CharSequence messageAlert = imsReasonInfo.mExtraMessage;
                CharSequence messageNotification = imsReasonInfo.mExtraMessage;
                if (!wfcOperatorErrorAlertMessages[i].isEmpty()) {
                    messageAlert = wfcOperatorErrorAlertMessages[i];
                if (!wfcOperatorErrorAlertMessages[idx].isEmpty()) {
                    messageAlert = wfcOperatorErrorAlertMessages[idx];
                }
                if (!wfcOperatorErrorNotificationMessages[i].isEmpty()) {
                    messageNotification = wfcOperatorErrorNotificationMessages[i];
                if (!wfcOperatorErrorNotificationMessages[idx].isEmpty()) {
                    messageNotification = wfcOperatorErrorNotificationMessages[idx];
                }

                // UX requirement is to disable WFC in case of "permanent" registration failures.