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.settings.applications.defaultapps; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.content.pm.ResolveInfo; 22 import android.provider.Settings; 23 import android.telephony.TelephonyManager; 24 25 import java.util.List; 26 27 public class DefaultEmergencyPreferenceController extends DefaultAppPreferenceController { 28 29 private static final boolean DEFAULT_EMERGENCY_APP_IS_CONFIGURABLE = false; 30 31 public static final Intent QUERY_INTENT = new Intent( 32 TelephonyManager.ACTION_EMERGENCY_ASSISTANCE); 33 34 public DefaultEmergencyPreferenceController(Context context) { 35 super(context); 36 } 37 38 @Override 39 public boolean isAvailable() { 40 return DEFAULT_EMERGENCY_APP_IS_CONFIGURABLE 41 && isCapable() 42 && mPackageManager.getPackageManager().resolveActivity(QUERY_INTENT, 0) != null; 43 } 44 45 @Override 46 public String getPreferenceKey() { 47 return "default_emergency_app"; 48 } 49 50 @Override 51 protected DefaultAppInfo getDefaultAppInfo() { 52 return null; 53 } 54 55 private boolean isCapable() { 56 return TelephonyManager.EMERGENCY_ASSISTANCE_ENABLED 57 && mContext.getResources().getBoolean( 58 com.android.internal.R.bool.config_voice_capable); 59 } 60 61 public static boolean hasEmergencyPreference(String pkg, Context context) { 62 Intent i = new Intent(QUERY_INTENT); 63 i.setPackage(pkg); 64 final List<ResolveInfo> resolveInfos = 65 context.getPackageManager().queryIntentActivities(i, 0); 66 return resolveInfos != null && resolveInfos.size() != 0; 67 } 68 69 public static boolean isEmergencyDefault(String pkg, Context context) { 70 String defaultPackage = Settings.Secure.getString(context.getContentResolver(), 71 Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION); 72 return defaultPackage != null && defaultPackage.equals(pkg); 73 } 74 } 75