• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.dialer.buildtype;
18 
19 import android.support.annotation.IntDef;
20 import com.android.dialer.common.Assert;
21 import com.android.dialer.common.LogUtil;
22 import java.lang.annotation.Retention;
23 import java.lang.annotation.RetentionPolicy;
24 
25 /** Utility to find out which build type the app is running as. */
26 public class BuildType {
27 
28   /** The type of build. */
29   @Retention(RetentionPolicy.SOURCE)
30   @IntDef({
31     BUGFOOD, FISHFOOD, DOGFOOD, RELEASE, TEST,
32   })
33   public @interface Type {}
34 
35   public static final int BUGFOOD = 1;
36   public static final int FISHFOOD = 2;
37   public static final int DOGFOOD = 3;
38   public static final int RELEASE = 4;
39   public static final int TEST = 5;
40 
41   private static int cachedBuildType;
42   private static boolean didInitializeBuildType;
43 
44   @Type
get()45   public static synchronized int get() {
46     if (!didInitializeBuildType) {
47       didInitializeBuildType = true;
48       try {
49         Class<?> clazz = Class.forName(BuildTypeAccessor.class.getName() + "Impl");
50         BuildTypeAccessor accessorImpl = (BuildTypeAccessor) clazz.getConstructor().newInstance();
51         cachedBuildType = accessorImpl.getBuildType();
52       } catch (ReflectiveOperationException e) {
53         LogUtil.e("BuildType.get", "error creating BuildTypeAccessorImpl", e);
54         Assert.fail(
55             "Unable to get build type. To fix this error include one of the build type "
56                 + "modules (bugfood, etc...) in your target.");
57       }
58     }
59     return cachedBuildType;
60   }
61 
BuildType()62   private BuildType() {}
63 }
64