Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1281e595 authored by Jason Chiu's avatar Jason Chiu
Browse files

[Settings] Add preference click metric log

- Move the log point of onPreferenceTreeClick from DashboardFragment to
  it's super class InstrumentedPreferenceFragment for better coverage.
- Write the preference click metric log in PreferenceController handling
  case in DashboardFragment which will skip super class's log point.

Bug: 137559984
Test: robotest
Change-Id: I67178f613c74f755e20fc9dc41319974cb02e83c
parent e7e4dd90
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -87,6 +87,12 @@ public abstract class InstrumentedPreferenceFragment extends ObservablePreferenc
        return super.findPreference(key);
    }

    @Override
    public boolean onPreferenceTreeClick(Preference preference) {
        writePreferenceClickMetric(preference);
        return super.onPreferenceTreeClick(preference);
    }

    protected final Context getPrefContext() {
        return getPreferenceManager().getContext();
    }
@@ -102,6 +108,10 @@ public abstract class InstrumentedPreferenceFragment extends ObservablePreferenc
        mVisibilityLoggerMixin.writeElapsedTimeMetric(action, key);
    }

    protected void writePreferenceClickMetric(Preference preference) {
        mMetricsFeatureProvider.logClickedPreference(preference, getMetricsCategory());
    }

    private void updateActivityTitleWithScreenTitle(PreferenceScreen screen) {
        if (screen != null) {
            final CharSequence title = screen.getTitle();
+3 −4
Original line number Diff line number Diff line
@@ -400,16 +400,15 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
        ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile);

        if (tile.userHandle == null || tile.isPrimaryProfileOnly()) {
            mMetricsFeatureProvider.logDashboardStartIntent(mContext, intent, sourceMetricCategory);
            mMetricsFeatureProvider.logStartedIntent(intent, sourceMetricCategory);
            activity.startActivityForResult(intent, 0);
        } else if (tile.userHandle.size() == 1) {
            mMetricsFeatureProvider.logDashboardStartIntent(mContext, intent, sourceMetricCategory);
            mMetricsFeatureProvider.logStartedIntent(intent, sourceMetricCategory);
            activity.startActivityForResultAsUser(intent, 0, tile.userHandle.get(0));
        } else {
            final UserHandle userHandle = intent.getParcelableExtra(EXTRA_USER);
            if (userHandle != null && tile.userHandle.contains(userHandle)) {
                mMetricsFeatureProvider.logDashboardStartIntent(
                        mContext, intent, sourceMetricCategory);
                mMetricsFeatureProvider.logStartedIntent(intent, sourceMetricCategory);
                activity.startActivityForResultAsUser(intent, 0, userHandle);
            } else {
                ProfileSelectDialog.show(activity.getSupportFragmentManager(), tile);
+3 −4
Original line number Diff line number Diff line
@@ -201,16 +201,15 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment

    @Override
    public boolean onPreferenceTreeClick(Preference preference) {
        Collection<List<AbstractPreferenceController>> controllers =
        final Collection<List<AbstractPreferenceController>> controllers =
                mPreferenceControllers.values();
        // If preference contains intent, log it before handling.
        mMetricsFeatureProvider.logDashboardStartIntent(
                getContext(), preference.getIntent(), getMetricsCategory());
        // Give all controllers a chance to handle click.
        preference.getExtras().putInt(CATEGORY, getMetricsCategory());
        for (List<AbstractPreferenceController> controllerList : controllers) {
            for (AbstractPreferenceController controller : controllerList) {
                if (controller.handlePreferenceTreeClick(preference)) {
                    // log here since calling super.onPreferenceTreeClick will be skipped
                    writePreferenceClickMetric(preference);
                    return true;
                }
            }
+2 −4
Original line number Diff line number Diff line
@@ -230,8 +230,7 @@ public class DashboardFeatureProviderImplTest {
                MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
        preference.getOnPreferenceClickListener().onPreferenceClick(null);

        verify(mFeatureFactory.metricsFeatureProvider).logDashboardStartIntent(
                any(Context.class),
        verify(mFeatureFactory.metricsFeatureProvider).logStartedIntent(
                any(Intent.class),
                eq(MetricsEvent.SETTINGS_GESTURES));
        verify(mActivity)
@@ -249,8 +248,7 @@ public class DashboardFeatureProviderImplTest {
        mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
                MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
        preference.getOnPreferenceClickListener().onPreferenceClick(null);
        verify(mFeatureFactory.metricsFeatureProvider).logDashboardStartIntent(
                any(Context.class),
        verify(mFeatureFactory.metricsFeatureProvider).logStartedIntent(
                any(Intent.class),
                anyInt());
        verify(mActivity)