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

Commit 1a599e82 authored by João Ventura's avatar João Ventura Committed by Gerrit Code Review
Browse files

Mms auto-retrieval (1/2): framework

- Settings: Add auto-retrieval and auto-retrieval-on-roaming strings
- GsmDataConnectionTracker: Gets settings and auto-connects APN_TYPE_MMS

Patch set 2   : Fix NPE when the preference was not yet set to a defaulted
                value
              : Add @hide's
              : Set proper defaults

Change-Id: I9c4ea47cd39cd017fba3d5b0649d0e84aaf78b4e
parent 749ded08
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -1317,6 +1317,23 @@ public final class Settings {
         */
        public static final String WIFI_STATIC_DNS2 = "wifi_static_dns2";

        /**
         * Allows automatic retrieval of mms contents
         * <p>Type: INT</p>
         * 0 -- false
         * 1 -- true
         * @hide
         */
        public static final String MMS_AUTO_RETRIEVAL = "mms_auto_retrieval";

        /**
         * Allows automatic retrieval of mms contents during roaming
         * <p>Type: INT</p>
         * 0 -- false
         * 1 -- true
         * @hide
         */
        public static final String MMS_AUTO_RETRIEVAL_ON_ROAMING = "mms_auto_on_roaming";

        /**
         * Determines whether remote devices may discover and/or connect to
@@ -2918,6 +2935,8 @@ public final class Settings {
            WIFI_STATIC_NETMASK,
            WIFI_STATIC_DNS1,
            WIFI_STATIC_DNS2,
            MMS_AUTO_RETRIEVAL,
            MMS_AUTO_RETRIEVAL_ON_ROAMING,
            BLUETOOTH_DISCOVERABILITY,
            BLUETOOTH_DISCOVERABILITY_TIMEOUT,
            DIM_SCREEN,
+37 −3
Original line number Diff line number Diff line
@@ -757,8 +757,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {

        boolean desiredPowerState = mPhone.getServiceStateTracker().getDesiredPowerState();

        if ((apnContext.getState() == State.IDLE || apnContext.getState() == State.SCANNING) &&
                isDataAllowed(apnContext) && getAnyDataEnabled() && !isEmergency()) {
        if (canSetupData(apnContext)) {

            if (apnContext.getState() == State.IDLE) {
                ArrayList<ApnSetting> waitingApns = buildWaitingApns(apnContext.getApnType());
@@ -793,6 +792,41 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
        }
    }

    /**
    * Report on whether data connectivity can be setup for any APN.
    * @param apnContext The apnContext
    * @return boolean
    */
    private boolean canSetupData(ApnContext apnContext) {
        if (apnContext.getState() != State.IDLE && apnContext.getState() != State.SCANNING) {
            return false;
        }

        if (isDataAllowed(apnContext) && getAnyDataEnabled() && !isEmergency()) {
            return true;
        }

        // Get the MMS retrieval settings. Defaults to enabled with roaming disabled
        final ContentResolver resolver = mPhone.getContext().getContentResolver();
        boolean mmsAutoRetrieval = Settings.System.getInt(resolver,
                Settings.System.MMS_AUTO_RETRIEVAL, 1) == 1;
        boolean mmsRetrievalRoaming = Settings.System.getInt(resolver,
                Settings.System.MMS_AUTO_RETRIEVAL_ON_ROAMING, 0) == 1;

        // Allow automatic Mms connections if user has enabled it
        if (mmsAutoRetrieval && apnContext.getApnType().equals(Phone.APN_TYPE_MMS)) {
            // don't allow MMS connections while roaming if disabled
            TelephonyManager tm = (TelephonyManager)
                    mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
            if (tm.isNetworkRoaming() && !mmsRetrievalRoaming) {
                return false;
            }
            return true;
        }

        return false;
    }

    @Override
    // Disabled apn's still need avail/unavail notificiations - send them out
    protected void notifyOffApnsOfAvailability(String reason) {