summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSvetoslav <svetoslavganov@google.com>2015-04-10 17:25:35 -0700
committerSvetoslav <svetoslavganov@google.com>2015-04-10 18:19:03 -0700
commitb0a78390ed834724e9c6adf0feff9931d7f9ec10 (patch)
tree95f0a64171ed82c9e7833f8d79d9492112a6db17
parent682a433d0b8ff3e4e0ffc8d2cfedc8907ab1e83b (diff)
downloadframeworks_base-b0a78390ed834724e9c6adf0feff9931d7f9ec10.zip
frameworks_base-b0a78390ed834724e9c6adf0feff9931d7f9ec10.tar.gz
frameworks_base-b0a78390ed834724e9c6adf0feff9931d7f9ec10.tar.bz2
Add a mechanism to make pending intents immutable.
bug:19618745 Change-Id: Ice742e0162cb9b7c0afbc32e0eea03d501666e2b
-rw-r--r--api/current.txt1
-rw-r--r--api/system-current.txt1
-rw-r--r--core/java/android/app/PendingIntent.java15
-rw-r--r--services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java11
-rw-r--r--services/core/java/com/android/server/am/PendingIntentRecord.java19
-rw-r--r--services/print/java/com/android/server/print/UserState.java4
6 files changed, 38 insertions, 13 deletions
diff --git a/api/current.txt b/api/current.txt
index 50f4f59..bb47365 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -5101,6 +5101,7 @@ package android.app {
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.app.PendingIntent> CREATOR;
field public static final int FLAG_CANCEL_CURRENT = 268435456; // 0x10000000
+ field public static final int FLAG_IMMUTABLE = 67108864; // 0x4000000
field public static final int FLAG_NO_CREATE = 536870912; // 0x20000000
field public static final int FLAG_ONE_SHOT = 1073741824; // 0x40000000
field public static final int FLAG_UPDATE_CURRENT = 134217728; // 0x8000000
diff --git a/api/system-current.txt b/api/system-current.txt
index 9518b18..7d3fc78 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -5192,6 +5192,7 @@ package android.app {
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.app.PendingIntent> CREATOR;
field public static final int FLAG_CANCEL_CURRENT = 268435456; // 0x10000000
+ field public static final int FLAG_IMMUTABLE = 67108864; // 0x4000000
field public static final int FLAG_NO_CREATE = 536870912; // 0x20000000
field public static final int FLAG_ONE_SHOT = 1073741824; // 0x40000000
field public static final int FLAG_UPDATE_CURRENT = 134217728; // 0x8000000
diff --git a/core/java/android/app/PendingIntent.java b/core/java/android/app/PendingIntent.java
index cf14202..2cfc1fa4 100644
--- a/core/java/android/app/PendingIntent.java
+++ b/core/java/android/app/PendingIntent.java
@@ -151,6 +151,14 @@ public final class PendingIntent implements Parcelable {
public static final int FLAG_UPDATE_CURRENT = 1<<27;
/**
+ * Flag indicating that the created PendingIntent should be immutable.
+ * This means that the additional intent argument passed to the send
+ * methods to fill in unpopulated properties of this intent will be
+ * ignored.
+ */
+ public static final int FLAG_IMMUTABLE = 1<<26;
+
+ /**
* Exception thrown when trying to send through a PendingIntent that
* has been canceled or is otherwise no longer able to execute the request.
*/
@@ -618,7 +626,8 @@ public final class PendingIntent implements Parcelable {
* @param code Result code to supply back to the PendingIntent's target.
* @param intent Additional Intent data. See {@link Intent#fillIn
* Intent.fillIn()} for information on how this is applied to the
- * original Intent.
+ * original Intent. If flag {@link #FLAG_IMMUTABLE} was set when this
+ * pending intent was created, this argument will be ignored.
*
* @see #send(Context, int, Intent, android.app.PendingIntent.OnFinished, Handler)
*
@@ -667,6 +676,8 @@ public final class PendingIntent implements Parcelable {
* @param intent Additional Intent data. See {@link Intent#fillIn
* Intent.fillIn()} for information on how this is applied to the
* original Intent. Use null to not modify the original Intent.
+ * If flag {@link #FLAG_IMMUTABLE} was set when this pending intent was
+ * created, this argument will be ignored.
* @param onFinished The object to call back on when the send has
* completed, or null for no callback.
* @param handler Handler identifying the thread on which the callback
@@ -703,6 +714,8 @@ public final class PendingIntent implements Parcelable {
* @param intent Additional Intent data. See {@link Intent#fillIn
* Intent.fillIn()} for information on how this is applied to the
* original Intent. Use null to not modify the original Intent.
+ * If flag {@link #FLAG_IMMUTABLE} was set when this pending intent was
+ * created, this argument will be ignored.
* @param onFinished The object to call back on when the send has
* completed, or null for no callback.
* @param handler Handler identifying the thread on which the callback
diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
index da11dad..f42aef1 100644
--- a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
+++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
@@ -674,7 +674,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
@Override
public IntentSender createAppWidgetConfigIntentSender(String callingPackage, int appWidgetId,
- int intentFlags) {
+ final int intentFlags) {
final int userId = UserHandle.getCallingUserId();
if (DEBUG) {
@@ -701,18 +701,21 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
throw new IllegalArgumentException("Widget not bound " + appWidgetId);
}
+ // Make sure only safe flags can be passed it.
+ final int secureFlags = intentFlags & ~Intent.IMMUTABLE_FLAGS;
+
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
intent.setComponent(provider.info.configure);
- intent.setFlags(intentFlags);
+ intent.setFlags(secureFlags);
// All right, create the sender.
final long identity = Binder.clearCallingIdentity();
try {
return PendingIntent.getActivityAsUser(
mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT
- | PendingIntent.FLAG_CANCEL_CURRENT, null,
- new UserHandle(provider.getUserId()))
+ | PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_CANCEL_CURRENT,
+ null, new UserHandle(provider.getUserId()))
.getIntentSender();
} finally {
Binder.restoreCallingIdentity(identity);
diff --git a/services/core/java/com/android/server/am/PendingIntentRecord.java b/services/core/java/com/android/server/am/PendingIntentRecord.java
index 9c0db87..531de46 100644
--- a/services/core/java/com/android/server/am/PendingIntentRecord.java
+++ b/services/core/java/com/android/server/am/PendingIntentRecord.java
@@ -222,19 +222,26 @@ final class PendingIntentRecord extends IIntentSender.Stub {
owner.cancelIntentSenderLocked(this, true);
canceled = true;
}
+
Intent finalIntent = key.requestIntent != null
? new Intent(key.requestIntent) : new Intent();
- if (intent != null) {
- int changes = finalIntent.fillIn(intent, key.flags);
- if ((changes&Intent.FILL_IN_DATA) == 0) {
+
+ final boolean immutable = (key.flags & PendingIntent.FLAG_IMMUTABLE) != 0;
+ if (!immutable) {
+ if (intent != null) {
+ int changes = finalIntent.fillIn(intent, key.flags);
+ if ((changes & Intent.FILL_IN_DATA) == 0) {
+ resolvedType = key.requestResolvedType;
+ }
+ } else {
resolvedType = key.requestResolvedType;
}
+ flagsMask &= ~Intent.IMMUTABLE_FLAGS;
+ flagsValues &= flagsMask;
+ finalIntent.setFlags((finalIntent.getFlags() & ~flagsMask) | flagsValues);
} else {
resolvedType = key.requestResolvedType;
}
- flagsMask &= ~Intent.IMMUTABLE_FLAGS;
- flagsValues &= flagsMask;
- finalIntent.setFlags((finalIntent.getFlags()&~flagsMask) | flagsValues);
final long origId = Binder.clearCallingIdentity();
diff --git a/services/print/java/com/android/server/print/UserState.java b/services/print/java/com/android/server/print/UserState.java
index 33edb11..ae19dac 100644
--- a/services/print/java/com/android/server/print/UserState.java
+++ b/services/print/java/com/android/server/print/UserState.java
@@ -204,8 +204,8 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks {
IntentSender intentSender = PendingIntent.getActivityAsUser(
mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT
- | PendingIntent.FLAG_CANCEL_CURRENT, null, new UserHandle(mUserId))
- .getIntentSender();
+ | PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE,
+ null, new UserHandle(mUserId)) .getIntentSender();
Bundle result = new Bundle();
result.putParcelable(PrintManager.EXTRA_PRINT_JOB, printJob);