Loading core/java/android/widget/RemoteViewsAdapter.java +27 −16 Original line number Diff line number Diff line Loading @@ -22,9 +22,11 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import android.Manifest; import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; Loading @@ -34,6 +36,7 @@ import android.os.Process; import android.os.RemoteException; import android.os.UserHandle; import android.util.Log; import android.util.Slog; import android.view.LayoutInflater; import android.view.View; import android.view.View.MeasureSpec; Loading @@ -50,6 +53,8 @@ import com.android.internal.widget.LockPatternUtils; */ /** @hide */ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback { private static final String MULTI_USER_PERM = Manifest.permission.INTERACT_ACROSS_USERS_FULL; private static final String TAG = "RemoteViewsAdapter"; // The max number of items in the cache Loading Loading @@ -155,13 +160,12 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback try { RemoteViewsAdapter adapter; final AppWidgetManager mgr = AppWidgetManager.getInstance(context); if (Process.myUid() == Process.SYSTEM_UID && (adapter = mAdapter.get()) != null) { if ((adapter = mAdapter.get()) != null) { checkInteractAcrossUsersPermission(context, adapter.mUserId); mgr.bindRemoteViewsService(appWidgetId, intent, asBinder(), new UserHandle(adapter.mUserId)); } else { mgr.bindRemoteViewsService(appWidgetId, intent, asBinder(), Process.myUserHandle()); Slog.w(TAG, "bind: adapter was null"); } mIsConnecting = true; } catch (Exception e) { Loading @@ -176,12 +180,12 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback try { RemoteViewsAdapter adapter; final AppWidgetManager mgr = AppWidgetManager.getInstance(context); if (Process.myUid() == Process.SYSTEM_UID && (adapter = mAdapter.get()) != null) { if ((adapter = mAdapter.get()) != null) { checkInteractAcrossUsersPermission(context, adapter.mUserId); mgr.unbindRemoteViewsService(appWidgetId, intent, new UserHandle(adapter.mUserId)); } else { mgr.unbindRemoteViewsService(appWidgetId, intent, Process.myUserHandle()); Slog.w(TAG, "unbind: adapter was null"); } mIsConnecting = false; } catch (Exception e) { Loading Loading @@ -828,11 +832,9 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback } mRequestedViews = new RemoteViewsFrameLayoutRefSet(); if (Process.myUid() == Process.SYSTEM_UID) { mUserId = new LockPatternUtils(context).getCurrentUser(); } else { mUserId = UserHandle.myUserId(); } checkInteractAcrossUsersPermission(context, UserHandle.myUserId()); mUserId = context.getUserId(); // Strip the previously injected app widget id from service intent if (intent.hasExtra(RemoteViews.EXTRA_REMOTEADAPTER_APPWIDGET_ID)) { intent.removeExtra(RemoteViews.EXTRA_REMOTEADAPTER_APPWIDGET_ID); Loading Loading @@ -876,6 +878,15 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback } } private static void checkInteractAcrossUsersPermission(Context context, int userId) { if (context.getUserId() != userId && context.checkCallingOrSelfPermission(MULTI_USER_PERM) != PackageManager.PERMISSION_GRANTED) { throw new SecurityException("Must have permission " + MULTI_USER_PERM + " to inflate another user's widget"); } } @Override protected void finalize() throws Throwable { try { Loading Loading
core/java/android/widget/RemoteViewsAdapter.java +27 −16 Original line number Diff line number Diff line Loading @@ -22,9 +22,11 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import android.Manifest; import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; Loading @@ -34,6 +36,7 @@ import android.os.Process; import android.os.RemoteException; import android.os.UserHandle; import android.util.Log; import android.util.Slog; import android.view.LayoutInflater; import android.view.View; import android.view.View.MeasureSpec; Loading @@ -50,6 +53,8 @@ import com.android.internal.widget.LockPatternUtils; */ /** @hide */ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback { private static final String MULTI_USER_PERM = Manifest.permission.INTERACT_ACROSS_USERS_FULL; private static final String TAG = "RemoteViewsAdapter"; // The max number of items in the cache Loading Loading @@ -155,13 +160,12 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback try { RemoteViewsAdapter adapter; final AppWidgetManager mgr = AppWidgetManager.getInstance(context); if (Process.myUid() == Process.SYSTEM_UID && (adapter = mAdapter.get()) != null) { if ((adapter = mAdapter.get()) != null) { checkInteractAcrossUsersPermission(context, adapter.mUserId); mgr.bindRemoteViewsService(appWidgetId, intent, asBinder(), new UserHandle(adapter.mUserId)); } else { mgr.bindRemoteViewsService(appWidgetId, intent, asBinder(), Process.myUserHandle()); Slog.w(TAG, "bind: adapter was null"); } mIsConnecting = true; } catch (Exception e) { Loading @@ -176,12 +180,12 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback try { RemoteViewsAdapter adapter; final AppWidgetManager mgr = AppWidgetManager.getInstance(context); if (Process.myUid() == Process.SYSTEM_UID && (adapter = mAdapter.get()) != null) { if ((adapter = mAdapter.get()) != null) { checkInteractAcrossUsersPermission(context, adapter.mUserId); mgr.unbindRemoteViewsService(appWidgetId, intent, new UserHandle(adapter.mUserId)); } else { mgr.unbindRemoteViewsService(appWidgetId, intent, Process.myUserHandle()); Slog.w(TAG, "unbind: adapter was null"); } mIsConnecting = false; } catch (Exception e) { Loading Loading @@ -828,11 +832,9 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback } mRequestedViews = new RemoteViewsFrameLayoutRefSet(); if (Process.myUid() == Process.SYSTEM_UID) { mUserId = new LockPatternUtils(context).getCurrentUser(); } else { mUserId = UserHandle.myUserId(); } checkInteractAcrossUsersPermission(context, UserHandle.myUserId()); mUserId = context.getUserId(); // Strip the previously injected app widget id from service intent if (intent.hasExtra(RemoteViews.EXTRA_REMOTEADAPTER_APPWIDGET_ID)) { intent.removeExtra(RemoteViews.EXTRA_REMOTEADAPTER_APPWIDGET_ID); Loading Loading @@ -876,6 +878,15 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback } } private static void checkInteractAcrossUsersPermission(Context context, int userId) { if (context.getUserId() != userId && context.checkCallingOrSelfPermission(MULTI_USER_PERM) != PackageManager.PERMISSION_GRANTED) { throw new SecurityException("Must have permission " + MULTI_USER_PERM + " to inflate another user's widget"); } } @Override protected void finalize() throws Throwable { try { Loading