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