From 7ca3851cdd7d87822b4615d58e1cb61dc232ddb8 Mon Sep 17 00:00:00 2001 From: zachh Date: Wed, 14 Feb 2018 17:46:51 -0800 Subject: Created a "Metrics" interface. Bug: 70989667 Test: existing PiperOrigin-RevId: 185773466 Change-Id: Ib40632fe87682f672df2f5e94a0e5bc4ca5970e9 --- .../binary/aosp/AospDialerRootComponent.java | 2 ++ .../basecomponent/BaseDialerRootComponent.java | 2 ++ .../google/GoogleStubDialerRootComponent.java | 2 ++ java/com/android/dialer/metrics/Metrics.java | 39 ++++++++++++++++++++ .../android/dialer/metrics/MetricsComponent.java | 41 ++++++++++++++++++++++ java/com/android/dialer/metrics/StubMetrics.java | 36 +++++++++++++++++++ .../dialer/metrics/StubMetricsInitializer.java | 30 ++++++++++++++++ .../android/dialer/metrics/StubMetricsModule.java | 31 ++++++++++++++++ 8 files changed, 183 insertions(+) create mode 100644 java/com/android/dialer/metrics/Metrics.java create mode 100644 java/com/android/dialer/metrics/MetricsComponent.java create mode 100644 java/com/android/dialer/metrics/StubMetrics.java create mode 100644 java/com/android/dialer/metrics/StubMetricsInitializer.java create mode 100644 java/com/android/dialer/metrics/StubMetricsModule.java diff --git a/java/com/android/dialer/binary/aosp/AospDialerRootComponent.java b/java/com/android/dialer/binary/aosp/AospDialerRootComponent.java index 0f00a5d82..35f854010 100644 --- a/java/com/android/dialer/binary/aosp/AospDialerRootComponent.java +++ b/java/com/android/dialer/binary/aosp/AospDialerRootComponent.java @@ -26,6 +26,7 @@ import com.android.dialer.enrichedcall.stub.StubEnrichedCallModule; import com.android.dialer.feedback.stub.StubFeedbackModule; import com.android.dialer.glidephotomanager.GlidePhotoManagerModule; import com.android.dialer.inject.ContextModule; +import com.android.dialer.metrics.StubMetricsModule; import com.android.dialer.phonelookup.PhoneLookupModule; import com.android.dialer.phonenumbergeoutil.impl.PhoneNumberGeoUtilModule; import com.android.dialer.precall.impl.PreCallModule; @@ -63,6 +64,7 @@ import javax.inject.Singleton; StubDuoModule.class, StubEnrichedCallModule.class, StubNewBubbleModule.class, + StubMetricsModule.class, StubFeedbackModule.class, StubMapsModule.class, StubSimSuggestionModule.class, diff --git a/java/com/android/dialer/binary/basecomponent/BaseDialerRootComponent.java b/java/com/android/dialer/binary/basecomponent/BaseDialerRootComponent.java index 3e7db9d8a..cd95c3ee7 100644 --- a/java/com/android/dialer/binary/basecomponent/BaseDialerRootComponent.java +++ b/java/com/android/dialer/binary/basecomponent/BaseDialerRootComponent.java @@ -27,6 +27,7 @@ import com.android.dialer.enrichedcall.EnrichedCallComponent; import com.android.dialer.feedback.FeedbackComponent; import com.android.dialer.glidephotomanager.GlidePhotoManagerComponent; import com.android.dialer.main.MainComponent; +import com.android.dialer.metrics.MetricsComponent; import com.android.dialer.phonelookup.PhoneLookupComponent; import com.android.dialer.phonenumbergeoutil.PhoneNumberGeoUtilComponent; import com.android.dialer.precall.PreCallComponent; @@ -59,6 +60,7 @@ public interface BaseDialerRootComponent GlidePhotoManagerComponent.HasComponent, MainComponent.HasComponent, MapsComponent.HasComponent, + MetricsComponent.HasComponent, NewBubbleComponent.HasComponent, PhoneLookupComponent.HasComponent, PhoneNumberGeoUtilComponent.HasComponent, diff --git a/java/com/android/dialer/binary/google/GoogleStubDialerRootComponent.java b/java/com/android/dialer/binary/google/GoogleStubDialerRootComponent.java index d4520f33e..497d97724 100644 --- a/java/com/android/dialer/binary/google/GoogleStubDialerRootComponent.java +++ b/java/com/android/dialer/binary/google/GoogleStubDialerRootComponent.java @@ -26,6 +26,7 @@ import com.android.dialer.enrichedcall.stub.StubEnrichedCallModule; import com.android.dialer.feedback.stub.StubFeedbackModule; import com.android.dialer.glidephotomanager.GlidePhotoManagerModule; import com.android.dialer.inject.ContextModule; +import com.android.dialer.metrics.StubMetricsModule; import com.android.dialer.phonelookup.PhoneLookupModule; import com.android.dialer.phonenumbergeoutil.impl.PhoneNumberGeoUtilModule; import com.android.dialer.precall.impl.PreCallModule; @@ -67,6 +68,7 @@ import javax.inject.Singleton; StubDuoModule.class, StubEnrichedCallModule.class, StubFeedbackModule.class, + StubMetricsModule.class, StubNewBubbleModule.class, StubSimSuggestionModule.class, StubSpamModule.class, diff --git a/java/com/android/dialer/metrics/Metrics.java b/java/com/android/dialer/metrics/Metrics.java new file mode 100644 index 000000000..3922a8cfa --- /dev/null +++ b/java/com/android/dialer/metrics/Metrics.java @@ -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.dialer.metrics; + +import android.app.Application; +import android.content.Context; + +/** Logs metrics. */ +public interface Metrics { + + /** Start a timer. */ + void startTimer(Context context, String timerEventName); + + /** Stop a timer. */ + void stopTimer(String timerEventName); + + /** Record memory. */ + void recordMemory(String memoryEventName); + + /** Initiazer for metrics. */ + interface Initializer { + /** Initialize metrics for the application . */ + void initialize(Application application); + } +} diff --git a/java/com/android/dialer/metrics/MetricsComponent.java b/java/com/android/dialer/metrics/MetricsComponent.java new file mode 100644 index 000000000..f37129791 --- /dev/null +++ b/java/com/android/dialer/metrics/MetricsComponent.java @@ -0,0 +1,41 @@ +/* + * 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.dialer.metrics; + +import android.content.Context; +import com.android.dialer.inject.HasRootComponent; +import dagger.Subcomponent; + +/** Component for metrics. */ +@Subcomponent +public abstract class MetricsComponent { + + public abstract Metrics metrics(); + + public abstract Metrics.Initializer metricsInitializer(); + + public static MetricsComponent get(Context context) { + return ((MetricsComponent.HasComponent) + ((HasRootComponent) context.getApplicationContext()).component()) + .metricsComponent(); + } + + /** Used to refer to the root application component. */ + public interface HasComponent { + MetricsComponent metricsComponent(); + } +} diff --git a/java/com/android/dialer/metrics/StubMetrics.java b/java/com/android/dialer/metrics/StubMetrics.java new file mode 100644 index 000000000..114eb4308 --- /dev/null +++ b/java/com/android/dialer/metrics/StubMetrics.java @@ -0,0 +1,36 @@ +/* + * 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.dialer.metrics; + +import android.content.Context; +import javax.inject.Inject; + +/** Stub {@link Metrics}. */ +public final class StubMetrics implements Metrics { + + @Inject + StubMetrics() {} + + @Override + public void startTimer(Context context, String timerEventName) {} + + @Override + public void stopTimer(String timerEventName) {} + + @Override + public void recordMemory(String memoryEventName) {} +} diff --git a/java/com/android/dialer/metrics/StubMetricsInitializer.java b/java/com/android/dialer/metrics/StubMetricsInitializer.java new file mode 100644 index 000000000..cea408737 --- /dev/null +++ b/java/com/android/dialer/metrics/StubMetricsInitializer.java @@ -0,0 +1,30 @@ +/* + * 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.dialer.metrics; + +import android.app.Application; +import javax.inject.Inject; + +/** Stub for {@link Metrics.Initializer}. */ +public class StubMetricsInitializer implements Metrics.Initializer { + + @Inject + StubMetricsInitializer() {} + + @Override + public void initialize(Application application) {} +} diff --git a/java/com/android/dialer/metrics/StubMetricsModule.java b/java/com/android/dialer/metrics/StubMetricsModule.java new file mode 100644 index 000000000..a2d9ebfe2 --- /dev/null +++ b/java/com/android/dialer/metrics/StubMetricsModule.java @@ -0,0 +1,31 @@ +/* + * 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.dialer.metrics; + +import dagger.Binds; +import dagger.Module; + +/** Binds stub {@link Metrics}. */ +@Module +public interface StubMetricsModule { + + @Binds + Metrics bindMetrics(StubMetrics stub); + + @Binds + Metrics.Initializer bindMetricsInitializer(StubMetricsInitializer stub); +} -- cgit v1.2.3