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

Commit 3e510535 authored by Jim Miller's avatar Jim Miller
Browse files

Fix keyguard listview widgets for secondary users

This fixes a bug where secondary user widgets weren't being updated
properly because the system was checking for SYSTEM_UID which no
longer works with keyguard in a separate process.  The symptom was an
app with a listview, like Gmail, would always show an empty list for
secondary users.

Change-Id: I3749a7a0b39f1eb7922966af0fbdcefdd804e41e
parent 07cd3f3f
Loading
Loading
Loading
Loading
+27 −16
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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
@@ -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) {
@@ -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) {
@@ -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);
@@ -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 {