Loading tests/telephonytests/src/com/android/internal/telephony/ims/FeatureConnectionTest.java 0 → 100644 +194 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony.ims; import junit.framework.AssertionFailedError; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; import android.content.Context; import android.content.pm.PackageManager; import android.os.IBinder; import android.os.RemoteException; import android.telephony.ims.feature.ImsFeature; import android.test.suitebuilder.annotation.SmallTest; import com.android.ims.FeatureConnection; import com.android.ims.ImsManager; import com.android.ims.internal.IImsServiceFeatureCallback; import com.android.internal.telephony.TelephonyTest; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import java.util.concurrent.Executor; public class FeatureConnectionTest extends TelephonyTest { private Executor mSimpleExecutor = new Executor() { @Override public void execute(Runnable r) { r.run(); } }; private class TestFeatureConnection extends FeatureConnection { private Integer mFeatureState = ImsFeature.STATE_READY; public boolean ImsFeatureCreatedCalled = false; public boolean ImsFeatureRemovedCalled = false; public int mNewStatus = ImsFeature.STATE_UNAVAILABLE; TestFeatureConnection(Context context, int slotId, int featureType) { super(context, slotId, featureType); if (!ImsManager.isImsSupportedOnDevice(context)) { sImsSupportedOnDevice = false; } } @Override public void checkServiceIsReady() throws RemoteException { super.checkServiceIsReady(); } @Override protected void handleImsFeatureCreatedCallback(int slotId, int feature) { ImsFeatureCreatedCalled = true; } @Override protected void handleImsFeatureRemovedCallback(int slotId, int feature) { ImsFeatureRemovedCalled = true; } @Override protected void handleImsStatusChangedCallback(int slotId, int feature, int status) { mNewStatus = status; } @Override protected Integer retrieveFeatureState() { return mFeatureState; } public void setFeatureState(int state) { mFeatureState = state; } }; private int mPhoneId; private TestFeatureConnection mFeatureConnection; @Mock IBinder mBinder; @Before public void setUp() throws Exception { super.setUp("FeatureConnectionTest"); mPhoneId = mPhone.getPhoneId(); doReturn(null).when(mContext).getMainLooper(); doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS); mFeatureConnection = new TestFeatureConnection(mContext, mPhoneId, ImsFeature.FEATURE_RCS); mFeatureConnection.mExecutor = mSimpleExecutor; mFeatureConnection.setBinder(mBinder); } @After public void tearDown() throws Exception { super.tearDown(); } /** * Test service is ready when binder is alive and IMS status is ready. */ @Test @SmallTest public void testServiceIsReady() { when(mBinder.isBinderAlive()).thenReturn(true); mFeatureConnection.setFeatureState(ImsFeature.STATE_READY); try { mFeatureConnection.checkServiceIsReady(); } catch (RemoteException e) { throw new AssertionFailedError("Exception in testServiceIsReady: " + e); } } /** * Test service is not ready when binder is not alive or status is not ready. */ @Test @SmallTest public void testServiceIsNotReady() { // Binder is not alive when(mBinder.isBinderAlive()).thenReturn(false); try { mFeatureConnection.checkServiceIsReady(); throw new AssertionFailedError("testServiceIsNotReady: binder isn't alive"); } catch (RemoteException e) { // expected result } // IMS feature status is unavailable when(mBinder.isBinderAlive()).thenReturn(true); mFeatureConnection.setFeatureState(ImsFeature.STATE_UNAVAILABLE); try { mFeatureConnection.checkServiceIsReady(); throw new AssertionFailedError("testServiceIsNotReady: status unavailable"); } catch (RemoteException e) { // expected result } } /** * Test callback is called when IMS feature created/removed/changed. */ @Test @SmallTest public void testListenerCallback() { IImsServiceFeatureCallback featureCallback = mFeatureConnection.getListener(); try { featureCallback.imsFeatureCreated(anyInt(), anyInt()); assertTrue(mFeatureConnection.ImsFeatureCreatedCalled); } catch (RemoteException e) { throw new AssertionFailedError("testListenerCallback(Created): " + e); } try { featureCallback.imsFeatureRemoved(anyInt(), anyInt()); assertTrue(mFeatureConnection.ImsFeatureRemovedCalled); } catch (RemoteException e) { throw new AssertionFailedError("testListenerCallback(Removed): " + e); } try { featureCallback.imsStatusChanged(anyInt(), anyInt(), ImsFeature.STATE_READY); assertEquals(mFeatureConnection.mNewStatus, ImsFeature.STATE_READY); } catch (RemoteException e) { throw new AssertionFailedError("testListenerCallback(Changed): " + e); } } } tests/telephonytests/src/com/android/internal/telephony/ims/RcsFeatureConnectionTest.java 0 → 100644 +254 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony.ims; import junit.framework.AssertionFailedError; import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; import android.content.Context; import android.content.pm.PackageManager; import android.net.Uri; import android.os.RemoteException; import android.telephony.SubscriptionManager; import android.telephony.ims.RcsContactUceCapability; import android.telephony.ims.aidl.IImsCapabilityCallback; import android.telephony.ims.aidl.IImsRcsFeature; import android.telephony.ims.aidl.IRcsFeatureListener; import android.telephony.ims.feature.CapabilityChangeRequest; import android.telephony.ims.feature.ImsFeature; import android.test.suitebuilder.annotation.SmallTest; import com.android.ims.RcsFeatureConnection; import com.android.ims.internal.IImsServiceFeatureCallback; import com.android.internal.telephony.TelephonyTest; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import java.util.List; import java.util.concurrent.Executor; public class RcsFeatureConnectionTest extends TelephonyTest { private Executor mSimpleExecutor = new Executor() { @Override public void execute(Runnable r) { r.run(); } }; private IImsRcsFeature mTestImsRcsFeatureBinder = new IImsRcsFeature.Stub() { @Override public void setListener(IRcsFeatureListener listener) { } @Override public int queryCapabilityStatus() { return 1; } @Override public int getFeatureState() { return ImsFeature.STATE_READY; } @Override public void addCapabilityCallback(IImsCapabilityCallback c) { } @Override public void removeCapabilityCallback(IImsCapabilityCallback c) { } @Override public void changeCapabilitiesConfiguration(CapabilityChangeRequest r, IImsCapabilityCallback c) { } @Override public void queryCapabilityConfiguration(int capability, int radioTech, IImsCapabilityCallback c) { } @Override public void requestCapabilities(List<Uri> uris, int operationToken) { } @Override public void updateCapabilities(RcsContactUceCapability capabilities, int operationToken) { } @Override public void sendCapabilityRequest(Uri contactUri, RcsContactUceCapability capabilities, int operationToken) { } @Override public void respondToCapabilityRequest(String contactUri, RcsContactUceCapability ownCapabilities, int operationToken) { } @Override public void respondToCapabilityRequestWithError(Uri contactUri, int code, String reason, int operationToken) { } }; private int mPhoneId; private SubscriptionManager mSubscriptionManager; private RcsFeatureConnection mRcsFeatureConnection; @Mock RcsFeatureConnection.RcsFeatureManagerProxy mRcsFeatureManagerProxy; @Before public void setUp() throws Exception { super.setUp("RcsFeatureConnectionTest"); mPhoneId = mPhone.getPhoneId(); mSubscriptionManager = (SubscriptionManager) mContext.getSystemService( Context.TELEPHONY_SUBSCRIPTION_SERVICE); doReturn(null).when(mContext).getMainLooper(); doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS); mRcsFeatureConnection = RcsFeatureConnection.create(mContext, mPhoneId); mRcsFeatureConnection.mExecutor = mSimpleExecutor; mRcsFeatureConnection.setBinder(mTestImsRcsFeatureBinder.asBinder()); } @After public void tearDown() throws Exception { super.tearDown(); } /** * Test that RcsFeatureConnection is ready when RCS UCE is supported by device and carrier. */ @Test @SmallTest public void testServiceIsReady() { // RCS UCE is supported by carrier setRcsUceIsSupportedByCarrier(true); try { mRcsFeatureConnection.checkServiceIsReady(); } catch (RemoteException e) { throw new AssertionFailedError("Exception in checkServiceIsReady: " + e); } } /** * Test that RcsFeatureConnection is not ready when RCS UCE is not supported carrier. */ @Test @SmallTest public void testServiceIsNotSupportedByCarrier() { // RCS UCE feature is NOT supported by carrier setRcsUceIsSupportedByCarrier(false); try { mRcsFeatureConnection.checkServiceIsReady(); throw new AssertionFailedError("Exception in testServiceIsNotSupportedByCarrier"); } catch (RemoteException e) { //expected result } } private void setRcsUceIsSupportedByCarrier(boolean isSupported) { when(mRcsFeatureManagerProxy.isRcsUceSupportedByCarrier(mContext, 0)) .thenReturn(isSupported); RcsFeatureConnection.setRcsFeatureManagerProxy(mRcsFeatureManagerProxy); } /** * Test that service is not ready after IMS feature is removed. */ @Test @SmallTest public void testImsFeatureRemoved() { setRcsUceIsSupportedByCarrier(true); IImsServiceFeatureCallback imsServiceCallback = mRcsFeatureConnection.getListener(); try { imsServiceCallback.imsFeatureRemoved(0, ImsFeature.FEATURE_RCS); mRcsFeatureConnection.checkServiceIsReady(); throw new AssertionFailedError("testImsFeatureRemoved"); } catch (RemoteException e) { //expected result } } /** * Test that service is not ready after the status of IMS feature is unavailable. */ @Test @SmallTest public void testImsStatusIsUnavailable() { setRcsUceIsSupportedByCarrier(true); IImsServiceFeatureCallback imsServiceCallback = mRcsFeatureConnection.getListener(); try { imsServiceCallback.imsStatusChanged(0, ImsFeature.FEATURE_RCS, ImsFeature.STATE_UNAVAILABLE); mRcsFeatureConnection.checkServiceIsReady(); throw new AssertionFailedError("testImsStatusIsUnavailable"); } catch (RemoteException e) { //expected result } } /** * Test that service is ready when the status is unavailable on different slot. */ @Test @SmallTest public void testImsStatusUnavailableOnDifferentSlot() { setRcsUceIsSupportedByCarrier(true); IImsServiceFeatureCallback imsServiceCallback = mRcsFeatureConnection.getListener(); try { imsServiceCallback.imsFeatureRemoved(1, ImsFeature.FEATURE_RCS); mRcsFeatureConnection.checkServiceIsReady(); } catch (RemoteException e) { throw new AssertionFailedError("testImsStatusUnavailableOnDifferentSlot: " + e); } } /** * Test that service is ready when the status is unavailable on different ImsFeature. */ @Test @SmallTest public void testImsStatusUnavailableOnDifferentFeature() { setRcsUceIsSupportedByCarrier(true); IImsServiceFeatureCallback imsServiceCallback = mRcsFeatureConnection.getListener(); try { imsServiceCallback.imsFeatureRemoved(1, ImsFeature.FEATURE_MMTEL); mRcsFeatureConnection.checkServiceIsReady(); } catch (RemoteException e) { throw new AssertionFailedError("testImsStatusUnavailableOnDifferentFeature: " + e); } } @Test @SmallTest public void testRetrieveFeatureState() { assertNotNull(mRcsFeatureConnection.retrieveFeatureState()); } } tests/telephonytests/src/com/android/internal/telephony/ims/RcsFeatureManagerTest.java 0 → 100644 +76 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony.ims; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; import android.os.PersistableBundle; import android.telephony.CarrierConfigManager; import android.test.suitebuilder.annotation.SmallTest; import com.android.ims.RcsFeatureManager; import com.android.internal.telephony.TelephonyTest; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; public class RcsFeatureManagerTest extends TelephonyTest { @Mock RcsFeatureManager.SubscriptionManagerProxy mSubscriptionManagerProxy; @Before public void setUp() throws Exception { super.setUp("RcsFeatureManagerTest"); when(mSubscriptionManagerProxy.getSubId(0)).thenReturn(1); RcsFeatureManager.setSubscriptionManager(mSubscriptionManagerProxy); } @After public void tearDown() throws Exception { super.tearDown(); } /** * Test RCS UCE feature is supported by carrier */ @Test @SmallTest public void testRcsUceFeatureIsSupportedByCarrier() { int phoneId = mPhone.getPhoneId(); PersistableBundle bundle = mContextFixture.getCarrierConfigBundle(); // RCS UCE is supported by carrier setIsSupportedByCarrier(bundle, true); assertTrue(RcsFeatureManager.isRcsUceSupportedByCarrier(mContext, phoneId)); // RCS UCE is not supported by carrier setIsSupportedByCarrier(bundle, false); assertFalse(RcsFeatureManager.isRcsUceSupportedByCarrier(mContext, phoneId)); } private void setIsSupportedByCarrier(PersistableBundle bundle, boolean isSupported) { bundle.putBoolean(CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL, isSupported); bundle.putBoolean(CarrierConfigManager.KEY_USE_RCS_SIP_OPTIONS_BOOL, isSupported); } } Loading
tests/telephonytests/src/com/android/internal/telephony/ims/FeatureConnectionTest.java 0 → 100644 +194 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony.ims; import junit.framework.AssertionFailedError; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; import android.content.Context; import android.content.pm.PackageManager; import android.os.IBinder; import android.os.RemoteException; import android.telephony.ims.feature.ImsFeature; import android.test.suitebuilder.annotation.SmallTest; import com.android.ims.FeatureConnection; import com.android.ims.ImsManager; import com.android.ims.internal.IImsServiceFeatureCallback; import com.android.internal.telephony.TelephonyTest; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import java.util.concurrent.Executor; public class FeatureConnectionTest extends TelephonyTest { private Executor mSimpleExecutor = new Executor() { @Override public void execute(Runnable r) { r.run(); } }; private class TestFeatureConnection extends FeatureConnection { private Integer mFeatureState = ImsFeature.STATE_READY; public boolean ImsFeatureCreatedCalled = false; public boolean ImsFeatureRemovedCalled = false; public int mNewStatus = ImsFeature.STATE_UNAVAILABLE; TestFeatureConnection(Context context, int slotId, int featureType) { super(context, slotId, featureType); if (!ImsManager.isImsSupportedOnDevice(context)) { sImsSupportedOnDevice = false; } } @Override public void checkServiceIsReady() throws RemoteException { super.checkServiceIsReady(); } @Override protected void handleImsFeatureCreatedCallback(int slotId, int feature) { ImsFeatureCreatedCalled = true; } @Override protected void handleImsFeatureRemovedCallback(int slotId, int feature) { ImsFeatureRemovedCalled = true; } @Override protected void handleImsStatusChangedCallback(int slotId, int feature, int status) { mNewStatus = status; } @Override protected Integer retrieveFeatureState() { return mFeatureState; } public void setFeatureState(int state) { mFeatureState = state; } }; private int mPhoneId; private TestFeatureConnection mFeatureConnection; @Mock IBinder mBinder; @Before public void setUp() throws Exception { super.setUp("FeatureConnectionTest"); mPhoneId = mPhone.getPhoneId(); doReturn(null).when(mContext).getMainLooper(); doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS); mFeatureConnection = new TestFeatureConnection(mContext, mPhoneId, ImsFeature.FEATURE_RCS); mFeatureConnection.mExecutor = mSimpleExecutor; mFeatureConnection.setBinder(mBinder); } @After public void tearDown() throws Exception { super.tearDown(); } /** * Test service is ready when binder is alive and IMS status is ready. */ @Test @SmallTest public void testServiceIsReady() { when(mBinder.isBinderAlive()).thenReturn(true); mFeatureConnection.setFeatureState(ImsFeature.STATE_READY); try { mFeatureConnection.checkServiceIsReady(); } catch (RemoteException e) { throw new AssertionFailedError("Exception in testServiceIsReady: " + e); } } /** * Test service is not ready when binder is not alive or status is not ready. */ @Test @SmallTest public void testServiceIsNotReady() { // Binder is not alive when(mBinder.isBinderAlive()).thenReturn(false); try { mFeatureConnection.checkServiceIsReady(); throw new AssertionFailedError("testServiceIsNotReady: binder isn't alive"); } catch (RemoteException e) { // expected result } // IMS feature status is unavailable when(mBinder.isBinderAlive()).thenReturn(true); mFeatureConnection.setFeatureState(ImsFeature.STATE_UNAVAILABLE); try { mFeatureConnection.checkServiceIsReady(); throw new AssertionFailedError("testServiceIsNotReady: status unavailable"); } catch (RemoteException e) { // expected result } } /** * Test callback is called when IMS feature created/removed/changed. */ @Test @SmallTest public void testListenerCallback() { IImsServiceFeatureCallback featureCallback = mFeatureConnection.getListener(); try { featureCallback.imsFeatureCreated(anyInt(), anyInt()); assertTrue(mFeatureConnection.ImsFeatureCreatedCalled); } catch (RemoteException e) { throw new AssertionFailedError("testListenerCallback(Created): " + e); } try { featureCallback.imsFeatureRemoved(anyInt(), anyInt()); assertTrue(mFeatureConnection.ImsFeatureRemovedCalled); } catch (RemoteException e) { throw new AssertionFailedError("testListenerCallback(Removed): " + e); } try { featureCallback.imsStatusChanged(anyInt(), anyInt(), ImsFeature.STATE_READY); assertEquals(mFeatureConnection.mNewStatus, ImsFeature.STATE_READY); } catch (RemoteException e) { throw new AssertionFailedError("testListenerCallback(Changed): " + e); } } }
tests/telephonytests/src/com/android/internal/telephony/ims/RcsFeatureConnectionTest.java 0 → 100644 +254 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony.ims; import junit.framework.AssertionFailedError; import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; import android.content.Context; import android.content.pm.PackageManager; import android.net.Uri; import android.os.RemoteException; import android.telephony.SubscriptionManager; import android.telephony.ims.RcsContactUceCapability; import android.telephony.ims.aidl.IImsCapabilityCallback; import android.telephony.ims.aidl.IImsRcsFeature; import android.telephony.ims.aidl.IRcsFeatureListener; import android.telephony.ims.feature.CapabilityChangeRequest; import android.telephony.ims.feature.ImsFeature; import android.test.suitebuilder.annotation.SmallTest; import com.android.ims.RcsFeatureConnection; import com.android.ims.internal.IImsServiceFeatureCallback; import com.android.internal.telephony.TelephonyTest; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import java.util.List; import java.util.concurrent.Executor; public class RcsFeatureConnectionTest extends TelephonyTest { private Executor mSimpleExecutor = new Executor() { @Override public void execute(Runnable r) { r.run(); } }; private IImsRcsFeature mTestImsRcsFeatureBinder = new IImsRcsFeature.Stub() { @Override public void setListener(IRcsFeatureListener listener) { } @Override public int queryCapabilityStatus() { return 1; } @Override public int getFeatureState() { return ImsFeature.STATE_READY; } @Override public void addCapabilityCallback(IImsCapabilityCallback c) { } @Override public void removeCapabilityCallback(IImsCapabilityCallback c) { } @Override public void changeCapabilitiesConfiguration(CapabilityChangeRequest r, IImsCapabilityCallback c) { } @Override public void queryCapabilityConfiguration(int capability, int radioTech, IImsCapabilityCallback c) { } @Override public void requestCapabilities(List<Uri> uris, int operationToken) { } @Override public void updateCapabilities(RcsContactUceCapability capabilities, int operationToken) { } @Override public void sendCapabilityRequest(Uri contactUri, RcsContactUceCapability capabilities, int operationToken) { } @Override public void respondToCapabilityRequest(String contactUri, RcsContactUceCapability ownCapabilities, int operationToken) { } @Override public void respondToCapabilityRequestWithError(Uri contactUri, int code, String reason, int operationToken) { } }; private int mPhoneId; private SubscriptionManager mSubscriptionManager; private RcsFeatureConnection mRcsFeatureConnection; @Mock RcsFeatureConnection.RcsFeatureManagerProxy mRcsFeatureManagerProxy; @Before public void setUp() throws Exception { super.setUp("RcsFeatureConnectionTest"); mPhoneId = mPhone.getPhoneId(); mSubscriptionManager = (SubscriptionManager) mContext.getSystemService( Context.TELEPHONY_SUBSCRIPTION_SERVICE); doReturn(null).when(mContext).getMainLooper(); doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS); mRcsFeatureConnection = RcsFeatureConnection.create(mContext, mPhoneId); mRcsFeatureConnection.mExecutor = mSimpleExecutor; mRcsFeatureConnection.setBinder(mTestImsRcsFeatureBinder.asBinder()); } @After public void tearDown() throws Exception { super.tearDown(); } /** * Test that RcsFeatureConnection is ready when RCS UCE is supported by device and carrier. */ @Test @SmallTest public void testServiceIsReady() { // RCS UCE is supported by carrier setRcsUceIsSupportedByCarrier(true); try { mRcsFeatureConnection.checkServiceIsReady(); } catch (RemoteException e) { throw new AssertionFailedError("Exception in checkServiceIsReady: " + e); } } /** * Test that RcsFeatureConnection is not ready when RCS UCE is not supported carrier. */ @Test @SmallTest public void testServiceIsNotSupportedByCarrier() { // RCS UCE feature is NOT supported by carrier setRcsUceIsSupportedByCarrier(false); try { mRcsFeatureConnection.checkServiceIsReady(); throw new AssertionFailedError("Exception in testServiceIsNotSupportedByCarrier"); } catch (RemoteException e) { //expected result } } private void setRcsUceIsSupportedByCarrier(boolean isSupported) { when(mRcsFeatureManagerProxy.isRcsUceSupportedByCarrier(mContext, 0)) .thenReturn(isSupported); RcsFeatureConnection.setRcsFeatureManagerProxy(mRcsFeatureManagerProxy); } /** * Test that service is not ready after IMS feature is removed. */ @Test @SmallTest public void testImsFeatureRemoved() { setRcsUceIsSupportedByCarrier(true); IImsServiceFeatureCallback imsServiceCallback = mRcsFeatureConnection.getListener(); try { imsServiceCallback.imsFeatureRemoved(0, ImsFeature.FEATURE_RCS); mRcsFeatureConnection.checkServiceIsReady(); throw new AssertionFailedError("testImsFeatureRemoved"); } catch (RemoteException e) { //expected result } } /** * Test that service is not ready after the status of IMS feature is unavailable. */ @Test @SmallTest public void testImsStatusIsUnavailable() { setRcsUceIsSupportedByCarrier(true); IImsServiceFeatureCallback imsServiceCallback = mRcsFeatureConnection.getListener(); try { imsServiceCallback.imsStatusChanged(0, ImsFeature.FEATURE_RCS, ImsFeature.STATE_UNAVAILABLE); mRcsFeatureConnection.checkServiceIsReady(); throw new AssertionFailedError("testImsStatusIsUnavailable"); } catch (RemoteException e) { //expected result } } /** * Test that service is ready when the status is unavailable on different slot. */ @Test @SmallTest public void testImsStatusUnavailableOnDifferentSlot() { setRcsUceIsSupportedByCarrier(true); IImsServiceFeatureCallback imsServiceCallback = mRcsFeatureConnection.getListener(); try { imsServiceCallback.imsFeatureRemoved(1, ImsFeature.FEATURE_RCS); mRcsFeatureConnection.checkServiceIsReady(); } catch (RemoteException e) { throw new AssertionFailedError("testImsStatusUnavailableOnDifferentSlot: " + e); } } /** * Test that service is ready when the status is unavailable on different ImsFeature. */ @Test @SmallTest public void testImsStatusUnavailableOnDifferentFeature() { setRcsUceIsSupportedByCarrier(true); IImsServiceFeatureCallback imsServiceCallback = mRcsFeatureConnection.getListener(); try { imsServiceCallback.imsFeatureRemoved(1, ImsFeature.FEATURE_MMTEL); mRcsFeatureConnection.checkServiceIsReady(); } catch (RemoteException e) { throw new AssertionFailedError("testImsStatusUnavailableOnDifferentFeature: " + e); } } @Test @SmallTest public void testRetrieveFeatureState() { assertNotNull(mRcsFeatureConnection.retrieveFeatureState()); } }
tests/telephonytests/src/com/android/internal/telephony/ims/RcsFeatureManagerTest.java 0 → 100644 +76 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony.ims; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; import android.os.PersistableBundle; import android.telephony.CarrierConfigManager; import android.test.suitebuilder.annotation.SmallTest; import com.android.ims.RcsFeatureManager; import com.android.internal.telephony.TelephonyTest; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; public class RcsFeatureManagerTest extends TelephonyTest { @Mock RcsFeatureManager.SubscriptionManagerProxy mSubscriptionManagerProxy; @Before public void setUp() throws Exception { super.setUp("RcsFeatureManagerTest"); when(mSubscriptionManagerProxy.getSubId(0)).thenReturn(1); RcsFeatureManager.setSubscriptionManager(mSubscriptionManagerProxy); } @After public void tearDown() throws Exception { super.tearDown(); } /** * Test RCS UCE feature is supported by carrier */ @Test @SmallTest public void testRcsUceFeatureIsSupportedByCarrier() { int phoneId = mPhone.getPhoneId(); PersistableBundle bundle = mContextFixture.getCarrierConfigBundle(); // RCS UCE is supported by carrier setIsSupportedByCarrier(bundle, true); assertTrue(RcsFeatureManager.isRcsUceSupportedByCarrier(mContext, phoneId)); // RCS UCE is not supported by carrier setIsSupportedByCarrier(bundle, false); assertFalse(RcsFeatureManager.isRcsUceSupportedByCarrier(mContext, phoneId)); } private void setIsSupportedByCarrier(PersistableBundle bundle, boolean isSupported) { bundle.putBoolean(CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL, isSupported); bundle.putBoolean(CarrierConfigManager.KEY_USE_RCS_SIP_OPTIONS_BOOL, isSupported); } }