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

Commit 89f73952 authored by Roman Birg's avatar Roman Birg Committed by Gerrit Code Review
Browse files

Settings: respect telephony config for profiles override



Some networks specifically disallow 2G to be selected as the preferred
setting. We should respect that.

Ref: CYNGNOS-1207
Change-Id: Ic4414ed78c9f38b5c11969300dc858725ee3b2c6
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 7a129270
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -40,6 +40,34 @@
        <item>@string/profile_action_none</item>
    </string-array>

    <!-- Profile 2G-3G and 4G mode values. -->
    <string-array name="profile_networkmode_values_4g" translatable="false">
        <item>0</item>
        <item>1</item>
        <item>2</item>
        <item>3</item>
        <item>4</item>
        <item>5</item>
    </string-array>

    <!-- Profile 2G-3G and 4G mode options. -->
    <string-array name="profile_networkmode_entries_no_2g" translatable="false">
        <item>@string/profile_networkmode_3g</item>
        <item>@string/profile_networkmode_4g</item>
        <item>@string/profile_networkmode_2g3g</item>
        <item>@string/profile_networkmode_2g3g4g</item>
        <item>@string/profile_action_none</item>
    </string-array>

    <!-- Profile 2G-3G and 4G mode values. -->
    <string-array name="profile_networkmode_values_no_2g" translatable="false">
        <item>1</item>
        <item>2</item>
        <item>3</item>
        <item>4</item>
        <item>5</item>
    </string-array>

    <!-- Profile lock mode summaries. Do not translate. -->
    <string-array name="profile_lockmode_entries" translatable="false">
        <item>@string/profile_action_system</item>
+28 −4
Original line number Diff line number Diff line
@@ -804,12 +804,36 @@ public class SetupActionsFragment extends SettingsPreferenceFragment
            throw new UnsupportedOperationException("connection setting cannot be null");
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

        // config_prefer_2g in p/s/Telephony
        final Context telephonyContext = Utils.createPackageContext(getActivity(),
                "com.android.phone");
        boolean allow2g = true;
        if (telephonyContext != null) {
            int identifier = telephonyContext.getResources().getIdentifier("config_prefer_2g",
                    "bool", telephonyContext.getPackageName());
            if (identifier > 0) {
                allow2g = telephonyContext.getResources().getBoolean(identifier);
            }
        }

        final String[] connectionNames =
                getResources().getStringArray(R.array.profile_networkmode_entries_4g);
                getResources().getStringArray(allow2g ? R.array.profile_networkmode_entries_4g
                        : R.array.profile_networkmode_entries_no_2g);
        final String[] connectionValues =
                getResources().getStringArray(allow2g ? R.array.profile_networkmode_values_4g
                        : R.array.profile_networkmode_values_no_2g);

        int defaultIndex = ConnectionOverrideItem.CM_MODE_UNCHANGED; // no action
        int defaultIndex = connectionValues.length - 1; // no action is the last
        if (setting.isOverride()) {
            defaultIndex = setting.getValue();
            // need to match the value
            final int value = setting.getValue();
            for (int i = 0; i < connectionValues.length; i++) {
                if (Integer.parseInt(connectionValues[i]) == value) {
                    defaultIndex = i;
                    break;
                }
            }
        }

        builder.setTitle(ConnectionOverrideItem.getConnectionTitle(setting.getConnectionId()));
@@ -823,7 +847,7 @@ public class SetupActionsFragment extends SettingsPreferenceFragment
                                break;
                            default:
                                setting.setOverride(true);
                                setting.setValue(item);
                                setting.setValue(Integer.parseInt(connectionValues[item]));
                        }
                        mProfile.setConnectionSettings(setting);
                        mAdapter.notifyDataSetChanged();