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

Commit 75e0af89 authored by Adam Powell's avatar Adam Powell
Browse files

TaskStackBuilder correctness fixes

* Don't mutate original intents when adding default flags.

* Add the relevant flags to the array returned by getIntents() such
  that it can be used directly in a call to startActivities or
  similar.

* Deep copy the component intents when building an intent array for
  getIntents()

* Clean up some internal code duplication

Change-Id: I71d3b7f30d4f7d8f1cce778d406ea0e513d382c5
parent e2f0ec89
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -216,11 +216,7 @@ public class TaskStackBuilder {
                    "No intents added to TaskStackBuilder; cannot startActivities");
        }

        Intent[] intents = mIntents.toArray(new Intent[mIntents.size()]);
        intents[0].addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                Intent.FLAG_ACTIVITY_CLEAR_TASK |
                Intent.FLAG_ACTIVITY_TASK_ON_HOME);
        mSourceContext.startActivities(intents, options);
        mSourceContext.startActivities(getIntents(), options);
    }

    /**
@@ -260,11 +256,8 @@ public class TaskStackBuilder {
                    "No intents added to TaskStackBuilder; cannot getPendingIntent");
        }

        Intent[] intents = mIntents.toArray(new Intent[mIntents.size()]);
        intents[0].addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                Intent.FLAG_ACTIVITY_CLEAR_TASK |
                Intent.FLAG_ACTIVITY_TASK_ON_HOME);
        return PendingIntent.getActivities(mSourceContext, requestCode, intents, flags, options);
        return PendingIntent.getActivities(mSourceContext, requestCode, getIntents(),
                flags, options);
    }

    /**
@@ -275,6 +268,15 @@ public class TaskStackBuilder {
     * @return An array containing the intents added to this builder.
     */
    public Intent[] getIntents() {
        return mIntents.toArray(new Intent[mIntents.size()]);
        Intent[] intents = new Intent[mIntents.size()];
        if (intents.length == 0) return intents;

        intents[0] = new Intent(mIntents.get(0)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                Intent.FLAG_ACTIVITY_CLEAR_TASK |
                Intent.FLAG_ACTIVITY_TASK_ON_HOME);
        for (int i = 1; i < intents.length; i++) {
            intents[i] = new Intent(mIntents.get(i));
        }
        return intents;
    }
}