• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.managedprovisioning.analytics;
18 
19 import android.content.Context;
20 
21 import com.android.internal.util.Preconditions;
22 import com.android.managedprovisioning.common.SettingsFacade;
23 import com.android.managedprovisioning.provisioning.Constants;
24 
25 /**
26  * Factory which determines what {@link MetricsWriter} to use.
27  */
28 public class MetricsWriterFactory {
29     /**
30      * Returns the appropriate {@link MetricsWriter}.
31      *
32      * <p>As we want to send statsd logs only after user has consented to the relevant
33      * consent screens, we defer the metrics until the end of the in-setup wizard provisioning flow.
34      * Statsd then uploads the logs if the user has consented.
35      *
36      * <p>If provisioning happens post-setup wizard, we send the logs to statsd right away.
37      */
getMetricsWriter(Context context, SettingsFacade settingsFacade)38     public static MetricsWriter getMetricsWriter(Context context, SettingsFacade settingsFacade) {
39         Preconditions.checkNotNull(context);
40         Preconditions.checkNotNull(settingsFacade);
41         if (settingsFacade.isDuringSetupWizard(context)) {
42             return new DeferredMetricsWriter(Constants.getDeferredMetricsFile(context));
43 
44         }
45         return new InstantMetricsWriter();
46     }
47 }
48