Fix activity interception bug

This addresses the issue where we stop intercepting activities in
CommunalManagerService when SLS is occluded by an activity.

Test: locally on device
Test: atest CommunalManagerUpdaterTest
Bug: 208442300
Change-Id: I9724dbe8fc9f76a32845c1bc908eb7fc40cff578
This commit is contained in:
Lucas Silva
2021-12-01 18:10:33 +00:00
parent 5874c9dfcd
commit 4af9bcaad5
5 changed files with 149 additions and 16 deletions

View File

@@ -0,0 +1,67 @@
/*
* Copyright (C) 2021 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.communal;
import android.app.communal.CommunalManager;
import android.content.Context;
import android.util.Log;
import com.android.systemui.CoreStartable;
import com.android.systemui.dagger.SysUISingleton;
import java.lang.ref.WeakReference;
import javax.inject.Inject;
/**
* The {@link CommunalManagerUpdater} is responsible for forwarding state from SystemUI to
* the {@link CommunalManager} system service.
*/
@SysUISingleton
public class CommunalManagerUpdater extends CoreStartable {
private static final String TAG = "CommunalManagerUpdater";
private final CommunalManager mCommunalManager;
private final CommunalSourceMonitor mMonitor;
private final CommunalSourceMonitor.Callback mSourceCallback =
new CommunalSourceMonitor.Callback() {
@Override
public void onSourceAvailable(WeakReference<CommunalSource> source) {
try {
mCommunalManager.setCommunalViewShowing(
source != null && source.get() != null);
} catch (RuntimeException e) {
Log.e(TAG, "Error updating communal manager service state", e);
}
}
};
@Inject
public CommunalManagerUpdater(Context context, CommunalSourceMonitor monitor) {
super(context);
mCommunalManager = context.getSystemService(CommunalManager.class);
mMonitor = monitor;
}
@Override
public void start() {
if (mCommunalManager != null) {
mMonitor.addCallback(mSourceCallback);
}
}
}

View File

@@ -17,9 +17,6 @@
package com.android.systemui.communal;
import android.annotation.NonNull;
import android.app.communal.CommunalManager;
import android.content.Context;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.dagger.SysUISingleton;
@@ -36,9 +33,7 @@ import javax.inject.Inject;
@SysUISingleton
public class CommunalStateController implements
CallbackController<CommunalStateController.Callback> {
private static final String TAG = CommunalStateController.class.getSimpleName();
private final ArrayList<Callback> mCallbacks = new ArrayList<>();
private final CommunalManager mCommunalManager;
private boolean mCommunalViewOccluded;
private boolean mCommunalViewShowing;
@@ -61,8 +56,7 @@ public class CommunalStateController implements
@VisibleForTesting
@Inject
public CommunalStateController(Context context) {
mCommunalManager = context.getSystemService(CommunalManager.class);
public CommunalStateController() {
}
/**
@@ -76,12 +70,6 @@ public class CommunalStateController implements
mCommunalViewShowing = communalViewShowing;
try {
mCommunalManager.setCommunalViewShowing(communalViewShowing);
} catch (RuntimeException e) {
Log.e(TAG, "Error updating communal manager service state", e);
}
final ArrayList<Callback> callbacks = new ArrayList<>(mCallbacks);
for (Callback callback : callbacks) {
callback.onCommunalViewShowingChanged();

View File

@@ -23,6 +23,7 @@ import com.android.systemui.SliceBroadcastRelayHandler;
import com.android.systemui.accessibility.SystemActions;
import com.android.systemui.accessibility.WindowMagnification;
import com.android.systemui.biometrics.AuthController;
import com.android.systemui.communal.CommunalManagerUpdater;
import com.android.systemui.dreams.DreamOverlayRegistrant;
import com.android.systemui.dreams.appwidgets.AppWidgetOverlayPrimer;
import com.android.systemui.globalactions.GlobalActionsComponent;
@@ -204,4 +205,11 @@ public abstract class SystemUIBinder {
@ClassKey(AppWidgetOverlayPrimer.class)
public abstract CoreStartable bindAppWidgetOverlayPrimer(
AppWidgetOverlayPrimer appWidgetOverlayPrimer);
/** Inject into CommunalManagerUpdater. */
@Binds
@IntoMap
@ClassKey(CommunalManagerUpdater.class)
public abstract CoreStartable bindCommunalManagerUpdater(
CommunalManagerUpdater communalManagerUpdater);
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2021 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.communal;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import android.app.communal.CommunalManager;
import android.os.Handler;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import androidx.test.filters.SmallTest;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.util.settings.FakeSettings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@SmallTest
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class CommunalManagerUpdaterTest extends SysuiTestCase {
private CommunalSourceMonitor mMonitor;
@Mock
private CommunalManager mCommunalManager;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext.addMockSystemService(CommunalManager.class, mCommunalManager);
mMonitor = new CommunalSourceMonitor(
Handler.createAsync(TestableLooper.get(this).getLooper()),
new FakeSettings());
final CommunalManagerUpdater updater = new CommunalManagerUpdater(mContext, mMonitor);
updater.start();
}
@Test
public void testUpdateSystemService_false() {
mMonitor.setSource(null);
verify(mCommunalManager).setCommunalViewShowing(false);
}
@Test
public void testUpdateSystemService_true() {
final CommunalSource source = mock(CommunalSource.class);
mMonitor.setSource(source);
verify(mCommunalManager).setCommunalViewShowing(true);
}
}

View File

@@ -48,13 +48,13 @@ public class CommunalStateControllerTest extends SysuiTestCase {
@Test
public void testDefaultCommunalViewShowingState() {
// The state controller should report the communal view as not showing by default.
final CommunalStateController stateController = new CommunalStateController(getContext());
final CommunalStateController stateController = new CommunalStateController();
assertThat(stateController.getCommunalViewShowing()).isFalse();
}
@Test
public void testNotifyCommunalSurfaceShow() {
final CommunalStateController stateController = new CommunalStateController(getContext());
final CommunalStateController stateController = new CommunalStateController();
stateController.addCallback(mCallback);
// Verify setting communal view to showing propagates to callback.
@@ -72,7 +72,7 @@ public class CommunalStateControllerTest extends SysuiTestCase {
@Test
public void testCallbackRegistration() {
final CommunalStateController stateController = new CommunalStateController(getContext());
final CommunalStateController stateController = new CommunalStateController();
stateController.addCallback(mCallback);
// Verify setting communal view to showing propagates to callback.