New "FalsingPlugin" to allow for easier data collection.
Bug: 117600098 Change-Id: I67b634f84a0e168eec269f7804c5169b130db586 Test: manual testing
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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<FalsingPlugin>() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user