Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2016 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.telecom.cts;
     18 
     19 import android.content.Intent;
     20 import android.telecom.Call;
     21 import android.telecom.Connection;
     22 import android.telecom.DisconnectCause;
     23 import android.telecom.TelecomManager;
     24 import android.telecom.cts.MockMissedCallNotificationReceiver.IntentListener;
     25 import android.util.Log;
     26 
     27 public class MissedCallTest extends BaseTelecomTestWithMockServices {
     28 
     29     TestUtils.InvokeCounter mShowMissedCallNotificationIntentCounter =
     30             new TestUtils.InvokeCounter("ShowMissedCallNotificationIntent");
     31 
     32     @Override
     33     protected void setUp() throws Exception {
     34         super.setUp();
     35         mContext = getInstrumentation().getContext();
     36 
     37         MockMissedCallNotificationReceiver.setIntentListener(new IntentListener() {
     38             @Override
     39             public void onIntentReceived(Intent intent) {
     40                 Log.i(TestUtils.TAG, intent.toString());
     41                 if (TelecomManager.ACTION_SHOW_MISSED_CALLS_NOTIFICATION
     42                         .equals(intent.getAction())) {
     43                     mShowMissedCallNotificationIntentCounter.invoke();
     44                 }
     45             }
     46         });
     47     }
     48 
     49     @Override
     50     public void tearDown() throws Exception {
     51         MockMissedCallNotificationReceiver.setIntentListener(null);
     52         super.tearDown();
     53     }
     54 
     55     public void testMissedCall_NotifyDialer() throws Exception {
     56         if (!mShouldTestTelecom) {
     57             return;
     58         }
     59         setupConnectionService(null, FLAG_REGISTER | FLAG_ENABLE);
     60 
     61         addAndVerifyNewIncomingCall(createTestNumber(), null);
     62         final MockConnection connection = verifyConnectionForIncomingCall();
     63 
     64         final MockInCallService inCallService = mInCallCallbacks.getService();
     65 
     66         final Call call = inCallService.getLastCall();
     67 
     68         assertCallState(call, Call.STATE_RINGING);
     69         assertConnectionState(connection, Connection.STATE_RINGING);
     70 
     71         connection.setDisconnected(new DisconnectCause(DisconnectCause.MISSED));
     72         connection.destroy();
     73         mShowMissedCallNotificationIntentCounter.waitForCount(1);
     74     }
     75 
     76 }
     77