Log visibility change for all fragments.
Bug: 30681771 Test: SettingsUnitTests Refactor visibility logging from InstrumentedFragment into a mixin. And apply mixin in remaining fragments. Change-Id: Ibbb59904336254a3e4bb9e8c7d0b36e5a6bc2622
This commit is contained in:
42
src/com/android/settings/core/InstrumentedActivity.java
Normal file
42
src/com/android/settings/core/InstrumentedActivity.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.settings.core;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.android.settings.core.instrumentation.Instrumentable;
|
||||
import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
|
||||
|
||||
/**
|
||||
* Instrumented activity that logs visibility state.
|
||||
*/
|
||||
public abstract class InstrumentedActivity extends Activity implements Instrumentable {
|
||||
|
||||
private final VisibilityLoggerMixin mVisibilityLoggerMixin = new VisibilityLoggerMixin(this);
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mVisibilityLoggerMixin.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mVisibilityLoggerMixin.onPause(this);
|
||||
}
|
||||
}
|
||||
47
src/com/android/settings/core/InstrumentedFragment.java
Normal file
47
src/com/android/settings/core/InstrumentedFragment.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.settings.core;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
|
||||
import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
|
||||
import com.android.settings.core.instrumentation.Instrumentable;
|
||||
|
||||
/**
|
||||
* Instrumented fragment that logs visibility state.
|
||||
*/
|
||||
public abstract class InstrumentedFragment extends PreferenceFragment implements Instrumentable {
|
||||
|
||||
private final VisibilityLoggerMixin mVisibilityLoggerMixin = new VisibilityLoggerMixin(this);
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mVisibilityLoggerMixin.onResume(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mVisibilityLoggerMixin.onPause(getActivity());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.settings.core.instrumentation;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
|
||||
/**
|
||||
* Pass-through Metrics logger for {@link MetricsLogger}.
|
||||
*/
|
||||
public class EventLogWriter {
|
||||
|
||||
public void visible(Context context, int category) {
|
||||
MetricsLogger.visible(context, category);
|
||||
}
|
||||
|
||||
public void hidden(Context context, int category) {
|
||||
MetricsLogger.hidden(context, category);
|
||||
}
|
||||
|
||||
public void action(Context context, int category) {
|
||||
MetricsLogger.action(context, category, "");
|
||||
}
|
||||
|
||||
public void action(Context context, int category, int value) {
|
||||
MetricsLogger.action(context, category, Integer.toString(value));
|
||||
}
|
||||
|
||||
public void action(Context context, int category, boolean value) {
|
||||
MetricsLogger.action(context, category, Boolean.toString(value));
|
||||
}
|
||||
|
||||
public void action(Context context, int category, String pkg) {
|
||||
MetricsLogger.action(context, category, pkg);
|
||||
}
|
||||
|
||||
public void count(Context context, String name, int value) {
|
||||
MetricsLogger.count(context, name, value);
|
||||
}
|
||||
|
||||
public void histogram(Context context, String name, int bucket) {
|
||||
MetricsLogger.histogram(context, name, bucket);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.settings.core.instrumentation;
|
||||
|
||||
public interface Instrumentable {
|
||||
|
||||
/**
|
||||
* Instrumented name for a view as defined in
|
||||
* {@link com.android.internal.logging.MetricsProto.MetricsEvent}.
|
||||
*/
|
||||
int getMetricsCategory();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.settings.core.instrumentation;
|
||||
|
||||
public class MetricsFactory {
|
||||
|
||||
private static MetricsFactory sInstance;
|
||||
|
||||
private EventLogWriter mLogger;
|
||||
|
||||
public static MetricsFactory get() {
|
||||
if (sInstance == null) {
|
||||
sInstance = new MetricsFactory();
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public EventLogWriter getLogger() {
|
||||
if (mLogger == null) {
|
||||
mLogger = new EventLogWriter();
|
||||
}
|
||||
return mLogger;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.settings.core.instrumentation;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* Logs visibility change of a fragment.
|
||||
*/
|
||||
public class VisibilityLoggerMixin {
|
||||
|
||||
private final Instrumentable mInstrumentable;
|
||||
private final EventLogWriter mEventLogWriter;
|
||||
|
||||
public VisibilityLoggerMixin(Instrumentable instrumentable) {
|
||||
this(instrumentable, MetricsFactory.get().getLogger());
|
||||
}
|
||||
|
||||
public VisibilityLoggerMixin(Instrumentable instrumentable, EventLogWriter eventLogWriter) {
|
||||
mInstrumentable = instrumentable;
|
||||
mEventLogWriter = eventLogWriter;
|
||||
}
|
||||
|
||||
public void onResume(Context context) {
|
||||
mEventLogWriter.visible(context, mInstrumentable.getMetricsCategory());
|
||||
}
|
||||
|
||||
public void onPause(Context context) {
|
||||
mEventLogWriter.hidden(context, mInstrumentable.getMetricsCategory());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user