Home | History | Annotate | Download | only in constants
      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.constants;
     18 
     19 import android.content.Context;
     20 import android.support.annotation.NonNull;
     21 import com.android.dialer.common.Assert;
     22 import com.android.dialer.proguard.UsedByReflection;
     23 
     24 /**
     25  * Utility to access constants that are different across build variants (Google Dialer, AOSP,
     26  * etc...). This functionality depends on a an implementation being present in the app that has the
     27  * same package and the class name ending in "Impl". For example,
     28  * com.android.dialer.constants.ConstantsImpl. This class is found by the module using reflection.
     29  */
     30 @UsedByReflection(value = "Constants.java")
     31 public abstract class Constants {
     32   private static Constants instance;
     33   private static boolean didInitializeInstance;
     34 
     35   @NonNull
     36   public static synchronized Constants get() {
     37     if (!didInitializeInstance) {
     38       didInitializeInstance = true;
     39       try {
     40         Class<?> clazz = Class.forName(Constants.class.getName() + "Impl");
     41         instance = (Constants) clazz.getConstructor().newInstance();
     42       } catch (ReflectiveOperationException e) {
     43         Assert.fail(
     44             "Unable to create an instance of ConstantsImpl. To fix this error include one of the "
     45                 + "constants modules (googledialer, aosp etc...) in your target.");
     46       }
     47     }
     48     return instance;
     49   }
     50 
     51   @NonNull
     52   public abstract String getFilteredNumberProviderAuthority();
     53 
     54   @NonNull
     55   public abstract String getFileProviderAuthority();
     56 
     57   @NonNull
     58   public abstract String getAnnotatedCallLogProviderAuthority();
     59 
     60   @NonNull
     61   public abstract String getPhoneLookupHistoryProviderAuthority();
     62 
     63   @NonNull
     64   public abstract String getPreferredSimFallbackProviderAuthority();
     65 
     66   public abstract String getUserAgent(Context context);
     67 
     68   @NonNull
     69   public abstract String getSettingsActivity();
     70 
     71   protected Constants() {}
     72 }
     73