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

Commit 42505a8d authored by Ling Ma's avatar Ling Ma Committed by Jack Yu
Browse files

Add auto_data_switch_availability_stability_time_threshold to control auto data switch

Bug: 244064524
Test: reviewed bugreport to check the flag is loaded on device
Merged-In: Id513a509b181ee3e991f2ebc7ddbb5d65375fce7
Change-Id: Id513a509b181ee3e991f2ebc7ddbb5d65375fce7
parent a9c12470
Loading
Loading
Loading
Loading
+40 −0
Original line number Original line Diff line number Diff line
@@ -53,6 +53,7 @@ import android.os.PersistableBundle;
import android.os.Registrant;
import android.os.Registrant;
import android.os.RegistrantList;
import android.os.RegistrantList;
import android.os.RemoteException;
import android.os.RemoteException;
import android.provider.DeviceConfig;
import android.telephony.CarrierConfigManager;
import android.telephony.CarrierConfigManager;
import android.telephony.PhoneCapability;
import android.telephony.PhoneCapability;
import android.telephony.PhoneStateListener;
import android.telephony.PhoneStateListener;
@@ -65,6 +66,7 @@ import android.telephony.ims.ImsReasonInfo;
import android.telephony.ims.ImsRegistrationAttributes;
import android.telephony.ims.ImsRegistrationAttributes;
import android.telephony.ims.RegistrationManager;
import android.telephony.ims.RegistrationManager;
import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.LocalLog;
import android.util.LocalLog;


@@ -109,6 +111,9 @@ import java.util.concurrent.CompletableFuture;
 */
 */
public class PhoneSwitcher extends Handler {
public class PhoneSwitcher extends Handler {
    private static final String LOG_TAG = "PhoneSwitcher";
    private static final String LOG_TAG = "PhoneSwitcher";
    /** DeviceConfig key of the time threshold in ms for defining a network status to be stable. **/
    private static final String KEY_AUTO_DATA_SWITCH_AVAILABILITY_STABILITY_TIME_THRESHOLD =
            "auto_data_switch_availability_stability_time_threshold";
    protected static final boolean VDBG = false;
    protected static final boolean VDBG = false;


    private static final int DEFAULT_NETWORK_CHANGE_TIMEOUT_MS = 5000;
    private static final int DEFAULT_NETWORK_CHANGE_TIMEOUT_MS = 5000;
@@ -294,6 +299,7 @@ public class PhoneSwitcher extends Handler {
    private static final int EVENT_PROCESS_SIM_STATE_CHANGE       = 119;
    private static final int EVENT_PROCESS_SIM_STATE_CHANGE       = 119;
    @VisibleForTesting
    @VisibleForTesting
    public static final int EVENT_IMS_RADIO_TECH_CHANGED          = 120;
    public static final int EVENT_IMS_RADIO_TECH_CHANGED          = 120;
    public static final int EVENT_DEVICE_CONFIG_CHANGED           = 121;


    // List of events triggers re-evaluations
    // List of events triggers re-evaluations
    private static final String EVALUATION_REASON_RADIO_ON = "EVENT_RADIO_ON";
    private static final String EVALUATION_REASON_RADIO_ON = "EVENT_RADIO_ON";
@@ -320,6 +326,13 @@ public class PhoneSwitcher extends Handler {


    private List<Set<CommandException.Error>> mCurrentDdsSwitchFailure;
    private List<Set<CommandException.Error>> mCurrentDdsSwitchFailure;


    /**
     * Time threshold in ms to define a internet connection status to be stable(e.g. out of service,
     * in service, wifi is the default active network.etc), while -1 indicates auto switch
     * feature disabled.
     */
    private long mAutoDataSwitchAvailabilityStabilityTimeThreshold = -1;

    /** Data settings manager callback. Key is the phone id. */
    /** Data settings manager callback. Key is the phone id. */
    private final @NonNull Map<Integer, DataSettingsManagerCallback> mDataSettingsManagerCallbacks =
    private final @NonNull Map<Integer, DataSettingsManagerCallback> mDataSettingsManagerCallbacks =
            new ArrayMap<>();
            new ArrayMap<>();
@@ -569,6 +582,17 @@ public class PhoneSwitcher extends Handler {
        // we want to see all requests
        // we want to see all requests
        networkFactory.registerIgnoringScore();
        networkFactory.registerIgnoringScore();


        // Register for device config update
        DeviceConfig.addOnPropertiesChangedListener(
                DeviceConfig.NAMESPACE_TELEPHONY, this::post,
                properties -> {
                    if (TextUtils.equals(DeviceConfig.NAMESPACE_TELEPHONY,
                            properties.getNamespace())) {
                        sendEmptyMessage(EVENT_DEVICE_CONFIG_CHANGED);
                    }
                });
        updateDeviceConfig();

        updateHalCommandToUse();
        updateHalCommandToUse();


        log("PhoneSwitcher started");
        log("PhoneSwitcher started");
@@ -840,7 +864,21 @@ public class PhoneSwitcher extends Handler {
                }
                }
                break;
                break;
            }
            }
            case EVENT_DEVICE_CONFIG_CHANGED: {
                updateDeviceConfig();
                break;
            }
        }
    }
    }

    /** Update local properties from {@link DeviceConfig} */
    private void updateDeviceConfig() {
        DeviceConfig.Properties properties = //read all telephony properties
                DeviceConfig.getProperties(DeviceConfig.NAMESPACE_TELEPHONY);

        mAutoDataSwitchAvailabilityStabilityTimeThreshold = properties.getInt(
                KEY_AUTO_DATA_SWITCH_AVAILABILITY_STABILITY_TIME_THRESHOLD, -1);

    }
    }


    private synchronized void onMultiSimConfigChanged(int activeModemCount) {
    private synchronized void onMultiSimConfigChanged(int activeModemCount) {
@@ -1701,6 +1739,8 @@ public class PhoneSwitcher extends Handler {
        pw.println("mActiveModemCount=" + mActiveModemCount);
        pw.println("mActiveModemCount=" + mActiveModemCount);
        pw.println("mPhoneIdInVoiceCall=" + mPhoneIdInVoiceCall);
        pw.println("mPhoneIdInVoiceCall=" + mPhoneIdInVoiceCall);
        pw.println("mCurrentDdsSwitchFailure=" + mCurrentDdsSwitchFailure);
        pw.println("mCurrentDdsSwitchFailure=" + mCurrentDdsSwitchFailure);
        pw.println("mAutoDataSwitchAvailabilityStabilityTimeThreshold="
                + mAutoDataSwitchAvailabilityStabilityTimeThreshold);
        pw.println("Local logs:");
        pw.println("Local logs:");
        pw.increaseIndent();
        pw.increaseIndent();
        mLocalLog.dump(fd, pw, args);
        mLocalLog.dump(fd, pw, args);