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

Commit 4d718b43 authored by Sarah Chin's avatar Sarah Chin
Browse files

DataSettingsManager broadcast initial state and add init check

Test: atest DataNetworkControllerTest, DataNetworkTest
Bug: 223473056
Change-Id: I6c84df98411a628d076a479bea8a89f2e9a324bf
Merged-In: I6c84df98411a628d076a479bea8a89f2e9a324bf
parent b9f93b22
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -273,7 +273,9 @@ public class DataEvaluation {
        /** VoPS is not supported by the network. */
        /** VoPS is not supported by the network. */
        VOPS_NOT_SUPPORTED(true),
        VOPS_NOT_SUPPORTED(true),
        /** Only one data network is allowed at one time. */
        /** Only one data network is allowed at one time. */
        ONLY_ALLOWED_SINGLE_NETWORK(true);
        ONLY_ALLOWED_SINGLE_NETWORK(true),
        /** Data enabled settings are not ready. */
        DATA_SETTINGS_NOT_READY(true);


        private final boolean mIsHardReason;
        private final boolean mIsHardReason;


+7 −3
Original line number Original line Diff line number Diff line
@@ -1270,10 +1270,14 @@ public class DataNetworkController extends Handler {
                    DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK);
                    DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK);
        }
        }


        if (mDataSettingsManager.isDataInitialized()) {
            if (!mDataSettingsManager.isDataEnabled(DataUtils.networkCapabilityToApnType(
            if (!mDataSettingsManager.isDataEnabled(DataUtils.networkCapabilityToApnType(
                    networkRequest.getApnTypeNetworkCapability()))) {
                    networkRequest.getApnTypeNetworkCapability()))) {
                evaluation.addDataDisallowedReason(DataDisallowedReason.DATA_DISABLED);
                evaluation.addDataDisallowedReason(DataDisallowedReason.DATA_DISABLED);
            }
            }
        } else {
            evaluation.addDataDisallowedReason(DataDisallowedReason.DATA_SETTINGS_NOT_READY);
        }


        // Check whether to allow data in certain situations if data is disallowed for soft reasons
        // Check whether to allow data in certain situations if data is disallowed for soft reasons
        if (!evaluation.containsDisallowedReasons()) {
        if (!evaluation.containsDisallowedReasons()) {
+31 −13
Original line number Original line Diff line number Diff line
@@ -75,8 +75,8 @@ public class DataSettingsManager extends Handler {
    private static final int EVENT_PROVISIONED_CHANGED = 9;
    private static final int EVENT_PROVISIONED_CHANGED = 9;
    /** Event for provisioning data enabled setting changed. */
    /** Event for provisioning data enabled setting changed. */
    private static final int EVENT_PROVISIONING_DATA_ENABLED_CHANGED = 10;
    private static final int EVENT_PROVISIONING_DATA_ENABLED_CHANGED = 10;
    /** Event for registering all events. */
    /** Event for initializing DataSettingsManager. */
    private static final int EVENT_REGISTER_ALL_EVENTS = 11;
    private static final int EVENT_INITIALIZE = 11;


    private final Phone mPhone;
    private final Phone mPhone;
    private final ContentResolver mResolver;
    private final ContentResolver mResolver;
@@ -100,7 +100,13 @@ public class DataSettingsManager extends Handler {
     * Flag indicating whether data is allowed or not for the device.
     * Flag indicating whether data is allowed or not for the device.
     * It can be disabled by user, carrier, policy or thermal.
     * It can be disabled by user, carrier, policy or thermal.
     */
     */
    private boolean mIsDataEnabled = false;
    private boolean mIsDataEnabled;

    /**
     * Used to indicate that the initial value for mIsDataEnabled was set.
     * Prevent race condition where the initial value might be incorrect.
     */
    private boolean mInitialized = false;


    /**
    /**
     * Data settings manager callback. This should be only used by {@link DataNetworkController}.
     * Data settings manager callback. This should be only used by {@link DataNetworkController}.
@@ -159,12 +165,9 @@ public class DataSettingsManager extends Handler {
        mDataEnabledSettings.put(TelephonyManager.DATA_ENABLED_REASON_CARRIER, true);
        mDataEnabledSettings.put(TelephonyManager.DATA_ENABLED_REASON_CARRIER, true);
        mDataEnabledSettings.put(TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
        mDataEnabledSettings.put(TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);


        mIsDataEnabled = isDataEnabled(ApnSetting.TYPE_ALL);
        // Instead of calling onInitialize directly from the constructor, send the event.
        log("mIsDataEnabled=" + mIsDataEnabled);

        // Instead of calling onRegisterAllEvents directly from the constructor, send the event.
        // The reason is that getImsPhone is null when we are still in the constructor here.
        // The reason is that getImsPhone is null when we are still in the constructor here.
        sendEmptyMessage(EVENT_REGISTER_ALL_EVENTS);
        sendEmptyMessage(EVENT_INITIALIZE);
    }
    }


    @Override
    @Override
@@ -255,8 +258,8 @@ public class DataSettingsManager extends Handler {
                updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_UNKNOWN);
                updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_UNKNOWN);
                break;
                break;
            }
            }
            case EVENT_REGISTER_ALL_EVENTS: {
            case EVENT_INITIALIZE: {
                onRegisterAllEvents();
                onInitialize();
                break;
                break;
            }
            }
            default:
            default:
@@ -267,7 +270,7 @@ public class DataSettingsManager extends Handler {
    /**
    /**
     * Called when needed to register for all events that data network controller is interested.
     * Called when needed to register for all events that data network controller is interested.
     */
     */
    private void onRegisterAllEvents() {
    private void onInitialize() {
        mDataConfigManager.registerForConfigUpdate(this, EVENT_DATA_CONFIG_UPDATED);
        mDataConfigManager.registerForConfigUpdate(this, EVENT_DATA_CONFIG_UPDATED);
        mSettingsObserver.observe(Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED),
        mSettingsObserver.observe(Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED),
                EVENT_PROVISIONED_CHANGED);
                EVENT_PROVISIONED_CHANGED);
@@ -293,6 +296,7 @@ public class DataSettingsManager extends Handler {
                        }
                        }
                    }
                    }
                }, this::post);
                }, this::post);
        updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_UNKNOWN);
    }
    }


    /**
    /**
@@ -320,7 +324,8 @@ public class DataSettingsManager extends Handler {
        boolean prevDataEnabled = mIsDataEnabled;
        boolean prevDataEnabled = mIsDataEnabled;
        mIsDataEnabled = isDataEnabled(ApnSetting.TYPE_ALL);
        mIsDataEnabled = isDataEnabled(ApnSetting.TYPE_ALL);
        log("mIsDataEnabled=" + mIsDataEnabled + ", prevDataEnabled=" + prevDataEnabled);
        log("mIsDataEnabled=" + mIsDataEnabled + ", prevDataEnabled=" + prevDataEnabled);
        if (prevDataEnabled != mIsDataEnabled) {
        if (!mInitialized || prevDataEnabled != mIsDataEnabled) {
            if (!mInitialized) mInitialized = true;
            notifyDataEnabledChanged(mIsDataEnabled, reason);
            notifyDataEnabledChanged(mIsDataEnabled, reason);
        }
        }
    }
    }
@@ -347,13 +352,26 @@ public class DataSettingsManager extends Handler {
    }
    }


    /**
    /**
     * Check whether the overall data is enabled for the device.
     * Check whether the overall data is enabled for the device. Note that this value will only
     * be accurate if {@link #isDataInitialized} is {@code true}.
     * @return {@code true} if the overall data is enabled and {@code false} otherwise.
     * @return {@code true} if the overall data is enabled and {@code false} otherwise.
     */
     */
    public boolean isDataEnabled() {
    public boolean isDataEnabled() {
        return mIsDataEnabled;
        return mIsDataEnabled;
    }
    }


    /**
     * Check whether data enabled value has been initialized. If this is {@code false}, then
     * {@link #isDataEnabled} is not guaranteed to be accurate. Once data is initialized,
     * {@link DataSettingsManagerCallback#onDataEnabledChanged} will be invoked with reason
     * {@link TelephonyManager#DATA_ENABLED_REASON_UNKNOWN}.
     * @return {@code true} if the data enabled value is initialized and {@code false} otherwise.
     */
    public boolean isDataInitialized() {
        // TODO: Create a new DATA_ENABLED_REASON_INITIALIZED for initial value broadcast
        return mInitialized;
    }

    /**
    /**
     * Check whether the overall data is enabled for the device for the given APN type.
     * Check whether the overall data is enabled for the device for the given APN type.
     * @param apnType A single APN type to check data enabled for.
     * @param apnType A single APN type to check data enabled for.