Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (C) 2015 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.messaging.util;
     18 
     19 import com.android.messaging.Factory;
     20 
     21 /**
     22  * A thin wrapper for getting GServices value. During constructor time a one time background thread
     23  * will cache all GServices key with the prefix of "bugle_". All get calls will wait for Gservices
     24  * to finish caching the first time. In practice, the background thread will finish before any get
     25  * request.
     26  */
     27 public abstract class BugleGservices {
     28     static final String BUGLE_GSERVICES_PREFIX = "bugle_";
     29 
     30     public static BugleGservices get() {
     31         return Factory.get().getBugleGservices();
     32     }
     33 
     34     public abstract void registerForChanges(final Runnable r);
     35 
     36     /**
     37      * @param key The key to look up in GServices
     38      * @param defaultValue The default value if value in GServices is null or if
     39      * NumberFormatException is caught.
     40      * @return The corresponding value, or the default value.
     41      */
     42     public abstract long getLong(final String key, final long defaultValue);
     43 
     44     /**
     45      * @param key The key to look up in GServices
     46      * @param defaultValue The default value if value in GServices is null or if
     47      * NumberFormatException is caught.
     48      * @return The corresponding value, or the default value.
     49      */
     50     public abstract int getInt(final String key, final int defaultValue);
     51 
     52     /**
     53      * @param key The key to look up in GServices
     54      * @param defaultValue The default value if value in GServices is null.
     55      * @return The corresponding value, or the default value.
     56      */
     57     public abstract boolean getBoolean(final String key, final boolean defaultValue);
     58 
     59     /**
     60      * @param key The key to look up in GServices
     61      * @param defaultValue The default value if value in GServices is null.
     62      * @return The corresponding value, or the default value.
     63      */
     64     public abstract String getString(final String key, final String defaultValue);
     65 
     66     /**
     67      * @param key The key to look up in GServices
     68      * @param defaultValue The default value if value in GServices is null.
     69      * @return The corresponding value, or the default value.
     70      */
     71     public abstract float getFloat(final String key, final float defaultValue);
     72 }
     73