diff options
| author | Sunny Goyal <sunnygoyal@google.com> | 2016-03-31 11:27:13 -0700 |
|---|---|---|
| committer | Sunny Goyal <sunnygoyal@google.com> | 2016-04-04 14:45:14 -0700 |
| commit | 2857f1c783e69461735a51159f9abdb85378e210 (patch) | |
| tree | 33ffee040c1b029d7a9c2ccbb3b0ac8f67805d0c /core/java/android/appwidget/AppWidgetHost.java | |
| parent | 08f41dfb8c43e8d34d8723ef22fe96b580af4d56 (diff) | |
Changing startListening to only fetch views which are bound
Also associating a lastUpdateTime with every widget. This allows
the host to query the widgets which were updated only after
the last stopListening call.
Change-Id: If9375cf2d8caa0ccca14b6649821d87ada1f3a84
Diffstat (limited to 'core/java/android/appwidget/AppWidgetHost.java')
| -rw-r--r-- | core/java/android/appwidget/AppWidgetHost.java | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/core/java/android/appwidget/AppWidgetHost.java b/core/java/android/appwidget/AppWidgetHost.java index 1af495365825..2d9f4a71b005 100644 --- a/core/java/android/appwidget/AppWidgetHost.java +++ b/core/java/android/appwidget/AppWidgetHost.java @@ -17,8 +17,7 @@ package android.appwidget; import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.HashMap; +import java.util.List; import android.annotation.NonNull; import android.annotation.Nullable; @@ -35,7 +34,9 @@ import android.os.Message; import android.os.Process; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.SystemClock; import android.util.DisplayMetrics; +import android.util.SparseArray; import android.util.TypedValue; import android.widget.RemoteViews; import android.widget.RemoteViews.OnClickHandler; @@ -62,7 +63,7 @@ public class AppWidgetHost { private final Handler mHandler; private final int mHostId; private final Callbacks mCallbacks; - private final HashMap<Integer,AppWidgetHostView> mViews = new HashMap<>(); + private final SparseArray<AppWidgetHostView> mViews = new SparseArray<>(); private OnClickHandler mOnClickHandler; static class Callbacks extends IAppWidgetHost.Stub { @@ -164,7 +165,6 @@ public class AppWidgetHost { bindService(); } - private static void bindService() { synchronized (sServiceLock) { if (sService == null) { @@ -179,17 +179,25 @@ public class AppWidgetHost { * becomes visible, i.e. from onStart() in your Activity. */ public void startListening() { - int[] updatedIds; - ArrayList<RemoteViews> updatedViews = new ArrayList<RemoteViews>(); + final int[] idsToUpdate; + synchronized (mViews) { + int N = mViews.size(); + idsToUpdate = new int[N]; + for (int i = 0; i < N; i++) { + idsToUpdate[i] = mViews.keyAt(i); + } + } + List<RemoteViews> updatedViews; + int[] updatedIds = new int[idsToUpdate.length]; try { - updatedIds = sService.startListening(mCallbacks, mContextOpPackageName, mHostId, - updatedViews); + updatedViews = sService.startListening( + mCallbacks, mContextOpPackageName, mHostId, idsToUpdate, updatedIds).getList(); } catch (RemoteException e) { throw new RuntimeException("system server dead?", e); } - final int N = updatedIds.length; + int N = updatedViews.size(); for (int i = 0; i < N; i++) { updateAppWidgetView(updatedIds[i], updatedViews.get(i)); } @@ -206,10 +214,6 @@ public class AppWidgetHost { catch (RemoteException e) { throw new RuntimeException("system server dead?", e); } - - // This is here because keyguard needs it since it'll be switching users after this call. - // If it turns out other apps need to call this often, we should re-think how this works. - clearViews(); } /** @@ -418,7 +422,9 @@ public class AppWidgetHost { * Clear the list of Views that have been created by this AppWidgetHost. */ protected void clearViews() { - mViews.clear(); + synchronized (mViews) { + mViews.clear(); + } } } |
