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.testapps;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.os.Bundle;
23 import android.telecom.Log;
24 import android.telecom.TelecomManager;
25 import android.telephony.DisconnectCause;
26 import android.view.View;
27 import android.widget.Button;
28 
29 /**
30  * Displays a UX to the user confirming whether they want to handover a call to the self-managed CS.
31  */
32 public class HandoverActivity extends Activity {
33     public static final String EXTRA_CALL_ID = "com.android.server.telecom.testapps.extra.CALL_ID";
34 
35     private Button mAcceptHandoverButton;
36     private Button mRejectHandoverButton;
37 
38     @Override
onCreate(Bundle savedInstanceState)39     public void onCreate(Bundle savedInstanceState) {
40         super.onCreate(savedInstanceState);
41         Intent launchingIntent = getIntent();
42         int callId = launchingIntent.getIntExtra(EXTRA_CALL_ID, 0);
43         Log.i(this, "showing fullscreen upgrade ux for call id %d", callId);
44 
45         setContentView(R.layout.self_managed_handover);
46         final SelfManagedConnection connection = SelfManagedCallList.getInstance()
47                 .getConnectionById(callId);
48         mAcceptHandoverButton = (Button) findViewById(R.id.acceptUpgradeButton);
49         mAcceptHandoverButton.setOnClickListener((View v) -> {
50             if (connection != null) {
51                 connection.setConnectionActive();
52                 Intent intent = new Intent(Intent.ACTION_MAIN, null);
53                 intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION |
54                         Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
55                 intent.setClass(this, SelfManagedCallingActivity.class);
56                 startActivity(intent);
57             }
58             finish();
59         });
60         mRejectHandoverButton = (Button) findViewById(R.id.rejectUpgradeButton);
61         mRejectHandoverButton.setOnClickListener((View v) -> {
62             if (connection != null) {
63                 connection.setConnectionDisconnected(DisconnectCause.INCOMING_REJECTED);
64                 connection.destroy();
65                 TelecomManager tm = this.getSystemService(TelecomManager.class);
66                 tm.showInCallScreen(false);
67             }
68             finish();
69         });
70     }
71 }
72