Loading core/java/android/widget/Toast.java +18 −56 Original line number Diff line number Diff line Loading @@ -207,11 +207,7 @@ public class Toast { INotificationManager service = getService(); String pkg = mContext.getOpPackageName(); TN tn = mTN; if (Flags.toastNoWeakref()) { tn.mNextView = mNextView; } else { tn.mNextViewWeakRef = new WeakReference<>(mNextView); } final boolean isUiContext = mContext.isUiContext(); final int displayId = mContext.getDisplayId(); Loading @@ -236,14 +232,12 @@ public class Toast { } catch (RemoteException e) { // Empty } finally { if (Flags.toastNoWeakref()) { if (!wasEnqueued) { tn.mNextViewWeakRef = null; tn.mNextView = null; } } } } /** * Close the view if it's showing, or don't show it if it isn't showing yet. Loading Loading @@ -694,22 +688,14 @@ public class Toast { handleHide(); // Don't do this in handleHide() because it is also invoked by // handleShow() if (Flags.toastNoWeakref()) { mNextView = null; } else { mNextViewWeakRef = null; } break; } case CANCEL: { handleHide(); // Don't do this in handleHide() because it is also invoked by // handleShow() if (Flags.toastNoWeakref()) { mNextView = null; } else { mNextViewWeakRef = null; } try { getService().cancelToast(mPackageName, mToken); } catch (RemoteException e) { Loading Loading @@ -756,23 +742,15 @@ public class Toast { } public void handleShow(IBinder windowToken) { if (Flags.toastNoWeakref()) { if (localLOGV) { Log.v(TAG, "HANDLE SHOW: " + this + " mView=" + mView + " mNextView=" + mNextView); } } else { if (localLOGV) { Log.v(TAG, "HANDLE SHOW: " + this + " mView=" + mView + " mNextView=" + mNextViewWeakRef); } } // If a cancel/hide is pending - no need to show - at this point // the window token is already invalid and no need to do any work. if (mHandler.hasMessages(CANCEL) || mHandler.hasMessages(HIDE)) { return; } if (Flags.toastNoWeakref()) { if (mNextView != null && mView != mNextView) { // remove the old view if necessary handleHide(); Loading @@ -783,18 +761,6 @@ public class Toast { new CallbackBinder(getCallbacks(), mHandler)); } } } else { if (mNextViewWeakRef != null && mView != mNextViewWeakRef.get()) { // remove the old view if necessary handleHide(); mView = mNextViewWeakRef.get(); if (mView != null) { mPresenter.show(mView, mToken, windowToken, mDuration, mGravity, mX, mY, mHorizontalMargin, mVerticalMargin, new CallbackBinder(getCallbacks(), mHandler)); } } } } @UnsupportedAppUsage Loading @@ -818,11 +784,7 @@ public class Toast { */ @VisibleForTesting public View getNextView() { if (Flags.toastNoWeakref()) { return mNextView; } else { return (mNextViewWeakRef != null) ? mNextViewWeakRef.get() : null; } } } Loading core/java/android/widget/flags/notification_widget_flags.aconfig +0 −10 Original line number Diff line number Diff line Loading @@ -28,16 +28,6 @@ flag { } } flag { name: "toast_no_weakref" namespace: "systemui" description: "Do not use WeakReference for custom view Toast" bug: "321732224" metadata { purpose: PURPOSE_BUGFIX } } flag { name: "big_picture_style_discard_empty_icon_bitmap_drawables" namespace: "systemui" Loading core/tests/mockingcoretests/src/android/widget/ToastTest.java +0 −25 Original line number Diff line number Diff line Loading @@ -94,7 +94,6 @@ public class ToastTest { } @Test @EnableFlags(Flags.FLAG_TOAST_NO_WEAKREF) public void enqueueFail_nullifiesNextView() throws RemoteException { Looper.prepare(); Loading @@ -116,28 +115,4 @@ public class ToastTest { tn = t.getTn(); assertThat(tn.getNextView()).isNull(); } @Test @DisableFlags(Flags.FLAG_TOAST_NO_WEAKREF) public void enqueueFail_doesNotNullifyNextView() throws RemoteException { Looper.prepare(); // allow 1st toast and fail on the 2nd when(sMockNMS.enqueueToast(anyString(), any(), any(), anyInt(), anyBoolean(), anyInt())).thenReturn(true, false); // first toast is enqueued Toast t = Toast.makeText(mContext, "Toast1", Toast.LENGTH_SHORT); t.setView(mock(View.class)); t.show(); Toast.TN tn = t.getTn(); assertThat(tn.getNextView()).isNotNull(); // second toast is not enqueued t = Toast.makeText(mContext, "Toast2", Toast.LENGTH_SHORT); t.setView(mock(View.class)); t.show(); tn = t.getTn(); assertThat(tn.getNextView()).isNotNull(); } } Loading
core/java/android/widget/Toast.java +18 −56 Original line number Diff line number Diff line Loading @@ -207,11 +207,7 @@ public class Toast { INotificationManager service = getService(); String pkg = mContext.getOpPackageName(); TN tn = mTN; if (Flags.toastNoWeakref()) { tn.mNextView = mNextView; } else { tn.mNextViewWeakRef = new WeakReference<>(mNextView); } final boolean isUiContext = mContext.isUiContext(); final int displayId = mContext.getDisplayId(); Loading @@ -236,14 +232,12 @@ public class Toast { } catch (RemoteException e) { // Empty } finally { if (Flags.toastNoWeakref()) { if (!wasEnqueued) { tn.mNextViewWeakRef = null; tn.mNextView = null; } } } } /** * Close the view if it's showing, or don't show it if it isn't showing yet. Loading Loading @@ -694,22 +688,14 @@ public class Toast { handleHide(); // Don't do this in handleHide() because it is also invoked by // handleShow() if (Flags.toastNoWeakref()) { mNextView = null; } else { mNextViewWeakRef = null; } break; } case CANCEL: { handleHide(); // Don't do this in handleHide() because it is also invoked by // handleShow() if (Flags.toastNoWeakref()) { mNextView = null; } else { mNextViewWeakRef = null; } try { getService().cancelToast(mPackageName, mToken); } catch (RemoteException e) { Loading Loading @@ -756,23 +742,15 @@ public class Toast { } public void handleShow(IBinder windowToken) { if (Flags.toastNoWeakref()) { if (localLOGV) { Log.v(TAG, "HANDLE SHOW: " + this + " mView=" + mView + " mNextView=" + mNextView); } } else { if (localLOGV) { Log.v(TAG, "HANDLE SHOW: " + this + " mView=" + mView + " mNextView=" + mNextViewWeakRef); } } // If a cancel/hide is pending - no need to show - at this point // the window token is already invalid and no need to do any work. if (mHandler.hasMessages(CANCEL) || mHandler.hasMessages(HIDE)) { return; } if (Flags.toastNoWeakref()) { if (mNextView != null && mView != mNextView) { // remove the old view if necessary handleHide(); Loading @@ -783,18 +761,6 @@ public class Toast { new CallbackBinder(getCallbacks(), mHandler)); } } } else { if (mNextViewWeakRef != null && mView != mNextViewWeakRef.get()) { // remove the old view if necessary handleHide(); mView = mNextViewWeakRef.get(); if (mView != null) { mPresenter.show(mView, mToken, windowToken, mDuration, mGravity, mX, mY, mHorizontalMargin, mVerticalMargin, new CallbackBinder(getCallbacks(), mHandler)); } } } } @UnsupportedAppUsage Loading @@ -818,11 +784,7 @@ public class Toast { */ @VisibleForTesting public View getNextView() { if (Flags.toastNoWeakref()) { return mNextView; } else { return (mNextViewWeakRef != null) ? mNextViewWeakRef.get() : null; } } } Loading
core/java/android/widget/flags/notification_widget_flags.aconfig +0 −10 Original line number Diff line number Diff line Loading @@ -28,16 +28,6 @@ flag { } } flag { name: "toast_no_weakref" namespace: "systemui" description: "Do not use WeakReference for custom view Toast" bug: "321732224" metadata { purpose: PURPOSE_BUGFIX } } flag { name: "big_picture_style_discard_empty_icon_bitmap_drawables" namespace: "systemui" Loading
core/tests/mockingcoretests/src/android/widget/ToastTest.java +0 −25 Original line number Diff line number Diff line Loading @@ -94,7 +94,6 @@ public class ToastTest { } @Test @EnableFlags(Flags.FLAG_TOAST_NO_WEAKREF) public void enqueueFail_nullifiesNextView() throws RemoteException { Looper.prepare(); Loading @@ -116,28 +115,4 @@ public class ToastTest { tn = t.getTn(); assertThat(tn.getNextView()).isNull(); } @Test @DisableFlags(Flags.FLAG_TOAST_NO_WEAKREF) public void enqueueFail_doesNotNullifyNextView() throws RemoteException { Looper.prepare(); // allow 1st toast and fail on the 2nd when(sMockNMS.enqueueToast(anyString(), any(), any(), anyInt(), anyBoolean(), anyInt())).thenReturn(true, false); // first toast is enqueued Toast t = Toast.makeText(mContext, "Toast1", Toast.LENGTH_SHORT); t.setView(mock(View.class)); t.show(); Toast.TN tn = t.getTn(); assertThat(tn.getNextView()).isNotNull(); // second toast is not enqueued t = Toast.makeText(mContext, "Toast2", Toast.LENGTH_SHORT); t.setView(mock(View.class)); t.show(); tn = t.getTn(); assertThat(tn.getNextView()).isNotNull(); } }