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

Commit 595884ed authored by Jiashen Wang's avatar Jiashen Wang
Browse files

Change Settings to be able to receive timeout values from LPA

Bug: 171846124
Test: Tested manually
Change-Id: I547315eabd7cc873b0dda7a3bb2d09c84225ddd3
parent 06abd142
Loading
Loading
Loading
Loading
+9 −5
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.telephony.CarrierConfigManager;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.telephony.UiccSlotInfo;
import android.telephony.UiccSlotInfo;
@@ -46,8 +47,7 @@ public class EnableMultiSimSidecar extends AsyncTaskSidecar<Void, Boolean> {
    // Tags
    // Tags
    private static final String TAG = "EnableMultiSimSidecar";
    private static final String TAG = "EnableMultiSimSidecar";


    // TODO(b/171846124): Pass timeout value from LPA to Settings
    private static final long DEFAULT_ENABLE_MULTI_SIM_TIMEOUT_MILLS = 40 * 1000L;
    private static final long ENABLE_MULTI_SIM_TIMEOUT_MILLS = 40 * 1000L;


    public static EnableMultiSimSidecar get(FragmentManager fm) {
    public static EnableMultiSimSidecar get(FragmentManager fm) {
        return SidecarFragment.get(fm, TAG, EnableMultiSimSidecar.class, null /* args */);
        return SidecarFragment.get(fm, TAG, EnableMultiSimSidecar.class, null /* args */);
@@ -123,8 +123,12 @@ public class EnableMultiSimSidecar extends AsyncTaskSidecar<Void, Boolean> {
                            mCarrierConfigChangeReceiver,
                            mCarrierConfigChangeReceiver,
                            new IntentFilter(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED));
                            new IntentFilter(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED));
            mTelephonyManager.switchMultiSimConfig(mNumOfActiveSim);
            mTelephonyManager.switchMultiSimConfig(mNumOfActiveSim);
            if (mSimCardStateChangedLatch.await(
            long waitingTimeMillis =
                    ENABLE_MULTI_SIM_TIMEOUT_MILLS, TimeUnit.MILLISECONDS)) {
                    Settings.Global.getLong(
                            getContext().getContentResolver(),
                            Settings.Global.ENABLE_MULTI_SLOT_TIMEOUT_MILLIS,
                            DEFAULT_ENABLE_MULTI_SIM_TIMEOUT_MILLS);
            if (mSimCardStateChangedLatch.await(waitingTimeMillis, TimeUnit.MILLISECONDS)) {
                Log.i(TAG, "Multi SIM were successfully enabled.");
                Log.i(TAG, "Multi SIM were successfully enabled.");
                return true;
                return true;
            } else {
            } else {
+9 −3
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settings.network;


import android.annotation.IntDef;
import android.annotation.IntDef;
import android.content.Context;
import android.content.Context;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.telephony.UiccSlotInfo;
import android.telephony.UiccSlotInfo;
import android.util.Log;
import android.util.Log;
@@ -35,8 +36,8 @@ public class UiccSlotUtil {


    private static final String TAG = "UiccSlotUtil";
    private static final String TAG = "UiccSlotUtil";


    // TODO(b/171846124): Pass timeout value from LPA to Settings
    private static final long DEFAULT_WAIT_AFTER_SWITCH_TIMEOUT_MILLIS = 25 * 1000L;
    private static final long WAIT_AFTER_SWITCH_TIMEOUT_MILLIS = 25000;
    ;


    public static final int INVALID_PHYSICAL_SLOT_ID = -1;
    public static final int INVALID_PHYSICAL_SLOT_ID = -1;


@@ -115,12 +116,17 @@ public class UiccSlotUtil {
    private static void performSwitchToRemovableSlot(int slotId, Context context)
    private static void performSwitchToRemovableSlot(int slotId, Context context)
            throws UiccSlotsException {
            throws UiccSlotsException {
        CarrierConfigChangedReceiver receiver = null;
        CarrierConfigChangedReceiver receiver = null;
        long waitingTimeMillis =
                Settings.Global.getLong(
                        context.getContentResolver(),
                        Settings.Global.EUICC_SWITCH_SLOT_TIMEOUT_MILLIS,
                        DEFAULT_WAIT_AFTER_SWITCH_TIMEOUT_MILLIS);
        try {
        try {
            CountDownLatch latch = new CountDownLatch(1);
            CountDownLatch latch = new CountDownLatch(1);
            receiver = new CarrierConfigChangedReceiver(latch);
            receiver = new CarrierConfigChangedReceiver(latch);
            receiver.registerOn(context);
            receiver.registerOn(context);
            switchSlots(context, slotId);
            switchSlots(context, slotId);
            latch.await(WAIT_AFTER_SWITCH_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
            latch.await(waitingTimeMillis, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            Thread.currentThread().interrupt();
            Log.e(TAG, "Failed switching to physical slot.", e);
            Log.e(TAG, "Failed switching to physical slot.", e);