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

Commit 1feecb5f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "The launcher to always listen to app widget" into tm-qpr-dev am: f532a9e4 am: c53401b5

parents 7b4318d0 c53401b5
Loading
Loading
Loading
Loading
+88 −36
Original line number Original line Diff line number Diff line
@@ -70,7 +70,7 @@ public class AppWidgetHost {
    private final Handler mHandler;
    private final Handler mHandler;
    private final int mHostId;
    private final int mHostId;
    private final Callbacks mCallbacks;
    private final Callbacks mCallbacks;
    private final SparseArray<AppWidgetHostView> mViews = new SparseArray<>();
    private final SparseArray<AppWidgetHostListener> mListeners = new SparseArray<>();
    private InteractionHandler mInteractionHandler;
    private InteractionHandler mInteractionHandler;


    static class Callbacks extends IAppWidgetHost.Stub {
    static class Callbacks extends IAppWidgetHost.Stub {
@@ -171,6 +171,15 @@ public class AppWidgetHost {
        this(context, hostId, null, context.getMainLooper());
        this(context, hostId, null, context.getMainLooper());
    }
    }


    @Nullable
    private AppWidgetHostListener getListener(final int appWidgetId) {
        AppWidgetHostListener tempListener = null;
        synchronized (mListeners) {
            tempListener = mListeners.get(appWidgetId);
        }
        return tempListener;
    }

    /**
    /**
     * @hide
     * @hide
     */
     */
@@ -210,11 +219,11 @@ public class AppWidgetHost {
            return;
            return;
        }
        }
        final int[] idsToUpdate;
        final int[] idsToUpdate;
        synchronized (mViews) {
        synchronized (mListeners) {
            int N = mViews.size();
            int n = mListeners.size();
            idsToUpdate = new int[N];
            idsToUpdate = new int[n];
            for (int i = 0; i < N; i++) {
            for (int i = 0; i < n; i++) {
                idsToUpdate[i] = mViews.keyAt(i);
                idsToUpdate[i] = mListeners.keyAt(i);
            }
            }
        }
        }
        List<PendingHostUpdate> updates;
        List<PendingHostUpdate> updates;
@@ -349,16 +358,13 @@ public class AppWidgetHost {
        if (sService == null) {
        if (sService == null) {
            return;
            return;
        }
        }
        synchronized (mViews) {
        removeListener(appWidgetId);
            mViews.remove(appWidgetId);
        try {
        try {
            sService.deleteAppWidgetId(mContextOpPackageName, appWidgetId);
            sService.deleteAppWidgetId(mContextOpPackageName, appWidgetId);
            }
        } catch (RemoteException e) {
            catch (RemoteException e) {
            throw new RuntimeException("system server dead?", e);
            throw new RuntimeException("system server dead?", e);
        }
        }
    }
    }
    }


    /**
    /**
     * Remove all records about this host from the AppWidget manager.
     * Remove all records about this host from the AppWidget manager.
@@ -412,9 +418,7 @@ public class AppWidgetHost {
        AppWidgetHostView view = onCreateView(context, appWidgetId, appWidget);
        AppWidgetHostView view = onCreateView(context, appWidgetId, appWidget);
        view.setInteractionHandler(mInteractionHandler);
        view.setInteractionHandler(mInteractionHandler);
        view.setAppWidget(appWidgetId, appWidget);
        view.setAppWidget(appWidgetId, appWidget);
        synchronized (mViews) {
        addListener(appWidgetId, view);
            mViews.put(appWidgetId, view);
        }
        RemoteViews views;
        RemoteViews views;
        try {
        try {
            views = sService.getAppWidgetViews(mContextOpPackageName, appWidgetId);
            views = sService.getAppWidgetViews(mContextOpPackageName, appWidgetId);
@@ -439,24 +443,52 @@ public class AppWidgetHost {
     * Called when the AppWidget provider for a AppWidget has been upgraded to a new apk.
     * Called when the AppWidget provider for a AppWidget has been upgraded to a new apk.
     */
     */
    protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidget) {
    protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidget) {
        AppWidgetHostView v;
        AppWidgetHostListener v = getListener(appWidgetId);


        // Convert complex to dp -- we are getting the AppWidgetProviderInfo from the
        // Convert complex to dp -- we are getting the AppWidgetProviderInfo from the
        // AppWidgetService, which doesn't have our context, hence we need to do the
        // AppWidgetService, which doesn't have our context, hence we need to do the
        // conversion here.
        // conversion here.
        appWidget.updateDimensions(mDisplayMetrics);
        appWidget.updateDimensions(mDisplayMetrics);
        synchronized (mViews) {
            v = mViews.get(appWidgetId);
        }
        if (v != null) {
        if (v != null) {
            v.resetAppWidget(appWidget);
            v.onUpdateProviderInfo(appWidget);
        }
        }
    }
    }


    void dispatchOnAppWidgetRemoved(int appWidgetId) {
    /**
        synchronized (mViews) {
     * This interface specifies the actions to be performed on the app widget based on the calls
            mViews.remove(appWidgetId);
     * from the service
     *
     * @hide
     */
    public interface AppWidgetHostListener {

        /**
         * This function is called when the service want to reset the app widget provider info
         * @param appWidget The new app widget provider info
         *
         * @hide
         */
        void onUpdateProviderInfo(@Nullable AppWidgetProviderInfo appWidget);

        /**
         * This function is called when the RemoteViews of the app widget is updated
         * @param views The new RemoteViews to be set for the app widget
         *
         * @hide
         */
        void updateAppWidget(@Nullable RemoteViews views);

        /**
         * This function is called when the view ID is changed for the app widget
         * @param viewId The new view ID to be be set for the widget
         *
         * @hide
         */
        void onViewDataChanged(int viewId);
    }
    }

    void dispatchOnAppWidgetRemoved(int appWidgetId) {
        removeListener(appWidgetId);
        onAppWidgetRemoved(appWidgetId);
        onAppWidgetRemoved(appWidgetId);
    }
    }


@@ -476,23 +508,43 @@ public class AppWidgetHost {
        // Does nothing
        // Does nothing
    }
    }


    void updateAppWidgetView(int appWidgetId, RemoteViews views) {
    /**
        AppWidgetHostView v;
     * Create an AppWidgetHostListener for the given widget.
        synchronized (mViews) {
     * The AppWidgetHost retains a pointer to the newly-created listener.
            v = mViews.get(appWidgetId);
     * @param appWidgetId The ID of the app widget for which to add the listener
     * @param listener The listener interface that deals with actions towards the widget view
     *
     * @hide
     */
    public void addListener(int appWidgetId, @NonNull AppWidgetHostListener listener) {
        synchronized (mListeners) {
            mListeners.put(appWidgetId, listener);
        }
    }

    /**
     * Delete the listener for the given widget
     * @param appWidgetId The ID of the app widget for which the listener is to be deleted

     * @hide
     */
    public void removeListener(int appWidgetId) {
        synchronized (mListeners) {
            mListeners.remove(appWidgetId);
        }
    }
    }

    void updateAppWidgetView(int appWidgetId, RemoteViews views) {
        AppWidgetHostListener v = getListener(appWidgetId);
        if (v != null) {
        if (v != null) {
            v.updateAppWidget(views);
            v.updateAppWidget(views);
        }
        }
    }
    }


    void viewDataChanged(int appWidgetId, int viewId) {
    void viewDataChanged(int appWidgetId, int viewId) {
        AppWidgetHostView v;
        AppWidgetHostListener v = getListener(appWidgetId);
        synchronized (mViews) {
            v = mViews.get(appWidgetId);
        }
        if (v != null) {
        if (v != null) {
            v.viewDataChanged(viewId);
            v.onViewDataChanged(viewId);
        }
        }
    }
    }


@@ -500,8 +552,8 @@ public class AppWidgetHost {
     * Clear the list of Views that have been created by this AppWidgetHost.
     * Clear the list of Views that have been created by this AppWidgetHost.
     */
     */
    protected void clearViews() {
    protected void clearViews() {
        synchronized (mViews) {
        synchronized (mListeners) {
            mViews.clear();
            mListeners.clear();
        }
        }
    }
    }
}
}
+10 −3
Original line number Original line Diff line number Diff line
@@ -66,7 +66,7 @@ import java.util.concurrent.Executor;
 * between updates, and will try recycling old views for each incoming
 * between updates, and will try recycling old views for each incoming
 * {@link RemoteViews}.
 * {@link RemoteViews}.
 */
 */
public class AppWidgetHostView extends FrameLayout {
public class AppWidgetHostView extends FrameLayout implements AppWidgetHost.AppWidgetHostListener {


    static final String TAG = "AppWidgetHostView";
    static final String TAG = "AppWidgetHostView";
    private static final String KEY_JAILED_ARRAY = "jail";
    private static final String KEY_JAILED_ARRAY = "jail";
@@ -492,8 +492,11 @@ public class AppWidgetHostView extends FrameLayout {
    /**
    /**
     * Update the AppWidgetProviderInfo for this view, and reset it to the
     * Update the AppWidgetProviderInfo for this view, and reset it to the
     * initial layout.
     * initial layout.
     *
     * @hide
     */
     */
    void resetAppWidget(AppWidgetProviderInfo info) {
    @Override
    public void onUpdateProviderInfo(@Nullable AppWidgetProviderInfo info) {
        setAppWidget(mAppWidgetId, info);
        setAppWidget(mAppWidgetId, info);
        mViewMode = VIEW_MODE_NOINIT;
        mViewMode = VIEW_MODE_NOINIT;
        updateAppWidget(null);
        updateAppWidget(null);
@@ -503,6 +506,7 @@ public class AppWidgetHostView extends FrameLayout {
     * Process a set of {@link RemoteViews} coming in as an update from the
     * Process a set of {@link RemoteViews} coming in as an update from the
     * AppWidget provider. Will animate into these new views as needed
     * AppWidget provider. Will animate into these new views as needed
     */
     */
    @Override
    public void updateAppWidget(RemoteViews remoteViews) {
    public void updateAppWidget(RemoteViews remoteViews) {
        mLastInflatedRemoteViews = remoteViews;
        mLastInflatedRemoteViews = remoteViews;
        applyRemoteViews(remoteViews, true);
        applyRemoteViews(remoteViews, true);
@@ -693,8 +697,11 @@ public class AppWidgetHostView extends FrameLayout {
    /**
    /**
     * Process data-changed notifications for the specified view in the specified
     * Process data-changed notifications for the specified view in the specified
     * set of {@link RemoteViews} views.
     * set of {@link RemoteViews} views.
     *
     * @hide
     */
     */
    void viewDataChanged(int viewId) {
    @Override
    public void onViewDataChanged(int viewId) {
        View v = findViewById(viewId);
        View v = findViewById(viewId);
        if ((v != null) && (v instanceof AdapterView<?>)) {
        if ((v != null) && (v instanceof AdapterView<?>)) {
            AdapterView<?> adapterView = (AdapterView<?>) v;
            AdapterView<?> adapterView = (AdapterView<?>) v;