Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a6c2591 authored by Christopher Tate's avatar Christopher Tate
Browse files

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 af0d3952
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -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);