Loading src/java/com/android/ims/ImsManager.java +51 −12 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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. Loading Loading @@ -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. * Loading Loading @@ -1856,10 +1900,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. Loading Loading @@ -2333,19 +2373,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, Loading tests/src/com/android/ims/ImsManagerTest.java +30 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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); Loading Loading
src/java/com/android/ims/ImsManager.java +51 −12 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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. Loading Loading @@ -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. * Loading Loading @@ -1856,10 +1900,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. Loading Loading @@ -2333,19 +2373,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, Loading
tests/src/com/android/ims/ImsManagerTest.java +30 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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); Loading