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

Commit d02ca165 authored by Rambo Wang's avatar Rambo Wang Committed by Gerrit Code Review
Browse files

Merge changes from topic "ANM-DSM-ENT-UP" into main

* changes:
  Fix phone process crash due to null carrier config
  Update EmergencyNumberTracker with new CarrierConfigManager APIs
  Update AccessNetworksManager with new CarrierConfigManager APIs
parents 25a31ae6 36e6584d
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 != null && !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 != null && !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;
    }
+2 −2
Original line number Diff line number Diff line
@@ -630,13 +630,13 @@ public class DataServiceManager extends Handler {

    @NonNull
    private PersistableBundle getCarrierConfigSubset(String key) {
        PersistableBundle configs = new PersistableBundle();
        PersistableBundle configs = null;
        try {
            configs = mCarrierConfigManager.getConfigForSubId(mPhone.getSubId(), key);
        } catch (RuntimeException e) {
            loge("CarrierConfigLoader is not available.");
        }
        return configs;
        return configs != null ? configs : new PersistableBundle();
    }

    private void sendCompleteMessage(Message msg, @DataServiceCallback.ResultCode int code) {
+40 −27
Original line number Diff line number Diff line
@@ -16,10 +16,10 @@

package com.android.internal.telephony.emergency;

import android.annotation.NonNull;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncResult;
import android.os.Environment;
import android.os.Handler;
@@ -142,10 +142,6 @@ public class EmergencyNumberTracker extends Handler {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(
                    CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
                onCarrierConfigChanged();
                return;
            } else if (intent.getAction().equals(
                    TelephonyManager.ACTION_NETWORK_COUNTRY_CHANGED)) {
                int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, -1);
                if (phoneId == mPhone.getPhoneId()) {
@@ -170,22 +166,20 @@ public class EmergencyNumberTracker extends Handler {
            CarrierConfigManager configMgr = (CarrierConfigManager)
                    mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
            if (configMgr != null) {
                PersistableBundle b = configMgr.getConfigForSubId(mPhone.getSubId());
                if (b != null) {
                PersistableBundle b = getCarrierConfigSubset(
                        CarrierConfigManager.KEY_EMERGENCY_NUMBER_PREFIX_STRING_ARRAY);
                if (!b.isEmpty()) {
                    mEmergencyNumberPrefix = b.getStringArray(
                            CarrierConfigManager.KEY_EMERGENCY_NUMBER_PREFIX_STRING_ARRAY);
                }

                // Callback which directly handle config change should be executed on handler thread
                configMgr.registerCarrierConfigChangeListener(this::post,
                        (slotIndex, subId, carrierId, specificCarrierId) ->
                                onCarrierConfigUpdated(slotIndex));
            } else {
                loge("CarrierConfigManager is null.");
            }

            // Receive Carrier Config Changes
            IntentFilter filter = new IntentFilter(
                    CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
            // Receive Telephony Network Country Changes
            filter.addAction(TelephonyManager.ACTION_NETWORK_COUNTRY_CHANGED);

            mPhone.getContext().registerReceiver(mIntentReceiver, filter);
        } else {
            loge("mPhone is null.");
        }
@@ -333,24 +327,43 @@ public class EmergencyNumberTracker extends Handler {
        }
    }

    private void onCarrierConfigChanged() {
    private void onCarrierConfigUpdated(int slotIndex) {
        if (mPhone != null) {
            CarrierConfigManager configMgr = (CarrierConfigManager)
                    mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
            if (configMgr != null) {
                PersistableBundle b = configMgr.getConfigForSubId(mPhone.getSubId());
                if (b != null) {
                    String[] emergencyNumberPrefix = b.getStringArray(
            if (slotIndex != mPhone.getPhoneId()) return;

            PersistableBundle b =
                    getCarrierConfigSubset(
                            CarrierConfigManager.KEY_EMERGENCY_NUMBER_PREFIX_STRING_ARRAY);
            if (!b.isEmpty()) {
                String[] emergencyNumberPrefix =
                        b.getStringArray(
                                CarrierConfigManager.KEY_EMERGENCY_NUMBER_PREFIX_STRING_ARRAY);
                if (!Arrays.equals(mEmergencyNumberPrefix, emergencyNumberPrefix)) {
                        this.obtainMessage(EVENT_UPDATE_EMERGENCY_NUMBER_PREFIX,
                                emergencyNumberPrefix).sendToTarget();
                    }
                    this.obtainMessage(EVENT_UPDATE_EMERGENCY_NUMBER_PREFIX, emergencyNumberPrefix)
                            .sendToTarget();
                }
            }
        } else {
            loge("onCarrierConfigChanged mPhone is null.");
            loge("onCarrierConfigurationChanged mPhone is null.");
        }
    }

    @NonNull
    private PersistableBundle getCarrierConfigSubset(String key) {
        PersistableBundle bundle = null;

        if (mPhone != null) {
            CarrierConfigManager ccm =
                    mPhone.getContext().getSystemService(CarrierConfigManager.class);
            try {
                if (ccm != null) {
                    bundle = ccm.getConfigForSubId(mPhone.getPhoneId(), key);
                }
            } catch (RuntimeException e) {
                loge("CarrierConfigLoader is not available.");
            }
        }
        return bundle != null ? bundle : new PersistableBundle();
    }

    private String getInitialCountryIso() {
+2 −2
Original line number Diff line number Diff line
@@ -1819,13 +1819,13 @@ public class UiccProfile extends IccCard {

    @NonNull
    private PersistableBundle getCarrierConfigSubset(int subId, String... keys) {
        PersistableBundle bundle = new PersistableBundle();
        PersistableBundle bundle = null;
        try {
            bundle = mCarrierConfigManager.getConfigForSubId(subId, keys);
        } catch (RuntimeException e) {
            loge("CarrierConfigLoader is not available.");
        }
        return bundle;
        return bundle != null ? bundle : new PersistableBundle();
    }

    private static String eventToString(int event) {
+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();
    }