2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
17 package com.android.internal.policy;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.net.Uri;
22 import android.os.Build;
23 import android.provider.Settings;
26 * A class that manages emergency affordances and enables immediate calling to emergency services
28 public class EmergencyAffordanceManager {
30 public static final boolean ENABLED = true;
33 * Global setting override with the number to call with the emergency affordance.
36 private static final String EMERGENCY_CALL_NUMBER_SETTING = "emergency_affordance_number";
39 * Global setting, whether the emergency affordance should be shown regardless of device state.
40 * The value is a boolean (1 or 0).
43 private static final String FORCE_EMERGENCY_AFFORDANCE_SETTING = "force_emergency_affordance";
45 private final Context mContext;
47 public EmergencyAffordanceManager(Context context) {
52 * perform an emergency call.
54 public final void performEmergencyCall() {
55 performEmergencyCall(mContext);
58 private static Uri getPhoneUri(Context context) {
59 String number = context.getResources().getString(
60 com.android.internal.R.string.config_emergency_call_number);
61 if (Build.IS_DEBUGGABLE) {
62 String override = Settings.Global.getString(
63 context.getContentResolver(), EMERGENCY_CALL_NUMBER_SETTING);
64 if (override != null) {
68 return Uri.fromParts("tel", number, null);
71 private static void performEmergencyCall(Context context) {
72 Intent intent = new Intent(Intent.ACTION_CALL_EMERGENCY);
73 intent.setData(getPhoneUri(context));
74 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
75 context.startActivity(intent);
79 * @return whether emergency affordance should be active.
81 public boolean needsEmergencyAffordance() {
88 return isEmergencyAffordanceNeeded();
91 private boolean isEmergencyAffordanceNeeded() {
92 return Settings.Global.getInt(mContext.getContentResolver(),
93 Settings.Global.EMERGENCY_AFFORDANCE_NEEDED, 0) != 0;
97 private boolean forceShowing() {
98 return Settings.Global.getInt(mContext.getContentResolver(),
99 FORCE_EMERGENCY_AFFORDANCE_SETTING, 0) != 0;