Log metrics for PK settings topics

1. Log metrics for touchpad settings
2. Log metrics for modifier keys remapping
3. Log metrics for physical keyboard settings

Bug: 271391879
Test: manual, atest
Change-Id: I3f948927719ec6fc3dca78cdcb995c3037d8f97f
This commit is contained in:
danielwbhuang
2023-06-07 16:40:37 +08:00
parent 2856b252d6
commit 7aaff67c3c
25 changed files with 363 additions and 57 deletions

View File

@@ -16,10 +16,12 @@
package com.android.settings.inputmethod;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.hardware.input.InputDeviceIdentifier;
import android.hardware.input.InputManager;
import android.hardware.input.KeyboardLayout;
import android.os.Bundle;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
@@ -27,8 +29,11 @@ import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.TickButtonPreference;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
@@ -38,38 +43,47 @@ import java.util.Map;
public class NewKeyboardLayoutPickerController extends BasePreferenceController implements
InputManager.InputDeviceListener, LifecycleObserver, OnStart, OnStop {
private final InputManager mIm;
private final Map<TickButtonPreference, KeyboardLayout> mPreferenceMap;
private Fragment mParent;
private CharSequence mTitle;
private int mInputDeviceId;
private int mUserId;
private InputDeviceIdentifier mInputDeviceIdentifier;
private InputMethodInfo mInputMethodInfo;
private InputMethodSubtype mInputMethodSubtype;
private KeyboardLayout[] mKeyboardLayouts;
private PreferenceScreen mScreen;
private String mPreviousSelection;
private String mFinalSelectedLayout;
private String mLayout;
private MetricsFeatureProvider mMetricsFeatureProvider;
public NewKeyboardLayoutPickerController(Context context, String key) {
super(context, key);
mIm = context.getSystemService(InputManager.class);
mInputDeviceId = -1;
mPreferenceMap = new HashMap<>();
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
}
public void initialize(Fragment parent, int userId, InputDeviceIdentifier inputDeviceIdentifier,
InputMethodInfo imeInfo, InputMethodSubtype imeSubtype, String layout) {
public void initialize(Fragment parent) {
mParent = parent;
mUserId = userId;
mInputDeviceIdentifier = inputDeviceIdentifier;
mInputMethodInfo = imeInfo;
mInputMethodSubtype = imeSubtype;
mLayout = layout;
Bundle arguments = parent.getArguments();
mTitle = arguments.getCharSequence(NewKeyboardSettingsUtils.EXTRA_TITLE);
mUserId = arguments.getInt(NewKeyboardSettingsUtils.EXTRA_USER_ID);
mInputDeviceIdentifier =
arguments.getParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_DEVICE_IDENTIFIER);
mInputMethodInfo =
arguments.getParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_METHOD_INFO);
mInputMethodSubtype =
arguments.getParcelable(NewKeyboardSettingsUtils.EXTRA_INPUT_METHOD_SUBTYPE);
mLayout = getSelectedLayoutLabel();
mFinalSelectedLayout = mLayout;
mKeyboardLayouts = mIm.getKeyboardLayoutListForInputDevice(
inputDeviceIdentifier, userId, imeInfo, imeSubtype);
mInputDeviceIdentifier, mUserId, mInputMethodInfo, mInputMethodSubtype);
parent.getActivity().setTitle(mTitle);
}
@Override
@@ -85,6 +99,11 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
@Override
public void onStop() {
if (!mLayout.equals(mFinalSelectedLayout)) {
String change = "From:" + mLayout + ", to:" + mFinalSelectedLayout;
mMetricsFeatureProvider.action(
mContext, SettingsEnums.ACTION_PK_LAYOUT_CHANGED, change);
}
mIm.unregisterInputDeviceListener(this);
mInputDeviceId = -1;
}
@@ -115,6 +134,7 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
}
setLayout(pref);
mPreviousSelection = preference.getKey();
mFinalSelectedLayout = pref.getTitle().toString();
return true;
}
@@ -162,4 +182,21 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
mInputMethodSubtype,
mPreferenceMap.get(preference).getDescriptor());
}
private String getSelectedLayoutLabel() {
String label = mContext.getString(R.string.keyboard_default_layout);
String layout = NewKeyboardSettingsUtils.getKeyboardLayout(
mIm, mUserId, mInputDeviceIdentifier, mInputMethodInfo, mInputMethodSubtype);
KeyboardLayout[] keyboardLayouts = NewKeyboardSettingsUtils.getKeyboardLayouts(
mIm, mUserId, mInputDeviceIdentifier, mInputMethodInfo, mInputMethodSubtype);
if (layout != null) {
for (KeyboardLayout keyboardLayout : keyboardLayouts) {
if (keyboardLayout.getDescriptor().equals(layout)) {
label = keyboardLayout.getLabel();
break;
}
}
}
return label;
}
}