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

Commit fd2112a0 authored by Brad Ebinger's avatar Brad Ebinger Committed by Automerger Merge Worker
Browse files

Merge "Move IMS metrics collection callback to a static map in ImsManager" am:...

Merge "Move IMS metrics collection callback to a static map in ImsManager" am: 8df39f23 am: 7b300561 am: 32f25274

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/net/ims/+/1707167

Change-Id: I2427ac14b61b2ae1ddbf6f6e73fb1323208c8312
parents a558ac9e 32f25274
Loading
Loading
Loading
Loading
+51 −12
Original line number Diff line number Diff line
@@ -316,6 +316,23 @@ public class ImsManager implements FeatureUpdates {
        }
    }

    /**
     * Events that will be triggered as part of metrics collection.
     */
    public interface ImsStatsCallback {
        /**
         * The MmTel capabilities that are enabled have changed.
         * @param capability The MmTel capability
         * @param regTech The IMS registration technology associated with the capability.
         * @param isEnabled {@code true} if the capability is enabled, {@code false} if it is
         *                  disabled.
         */
        void onEnabledMmTelCapabilitiesChanged(
                @MmTelFeature.MmTelCapabilities.MmTelCapability int capability,
                @ImsRegistrationImplBase.ImsRegistrationTech int regTech,
                boolean isEnabled);
    }

    /**
     * Internally we will create a FeatureConnector when {@link #getInstance(Context, int)} is
     * called to keep the MmTelFeatureConnection instance fresh as new SIM cards are
@@ -419,8 +436,10 @@ public class ImsManager implements FeatureUpdates {

    public static final String TRUE = "true";
    public static final String FALSE = "false";

    // Map of phoneId -> InstanceManager
    private static final SparseArray<InstanceManager> IMS_MANAGER_INSTANCES = new SparseArray<>(2);
    // Map of phoneId -> ImsStatsCallback
    private static final SparseArray<ImsStatsCallback> IMS_STATS_CALLBACKS = new SparseArray<>(2);

    // A log prefix added to some instances of ImsManager to make it distinguishable from others.
    // - "IM" added to ImsManager for ImsManagers created using getInstance.
@@ -482,6 +501,31 @@ public class ImsManager implements FeatureUpdates {
        return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS);
    }

    /**
     * Sets the callback that will be called when events related to IMS metric collection occur.
     * <p>
     * Note: Subsequent calls to this method will replace the previous stats callback.
     */
    public static void setImsStatsCallback(int phoneId, ImsStatsCallback cb) {
        synchronized (IMS_STATS_CALLBACKS) {
            if (cb == null) {
                IMS_STATS_CALLBACKS.remove(phoneId);
            } else {
                IMS_STATS_CALLBACKS.put(phoneId, cb);
            }
        }
    }

    /**
     * @return the {@link ImsStatsCallback} instance associated with the provided phoneId or
     * {@link null} if none currently exists.
     */
    private static ImsStatsCallback getStatsCallback(int phoneId) {
        synchronized (IMS_STATS_CALLBACKS) {
            return IMS_STATS_CALLBACKS.get(phoneId);
        }
    }

    /**
     * Returns the user configuration of Enhanced 4G LTE Mode setting.
     *
@@ -1949,10 +1993,6 @@ public class ImsManager implements FeatureUpdates {
        return mMmTelConnectionRef.get().isBinderReady();
    }

    public void setConfigListener(ImsConfigListener listener) {
        mImsConfigListener = listener;
    }

    /**
     * Opens the IMS service for making calls and/or receiving generic IMS calls as well as
     * register listeners for ECBM, Multiendpoint, and UT if the ImsService supports it.
@@ -2426,19 +2466,18 @@ public class ImsManager implements FeatureUpdates {
            logi("changeMmTelCapability: changing capabilities for sub: " + getSubId()
                    + ", request: " + r);
            c.changeEnabledCapabilities(r, null);
            if (mImsConfigListener == null) {
            ImsStatsCallback cb = getStatsCallback(mPhoneId);
            if (cb == null) {
                return;
            }
            for (CapabilityChangeRequest.CapabilityPair enabledCaps : r.getCapabilitiesToEnable()) {
                mImsConfigListener.onSetFeatureResponse(enabledCaps.getCapability(),
                        enabledCaps.getRadioTech(),
                        ProvisioningManager.PROVISIONING_VALUE_ENABLED, -1);
                cb.onEnabledMmTelCapabilitiesChanged(enabledCaps.getCapability(),
                        enabledCaps.getRadioTech(), true);
            }
            for (CapabilityChangeRequest.CapabilityPair disabledCaps :
                    r.getCapabilitiesToDisable()) {
                mImsConfigListener.onSetFeatureResponse(disabledCaps.getCapability(),
                        disabledCaps.getRadioTech(),
                        ProvisioningManager.PROVISIONING_VALUE_DISABLED, -1);
                cb.onEnabledMmTelCapabilitiesChanged(disabledCaps.getCapability(),
                        disabledCaps.getRadioTech(), false);
            }
        } catch (RemoteException e) {
            throw new ImsException("changeMmTelCapability(CCR)", e,
+30 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.ims;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.anyInt;
@@ -37,11 +38,15 @@ import android.telephony.ims.ProvisioningManager;
import android.telephony.ims.aidl.IImsConfig;
import android.telephony.ims.aidl.IImsRegistration;
import android.telephony.ims.aidl.ISipTransport;
import android.telephony.ims.feature.MmTelFeature;
import android.telephony.ims.stub.ImsConfigImplBase;
import android.telephony.ims.stub.ImsRegistrationImplBase;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.internal.os.SomeArgs;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -178,6 +183,31 @@ public class ImsManagerTest extends ImsTestBase {
                anyInt());
    }

    @SmallTest
    @Test
    public void testImsStats() {
        setWfcEnabledByUser(true);
        SomeArgs args = SomeArgs.obtain();
        ImsManager.setImsStatsCallback(mPhoneId, new ImsManager.ImsStatsCallback() {
            @Override
            public void onEnabledMmTelCapabilitiesChanged(int capability, int regTech,
                    boolean isEnabled) {
                args.arg1 = capability;
                args.arg2 = regTech;
                args.arg3 = isEnabled;
            }
        });
        mBundle.putBoolean(CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL,
                false);
        ImsManager imsManager = getImsManagerAndInitProvisionedValues();
        // Assert that the IMS stats callback is called properly when a setting changes.
        imsManager.setWfcSetting(true);
        assertEquals(args.arg1, MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE);
        assertEquals(args.arg2, ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN);
        assertEquals(args.arg3, true);
        args.recycle();
    }

    @Test @SmallTest
    public void testSetValues() {
        setWfcEnabledByUser(true);