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

Commit 6fedf86e authored by rambowang's avatar rambowang Committed by Automerger Merge Worker
Browse files

Update AccessNetworksManager with new CarrierConfigManager APIs am: 99f4f9d9

parents 8983a66c 99f4f9d9
Loading
Loading
Loading
Loading
+48 −48
Original line number Diff line number Diff line
@@ -20,13 +20,10 @@ import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@@ -35,7 +32,6 @@ import android.os.Registrant;
import android.os.RegistrantList;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants.AccessNetworkType;
import android.telephony.AccessNetworkConstants.RadioAccessNetworkType;
@@ -154,22 +150,6 @@ public class AccessNetworksManager extends Handler {

    private final RegistrantList mQualifiedNetworksChangedRegistrants = new RegistrantList();

    private final BroadcastReceiver mConfigChangedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(action)
                    && mPhone.getPhoneId() == intent.getIntExtra(
                    CarrierConfigManager.EXTRA_SLOT_INDEX, 0)) {
                // We should wait for carrier config changed event because the target binding
                // package name can come from the carrier config. Note that we still get this event
                // even when SIM is absent.
                if (DBG) log("Carrier config changed. Try to bind qualified network service.");
                bindQualifiedNetworksService();
            }
        }
    };

    /**
     * The preferred transport of the APN type. The key is the APN type, and the value is the
     * transport. The preferred transports are updated as soon as QNS changes the preference.
@@ -376,17 +356,25 @@ public class AccessNetworksManager extends Handler {
            log("operates in AP-assisted mode.");
            mAvailableTransports = new int[]{AccessNetworkConstants.TRANSPORT_TYPE_WWAN,
                    AccessNetworkConstants.TRANSPORT_TYPE_WLAN};
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
            try {
                Context contextAsUser = phone.getContext().createPackageContextAsUser(
                        phone.getContext().getPackageName(), 0, UserHandle.ALL);
                contextAsUser.registerReceiver(mConfigChangedReceiver, intentFilter,
                        null /* broadcastPermission */, null);
            } catch (PackageManager.NameNotFoundException e) {
                loge("Package name not found: ", e);

            // bindQualifiedNetworksService posts real work to handler thread. So here we can
            // let the callback execute in binder thread to avoid post twice.
            mCarrierConfigManager.registerCarrierConfigChangeListener(Runnable::run,
                    (slotIndex, subId, carrierId, specificCarrierId) -> {
                        if (slotIndex != mPhone.getPhoneId()) return;
                        // We should wait for carrier config changed event because the target
                        // binding
                        // package name can come from the carrier config. Note that we still get
                        // this
                        // event even when SIM is absent.
                        if (DBG) {
                            log(
                                    "Carrier config changed. Try to bind qualified network "
                                            + "service.");
                        }
                        bindQualifiedNetworksService();
                    });
            bindQualifiedNetworksService();
        }

        // Using post to delay the registering because data retry manager and data config
@@ -498,9 +486,12 @@ public class AccessNetworksManager extends Handler {
        String packageName = mPhone.getContext().getResources().getString(
                com.android.internal.R.string.config_qualified_networks_service_package);

        PersistableBundle b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId());

        if (b != null) {
        PersistableBundle b;
        try {
            b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId(),
                    CarrierConfigManager
                            .KEY_CARRIER_QUALIFIED_NETWORKS_SERVICE_PACKAGE_OVERRIDE_STRING);
            if (!b.isEmpty()) {
                // If carrier config overrides it, use the one from carrier config
                String carrierConfigPackageName = b.getString(CarrierConfigManager
                        .KEY_CARRIER_QUALIFIED_NETWORKS_SERVICE_PACKAGE_OVERRIDE_STRING);
@@ -509,6 +500,9 @@ public class AccessNetworksManager extends Handler {
                    packageName = carrierConfigPackageName;
                }
            }
        } catch (RuntimeException e) {
            loge("Carrier config loader is not available.");
        }

        return packageName;
    }
@@ -523,9 +517,12 @@ public class AccessNetworksManager extends Handler {
        String className = mPhone.getContext().getResources().getString(
                com.android.internal.R.string.config_qualified_networks_service_class);

        PersistableBundle b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId());

        if (b != null) {
        PersistableBundle b;
        try {
            b = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId(),
                    CarrierConfigManager
                            .KEY_CARRIER_QUALIFIED_NETWORKS_SERVICE_CLASS_OVERRIDE_STRING);
            if (!b.isEmpty()) {
                // If carrier config overrides it, use the one from carrier config
                String carrierConfigClassName = b.getString(CarrierConfigManager
                        .KEY_CARRIER_QUALIFIED_NETWORKS_SERVICE_CLASS_OVERRIDE_STRING);
@@ -534,6 +531,9 @@ public class AccessNetworksManager extends Handler {
                    className = carrierConfigClassName;
                }
            }
        } catch (RuntimeException e) {
            loge("Carrier config loader is not available.");
        }

        return className;
    }
+8 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.ComponentName;
import android.content.IntentFilter;
@@ -34,6 +35,7 @@ import android.content.pm.ServiceInfo;
import android.net.NetworkCapabilities;
import android.os.IBinder;
import android.os.Looper;
import android.os.PersistableBundle;
import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants.AccessNetworkType;
import android.telephony.NetworkService;
@@ -66,6 +68,8 @@ public class AccessNetworksManagerTest extends TelephonyTest {
    // The real callback passed created by AccessNetworksManager.
    private IQualifiedNetworksServiceCallback.Stub mQnsCallback;

    private PersistableBundle mBundle;

    private void addQnsService() throws Exception {
        ServiceInfo QnsInfo = new ServiceInfo();
        QnsInfo.packageName = "fake.qns";
@@ -96,6 +100,9 @@ public class AccessNetworksManagerTest extends TelephonyTest {
        mMockedQns = mock(IQualifiedNetworksService.class);
        mMockedIBinder = mock(IBinder.class);

        mBundle = mContextFixture.getCarrierConfigBundle();
        when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mBundle);

        addQnsService();
        mContextFixture.putResource(
                com.android.internal.R.string.config_qualified_networks_service_package,
@@ -120,6 +127,7 @@ public class AccessNetworksManagerTest extends TelephonyTest {
    @After
    public void tearDown() throws Exception {
        mAccessNetworksManager = null;
        mBundle = null;
        super.tearDown();
    }