From fa80cb05c48fcc741912551b1fc9d22b936cae80 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Thu, 8 Oct 2020 10:24:27 -0700 Subject: [PATCH] Remove injection from BubbleOverflowActivity Bug: 161980186 Test: atest BubbleControllerTest BubbleDataTest manual - check bubbles appear in overflow & can be promoted Change-Id: I1edf1ed14d48c5a4dfeb23c92cb7d952d50ca0ce --- .../systemui/bubbles/BubbleExpandedView.java | 5 ++ .../bubbles/BubbleOverflowActivity.java | 19 +++++--- .../systemui/bubbles/ObjectWrapper.java | 46 +++++++++++++++++++ .../dagger/DefaultActivityBinder.java | 7 --- 4 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/bubbles/ObjectWrapper.java diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java index 83a816b85d78d..3af36a99374e6 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java @@ -30,6 +30,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; import static com.android.systemui.bubbles.BubbleDebugConfig.DEBUG_BUBBLE_EXPANDED_VIEW; import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_BUBBLES; import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME; +import static com.android.systemui.bubbles.BubbleOverflowActivity.EXTRA_BUBBLE_CONTROLLER; import android.annotation.NonNull; import android.annotation.SuppressLint; @@ -51,6 +52,7 @@ import android.graphics.Rect; import android.graphics.drawable.ShapeDrawable; import android.hardware.display.VirtualDisplay; import android.os.Binder; +import android.os.Bundle; import android.os.RemoteException; import android.util.AttributeSet; import android.util.Log; @@ -576,6 +578,9 @@ public class BubbleExpandedView extends LinearLayout { mIsOverflow = overflow; Intent target = new Intent(mContext, BubbleOverflowActivity.class); + Bundle extras = new Bundle(); + extras.putBinder(EXTRA_BUBBLE_CONTROLLER, ObjectWrapper.wrap(mBubbles)); + target.putExtras(extras); mPendingIntent = PendingIntent.getActivity(mContext, /* requestCode */ 0, target, PendingIntent.FLAG_UPDATE_CURRENT); mSettingsIcon.setVisibility(GONE); diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleOverflowActivity.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleOverflowActivity.java index 5fdda97596590..fc3f5b6cbf5e7 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleOverflowActivity.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleOverflowActivity.java @@ -22,11 +22,13 @@ import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Color; import android.os.Bundle; +import android.os.IBinder; import android.util.DisplayMetrics; import android.util.Log; import android.view.LayoutInflater; @@ -47,13 +49,14 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; -import javax.inject.Inject; /** * Activity for showing aged out bubbles. * Must be public to be accessible to androidx...AppComponentFactory */ public class BubbleOverflowActivity extends Activity { + static final String EXTRA_BUBBLE_CONTROLLER = "bubble_controller"; + private static final String TAG = TAG_WITH_CLASS_NAME ? "BubbleOverflowActivity" : TAG_BUBBLES; private LinearLayout mEmptyState; @@ -93,11 +96,6 @@ public class BubbleOverflowActivity extends Activity { } } - @Inject - public BubbleOverflowActivity(Bubbles bubbles) { - mBubbles = bubbles; - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -109,6 +107,15 @@ public class BubbleOverflowActivity extends Activity { mEmptyStateSubtitle = findViewById(R.id.bubble_overflow_empty_subtitle); mEmptyStateImage = findViewById(R.id.bubble_overflow_empty_state_image); + Intent intent = getIntent(); + if (intent != null && intent.getExtras() != null) { + IBinder binder = intent.getExtras().getBinder(EXTRA_BUBBLE_CONTROLLER); + if (binder instanceof ObjectWrapper) { + mBubbles = ((ObjectWrapper) binder).get(); + } + } else { + Log.w(TAG, "Bubble overflow activity created without bubble controller!"); + } updateOverflow(); } diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/ObjectWrapper.java b/packages/SystemUI/src/com/android/systemui/bubbles/ObjectWrapper.java new file mode 100644 index 0000000000000..f054122eaa470 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/bubbles/ObjectWrapper.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.systemui.bubbles; + +import android.os.Binder; +import android.os.IBinder; + +// Copied from Launcher3 +/** + * Utility class to pass non-parcealable objects within same process using parcealable payload. + * + * It wraps the object in a binder as binders are singleton within a process + */ +public class ObjectWrapper extends Binder { + + private T mObject; + + public ObjectWrapper(T object) { + mObject = object; + } + + public T get() { + return mObject; + } + + public void clear() { + mObject = null; + } + + public static IBinder wrap(Object obj) { + return new ObjectWrapper<>(obj); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/dagger/DefaultActivityBinder.java b/packages/SystemUI/src/com/android/systemui/dagger/DefaultActivityBinder.java index ba88a599b785e..d13e194a0d447 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/DefaultActivityBinder.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/DefaultActivityBinder.java @@ -19,7 +19,6 @@ package com.android.systemui.dagger; import android.app.Activity; import com.android.systemui.ForegroundServicesDialog; -import com.android.systemui.bubbles.BubbleOverflowActivity; import com.android.systemui.keyguard.WorkLockActivity; import com.android.systemui.screenrecord.ScreenRecordDialog; import com.android.systemui.settings.BrightnessDialog; @@ -68,12 +67,6 @@ public abstract class DefaultActivityBinder { @ClassKey(ScreenRecordDialog.class) public abstract Activity bindScreenRecordDialog(ScreenRecordDialog activity); - /** Inject into BubbleOverflowActivity. */ - @Binds - @IntoMap - @ClassKey(BubbleOverflowActivity.class) - public abstract Activity bindBubbleOverflowActivity(BubbleOverflowActivity activity); - /** Inject into UsbDebuggingActivity. */ @Binds @IntoMap