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.settings;
18 
19 import android.app.Activity;
20 import android.app.AlertDialog;
21 import android.content.DialogInterface;
22 import android.os.Bundle;
23 import android.provider.BlockedNumbersManager;
24 
25 import com.android.server.telecom.R;
26 import com.android.server.telecom.flags.FeatureFlags;
27 import com.android.server.telecom.flags.FeatureFlagsImpl;
28 
29 /**
30  * Shows a dialog when user taps an notification in notification tray.
31  */
32 public class CallBlockDisabledActivity extends Activity {
33     private AlertDialog mDialog;
34     private FeatureFlags mFeatureFlags;
35 
36     @Override
onCreate(Bundle savedInstanceState)37     protected void onCreate(Bundle savedInstanceState) {
38         super.onCreate(savedInstanceState);
39         mFeatureFlags = new FeatureFlagsImpl();
40         showCallBlockingOffDialog();
41     }
42 
43     @Override
onDestroy()44     protected void onDestroy() {
45         super.onDestroy();
46         dismissCallBlockingOffDialog();
47     }
48 
49     /**
50      * Shows the dialog that notifies user that [Call Blocking] has been turned off.
51      */
showCallBlockingOffDialog()52     private void showCallBlockingOffDialog() {
53         if (isShowingCallBlockingOffDialog()) {
54             return;
55         }
56 
57         AlertDialog.Builder builder = new AlertDialog.Builder(this);
58         mDialog = builder
59                 .setTitle(R.string.phone_strings_emergency_call_made_dialog_title_txt)
60                 .setMessage(R.string
61                         .phone_strings_emergency_call_made_dialog_call_blocking_text_txt)
62                 .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
63                     @Override
64                     public void onClick(DialogInterface dialog, int which) {
65                         BlockedNumbersUtil.setBlockedNumberSetting(
66                                 CallBlockDisabledActivity.this,
67                                 BlockedNumbersManager
68                                         .ENHANCED_SETTING_KEY_SHOW_EMERGENCY_CALL_NOTIFICATION,
69                                 false, mFeatureFlags);
70                         BlockedNumbersUtil.updateEmergencyCallNotification(
71                                 CallBlockDisabledActivity.this, false);
72                         finish();
73                     }
74                 })
75                 .setOnCancelListener(new DialogInterface.OnCancelListener() {
76                     @Override
77                     public void onCancel(DialogInterface dialog) {
78                         finish();
79                     }
80                 })
81                 .create();
82         mDialog.setCanceledOnTouchOutside(false);
83         mDialog.show();
84     }
85 
86     /**
87      * Dismisses the dialog that notifies user that [Call Blocking] has been turned off.
88      */
dismissCallBlockingOffDialog()89     private void dismissCallBlockingOffDialog() {
90         if (isShowingCallBlockingOffDialog()) {
91             mDialog.dismiss();
92         }
93         mDialog = null;
94     }
95 
96     /**
97      * Checks whether the dialog is currently showing.
98      *
99      * @return true if the dialog is currently showing, false otherwise.
100      */
isShowingCallBlockingOffDialog()101     private boolean isShowingCallBlockingOffDialog() {
102         return (mDialog != null && mDialog.isShowing());
103     }
104 }
105