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 com.android.cts.verifier.dialer; 18 19 import android.app.Notification; 20 import android.app.NotificationChannel; 21 import android.app.NotificationManager; 22 import android.content.Context; 23 import android.os.Bundle; 24 import android.view.View; 25 import android.widget.CheckBox; 26 import android.widget.CompoundButton; 27 import com.android.cts.verifier.PassFailButtons; 28 import com.android.cts.verifier.R; 29 import com.android.cts.verifier.voicemail.DefaultDialerChanger; 30 import java.util.Observable; 31 import java.util.Observer; 32 33 /** Tests that a third party dialer can show a heads up notification on an incoming call. */ 34 public class DialerShowsHunOnIncomingCallActivity extends PassFailButtons.Activity 35 implements Observer { 36 37 private CheckBox mConfirmHunShown; 38 private DefaultDialerChanger mDefaultDialerChanger; 39 40 @Override onCreate(Bundle savedInstanceState)41 protected void onCreate(Bundle savedInstanceState) { 42 super.onCreate(savedInstanceState); 43 44 View view = getLayoutInflater().inflate(R.layout.dialer_hun_on_incoming, null); 45 setContentView(view); 46 setInfoResources( 47 R.string.dialer_shows_hun_test, R.string.dialer_shows_hun_test_instructions, -1); 48 setPassFailButtonClickListeners(); 49 getPassButton().setEnabled(false); 50 51 mConfirmHunShown = findViewById(R.id.dialer_shows_hun_check_box); 52 53 mConfirmHunShown.setOnCheckedChangeListener( 54 (CompoundButton unusedButton, boolean unusedBoolean) -> onCheckedChangeListener()); 55 DialerCallTestService.getObservable().addObserver(this); 56 mDefaultDialerChanger = new DefaultDialerChanger(this); 57 } 58 59 @Override update(Observable observable, Object data)60 public void update(Observable observable, Object data) { 61 if (DialerCallTestService.getObservable().getOnIncoming()) { 62 NotificationManager notificationManager = 63 (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 64 65 String id = "dialer_hun_test"; 66 NotificationChannel channel = 67 new NotificationChannel(id, "incoming_call", NotificationManager.IMPORTANCE_MAX); 68 channel.enableLights(true); 69 channel.enableVibration(true); 70 channel.setShowBadge(false); 71 notificationManager.createNotificationChannel(channel); 72 73 Notification notification = 74 new Notification.Builder(DialerShowsHunOnIncomingCallActivity.this) 75 .setContentTitle(getResources().getString(R.string.dialer_incoming_call_hun_teaser)) 76 .setContentText(getResources().getString(R.string.dialer_incoming_call_hun_desc)) 77 .setSmallIcon(R.drawable.fs_good) 78 .setChannelId(id) 79 .build(); 80 81 int notifyID = 1; 82 notificationManager.notify(notifyID, notification); 83 } 84 } 85 onCheckedChangeListener()86 private void onCheckedChangeListener() { 87 mDefaultDialerChanger.setRestorePending(true); 88 if (mConfirmHunShown.isChecked()) { 89 getPassButton().setEnabled(true); 90 } else { 91 getPassButton().setEnabled(false); 92 } 93 } 94 95 @Override onDestroy()96 protected void onDestroy() { 97 mDefaultDialerChanger.destroy(); 98 DialerCallTestService.getObservable().deleteObserver(this); 99 super.onDestroy(); 100 } 101 } 102