• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.dialer.configprovider;
18 
19 import android.content.Context;
20 import android.support.annotation.NonNull;
21 import android.support.annotation.Nullable;
22 import android.support.annotation.VisibleForTesting;
23 import android.support.v4.os.UserManagerCompat;
24 import com.android.dialer.common.Assert;
25 
26 /** Accessor for getting a {@link ConfigProvider}. */
27 public class ConfigProviderBindings {
28 
29   private static ConfigProvider configProvider;
30   private static ConfigProvider configProviderStub;
31 
get(@onNull Context context)32   public static ConfigProvider get(@NonNull Context context) {
33     Assert.isNotNull(context);
34     if (configProvider != null) {
35       return configProvider;
36     }
37     if (!UserManagerCompat.isUserUnlocked(context)) {
38       if (configProviderStub == null) {
39         configProviderStub = new ConfigProviderStub();
40       }
41       return configProviderStub;
42     }
43     configProvider = ConfigProviderComponent.get(context).getConfigProvider();
44     return configProvider;
45   }
46 
47   @VisibleForTesting
setForTesting(@ullable ConfigProvider configProviderForTesting)48   public static void setForTesting(@Nullable ConfigProvider configProviderForTesting) {
49     configProvider = configProviderForTesting;
50   }
51 
52   private static class ConfigProviderStub implements ConfigProvider {
53     @Override
getString(String key, String defaultValue)54     public String getString(String key, String defaultValue) {
55       return defaultValue;
56     }
57 
58     @Override
getLong(String key, long defaultValue)59     public long getLong(String key, long defaultValue) {
60       return defaultValue;
61     }
62 
63     @Override
getBoolean(String key, boolean defaultValue)64     public boolean getBoolean(String key, boolean defaultValue) {
65       return defaultValue;
66     }
67   }
68 }
69