diff options
| author | Xin Li <delphij@google.com> | 2016-10-13 13:39:53 -0700 |
|---|---|---|
| committer | Xin Li <delphij@google.com> | 2016-10-13 13:40:33 -0700 |
| commit | 9b9906e9c017d84e722d9419d1025272db4bb582 (patch) | |
| tree | 092c176c552ce1b3ba9fadf31afdb4a7ccc89699 /core/java | |
| parent | 137c545e4e153200424f1d6cb368394827cdc6a2 (diff) | |
| parent | 15592d4a8e8317d88a3bf9301ce4939351e4766e (diff) | |
Merge "Merge "DO NOT MERGE - Added Emergency affordance feature"
into nougat-dev" into nyc-dev.
Change-Id: Iffde36524f2335b90d4887dcdd189eaf55dc60e6
Diffstat (limited to 'core/java')
| -rwxr-xr-x | core/java/android/provider/Settings.java | 7 | ||||
| -rw-r--r-- | core/java/com/android/internal/policy/EmergencyAffordanceManager.java | 101 |
2 files changed, 108 insertions, 0 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 42ac76bf84c0..19dc408b4f26 100755 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -8196,6 +8196,13 @@ public final class Settings { public static final String CALL_AUTO_RETRY = "call_auto_retry"; /** + * A setting that can be read whether the emergency affordance is currently needed. + * The value is a boolean (1 or 0). + * @hide + */ + public static final String EMERGENCY_AFFORDANCE_NEEDED = "emergency_affordance_needed"; + + /** * See RIL_PreferredNetworkType in ril.h * @hide */ diff --git a/core/java/com/android/internal/policy/EmergencyAffordanceManager.java b/core/java/com/android/internal/policy/EmergencyAffordanceManager.java new file mode 100644 index 000000000000..bed7c1ba4ed3 --- /dev/null +++ b/core/java/com/android/internal/policy/EmergencyAffordanceManager.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.internal.policy; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Build; +import android.provider.Settings; + +/** + * A class that manages emergency affordances and enables immediate calling to emergency services + */ +public class EmergencyAffordanceManager { + + public static final boolean ENABLED = true; + + /** + * Global setting override with the number to call with the emergency affordance. + * @hide + */ + private static final String EMERGENCY_CALL_NUMBER_SETTING = "emergency_affordance_number"; + + /** + * Global setting, whether the emergency affordance should be shown regardless of device state. + * The value is a boolean (1 or 0). + * @hide + */ + private static final String FORCE_EMERGENCY_AFFORDANCE_SETTING = "force_emergency_affordance"; + + private final Context mContext; + + public EmergencyAffordanceManager(Context context) { + mContext = context; + } + + /** + * perform an emergency call. + */ + public final void performEmergencyCall() { + performEmergencyCall(mContext); + } + + private static Uri getPhoneUri(Context context) { + String number = context.getResources().getString( + com.android.internal.R.string.config_emergency_call_number); + if (Build.IS_DEBUGGABLE) { + String override = Settings.Global.getString( + context.getContentResolver(), EMERGENCY_CALL_NUMBER_SETTING); + if (override != null) { + number = override; + } + } + return Uri.fromParts("tel", number, null); + } + + private static void performEmergencyCall(Context context) { + Intent intent = new Intent(Intent.ACTION_CALL_EMERGENCY); + intent.setData(getPhoneUri(context)); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } + + /** + * @return whether emergency affordance should be active. + */ + public boolean needsEmergencyAffordance() { + if (!ENABLED) { + return false; + } + if (forceShowing()) { + return true; + } + return isEmergencyAffordanceNeeded(); + } + + private boolean isEmergencyAffordanceNeeded() { + return Settings.Global.getInt(mContext.getContentResolver(), + Settings.Global.EMERGENCY_AFFORDANCE_NEEDED, 0) != 0; + } + + + private boolean forceShowing() { + return Settings.Global.getInt(mContext.getContentResolver(), + FORCE_EMERGENCY_AFFORDANCE_SETTING, 0) != 0; + } +} |
