Fallback to AOSP emergency info if the original intent is broken

If the variant of emergency info is broken, we should try to show
AOSP emergency info instead.

Test: Rebuilt rom and see the Ui. Run robo test
Fix: 154114259
Change-Id: I5bc3f6cbf9102a7b7299c3edf718a58101effbf8
This commit is contained in:
Tsung-Mao Fang
2020-04-16 17:17:38 +08:00
parent 79a38a733f
commit b3bb7a0237
3 changed files with 50 additions and 16 deletions

View File

@@ -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();
}
}