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

Commit fb60386b authored by Adam Cohen's avatar Adam Cohen
Browse files

Addressing issues associated RemoteViewsAdapter's service crashes / disconnects

-See issue: 3052667

Change-Id: I95f1cac3defeadc38ac75453d9d59cd1b3cbcc83
parent 8903058a
Loading
Loading
Loading
Loading
+7 −4
Original line number Original line Diff line number Diff line
@@ -5184,6 +5184,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
    public void onRemoteAdapterConnected() {
    public void onRemoteAdapterConnected() {
        if (mRemoteAdapter != mAdapter) {
        if (mRemoteAdapter != mAdapter) {
            setAdapter(mRemoteAdapter);
            setAdapter(mRemoteAdapter);
        } else if (mRemoteAdapter != null) {
            mRemoteAdapter.superNotifyDataSetChanged();
        }
        }
    }
    }


@@ -5191,10 +5193,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
     * Called back when the adapter disconnects from the RemoteViewsService.
     * Called back when the adapter disconnects from the RemoteViewsService.
     */
     */
    public void onRemoteAdapterDisconnected() {
    public void onRemoteAdapterDisconnected() {
        if (mRemoteAdapter == mAdapter) {
        // If the remote adapter disconnects, we keep it around
            mRemoteAdapter = null;
        // since the currently displayed items are still cached.
            setAdapter(null);
        // Further, we want the service to eventually reconnect
        }
        // when necessary, as triggered by this view requesting
        // items from the Adapter.
    }
    }


    /**
    /**
+7 −4
Original line number Original line Diff line number Diff line
@@ -964,6 +964,8 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
    public void onRemoteAdapterConnected() {
    public void onRemoteAdapterConnected() {
        if (mRemoteViewsAdapter != mAdapter) {
        if (mRemoteViewsAdapter != mAdapter) {
            setAdapter(mRemoteViewsAdapter);
            setAdapter(mRemoteViewsAdapter);
        } else if (mRemoteViewsAdapter != null) {
            mRemoteViewsAdapter.superNotifyDataSetChanged();
        }
        }
    }
    }


@@ -971,10 +973,11 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
     * Called back when the adapter disconnects from the RemoteViewsService.
     * Called back when the adapter disconnects from the RemoteViewsService.
     */
     */
    public void onRemoteAdapterDisconnected() {
    public void onRemoteAdapterDisconnected() {
        if (mRemoteViewsAdapter != mAdapter) {
        // If the remote adapter disconnects, we keep it around
            mRemoteViewsAdapter = null;
        // since the currently displayed items are still cached.
            setAdapter(mRemoteViewsAdapter);
        // Further, we want the service to eventually reconnect
        }
        // when necessary, as triggered by this view requesting
        // items from the Adapter.
    }
    }


    public void advance() {
    public void advance() {
+1 −2
Original line number Original line Diff line number Diff line
@@ -1535,7 +1535,6 @@ public class ListView extends AbsListView {
            // reset the focus restoration
            // reset the focus restoration
            View focusLayoutRestoreDirectChild = null;
            View focusLayoutRestoreDirectChild = null;



            // Don't put header or footer views into the Recycler. Those are
            // Don't put header or footer views into the Recycler. Those are
            // already cached in mHeaderViews;
            // already cached in mHeaderViews;
            if (dataChanged) {
            if (dataChanged) {
+3 −8
Original line number Original line Diff line number Diff line
@@ -148,11 +148,6 @@ public class RemoteViewsAdapter extends BaseAdapter {
            adapter.mMainQueue.removeMessages(0);
            adapter.mMainQueue.removeMessages(0);
            adapter.mWorkerQueue.removeMessages(0);
            adapter.mWorkerQueue.removeMessages(0);


            // Clear the cache (the meta data will be re-requested on service re-connection)
            synchronized (adapter.mCache) {
                adapter.mCache.reset();
            }

            final RemoteAdapterConnectionCallback callback = adapter.mCallback.get();
            final RemoteAdapterConnectionCallback callback = adapter.mCallback.get();
            if (callback != null) {
            if (callback != null) {
                callback.onRemoteAdapterDisconnected();
                callback.onRemoteAdapterDisconnected();
@@ -880,7 +875,7 @@ public class RemoteViewsAdapter extends BaseAdapter {
        // a chance to update itself and return new meta data associated with the new data.
        // a chance to update itself and return new meta data associated with the new data.
    }
    }


    private void superNotifyDataSetChanged() {
    void superNotifyDataSetChanged() {
        super.notifyDataSetChanged();
        super.notifyDataSetChanged();
    }
    }