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

Commit 67cf7d31 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Fix Power Control widget

Some changes in AppWidgetService were interfering with widget permissions.

Added some hidden methods in Context to communicate the requesting user
information instead of using the calling uid.

Bug: 6019296
Change-Id: I5e519fd3fbbfa5b3fcc5c297b729c671dac8e7c7
parent 8181201c
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -911,6 +911,19 @@ class ContextImpl extends Context {
        }
    }

    /** @hide */
    @Override
    public void sendBroadcast(Intent intent, int userId) {
        String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
        try {
            intent.setAllowFds(false);
            ActivityManagerNative.getDefault().broadcastIntent(mMainThread.getApplicationThread(),
                    intent, resolvedType, null, Activity.RESULT_OK, null, null, null, false, false,
                    userId);
        } catch (RemoteException e) {
        }
    }

    @Override
    public void sendBroadcast(Intent intent, String receiverPermission) {
        String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
+10 −0
Original line number Diff line number Diff line
@@ -904,6 +904,16 @@ public abstract class Context {
     */
    public abstract void sendBroadcast(Intent intent);

    /**
     * Same as #sendBroadcast(Intent intent), but for a specific user. Used by the system only.
     * @param intent the intent to broadcast
     * @param userId user to send the intent to
     * @hide
     */
    public void sendBroadcast(Intent intent, int userId) {
        throw new RuntimeException("Not implemented. Must override in a subclass.");
    }

    /**
     * Broadcast the given intent to all interested BroadcastReceivers, allowing
     * an optional required permission to be enforced.  This
+6 −0
Original line number Diff line number Diff line
@@ -294,6 +294,12 @@ public class ContextWrapper extends Context {
        mBase.sendBroadcast(intent);
    }

    /** @hide */
    @Override
    public void sendBroadcast(Intent intent, int userId) {
        mBase.sendBroadcast(intent, userId);
    }

    @Override
    public void sendBroadcast(Intent intent, String receiverPermission) {
        mBase.sendBroadcast(intent, receiverPermission);
+6 −9
Original line number Diff line number Diff line
@@ -463,7 +463,7 @@ class AppWidgetServiceImpl {
                Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DELETED);
                intent.setComponent(p.info.provider);
                intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id.appWidgetId);
                mContext.sendBroadcast(intent);
                mContext.sendBroadcast(intent, mUserId);
                if (p.instances.size() == 0) {
                    // cancel the future updates
                    cancelBroadcasts(p);
@@ -471,7 +471,7 @@ class AppWidgetServiceImpl {
                    // send the broacast saying that the provider is not in use any more
                    intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DISABLED);
                    intent.setComponent(p.info.provider);
                    mContext.sendBroadcast(intent);
                    mContext.sendBroadcast(intent, mUserId);
                }
            }
        }
@@ -515,8 +515,6 @@ class AppWidgetServiceImpl {
                            + " safe mode: " + provider);
                }

                Binder.restoreCallingIdentity(ident);

                id.provider = p;
                p.instances.add(id);
                int instancesSize = p.instances.size();
@@ -1066,7 +1064,7 @@ class AppWidgetServiceImpl {
    void sendEnableIntentLocked(Provider p) {
        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_ENABLED);
        intent.setComponent(p.info.provider);
        mContext.sendBroadcast(intent);
        mContext.sendBroadcast(intent, mUserId);
    }

    void sendUpdateIntentLocked(Provider p, int[] appWidgetIds) {
@@ -1074,7 +1072,7 @@ class AppWidgetServiceImpl {
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
            intent.setComponent(p.info.provider);
            mContext.sendBroadcast(intent);
            mContext.sendBroadcast(intent, mUserId);
        }
    }

@@ -1477,12 +1475,11 @@ class AppWidgetServiceImpl {
    }

    AtomicFile savedStateFile() {
        int userId = UserId.getCallingUserId();
        File dir = new File("/data/system/users/" + userId);
        File dir = new File("/data/system/users/" + mUserId);
        File settingsFile = new File(dir, SETTINGS_FILENAME);
        if (!dir.exists()) {
            dir.mkdirs();
            if (userId == 0) {
            if (mUserId == 0) {
                // Migrate old data
                File oldFile = new File("/data/system/" + SETTINGS_FILENAME);
                // Method doesn't throw an exception on failure. Ignore any errors
+6 −0
Original line number Diff line number Diff line
@@ -267,6 +267,12 @@ public class MockContext extends Context {
        throw new UnsupportedOperationException();
    }

    /** @hide */
    @Override
    public void sendBroadcast(Intent intent, int userId) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void sendBroadcast(Intent intent, String receiverPermission) {
        throw new UnsupportedOperationException();