Maybe fix issue #6756472: Share button is not defocusing the shade

I got this reproduce a few times, then wasn't able to.  I made this
change and then couldn't reproduce it.  Maybe it fixed it.

The change here is to explicitly pass in the handler class to
apply() and reapply(), instead of relying it being set as a member of
the RemoteViews class.  This is much cleaner and more explicitly about
setting that for the click callbacks.

Bug: 6756472
Change-Id: I8d029c3836501df3206c433838124b4be3890a8b
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index e29000d..4710798f 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -128,7 +128,6 @@
     private boolean mIsWidgetCollectionChild = false;
 
     private static final OnClickHandler DEFAULT_ON_CLICK_HANDLER = new OnClickHandler();
-    private OnClickHandler mOnClickHandler = DEFAULT_ON_CLICK_HANDLER;
 
     /**
      * This annotation indicates that a subclass of View is alllowed to be used
@@ -185,8 +184,8 @@
      *  SUBCLASSES MUST BE IMMUTABLE SO CLONE WORKS!!!!!
      */
     private abstract static class Action implements Parcelable {
-        public abstract void apply(RemoteViews owner, View root,
-                ViewGroup rootParent) throws ActionException;
+        public abstract void apply(View root, ViewGroup rootParent,
+                OnClickHandler handler) throws ActionException;
 
         public int describeContents() {
             return 0;
@@ -229,7 +228,7 @@
         }
 
         @Override
-        public void apply(RemoteViews owner, View root, ViewGroup rootParent) {
+        public void apply(View root, ViewGroup rootParent, OnClickHandler handler) {
             final View view = root.findViewById(viewId);
             if (!(view instanceof AdapterView<?>)) return;
 
@@ -260,7 +259,7 @@
         }
 
         @Override
-        public void apply(RemoteViews owner, View root, ViewGroup rootParent) {
+        public void apply(View root, ViewGroup rootParent, final OnClickHandler handler) {
             final View target = root.findViewById(viewId);
             if (target == null) return;
 
@@ -272,7 +271,6 @@
             if (target == root) {
                 target.setTagInternal(com.android.internal.R.id.fillInIntent, fillInIntent);
             } else if (target != null && fillInIntent != null) {
-                final OnClickHandler clicker = owner.mOnClickHandler;
                 OnClickListener listener = new OnClickListener() {
                     public void onClick(View v) {
                         // Insure that this view is a child of an AdapterView
@@ -310,7 +308,7 @@
                         rect.bottom = (int) ((pos[1] + v.getHeight()) * appScale + 0.5f);
 
                         fillInIntent.setSourceBounds(rect);
-                        clicker.onClickHandler(v, pendingIntent, fillInIntent);
+                        handler.onClickHandler(v, pendingIntent, fillInIntent);
                     }
 
                 };
@@ -342,14 +340,13 @@
         }
 
         @Override
-        public void apply(RemoteViews owner, View root, ViewGroup rootParent) {
+        public void apply(View root, ViewGroup rootParent, final OnClickHandler handler) {
             final View target = root.findViewById(viewId);
             if (target == null) return;
 
             // If the view isn't an AdapterView, setting a PendingIntent template doesn't make sense
             if (target instanceof AdapterView<?>) {
                 AdapterView<?> av = (AdapterView<?>) target;
-                final OnClickHandler clicker = owner.mOnClickHandler;
                 // The PendingIntent template is stored in the view's tag.
                 OnItemClickListener listener = new OnItemClickListener() {
                     public void onItemClick(AdapterView<?> parent, View view,
@@ -389,7 +386,7 @@
 
                             final Intent intent = new Intent();
                             intent.setSourceBounds(rect);
-                            clicker.onClickHandler(view, pendingIntentTemplate, fillInIntent);
+                            handler.onClickHandler(view, pendingIntentTemplate, fillInIntent);
                         }
                     }
                 };
@@ -426,7 +423,7 @@
         }
 
         @Override
-        public void apply(RemoteViews owner, View root, ViewGroup rootParent) {
+        public void apply(View root, ViewGroup rootParent, OnClickHandler handler) {
             final View target = root.findViewById(viewId);
             if (target == null) return;
 
@@ -494,7 +491,7 @@
         }
 
         @Override
-        public void apply(RemoteViews owner, View root, ViewGroup rootParent) {
+        public void apply(View root, ViewGroup rootParent, final OnClickHandler handler) {
             final View target = root.findViewById(viewId);
             if (target == null) return;
 
@@ -515,7 +512,6 @@
 
             if (target != null) {
                 // If the pendingIntent is null, we clear the onClickListener
-                final OnClickHandler clicker = owner.mOnClickHandler;
                 OnClickListener listener = null;
                 if (pendingIntent != null) {
                     listener = new OnClickListener() {
@@ -535,7 +531,7 @@
     
                             final Intent intent = new Intent();
                             intent.setSourceBounds(rect);
-                            clicker.onClickHandler(v, pendingIntent, intent);
+                            handler.onClickHandler(v, pendingIntent, intent);
                         }
                     };
                 }
@@ -602,7 +598,7 @@
         }
         
         @Override
-        public void apply(RemoteViews owner, View root, ViewGroup rootParent) {
+        public void apply(View root, ViewGroup rootParent, OnClickHandler handler) {
             final View target = root.findViewById(viewId);
             if (target == null) return;
             
@@ -662,7 +658,7 @@
         }
 
         @Override
-        public void apply(RemoteViews owner, View root, ViewGroup rootParent) {
+        public void apply(View root, ViewGroup rootParent, OnClickHandler handler) {
             final View view = root.findViewById(viewId);
             if (view == null) return;
 
@@ -786,11 +782,11 @@
         }
 
         @Override
-        public void apply(RemoteViews owner, View root,
-                ViewGroup rootParent) throws ActionException {
+        public void apply(View root, ViewGroup rootParent,
+                OnClickHandler handler) throws ActionException {
             ReflectionAction ra = new ReflectionAction(viewId, methodName, ReflectionAction.BITMAP,
                     bitmap);
-            ra.apply(owner, root, rootParent);
+            ra.apply(root, rootParent, handler);
         }
 
         @Override
@@ -1006,7 +1002,7 @@
         }
 
         @Override
-        public void apply(RemoteViews owner, View root, ViewGroup rootParent) {
+        public void apply(View root, ViewGroup rootParent, OnClickHandler handler) {
             final View view = root.findViewById(viewId);
             if (view == null) return;
 
@@ -1108,13 +1104,13 @@
         }
 
         @Override
-        public void apply(RemoteViews owner, View root, ViewGroup rootParent) {
+        public void apply(View root, ViewGroup rootParent, OnClickHandler handler) {
             final Context context = root.getContext();
             final ViewGroup target = (ViewGroup) root.findViewById(viewId);
             if (target == null) return;
             if (nestedViews != null) {
                 // Inflate nested views and add as children
-                target.addView(nestedViews.apply(owner, context, target));
+                target.addView(nestedViews.apply(context, target, handler));
             } else {
                 // Clear all children when nested views omitted
                 target.removeAllViews();
@@ -1175,7 +1171,7 @@
         }
 
         @Override
-        public void apply(RemoteViews owner, View root, ViewGroup rootParent) {
+        public void apply(View root, ViewGroup rootParent, OnClickHandler handler) {
             final Context context = root.getContext();
             final TextView target = (TextView) root.findViewById(viewId);
             if (target == null) return;
@@ -1217,7 +1213,7 @@
         }
 
         @Override
-        public void apply(RemoteViews owner, View root, ViewGroup rootParent) {
+        public void apply(View root, ViewGroup rootParent, OnClickHandler handler) {
             final Context context = root.getContext();
             final TextView target = (TextView) root.findViewById(viewId);
             if (target == null) return;
@@ -1261,7 +1257,7 @@
         }
 
         @Override
-        public void apply(RemoteViews owner, View root, ViewGroup rootParent) {
+        public void apply(View root, ViewGroup rootParent, OnClickHandler handler) {
             final Context context = root.getContext();
             final View target = root.findViewById(viewId);
             if (target == null) return;
@@ -2099,11 +2095,6 @@
         return this;
     }
 
-    /** @hide */
-    public void setOnClickHandler(OnClickHandler handler) {
-        mOnClickHandler = handler;
-    }
-
     /**
      * Inflates the view hierarchy represented by this object and applies
      * all of the actions.
@@ -2116,10 +2107,11 @@
      * @return The inflated view hierarchy
      */
     public View apply(Context context, ViewGroup parent) {
-        return apply(this, context, parent);
+        return apply(context, parent, DEFAULT_ON_CLICK_HANDLER);
     }
 
-    View apply(RemoteViews owner, Context context, ViewGroup parent) {
+    /** @hide */
+    public View apply(Context context, ViewGroup parent, OnClickHandler handler) {
         RemoteViews rvToApply = getRemoteViewsToApply(context);
 
         View result;
@@ -2134,7 +2126,7 @@
 
         result = inflater.inflate(rvToApply.getLayoutId(), parent, false);
 
-        rvToApply.performApply(owner, result, parent);
+        rvToApply.performApply(result, parent, handler);
 
         return result;
     }
@@ -2148,6 +2140,11 @@
      * the {@link #apply(Context,ViewGroup)} call.
      */
     public void reapply(Context context, View v) {
+        reapply(context, v, DEFAULT_ON_CLICK_HANDLER);
+    }
+
+    /** @hide */
+    public void reapply(Context context, View v, OnClickHandler handler) {
         RemoteViews rvToApply = getRemoteViewsToApply(context);
 
         // In the case that a view has this RemoteViews applied in one orientation, is persisted
@@ -2161,15 +2158,15 @@
         }
 
         prepareContext(context);
-        rvToApply.performApply(this, v, (ViewGroup) v.getParent());
+        rvToApply.performApply(v, (ViewGroup) v.getParent(), handler);
     }
 
-    private void performApply(RemoteViews owner, View v, ViewGroup parent) {
+    private void performApply(View v, ViewGroup parent, OnClickHandler handler) {
         if (mActions != null) {
             final int count = mActions.size();
             for (int i = 0; i < count; i++) {
                 Action a = mActions.get(i);
-                a.apply(owner, v, parent);
+                a.apply(v, parent, handler);
             }
         }
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
index ec99513..1204a89 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
@@ -577,11 +577,9 @@
         View expandedLarge = null;
         Exception exception = null;
         try {
-            oneU.setOnClickHandler(mOnClickHandler);
-            expandedOneU = oneU.apply(mContext, adaptive);
+            expandedOneU = oneU.apply(mContext, adaptive, mOnClickHandler);
             if (large != null) {
-                large.setOnClickHandler(mOnClickHandler);
-                expandedLarge = large.apply(mContext, adaptive);
+                expandedLarge = large.apply(mContext, adaptive, mOnClickHandler);
             }
         }
         catch (RuntimeException e) {
@@ -872,9 +870,9 @@
             oldEntry.notification = notification;
             try {
                 // Reapply the RemoteViews
-                contentView.reapply(mContext, oldEntry.expanded);
+                contentView.reapply(mContext, oldEntry.expanded, mOnClickHandler);
                 if (bigContentView != null && oldEntry.getLargeView() != null) {
-                    bigContentView.reapply(mContext, oldEntry.getLargeView());
+                    bigContentView.reapply(mContext, oldEntry.getLargeView(), mOnClickHandler);
                 }
                 // update the contentIntent
                 final PendingIntent contentIntent = notification.notification.contentIntent;