Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc115c59 authored by Xin Li's avatar Xin Li Committed by Android (Google) Code Review
Browse files

Merge "Merge "Merge "DO NOT MERGE - Added Emergency affordance feature" into...

Merge "Merge "Merge "DO NOT MERGE - Added Emergency affordance feature" into marshmallow-dev" into mnc-dev." into mnc-dev
parents 34849c22 ee290368
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -7405,6 +7405,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
+101 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}
+34 −0
Original line number Diff line number Diff line
<!--
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24.0dp"
    android:height="24.0dp"
    android:viewportWidth="68.0"
    android:viewportHeight="68.0"
    android:tint="?attr/colorControlNormal">
    <path
        android:fillColor="#FF000000"
        android:pathData="M55.2,58.3l-6.3,-7.8C54.0,46.3 57.0,40.1 57.0,33.4c0.0,-6.2 -2.6,-12.1 -7.2,-16.3l6.7,-7.4C63.2,15.8 67.0,24.4 67.0,33.4C67.0,43.1 62.7,52.2 55.2,58.3z"/>
    <path
        android:fillColor="#FF000000"
        android:pathData="M12.9,58.3C5.3,52.2 1.0,43.1 1.0,33.4c0.0,-9.0 3.8,-17.6 10.5,-23.7l6.7,7.4C13.6,21.3 11.0,27.2 11.0,33.4c0.0,6.7 3.0,12.9 8.2,17.1L12.9,58.3z"/>
    <path
        android:fillColor="#FF000000"
        android:pathData="M29.0,11.4l10.0,0.0l0.0,29.0l-10.0,0.0z"/>
    <path
        android:fillColor="#FF000000"
        android:pathData="M29.0,48.4l10.0,0.0l0.0,9.0l-10.0,0.0z"/>
</vector>
+1 −0
Original line number Diff line number Diff line
@@ -208,6 +208,7 @@
    <string name="global_actions" product="default" msgid="2406416831541615258">"Foonopsies"</string>
    <string name="global_action_lock" msgid="2844945191792119712">"Skermslot"</string>
    <string name="global_action_power_off" msgid="4471879440839879722">"Sit af"</string>
    <string name="global_action_emergency" msgid="7112311161137421166">"Noodgeval"</string>
    <string name="global_action_bug_report" msgid="7934010578922304799">"Foutverslag"</string>
    <string name="bugreport_title" msgid="2667494803742548533">"Neem foutverslag"</string>
    <string name="bugreport_message" msgid="398447048750350456">"Dit sal inligting oor die huidige toestand van jou toestel insamel om as \'n e-posboodskap te stuur. Dit sal \'n tydjie neem vandat die foutverslag begin is totdat dit reg is om gestuur te word; wees asseblief geduldig."</string>
+1 −0
Original line number Diff line number Diff line
@@ -208,6 +208,7 @@
    <string name="global_actions" product="default" msgid="2406416831541615258">"የስልክ አማራጮች"</string>
    <string name="global_action_lock" msgid="2844945191792119712">"ማያ ቆልፍ"</string>
    <string name="global_action_power_off" msgid="4471879440839879722">"ኃይል አጥፋ"</string>
    <string name="global_action_emergency" msgid="7112311161137421166">"ድንገተኛ አደጋ"</string>
    <string name="global_action_bug_report" msgid="7934010578922304799">"የሳንካ ሪፖርት"</string>
    <string name="bugreport_title" msgid="2667494803742548533">"የሳንካ ሪፖርት ውሰድ"</string>
    <string name="bugreport_message" msgid="398447048750350456">"ይሄ እንደ የኢሜይል መልዕክት አድርጎ የሚልከውን ስለመሣሪያዎ የአሁኑ ሁኔታ መረጃ ይሰበስባል። የሳንካ ሪፖርቱን ከመጀመር ጀምሮ እስኪላክ ድረስ ትንሽ ጊዜ ይወስዳል፤ እባክዎ ይታገሱ።"</string>
Loading