1 /* 2 * Copyright (C) 2016 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.incallui.spam; 18 19 import android.content.Context; 20 import com.android.dialer.common.LogUtil; 21 import com.android.dialer.configprovider.ConfigProviderComponent; 22 23 /** Returns resource id based on experiment number. */ 24 public final class SpamAlternativeExperimentUtil { 25 26 /** 27 * Returns the resource id using a resource name for an experiment where we want to use 28 * alternative words for the keyword spam. 29 */ getResourceIdByName(String resourceName, Context context)30 public static int getResourceIdByName(String resourceName, Context context) { 31 long experiment = 32 ConfigProviderComponent.get(context) 33 .getConfigProvider() 34 .getLong("experiment_for_alternative_spam_word", 230150); 35 LogUtil.i( 36 "SpamAlternativeExperimentUtil.getResourceIdByName", "using experiment %d", experiment); 37 String modifiedResourceName = resourceName; 38 if (experiment != 230150) { 39 modifiedResourceName = resourceName + "_" + experiment; 40 } 41 int resourceId = 42 context 43 .getResources() 44 .getIdentifier(modifiedResourceName, "string", context.getPackageName()); 45 if (resourceId == 0) { 46 LogUtil.i( 47 "SpamAlternativeExperimentUtil.getResourceIdByName", 48 "not found experiment %d", 49 experiment); 50 return context.getResources().getIdentifier(resourceName, "string", context.getPackageName()); 51 } 52 return resourceId; 53 } 54 } 55