summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget/RemoteViews.java
diff options
context:
space:
mode:
authorSvetoslav <svetoslavganov@google.com>2014-07-16 15:12:03 -0700
committerSvetoslav Ganov <svetoslavganov@google.com>2014-08-05 20:57:20 +0000
commit976e8bd2017d0263216c62111454438cc0f130e3 (patch)
tree5cf592fb85841f9e41d3bf6b43422641c3609ab2 /core/java/android/widget/RemoteViews.java
parentc79eabcd3c6306bb2ec75f9584b79e661f265127 (diff)
downloadframeworks_base-976e8bd2017d0263216c62111454438cc0f130e3.zip
frameworks_base-976e8bd2017d0263216c62111454438cc0f130e3.tar.gz
frameworks_base-976e8bd2017d0263216c62111454438cc0f130e3.tar.bz2
Allow adding widgets from user profiles.
The goal of this change is to enable support for appwidget from user profiles to the user main profile. A user profile is a user which is associated as a child of the main user profile. For example, a user may have a personal (parent) and corporate (child) profile. The device policy should be able to control whether adding a widget from a child profile and given packages is allowed. This change assumes that all packages from managed profiles are white listed. Another change will add the device policy changes. Change-Id: I267260b55d74c48b112a29979a9f59eef7a8194e
Diffstat (limited to 'core/java/android/widget/RemoteViews.java')
-rw-r--r--core/java/android/widget/RemoteViews.java167
1 files changed, 89 insertions, 78 deletions
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index 5c7a43b..1098fa2 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -17,6 +17,7 @@
package android.widget;
import android.app.ActivityOptions;
+import android.app.ActivityThread;
import android.app.PendingIntent;
import android.appwidget.AppWidgetHostView;
import android.content.Context;
@@ -73,11 +74,11 @@ public class RemoteViews implements Parcelable, Filter {
static final String EXTRA_REMOTEADAPTER_APPWIDGET_ID = "remoteAdapterAppWidgetId";
/**
- * User that these views should be applied as. Requires
- * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} when
- * crossing user boundaries.
+ * Application that hosts the remote views.
+ *
+ * @hide
*/
- private UserHandle mUser = android.os.Process.myUserHandle();
+ private ApplicationInfo mApplication;
/**
* The package name of the package containing the layout
@@ -275,9 +276,9 @@ public class RemoteViews implements Parcelable, Filter {
/**
* Merges the passed RemoteViews actions with this RemoteViews actions according to
* action-specific merge rules.
- *
+ *
* @param newRv
- *
+ *
* @hide
*/
public void mergeRemoteViews(RemoteViews newRv) {
@@ -1608,16 +1609,16 @@ public class RemoteViews implements Parcelable, Filter {
int bpp = 4;
if (c != null) {
switch (c) {
- case ALPHA_8:
- bpp = 1;
- break;
- case RGB_565:
- case ARGB_4444:
- bpp = 2;
- break;
- case ARGB_8888:
- bpp = 4;
- break;
+ case ALPHA_8:
+ bpp = 1;
+ break;
+ case RGB_565:
+ case ARGB_4444:
+ bpp = 2;
+ break;
+ case ARGB_8888:
+ bpp = 4;
+ break;
}
}
increment(b.getWidth() * b.getHeight() * bpp);
@@ -1637,17 +1638,13 @@ public class RemoteViews implements Parcelable, Filter {
mPackage = packageName;
mLayoutId = layoutId;
mBitmapCache = new BitmapCache();
+ mApplication = ActivityThread.currentApplication().getApplicationInfo();
// setup the memory usage statistics
mMemoryUsageCounter = new MemoryUsageCounter();
recalculateMemoryUsage();
}
- /** {@hide} */
- public void setUser(UserHandle user) {
- mUser = user;
- }
-
private boolean hasLandscapeAndPortraitLayouts() {
return (mLandscape != null) && (mPortrait != null);
}
@@ -1713,53 +1710,53 @@ public class RemoteViews implements Parcelable, Filter {
for (int i=0; i<count; i++) {
int tag = parcel.readInt();
switch (tag) {
- case SetOnClickPendingIntent.TAG:
- mActions.add(new SetOnClickPendingIntent(parcel));
- break;
- case SetDrawableParameters.TAG:
- mActions.add(new SetDrawableParameters(parcel));
- break;
- case ReflectionAction.TAG:
- mActions.add(new ReflectionAction(parcel));
- break;
- case ViewGroupAction.TAG:
- mActions.add(new ViewGroupAction(parcel, mBitmapCache));
- break;
- case ReflectionActionWithoutParams.TAG:
- mActions.add(new ReflectionActionWithoutParams(parcel));
- break;
- case SetEmptyView.TAG:
- mActions.add(new SetEmptyView(parcel));
- break;
- case SetPendingIntentTemplate.TAG:
- mActions.add(new SetPendingIntentTemplate(parcel));
- break;
- case SetOnClickFillInIntent.TAG:
- mActions.add(new SetOnClickFillInIntent(parcel));
- break;
- case SetRemoteViewsAdapterIntent.TAG:
- mActions.add(new SetRemoteViewsAdapterIntent(parcel));
- break;
- case TextViewDrawableAction.TAG:
- mActions.add(new TextViewDrawableAction(parcel));
- break;
- case TextViewSizeAction.TAG:
- mActions.add(new TextViewSizeAction(parcel));
- break;
- case ViewPaddingAction.TAG:
- mActions.add(new ViewPaddingAction(parcel));
- break;
- case BitmapReflectionAction.TAG:
- mActions.add(new BitmapReflectionAction(parcel));
- break;
- case SetRemoteViewsAdapterList.TAG:
- mActions.add(new SetRemoteViewsAdapterList(parcel));
- break;
- case TextViewDrawableColorFilterAction.TAG:
- mActions.add(new TextViewDrawableColorFilterAction(parcel));
- break;
- default:
- throw new ActionException("Tag " + tag + " not found");
+ case SetOnClickPendingIntent.TAG:
+ mActions.add(new SetOnClickPendingIntent(parcel));
+ break;
+ case SetDrawableParameters.TAG:
+ mActions.add(new SetDrawableParameters(parcel));
+ break;
+ case ReflectionAction.TAG:
+ mActions.add(new ReflectionAction(parcel));
+ break;
+ case ViewGroupAction.TAG:
+ mActions.add(new ViewGroupAction(parcel, mBitmapCache));
+ break;
+ case ReflectionActionWithoutParams.TAG:
+ mActions.add(new ReflectionActionWithoutParams(parcel));
+ break;
+ case SetEmptyView.TAG:
+ mActions.add(new SetEmptyView(parcel));
+ break;
+ case SetPendingIntentTemplate.TAG:
+ mActions.add(new SetPendingIntentTemplate(parcel));
+ break;
+ case SetOnClickFillInIntent.TAG:
+ mActions.add(new SetOnClickFillInIntent(parcel));
+ break;
+ case SetRemoteViewsAdapterIntent.TAG:
+ mActions.add(new SetRemoteViewsAdapterIntent(parcel));
+ break;
+ case TextViewDrawableAction.TAG:
+ mActions.add(new TextViewDrawableAction(parcel));
+ break;
+ case TextViewSizeAction.TAG:
+ mActions.add(new TextViewSizeAction(parcel));
+ break;
+ case ViewPaddingAction.TAG:
+ mActions.add(new ViewPaddingAction(parcel));
+ break;
+ case BitmapReflectionAction.TAG:
+ mActions.add(new BitmapReflectionAction(parcel));
+ break;
+ case SetRemoteViewsAdapterList.TAG:
+ mActions.add(new SetRemoteViewsAdapterList(parcel));
+ break;
+ case TextViewDrawableColorFilterAction.TAG:
+ mActions.add(new TextViewDrawableColorFilterAction(parcel));
+ break;
+ default:
+ throw new ActionException("Tag " + tag + " not found");
}
}
}
@@ -1771,6 +1768,8 @@ public class RemoteViews implements Parcelable, Filter {
mLayoutId = mPortrait.getLayoutId();
}
+ mApplication = parcel.readParcelable(null);
+
// setup the memory usage statistics
mMemoryUsageCounter = new MemoryUsageCounter();
recalculateMemoryUsage();
@@ -2557,22 +2556,32 @@ public class RemoteViews implements Parcelable, Filter {
}
private Context prepareContext(Context context) {
- Context c;
- String packageName = mPackage;
+ if (mApplication != null) {
+ if (context.getUserId() == UserHandle.getUserId(mApplication.uid)
+ && context.getPackageName().equals(mApplication.packageName)) {
+ return context;
+ }
+ try {
+ return context.createApplicationContext(mApplication,
+ Context.CONTEXT_RESTRICTED);
+ } catch (NameNotFoundException e) {
+ Log.e(LOG_TAG, "Package name " + mPackage + " not found");
+ }
+ }
- if (packageName != null) {
+ if (mPackage != null) {
+ if (context.getPackageName().equals(mPackage)) {
+ return context;
+ }
try {
- c = context.createPackageContextAsUser(
- packageName, Context.CONTEXT_RESTRICTED, mUser);
+ return context.createPackageContext(
+ mPackage, Context.CONTEXT_RESTRICTED);
} catch (NameNotFoundException e) {
- Log.e(LOG_TAG, "Package name " + packageName + " not found");
- c = context;
+ Log.e(LOG_TAG, "Package name " + mPackage + " not found");
}
- } else {
- c = context;
}
- return c;
+ return context;
}
/**
@@ -2629,6 +2638,8 @@ public class RemoteViews implements Parcelable, Filter {
mLandscape.writeToParcel(dest, flags);
mPortrait.writeToParcel(dest, flags);
}
+
+ dest.writeParcelable(mApplication, 0);
}
/**