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
This commit is contained in:
@@ -21,6 +21,8 @@ import android.app.backup.IBackupManager;
|
|||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
@@ -155,9 +157,11 @@ public class PrivacySettings extends SettingsPreferenceFragment implements Index
|
|||||||
try {
|
try {
|
||||||
backupEnabled = mBackupManager.isBackupEnabled();
|
backupEnabled = mBackupManager.isBackupEnabled();
|
||||||
String transport = mBackupManager.getCurrentTransport();
|
String transport = mBackupManager.getCurrentTransport();
|
||||||
configIntent = mBackupManager.getConfigurationIntent(transport);
|
configIntent = validatedActivityIntent(
|
||||||
|
mBackupManager.getConfigurationIntent(transport), "config");
|
||||||
configSummary = mBackupManager.getDestinationString(transport);
|
configSummary = mBackupManager.getDestinationString(transport);
|
||||||
manageIntent = mBackupManager.getDataManagementIntent(transport);
|
manageIntent = validatedActivityIntent(
|
||||||
|
mBackupManager.getDataManagementIntent(transport), "management");
|
||||||
manageLabel = mBackupManager.getDataManagementLabel(transport);
|
manageLabel = mBackupManager.getDataManagementLabel(transport);
|
||||||
|
|
||||||
mBackup.setSummary(backupEnabled
|
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) {
|
private void setConfigureSummary(String summary) {
|
||||||
if (summary != null) {
|
if (summary != null) {
|
||||||
mConfigure.setSummary(summary);
|
mConfigure.setSummary(summary);
|
||||||
|
Reference in New Issue
Block a user