Merge "By default, only eng builds allow latency-test broadcasts" into tm-dev am: 447af5dee2
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17574383 Change-Id: Ie49fcb6c59add6fdc4fede73d7965235f368ade2 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -48,7 +48,7 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class LatencyTracker {
|
||||
private static final String TAG = "LatencyTracker";
|
||||
private static final String SETTINGS_ENABLED_KEY = "enabled";
|
||||
public static final String SETTINGS_ENABLED_KEY = "enabled";
|
||||
private static final String SETTINGS_SAMPLING_INTERVAL_KEY = "sampling_interval";
|
||||
private static final boolean DEBUG = false;
|
||||
/** Default to being enabled on debug builds. */
|
||||
|
||||
@@ -23,21 +23,31 @@ import android.content.IntentFilter;
|
||||
import android.hardware.biometrics.BiometricConstants;
|
||||
import android.hardware.biometrics.BiometricSourceType;
|
||||
import android.os.Build;
|
||||
import android.provider.DeviceConfig;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.internal.util.LatencyTracker;
|
||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.statusbar.phone.BiometricUnlockController;
|
||||
import com.android.systemui.util.DeviceConfigProxy;
|
||||
import com.android.systemui.util.concurrency.DelayableExecutor;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Class that only runs on debuggable builds that listens to broadcasts that simulate actions in the
|
||||
* Class that only runs on debuggable builds with the LatencyTracker setting enabled
|
||||
* that listens to broadcasts that simulate actions in the
|
||||
* system that are used for testing the latency.
|
||||
*/
|
||||
@SysUISingleton
|
||||
public class LatencyTester extends CoreStartable {
|
||||
|
||||
private static final boolean DEFAULT_ENABLED = Build.IS_ENG;
|
||||
private static final String
|
||||
ACTION_FINGERPRINT_WAKE =
|
||||
"com.android.systemui.latency.ACTION_FINGERPRINT_WAKE";
|
||||
@@ -46,42 +56,78 @@ public class LatencyTester extends CoreStartable {
|
||||
"com.android.systemui.latency.ACTION_FACE_WAKE";
|
||||
private final BiometricUnlockController mBiometricUnlockController;
|
||||
private final BroadcastDispatcher mBroadcastDispatcher;
|
||||
private final DeviceConfigProxy mDeviceConfigProxy;
|
||||
|
||||
private boolean mEnabled;
|
||||
|
||||
@Inject
|
||||
public LatencyTester(Context context, BiometricUnlockController biometricUnlockController,
|
||||
BroadcastDispatcher broadcastDispatcher) {
|
||||
public LatencyTester(
|
||||
Context context,
|
||||
BiometricUnlockController biometricUnlockController,
|
||||
BroadcastDispatcher broadcastDispatcher,
|
||||
DeviceConfigProxy deviceConfigProxy,
|
||||
@Main DelayableExecutor mainExecutor
|
||||
) {
|
||||
super(context);
|
||||
|
||||
mBiometricUnlockController = biometricUnlockController;
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mDeviceConfigProxy = deviceConfigProxy;
|
||||
|
||||
updateEnabled();
|
||||
mDeviceConfigProxy.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_LATENCY_TRACKER,
|
||||
mainExecutor, properties -> updateEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (!Build.IS_DEBUGGABLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ACTION_FINGERPRINT_WAKE);
|
||||
filter.addAction(ACTION_FACE_WAKE);
|
||||
mBroadcastDispatcher.registerReceiver(new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (ACTION_FINGERPRINT_WAKE.equals(action)) {
|
||||
fakeWakeAndUnlock(BiometricSourceType.FINGERPRINT);
|
||||
} else if (ACTION_FACE_WAKE.equals(action)) {
|
||||
fakeWakeAndUnlock(BiometricSourceType.FACE);
|
||||
}
|
||||
}
|
||||
}, filter);
|
||||
registerForBroadcasts(mEnabled);
|
||||
}
|
||||
|
||||
private void fakeWakeAndUnlock(BiometricSourceType type) {
|
||||
if (!mEnabled) {
|
||||
return;
|
||||
}
|
||||
mBiometricUnlockController.onBiometricAcquired(type,
|
||||
BiometricConstants.BIOMETRIC_ACQUIRED_GOOD);
|
||||
mBiometricUnlockController.onBiometricAuthenticated(
|
||||
KeyguardUpdateMonitor.getCurrentUser(), type, true /* isStrongBiometric */);
|
||||
}
|
||||
|
||||
private void registerForBroadcasts(boolean register) {
|
||||
if (register) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ACTION_FINGERPRINT_WAKE);
|
||||
filter.addAction(ACTION_FACE_WAKE);
|
||||
mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter);
|
||||
} else {
|
||||
mBroadcastDispatcher.unregisterReceiver(mBroadcastReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateEnabled() {
|
||||
boolean wasEnabled = mEnabled;
|
||||
mEnabled = Build.IS_DEBUGGABLE
|
||||
&& mDeviceConfigProxy.getBoolean(DeviceConfig.NAMESPACE_LATENCY_TRACKER,
|
||||
LatencyTracker.SETTINGS_ENABLED_KEY, DEFAULT_ENABLED);
|
||||
if (mEnabled != wasEnabled) {
|
||||
registerForBroadcasts(mEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dump(@NonNull PrintWriter pw, @NonNull String[] args) {
|
||||
pw.println("mEnabled=" + mEnabled);
|
||||
}
|
||||
|
||||
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (ACTION_FINGERPRINT_WAKE.equals(action)) {
|
||||
fakeWakeAndUnlock(BiometricSourceType.FINGERPRINT);
|
||||
} else if (ACTION_FACE_WAKE.equals(action)) {
|
||||
fakeWakeAndUnlock(BiometricSourceType.FACE);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user