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

Commit a21ce1f1 authored by Winson Chung's avatar Winson Chung Committed by Android Git Automerger
Browse files

am 0a361b10: Merge "Workaround for issue where the notifyDatasetChanged call...

am 0a361b10: Merge "Workaround for issue where the notifyDatasetChanged call chain is broken when Launcher is killed. (Bug 5703782)" into ics-mr1

* commit '0a361b10':
  Workaround for issue where the notifyDatasetChanged call chain is broken when Launcher is killed. (Bug 5703782)
parents 6727a43f 0a361b10
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -145,6 +145,9 @@ public abstract class RemoteViewsService extends Service {
                Thread.getDefaultUncaughtExceptionHandler().uncaughtException(t, ex);
            }
        }
        public synchronized void onDataSetChangedAsync() {
            onDataSetChanged();
        }
        public synchronized int getCount() {
            int count = 0;
            try {
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.widget.RemoteViews;
/** {@hide} */
interface IRemoteViewsFactory {
    void onDataSetChanged();
    oneway void onDataSetChangedAsync();
    oneway void onDestroy(in Intent intent);
    int getCount();
    RemoteViews getViewAt(int position);
+43 −1
Original line number Diff line number Diff line
@@ -24,9 +24,9 @@ import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.Intent.FilterComparison;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.Intent.FilterComparison;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
@@ -39,6 +39,8 @@ import android.content.res.XmlResourceParser;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.SystemClock;
@@ -74,6 +76,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;

class AppWidgetService extends IAppWidgetService.Stub
{
@@ -805,6 +808,45 @@ class AppWidgetService extends IAppWidgetService.Stub
                    id.host.callbacks = null;
                }
            }

            // If the host is unavailable, then we call the associated
            // RemoteViewsFactory.onDataSetChanged() directly
            if (id.host.callbacks == null) {
                Set<FilterComparison> keys = mRemoteViewsServicesAppWidgets.keySet();
                for (FilterComparison key : keys) {
                    if (mRemoteViewsServicesAppWidgets.get(key).contains(id.appWidgetId)) {
                        Intent intent = key.getIntent();

                        final ServiceConnection conn = new ServiceConnection() {
                            @Override
                            public void onServiceConnected(ComponentName name, IBinder service) {
                                IRemoteViewsFactory cb =
                                    IRemoteViewsFactory.Stub.asInterface(service);
                                try {
                                    cb.onDataSetChangedAsync();
                                } catch (RemoteException e) {
                                    e.printStackTrace();
                                } catch (RuntimeException e) {
                                    e.printStackTrace();
                                }
                                mContext.unbindService(this);
                            }
                            @Override
                            public void onServiceDisconnected(android.content.ComponentName name) {
                                // Do nothing
                            }
                        };

                        // Bind to the service and call onDataSetChanged()
                        final long token = Binder.clearCallingIdentity();
                        try {
                            mContext.bindService(intent, conn, Context.BIND_AUTO_CREATE);
                        } finally {
                            Binder.restoreCallingIdentity(token);
                        }
                    }
                }
            }
        }
    }