1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package android.telephony.embms.cts; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertNotNull; 21 22 import android.annotation.Nullable; 23 import android.telephony.cts.embmstestapp.CtsGroupCallService; 24 import android.telephony.mbms.GroupCallCallback; 25 import android.telephony.mbms.MbmsErrors; 26 import android.telephony.mbms.GroupCall; 27 28 import java.util.Arrays; 29 import java.util.Collections; 30 import java.util.List; 31 import java.util.concurrent.BlockingQueue; 32 import java.util.concurrent.LinkedBlockingQueue; 33 import java.util.concurrent.TimeUnit; 34 import org.junit.Test; 35 36 public class MbmsGroupCallTest extends MbmsGroupCallTestBase { 37 private class TestGroupCallCallback implements GroupCallCallback { 38 private final BlockingQueue<SomeArgs> mErrorCalls = new LinkedBlockingQueue<>(); 39 private final BlockingQueue<SomeArgs> mGroupCallStateChangedCalls= 40 new LinkedBlockingQueue<>(); 41 private final BlockingQueue<SomeArgs> mBroadcastSignalStrengthUpdatedCalls = 42 new LinkedBlockingQueue<>(); 43 44 @Override 45 public void onError(int errorCode, @Nullable String message) { 46 GroupCallCallback.super.onError(errorCode, message); 47 SomeArgs args = SomeArgs.obtain(); 48 args.arg1 = errorCode; 49 args.arg2 = message; 50 mErrorCalls.add(args); 51 } 52 53 @Override 54 public void onGroupCallStateChanged(int state, int reason) { 55 GroupCallCallback.super.onGroupCallStateChanged(state, reason); 56 SomeArgs args = SomeArgs.obtain(); 57 args.arg1 = state; 58 args.arg2 = reason; 59 mGroupCallStateChangedCalls.add(args); 60 } 61 62 @Override 63 public void onBroadcastSignalStrengthUpdated(int signalStrength) { 64 GroupCallCallback.super.onBroadcastSignalStrengthUpdated(signalStrength); 65 SomeArgs args = SomeArgs.obtain(); 66 args.arg1 = signalStrength; 67 mBroadcastSignalStrengthUpdatedCalls.add(args); 68 } 69 70 public SomeArgs waitOnError() { 71 try { 72 return mErrorCalls.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS); 73 } catch (InterruptedException e) { 74 return null; 75 } 76 } 77 78 public SomeArgs waitOnGroupCallStateChanged() { 79 try { 80 return mGroupCallStateChangedCalls.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS); 81 } catch (InterruptedException e) { 82 return null; 83 } 84 } 85 86 public SomeArgs waitOnBroadcastSignalStrengthUpdated() { 87 try { 88 return mBroadcastSignalStrengthUpdatedCalls.poll( 89 ASYNC_TIMEOUT, TimeUnit.MILLISECONDS); 90 } catch (InterruptedException e) { 91 return null; 92 } 93 } 94 } 95 96 private static final long TMGI = 568734963245L; 97 private static final List<Integer> SAI_LIST = Arrays.asList(16, 24, 46, 76); 98 private static final List<Integer> FREQUENCY_LIST = Arrays.asList(2075, 2050, 1865); 99 100 private TestGroupCallCallback mGroupCallCallback = 101 new TestGroupCallCallback(); 102 103 @Test 104 public void testStartGroupCall() throws Exception { 105 GroupCall groupCall = mGroupCallSession.startGroupCall(TMGI, SAI_LIST, FREQUENCY_LIST, 106 mCallbackExecutor, mGroupCallCallback 107 ); 108 assertNotNull(groupCall); 109 assertEquals(TMGI, groupCall.getTmgi()); 110 111 SomeArgs args = mGroupCallCallback.waitOnGroupCallStateChanged(); 112 assertEquals(GroupCall.STATE_STARTED, args.arg1); 113 assertEquals(GroupCall.REASON_BY_USER_REQUEST, args.arg2); 114 115 List<List<Object>> startGroupCallCalls = 116 getMiddlewareCalls(CtsGroupCallService.METHOD_START_GROUP_CALL); 117 assertEquals(1, startGroupCallCalls.size()); 118 List<Object> startGroupCallCall = startGroupCallCalls.get(0); 119 assertEquals(TMGI, startGroupCallCall.get(2)); 120 assertEquals(SAI_LIST, startGroupCallCall.get(3)); 121 assertEquals(FREQUENCY_LIST, startGroupCallCall.get(4)); 122 } 123 124 @Test 125 public void testUpdateGroupCall() throws Exception { 126 GroupCall groupCall = mGroupCallSession.startGroupCall(TMGI, SAI_LIST, FREQUENCY_LIST, 127 mCallbackExecutor, mGroupCallCallback 128 ); 129 List<Integer> newSais = Collections.singletonList(16); 130 List<Integer> newFreqs = Collections.singletonList(2025); 131 groupCall.updateGroupCall(newSais, newFreqs); 132 133 List<List<Object>> updateGroupCallCalls = 134 getMiddlewareCalls(CtsGroupCallService.METHOD_UPDATE_GROUP_CALL); 135 assertEquals(1, updateGroupCallCalls.size()); 136 List<Object> updateGroupCallCall = updateGroupCallCalls.get(0); 137 assertEquals(TMGI, updateGroupCallCall.get(2)); 138 assertEquals(newSais, updateGroupCallCall.get(3)); 139 assertEquals(newFreqs, updateGroupCallCall.get(4)); 140 } 141 142 @Test 143 public void testStopGroupCall() throws Exception { 144 GroupCall groupCall = mGroupCallSession.startGroupCall(TMGI, SAI_LIST, FREQUENCY_LIST, 145 mCallbackExecutor, mGroupCallCallback 146 ); 147 groupCall.close(); 148 List<List<Object>> stopGroupCallCalls = 149 getMiddlewareCalls(CtsGroupCallService.METHOD_STOP_GROUP_CALL); 150 assertEquals(1, stopGroupCallCalls.size()); 151 assertEquals(TMGI, stopGroupCallCalls.get(0).get(2)); 152 } 153 154 @Test 155 public void testGroupCallCallbacks() throws Exception { 156 mGroupCallSession.startGroupCall(TMGI, SAI_LIST, FREQUENCY_LIST, mCallbackExecutor, 157 mGroupCallCallback 158 ); 159 mMiddlewareControl.fireErrorOnGroupCall(MbmsErrors.GeneralErrors.ERROR_IN_E911, 160 MbmsGroupCallTest.class.getSimpleName()); 161 SomeArgs groupCallErrorArgs = mGroupCallCallback.waitOnError(); 162 assertEquals(MbmsErrors.GeneralErrors.ERROR_IN_E911, groupCallErrorArgs.arg1); 163 assertEquals(MbmsGroupCallTest.class.getSimpleName(), groupCallErrorArgs.arg2); 164 165 int broadcastSignalStrength = 3; 166 mMiddlewareControl.fireBroadcastSignalStrengthUpdated(broadcastSignalStrength); 167 assertEquals(broadcastSignalStrength, 168 mGroupCallCallback.waitOnBroadcastSignalStrengthUpdated().arg1); 169 } 170 171 @Test 172 public void testStartGroupCallFailure() throws Exception { 173 mMiddlewareControl.forceErrorCode( 174 MbmsErrors.GeneralErrors.ERROR_MIDDLEWARE_TEMPORARILY_UNAVAILABLE); 175 mGroupCallSession.startGroupCall(TMGI, SAI_LIST, FREQUENCY_LIST, mCallbackExecutor, 176 mGroupCallCallback 177 ); 178 assertEquals(MbmsErrors.GeneralErrors.ERROR_MIDDLEWARE_TEMPORARILY_UNAVAILABLE, 179 mCallback.waitOnError().arg1); 180 } 181 } 182