Merge "Fallback to AOSP emergency info if the original intent is broken" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
afbf9e60c0
@@ -220,10 +220,21 @@
|
||||
<!-- Settings intelligence interaction log intent action -->
|
||||
<string name="config_settingsintelligence_log_action" translatable="false"></string>
|
||||
|
||||
<!-- AOSP Emergency app package name -->
|
||||
<string name="config_aosp_emergency_package_name" translatable="false">
|
||||
com.android.emergency
|
||||
</string>
|
||||
|
||||
<!-- AOSP Emergency app intent action -->
|
||||
<string name="config_aosp_emergency_intent_action" translatable="false">
|
||||
android.settings.EDIT_EMERGENCY_INFO
|
||||
</string>
|
||||
|
||||
<!-- Emergency app package name -->
|
||||
<string name="config_emergency_package_name" translatable="false">
|
||||
com.android.emergency
|
||||
</string>
|
||||
|
||||
<!-- Emergency app intent action -->
|
||||
<string name="config_emergency_intent_action" translatable="false">
|
||||
android.settings.EDIT_EMERGENCY_INFO
|
||||
|
@@ -24,6 +24,7 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -34,9 +35,8 @@ import java.util.List;
|
||||
|
||||
public class EmergencyInfoPreferenceController extends BasePreferenceController {
|
||||
|
||||
public static String getIntentAction(Context context) {
|
||||
return context.getResources().getString(R.string.config_emergency_intent_action);
|
||||
}
|
||||
@VisibleForTesting
|
||||
Intent mIntent;
|
||||
|
||||
public EmergencyInfoPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
@@ -62,10 +62,9 @@ public class EmergencyInfoPreferenceController extends BasePreferenceController
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (TextUtils.equals(getPreferenceKey(), preference.getKey())) {
|
||||
Intent intent = new Intent(getIntentAction(mContext));
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
mContext.startActivity(intent);
|
||||
if (TextUtils.equals(getPreferenceKey(), preference.getKey()) && mIntent != null) {
|
||||
mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
mContext.startActivity(mIntent);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -76,15 +75,38 @@ public class EmergencyInfoPreferenceController extends BasePreferenceController
|
||||
if (!mContext.getResources().getBoolean(R.bool.config_show_emergency_info_in_device_info)) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
final Intent intent = new Intent(getIntentAction(mContext)).setPackage(
|
||||
getPackageName(mContext));
|
||||
final List<ResolveInfo> infos = mContext.getPackageManager().queryIntentActivities(intent,
|
||||
0);
|
||||
return infos != null && !infos.isEmpty()
|
||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
// If the variant of emergency info can not work, we should fallback to AOSP version.
|
||||
if (isEmergencyInfoSupported()) {
|
||||
return AVAILABLE;
|
||||
} else if (isAOSPVersionSupported()) {
|
||||
return AVAILABLE;
|
||||
}
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
private static String getPackageName(Context context) {
|
||||
return context.getResources().getString(R.string.config_emergency_package_name);
|
||||
private boolean isEmergencyInfoSupported() {
|
||||
final String packageName = mContext.getResources().getString(
|
||||
R.string.config_emergency_package_name);
|
||||
final String intentName = mContext.getResources().getString(
|
||||
R.string.config_emergency_intent_action);
|
||||
mIntent = new Intent(intentName).setPackage(packageName);
|
||||
final List<ResolveInfo> infos = mContext.getPackageManager().queryIntentActivities(mIntent,
|
||||
0);
|
||||
|
||||
return infos != null && !infos.isEmpty();
|
||||
}
|
||||
|
||||
private boolean isAOSPVersionSupported() {
|
||||
final String aospPackageName = mContext.getResources().getString(
|
||||
R.string.config_aosp_emergency_package_name);
|
||||
final String aospIntentName = mContext.getResources().getString(
|
||||
R.string.config_aosp_emergency_intent_action);
|
||||
|
||||
mIntent = new Intent(aospIntentName).setPackage(aospPackageName);
|
||||
final List<ResolveInfo> infos = mContext.getPackageManager().queryIntentActivities(mIntent,
|
||||
0);
|
||||
|
||||
return infos != null && !infos.isEmpty();
|
||||
}
|
||||
}
|
||||
|
@@ -156,10 +156,11 @@ public class EmergencyInfoPreferenceControllerTest {
|
||||
final Preference preference = new Preference(activity);
|
||||
preference.setKey("emergency_info");
|
||||
mController = new EmergencyInfoPreferenceController(activity, preference.getKey());
|
||||
mController.mIntent = new Intent("com.example.action.new").setPackage("com.example.test");
|
||||
|
||||
mController.handlePreferenceTreeClick(preference);
|
||||
|
||||
assertThat(application.getNextStartedActivity().getAction())
|
||||
.isEqualTo("android.settings.EDIT_EMERGENCY_INFO");
|
||||
.isEqualTo("com.example.action.new");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user