DO NOT MERGE Allow the new BrightLineFalsingManager to be enabled via PhenoType.
Test: atest SystemUITests Bug: 111394067 Change-Id: I0ab9a72d66bf56a56df2de2ad2d247f299d1b748 Merged-In: I0ab9a72d66bf56a56df2de2ad2d247f299d1b748
This commit is contained in:
@@ -176,5 +176,11 @@ public final class SystemUiDeviceConfigFlags {
|
||||
public static final String ASSIST_HANDLES_SUPPRESS_ON_APPS =
|
||||
"assist_handles_suppress_on_apps";
|
||||
|
||||
/**
|
||||
* (bool) Whether to use the new BrightLineFalsingManager.
|
||||
*/
|
||||
public static final String BRIGHTLINE_FALSING_MANAGER_ENABLED =
|
||||
"brightline_falsing_manager_enabled";
|
||||
|
||||
private SystemUiDeviceConfigFlags() { }
|
||||
}
|
||||
|
||||
@@ -16,31 +16,51 @@
|
||||
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.BRIGHTLINE_FALSING_MANAGER_ENABLED;
|
||||
import static com.android.systemui.Dependency.MAIN_HANDLER_NAME;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.classifier.brightline.BrightLineFalsingManager;
|
||||
import com.android.systemui.classifier.brightline.FalsingDataProvider;
|
||||
import com.android.systemui.plugins.FalsingManager;
|
||||
import com.android.systemui.plugins.FalsingPlugin;
|
||||
import com.android.systemui.plugins.PluginListener;
|
||||
import com.android.systemui.shared.plugins.PluginManager;
|
||||
import com.android.systemui.util.AsyncSensorManager;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Simple passthrough implementation of {@link FalsingManager} allowing plugins to swap in.
|
||||
*
|
||||
* {@link FalsingManagerImpl} is used when a Plugin is not loaded.
|
||||
*/
|
||||
@Singleton
|
||||
public class FalsingManagerProxy implements FalsingManager {
|
||||
|
||||
private FalsingManager mInternalFalsingManager;
|
||||
private final Handler mMainHandler;
|
||||
|
||||
@Inject
|
||||
FalsingManagerProxy(Context context, PluginManager pluginManager) {
|
||||
mInternalFalsingManager = new FalsingManagerImpl(context);
|
||||
FalsingManagerProxy(Context context, PluginManager pluginManager,
|
||||
@Named(MAIN_HANDLER_NAME) Handler handler) {
|
||||
mMainHandler = handler;
|
||||
DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
command -> mMainHandler.post(command),
|
||||
properties -> onDeviceConfigPropertiesChanged(context, properties.getNamespace())
|
||||
);
|
||||
setupFalsingManager(context);
|
||||
final PluginListener<FalsingPlugin> mPluginListener = new PluginListener<FalsingPlugin>() {
|
||||
public void onPluginConnected(FalsingPlugin plugin, Context context) {
|
||||
FalsingManager pluginFalsingManager = plugin.getFalsingManager(context);
|
||||
@@ -57,6 +77,40 @@ public class FalsingManagerProxy implements FalsingManager {
|
||||
pluginManager.addPluginListener(mPluginListener, FalsingPlugin.class);
|
||||
}
|
||||
|
||||
private void onDeviceConfigPropertiesChanged(Context context, String namespace) {
|
||||
if (!DeviceConfig.NAMESPACE_SYSTEMUI.equals(namespace)) {
|
||||
return;
|
||||
}
|
||||
|
||||
setupFalsingManager(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Chooses the FalsingManager implementation.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void setupFalsingManager(Context context) {
|
||||
boolean brightlineEnabled = DeviceConfig.getBoolean(
|
||||
DeviceConfig.NAMESPACE_SYSTEMUI, BRIGHTLINE_FALSING_MANAGER_ENABLED, false);
|
||||
if (!brightlineEnabled) {
|
||||
mInternalFalsingManager = new FalsingManagerImpl(context);
|
||||
} else {
|
||||
mInternalFalsingManager = new BrightLineFalsingManager(
|
||||
new FalsingDataProvider(context),
|
||||
Dependency.get(AsyncSensorManager.class)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the FalsingManager implementation in use.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
FalsingManager getInternalFalsingManager() {
|
||||
return mInternalFalsingManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSucccessfulUnlock() {
|
||||
mInternalFalsingManager.onSucccessfulUnlock();
|
||||
|
||||
@@ -60,7 +60,8 @@ public class BrightLineFalsingManager implements FalsingManager {
|
||||
}
|
||||
};
|
||||
|
||||
BrightLineFalsingManager(FalsingDataProvider falsingDataProvider, SensorManager sensorManager) {
|
||||
public BrightLineFalsingManager(FalsingDataProvider falsingDataProvider,
|
||||
SensorManager sensorManager) {
|
||||
mDataProvider = falsingDataProvider;
|
||||
mSensorManager = sensorManager;
|
||||
mClassifiers = new ArrayList<>();
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.List;
|
||||
/**
|
||||
* Acts as a cache and utility class for FalsingClassifiers.
|
||||
*/
|
||||
class FalsingDataProvider {
|
||||
public class FalsingDataProvider {
|
||||
|
||||
private static final long MOTION_EVENT_AGE_MS = 1000;
|
||||
private static final float THREE_HUNDRED_SIXTY_DEG = (float) (2 * Math.PI);
|
||||
@@ -51,7 +51,7 @@ class FalsingDataProvider {
|
||||
private MotionEvent mFirstRecentMotionEvent;
|
||||
private MotionEvent mLastMotionEvent;
|
||||
|
||||
FalsingDataProvider(Context context) {
|
||||
public FalsingDataProvider(Context context) {
|
||||
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||
mXdpi = displayMetrics.xdpi;
|
||||
mYdpi = displayMetrics.ydpi;
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.classifier;
|
||||
|
||||
import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.BRIGHTLINE_FALSING_MANAGER_ENABLED;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.classifier.brightline.BrightLineFalsingManager;
|
||||
import com.android.systemui.shared.plugins.PluginManager;
|
||||
|
||||
import org.junit.After;
|
||||
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 FalsingManagerProxyTest extends SysuiTestCase {
|
||||
@Mock
|
||||
PluginManager mPluginManager;
|
||||
private boolean mDefaultConfigValue;
|
||||
private Handler mHandler;
|
||||
private TestableLooper mTestableLooper;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mTestableLooper = TestableLooper.get(this);
|
||||
mHandler = new Handler(mTestableLooper.getLooper());
|
||||
mDefaultConfigValue = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
BRIGHTLINE_FALSING_MANAGER_ENABLED, false);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
BRIGHTLINE_FALSING_MANAGER_ENABLED, mDefaultConfigValue ? "true" : "false", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_brightLineFalsingManagerDisabled() {
|
||||
FalsingManagerProxy proxy = new FalsingManagerProxy(getContext(), mPluginManager, mHandler);
|
||||
|
||||
assertThat(proxy.getInternalFalsingManager(), instanceOf(FalsingManagerImpl.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_brightLineFalsingManagerEnabled() {
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
BRIGHTLINE_FALSING_MANAGER_ENABLED, "true", false);
|
||||
FalsingManagerProxy proxy = new FalsingManagerProxy(getContext(), mPluginManager, mHandler);
|
||||
|
||||
assertThat(proxy.getInternalFalsingManager(), instanceOf(BrightLineFalsingManager.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_brightLineFalsingManagerToggled() {
|
||||
FalsingManagerProxy proxy = new FalsingManagerProxy(getContext(), mPluginManager, mHandler);
|
||||
assertThat(proxy.getInternalFalsingManager(), instanceOf(FalsingManagerImpl.class));
|
||||
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
BRIGHTLINE_FALSING_MANAGER_ENABLED, "true", false);
|
||||
mTestableLooper.processAllMessages();
|
||||
proxy.setupFalsingManager(getContext());
|
||||
assertThat(proxy.getInternalFalsingManager(), instanceOf(BrightLineFalsingManager.class));
|
||||
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
BRIGHTLINE_FALSING_MANAGER_ENABLED, "false", false);
|
||||
mTestableLooper.processAllMessages();
|
||||
proxy.setupFalsingManager(getContext());
|
||||
assertThat(proxy.getInternalFalsingManager(), instanceOf(FalsingManagerImpl.class));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user