• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.server.telecom.ui;
18 
19 import com.android.server.telecom.R;
20 import com.android.server.telecom.TelecomBroadcastIntentProcessor;
21 import com.android.server.telecom.components.TelecomBroadcastReceiver;
22 
23 import android.app.Activity;
24 import android.app.AlertDialog;
25 import android.content.DialogInterface;
26 import android.content.Intent;
27 import android.os.Bundle;
28 import android.telecom.Log;
29 
30 /**
31  * Dialog activity used when there is an ongoing self-managed call and the user initiates a new
32  * outgoing managed call.  The dialog prompts the user to see if they want to disconnect the ongoing
33  * self-managed call in order to place the new managed call.
34  */
35 public class ConfirmCallDialogActivity extends Activity {
36     public static final String EXTRA_OUTGOING_CALL_ID = "android.telecom.extra.OUTGOING_CALL_ID";
37     public static final String EXTRA_ONGOING_APP_NAME = "android.telecom.extra.ONGOING_APP_NAME";
38 
39     @Override
onCreate(Bundle savedInstanceState)40     protected void onCreate(Bundle savedInstanceState) {
41         super.onCreate(savedInstanceState);
42         final String callId = getIntent().getStringExtra(EXTRA_OUTGOING_CALL_ID);
43         final CharSequence ongoingAppName = getIntent().getCharSequenceExtra(
44                 EXTRA_ONGOING_APP_NAME);
45         showDialog(callId, ongoingAppName);
46     }
47 
showDialog(final String callId, CharSequence ongoingAppName)48     private void showDialog(final String callId, CharSequence ongoingAppName) {
49         Log.i(this, "showDialog: confirming callId=%s, ongoing=%s", callId, ongoingAppName);
50         CharSequence message = getString(R.string.alert_outgoing_call, ongoingAppName);
51         final AlertDialog errorDialog = new AlertDialog.Builder(this)
52                 .setMessage(message)
53                 .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
54                     @Override
55                     public void onClick(DialogInterface dialog, int which) {
56                         Intent proceedWithCall = new Intent(
57                                 TelecomBroadcastIntentProcessor.ACTION_PROCEED_WITH_CALL, null,
58                                 ConfirmCallDialogActivity.this,
59                                 TelecomBroadcastReceiver.class);
60                         proceedWithCall.putExtra(EXTRA_OUTGOING_CALL_ID, callId);
61                         sendBroadcast(proceedWithCall);
62                         dialog.dismiss();
63                         finish();
64                     }
65                 })
66                 .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
67                     @Override
68                     public void onClick(DialogInterface dialog, int which) {
69                         Intent cancelCall = new Intent(
70                                 TelecomBroadcastIntentProcessor.ACTION_CANCEL_CALL, null,
71                                 ConfirmCallDialogActivity.this,
72                                 TelecomBroadcastReceiver.class);
73                         cancelCall.putExtra(EXTRA_OUTGOING_CALL_ID, callId);
74                         sendBroadcast(cancelCall);
75                         dialog.dismiss();
76                         finish();
77                     }
78                 })
79                 .setOnCancelListener(new DialogInterface.OnCancelListener() {
80                     @Override
81                     public void onCancel(DialogInterface dialog) {
82                         Intent cancelCall = new Intent(
83                                 TelecomBroadcastIntentProcessor.ACTION_CANCEL_CALL, null,
84                                 ConfirmCallDialogActivity.this,
85                                 TelecomBroadcastReceiver.class);
86                         cancelCall.putExtra(EXTRA_OUTGOING_CALL_ID, callId);
87                         sendBroadcast(cancelCall);
88                         dialog.dismiss();
89                         finish();
90                     }
91                 })
92                 .create();
93 
94         errorDialog.show();
95     }
96 }
97