Adding ViewCaptureAwareWindowManager to InattentiveSleepWarningView window.
Bug: 356995200
Flag: com.android.systemui.enable_view_capture_tracing
Test: Ran relevant unit tests locally.
Change-Id: I01b0af480836037518d65476246f64f878bf4a7c
diff --git a/packages/SystemUI/src/com/android/systemui/power/InattentiveSleepWarningView.java b/packages/SystemUI/src/com/android/systemui/power/InattentiveSleepWarningView.java
index 1cd5d91..2ecca2d 100644
--- a/packages/SystemUI/src/com/android/systemui/power/InattentiveSleepWarningView.java
+++ b/packages/SystemUI/src/com/android/systemui/power/InattentiveSleepWarningView.java
@@ -16,6 +16,8 @@
package com.android.systemui.power;
+import static com.android.systemui.Flags.enableViewCaptureTracing;
+
import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
@@ -29,21 +31,27 @@
import android.view.WindowManager;
import android.widget.FrameLayout;
+import com.android.app.viewcapture.ViewCapture;
+import com.android.app.viewcapture.ViewCaptureAwareWindowManager;
import com.android.systemui.res.R;
+import kotlin.Lazy;
+
/**
* View that shows a warning shortly before the device goes into sleep
* after prolonged user inactivity when bound to.
*/
public class InattentiveSleepWarningView extends FrameLayout {
private final IBinder mWindowToken = new Binder();
- private final WindowManager mWindowManager;
+ private final ViewCaptureAwareWindowManager mWindowManager;
private Animator mFadeOutAnimator;
private boolean mDismissing;
- InattentiveSleepWarningView(Context context) {
+ InattentiveSleepWarningView(Context context, Lazy<ViewCapture> lazyViewCapture) {
super(context);
- mWindowManager = mContext.getSystemService(WindowManager.class);
+ WindowManager wm = mContext.getSystemService(WindowManager.class);
+ mWindowManager = new ViewCaptureAwareWindowManager(wm, lazyViewCapture,
+ enableViewCaptureTracing());
final LayoutInflater layoutInflater = LayoutInflater.from(mContext);
layoutInflater.inflate(R.layout.inattentive_sleep_warning, this, true /* attachToRoot */);
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
index 958ace35..861a7ce 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
@@ -16,6 +16,8 @@
package com.android.systemui.power;
+import static com.android.systemui.util.ConvenienceExtensionsKt.toKotlinLazy;
+
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
@@ -44,6 +46,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import com.android.app.viewcapture.ViewCapture;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.fuelgauge.Estimate;
import com.android.settingslib.utils.ThreadUtils;
@@ -56,6 +59,8 @@
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.policy.ConfigurationController;
+import kotlin.Lazy;
+
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.concurrent.Future;
@@ -117,6 +122,7 @@
private final Context mContext;
private final BroadcastDispatcher mBroadcastDispatcher;
private final CommandQueue mCommandQueue;
+ private final Lazy<ViewCapture> mLazyViewCapture;
@Nullable
private final IVrManager mVrManager;
private final WakefulnessLifecycle.Observer mWakefulnessObserver =
@@ -157,7 +163,8 @@
EnhancedEstimates enhancedEstimates,
WakefulnessLifecycle wakefulnessLifecycle,
PowerManager powerManager,
- UserTracker userTracker) {
+ UserTracker userTracker,
+ dagger.Lazy<ViewCapture> daggerLazyViewCapture) {
mContext = context;
mBroadcastDispatcher = broadcastDispatcher;
mCommandQueue = commandQueue;
@@ -167,6 +174,7 @@
mPowerManager = powerManager;
mWakefulnessLifecycle = wakefulnessLifecycle;
mUserTracker = userTracker;
+ mLazyViewCapture = toKotlinLazy(daggerLazyViewCapture);
}
public void start() {
@@ -641,7 +649,7 @@
@Override
public void showInattentiveSleepWarning() {
if (mOverlayView == null) {
- mOverlayView = new InattentiveSleepWarningView(mContext);
+ mOverlayView = new InattentiveSleepWarningView(mContext, mLazyViewCapture);
}
mOverlayView.show();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
index 4f4f0d9..2f41ac17 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
@@ -45,6 +45,7 @@
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
+import com.android.app.viewcapture.ViewCapture;
import com.android.settingslib.fuelgauge.Estimate;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher;
@@ -54,6 +55,8 @@
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.CommandQueue;
+import dagger.Lazy;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -94,6 +97,7 @@
@Mock private BroadcastDispatcher mBroadcastDispatcher;
@Mock private CommandQueue mCommandQueue;
@Mock private IVrManager mVrManager;
+ @Mock private Lazy<ViewCapture> mLazyViewCapture;
@Before
public void setup() {
@@ -705,7 +709,8 @@
mEnhancedEstimates,
mWakefulnessLifecycle,
mPowerManager,
- mUserTracker);
+ mUserTracker,
+ mLazyViewCapture);
mPowerUI.mThermalService = mThermalServiceMock;
}