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

Commit d698b0f0 authored by Jim Miller's avatar Jim Miller Committed by Android (Google) Code Review
Browse files

Merge "Fix keyguard listview widgets for secondary users"

parents f9c4c610 3e510535
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 {