Hide emergency app setting when not available
Bug: 20117344 Change-Id: Ieb6d166c0fa7c7376bbf262fa831ff3f626fce57
This commit is contained in:
@@ -43,6 +43,9 @@ public class DefaultEmergencyPreference extends AppListPreference {
|
|||||||
|
|
||||||
private final ContentResolver mContentResolver;
|
private final ContentResolver mContentResolver;
|
||||||
|
|
||||||
|
public static final Intent QUERY_INTENT = new Intent(
|
||||||
|
TelephonyManager.ACTION_EMERGENCY_ASSISTANCE);
|
||||||
|
|
||||||
public DefaultEmergencyPreference(Context context, AttributeSet attrs) {
|
public DefaultEmergencyPreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
mContentResolver = context.getContentResolver();
|
mContentResolver = context.getContentResolver();
|
||||||
@@ -85,18 +88,19 @@ public class DefaultEmergencyPreference extends AppListPreference {
|
|||||||
private Set<String> resolveAssistPackageAndQueryApps() {
|
private Set<String> resolveAssistPackageAndQueryApps() {
|
||||||
Set<String> packages = new ArraySet<>();
|
Set<String> packages = new ArraySet<>();
|
||||||
|
|
||||||
Intent queryIntent = new Intent(TelephonyManager.ACTION_EMERGENCY_ASSISTANCE);
|
|
||||||
PackageManager packageManager = getContext().getPackageManager();
|
PackageManager packageManager = getContext().getPackageManager();
|
||||||
List<ResolveInfo> infos = packageManager.queryIntentActivities(queryIntent, 0);
|
List<ResolveInfo> infos = packageManager.queryIntentActivities(QUERY_INTENT, 0);
|
||||||
|
|
||||||
PackageInfo bestMatch = null;
|
PackageInfo bestMatch = null;
|
||||||
for (int i = 0; i < infos.size(); i++) {
|
final int size = infos.size();
|
||||||
if (infos.get(i) == null || infos.get(i).activityInfo == null
|
for (int i = 0; i < size; i++) {
|
||||||
|| packages.contains(infos.get(i).activityInfo.packageName)) {
|
ResolveInfo info = infos.get(i);
|
||||||
|
if (info == null || info.activityInfo == null
|
||||||
|
|| packages.contains(info.activityInfo.packageName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String packageName = infos.get(i).activityInfo.packageName;
|
String packageName = info.activityInfo.packageName;
|
||||||
|
|
||||||
packages.add(packageName);
|
packages.add(packageName);
|
||||||
|
|
||||||
@@ -130,6 +134,11 @@ public class DefaultEmergencyPreference extends AppListPreference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAvailable(Context context) {
|
public static boolean isAvailable(Context context) {
|
||||||
|
return isCapable(context)
|
||||||
|
&& context.getPackageManager().resolveActivity(QUERY_INTENT, 0) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isCapable(Context context) {
|
||||||
return context.getResources().getBoolean(
|
return context.getResources().getBoolean(
|
||||||
com.android.internal.R.bool.config_voice_capable);
|
com.android.internal.R.bool.config_voice_capable);
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,7 @@ import com.android.settings.InstrumentedFragment;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settings.search.Index;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -86,6 +87,11 @@ public class ManageDefaultApps extends SettingsPreferenceFragment
|
|||||||
if (!DefaultEmergencyPreference.isAvailable(getActivity())) {
|
if (!DefaultEmergencyPreference.isAvailable(getActivity())) {
|
||||||
removePreference(KEY_DEFAULT_EMERGENCY_APP);
|
removePreference(KEY_DEFAULT_EMERGENCY_APP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DefaultEmergencyPreference.isCapable(getActivity())) {
|
||||||
|
Index.getInstance(getActivity()).updateFromClassNameResource(
|
||||||
|
ManageDefaultApps.class.getName(), true, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user