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

Commit 86aa924b authored by Roman Birg's avatar Roman Birg
Browse files

MultiSim: move getFormattedSimName() to frameworks (2/2)



Move this into one location any app can call.

Change-Id: I02a96f72be1e41783faeb5862cb26b96ca776672
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 640fe8ce
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -274,6 +274,9 @@
    <!-- Shown in the lock screen when there is SIM card IO error. -->
    <string name="lockscreen_sim_error_message_short">Invalid card.</string>

    <string name="multi_sim_entry_format_no_carrier" translatable="false">SIM - <xliff:g id="index">%1$d</xliff:g></string>
    <string name="multi_sim_entry_format" translatable="false"><xliff:g id="operator">%1$s</xliff:g> - <xliff:g id="index">%2$d</xliff:g></string>

    <!-- Shown in the lock screen to tell the user that phone is in airplane mode-->
    <string name="lockscreen_airplane_mode_on">Airplane mode</string>

+4 −0
Original line number Diff line number Diff line
@@ -2103,4 +2103,8 @@
  <java-symbol type="string" name="usb_media_checking" />
  <java-symbol type="string" name="usb_media_removed" />
  <java-symbol type="string" name="usb_media_shared" />

  <!-- Strings for MultiSim -->
  <java-symbol type="string" name="multi_sim_entry_format" />
  <java-symbol type="string" name="multi_sim_entry_format_no_carrier" />
</resources>
+31 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.provider.Settings;
import android.text.TextUtils;

import com.android.internal.telephony.msim.ITelephonyMSim;
@@ -36,6 +37,9 @@ import com.android.internal.telephony.TelephonyProperties;

import java.util.List;

import static android.telephony.TelephonyManager.SIM_STATE_ABSENT;
import static android.telephony.TelephonyManager.SIM_STATE_READY;

/**
 * Provides access to information about the telephony services on
 * the device. Applications can use the methods in this class to
@@ -1166,4 +1170,31 @@ public class MSimTelephonyManager {
        }
        return android.provider.Settings.Global.putString(cr, name, data);
    }

    /**
     * Helper method to retrieve a custom SIM name if a user has set one.
     * Handles logic to fall back to operator name if no custom name has been set for the SIM,
     *
     * @param context
     * @param subscription SIM subscription ID
     * @return returns the formatted SIM name ready to display to the user.
     * @hide
     */
    public static String getFormattedSimName(Context context, int subscription) {
        String label = Settings.Global.getSimNameForSubscription(context, subscription, null);
        if (TextUtils.isEmpty(label)) {
            MSimTelephonyManager tm = MSimTelephonyManager.from(context);
            String operatorName = tm.getSimOperatorName(subscription);
            if (tm.getSimState(subscription) == SIM_STATE_ABSENT
                    || tm.getSimState(subscription) != SIM_STATE_READY
                    || TextUtils.isEmpty(operatorName)) {
                label = context.getString(com.android.internal.R.string.multi_sim_entry_format_no_carrier, subscription + 1);
            } else {
                label = context.getString(com.android.internal.R.string.multi_sim_entry_format, operatorName, subscription + 1);
            }
        } else {
            label = context.getString(com.android.internal.R.string.multi_sim_entry_format, label, subscription + 1);
        }
        return label;
    }
}