From 21beba8bcdddc03df638153be8ba612882394ee8 Mon Sep 17 00:00:00 2001 From: Dave Mankoff Date: Tue, 6 Nov 2018 16:25:39 -0500 Subject: [PATCH] New "FalsingPlugin" to allow for easier data collection. Bug: 117600098 Change-Id: I67b634f84a0e168eec269f7804c5169b130db586 Test: manual testing --- .../systemui/plugins/FalsingPlugin.java | 39 +++++++++++++ .../systemui/analytics/DataCollector.java | 55 +++++++++++++------ 2 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 packages/SystemUI/plugin/src/com/android/systemui/plugins/FalsingPlugin.java diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/FalsingPlugin.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/FalsingPlugin.java new file mode 100644 index 0000000000000..dce02e1a6c568 --- /dev/null +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/FalsingPlugin.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2018 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.plugins; + +import com.android.systemui.plugins.annotations.ProvidesInterface; + +/** + * Used to capture Falsing data (related to unlocking the screen). + * + * The intent is that the data can later be analyzed to validate the quality of the + * {@link com.android.systemui.classifier.FalsingManager}. + */ +@ProvidesInterface(action = FalsingPlugin.ACTION, version = FalsingPlugin.VERSION) +public interface FalsingPlugin extends Plugin { + String ACTION = "com.android.systemui.action.FALSING_PLUGIN"; + int VERSION = 1; + + /** + * Called when there is data to be recorded. + * + * @param success Indicates whether the action is considered a success. + * @param data The raw data to be recorded for analysis. + */ + void dataCollected(boolean success, byte[] data); +} diff --git a/packages/SystemUI/src/com/android/systemui/analytics/DataCollector.java b/packages/SystemUI/src/com/android/systemui/analytics/DataCollector.java index 4010c43f675e6..46e004c5304ac 100644 --- a/packages/SystemUI/src/com/android/systemui/analytics/DataCollector.java +++ b/packages/SystemUI/src/com/android/systemui/analytics/DataCollector.java @@ -35,6 +35,11 @@ import android.util.Log; import android.view.MotionEvent; import android.widget.Toast; +import com.android.systemui.Dependency; +import com.android.systemui.plugins.FalsingPlugin; +import com.android.systemui.plugins.PluginListener; +import com.android.systemui.shared.plugins.PluginManager; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -75,6 +80,8 @@ public class DataCollector implements SensorEventListener { private static DataCollector sInstance = null; + private FalsingPlugin mFalsingPlugin = null; + protected final ContentObserver mSettingsObserver = new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange) { @@ -82,6 +89,16 @@ public class DataCollector implements SensorEventListener { } }; + private final PluginListener mPluginListener = new PluginListener() { + public void onPluginConnected(FalsingPlugin plugin, Context context) { + mFalsingPlugin = plugin; + } + + public void onPluginDisconnected(FalsingPlugin plugin) { + mFalsingPlugin = null; + } + }; + private DataCollector(Context context) { mContext = context; @@ -106,6 +123,8 @@ public class DataCollector implements SensorEventListener { UserHandle.USER_ALL); updateConfiguration(); + + Dependency.get(PluginManager.class).addPluginListener(mPluginListener, FalsingPlugin.class); } public static DataCollector getInstance(Context context) { @@ -191,24 +210,28 @@ public class DataCollector implements SensorEventListener { @Override public void run() { byte[] b = Session.toByteArray(currentSession.toProto()); - String dir = mContext.getFilesDir().getAbsolutePath(); - if (currentSession.getResult() != Session.SUCCESS) { - if (!mDisableUnlocking && !mCollectBadTouches) { - return; + + if (mFalsingPlugin != null) { + mFalsingPlugin.dataCollected(currentSession.getResult() == Session.SUCCESS, b); + } else { + String dir = mContext.getFilesDir().getAbsolutePath(); + if (currentSession.getResult() != Session.SUCCESS) { + if (!mDisableUnlocking && !mCollectBadTouches) { + return; + } + dir += "/bad_touches"; + } else if (!mDisableUnlocking) { + dir += "/good_touches"; } - dir += "/bad_touches"; - } else if (!mDisableUnlocking) { - dir += "/good_touches"; - } - File file = new File(dir); - file.mkdir(); - File touch = new File(file, "trace_" + System.currentTimeMillis()); - - try { - new FileOutputStream(touch).write(b); - } catch (IOException e) { - throw new RuntimeException(e); + File file = new File(dir); + file.mkdir(); + File touch = new File(file, "trace_" + System.currentTimeMillis()); + try { + new FileOutputStream(touch).write(b); + } catch (IOException e) { + throw new RuntimeException(e); + } } } });