Commit 89487296 authored by Christopher Tate's avatar Christopher Tate Committed by The Android Automerger

Don't crash if the backup transport supplies bogus intents

Preflight the (activity) intents supplied by the transport so that when
clicked, they don't crash the Preference that called startActivity().

Bug 27689847

Change-Id: I7cbdd6077ac74500ecdf9607310727af56d55a3c
parent 267efeb7
......@@ -21,6 +21,8 @@ import android.app.backup.IBackupManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
......@@ -155,9 +157,11 @@ public class PrivacySettings extends SettingsPreferenceFragment implements Index
try {
backupEnabled = mBackupManager.isBackupEnabled();
String transport = mBackupManager.getCurrentTransport();
configIntent = mBackupManager.getConfigurationIntent(transport);
configIntent = validatedActivityIntent(
mBackupManager.getConfigurationIntent(transport), "config");
configSummary = mBackupManager.getDestinationString(transport);
manageIntent = mBackupManager.getDataManagementIntent(transport);
manageIntent = validatedActivityIntent(
mBackupManager.getDataManagementIntent(transport), "management");
manageLabel = mBackupManager.getDataManagementLabel(transport);
mBackup.setSummary(backupEnabled
......@@ -189,6 +193,19 @@ public class PrivacySettings extends SettingsPreferenceFragment implements Index
}
}
private Intent validatedActivityIntent(Intent intent, String logLabel) {
if (intent != null) {
PackageManager pm = getPackageManager();
List<ResolveInfo> resolved = pm.queryIntentActivities(intent, 0);
if (resolved == null || resolved.isEmpty()) {
intent = null;
Log.e(TAG, "Backup " + logLabel + " intent " + intent
+ " fails to resolve; ignoring");
}
}
return intent;
}
private void setConfigureSummary(String summary) {
if (summary != null) {
mConfigure.setSummary(summary);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment