Home | History | Annotate | Download | only in v1
      1 /*
      2  * Copyright (C) 2009 Google Inc.
      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.vending.sectool.v1;
     18 
     19 import android.content.ContentResolver;
     20 import android.content.ContentValues;
     21 import android.database.Cursor;
     22 import android.database.SQLException;
     23 import android.net.Uri;
     24 import android.provider.BaseColumns;
     25 import android.util.Log;
     26 
     27 /**
     28  * The GoogleSettings provider contains Google app/service specific preferences.
     29  *
     30  * This class is duplicated in vendor/google/frameworks/maps, see
     31  * http://b/2553658.
     32  */
     33 public final class GoogleSettingsContract {
     34 
     35     public static final String AUTHORITY = "com.google.settings";
     36 
     37     private static final String TAG = "GoogleSettings";
     38 
     39     /**
     40      * Common base for tables of name/value settings.
     41      */
     42     public static class NameValueTable implements BaseColumns {
     43         public static final String NAME = "name";
     44         public static final String VALUE = "value";
     45 
     46         protected static boolean putString(ContentResolver resolver, Uri uri,
     47                 String name, String value) {
     48             // The database will take care of replacing duplicates.
     49             try {
     50                 ContentValues values = new ContentValues();
     51                 values.put(NAME, name);
     52                 values.put(VALUE, value);
     53                 resolver.insert(uri, values);
     54                 return true;
     55             } catch (SQLException e) {
     56                 Log.e(TAG, "Can't set key " + name + " in " + uri, e);
     57                 return false;
     58             } catch (IllegalArgumentException e) {
     59                 // ContentResolver.insert() throws IllegalArgumentException if there is no
     60                 // provider for the URI.
     61                 Log.e(TAG, "Can't set key " + name + " in " + uri, e);
     62                 return false;
     63             }
     64         }
     65 
     66         public static Uri getUriFor(Uri uri, String name) {
     67             return Uri.withAppendedPath(uri, name);
     68         }
     69     }
     70 
     71     /**
     72      * "Partner" settings,  Actually this is the only settings table, and
     73      * it gets used for general Google-specific settings.  The fact that it's
     74      * called "Partner" is just a historical accident.
     75      */
     76     public static final class Partner extends NameValueTable {
     77         /**
     78          * Look up a name in the database.
     79          * @param resolver to access the database with
     80          * @param name to look up in the table
     81          * @return the corresponding value, or null if not present
     82          */
     83         public static String getString(ContentResolver resolver, String name) {
     84             String value = null;
     85             Cursor c = null;
     86             try {
     87                 c = resolver.query(CONTENT_URI, new String[] { NameValueTable.VALUE },
     88                         NameValueTable.NAME + "=?", new String[]{ name }, null);
     89                 if (c != null && c.moveToNext()) value = c.getString(0);
     90             } catch (SQLException e) {
     91                 // SQL error: return null, but don't cache it.
     92                 Log.e(TAG, "Can't get key " + name + " from " + CONTENT_URI, e);
     93             } finally {
     94                 if (c != null) c.close();
     95             }
     96             return value;
     97         }
     98 
     99         /**
    100          * Look up a name in the database
    101          * @param resolver to access the database
    102          * @param name to look up in the table
    103          * @param defaultValue value to set if not found in table
    104          * @return the value found in the table or default
    105          */
    106         public static String getString(ContentResolver resolver, String name, String defaultValue) {
    107             String value = getString(resolver, name);
    108             if (value == null) {
    109                 value = defaultValue;
    110             }
    111 
    112             return value;
    113         }
    114 
    115         /**
    116          * Store a name/value pair into the database.
    117          * @param resolver to access the database with
    118          * @param name to store
    119          * @param value to associate with the name
    120          * @return true if the value was set, false on database errors
    121          */
    122         public static boolean putString(ContentResolver resolver,
    123                 String name, String value) {
    124             return putString(resolver, CONTENT_URI, name, value);
    125         }
    126 
    127         /**
    128          * Store a name/value pair into the database.
    129          * @param resolver to access the database with
    130          * @param name to store
    131          * @param value to associate with the name
    132          * @return true if the value was set, false on database errors
    133          */
    134         public static boolean putInt(ContentResolver resolver,
    135                 String name, int value) {
    136             return putString(resolver, name, String.valueOf(value));
    137         }
    138 
    139         /**
    140          * Look up the value for name in the database, convert it to an int using Integer.parseInt
    141          * and return it. If it is null or if a NumberFormatException is caught during the
    142          * conversion then return defValue.
    143          */
    144         public static int getInt(ContentResolver resolver, String name, int defValue) {
    145             String valString = getString(resolver, name);
    146             int value;
    147             try {
    148                 value = valString != null ? Integer.parseInt(valString) : defValue;
    149             } catch (NumberFormatException e) {
    150                 value = defValue;
    151             }
    152             return value;
    153         }
    154 
    155         /**
    156          * Look up the value for name in the database, convert it to a long using Long.parseLong
    157          * and return it. If it is null or if a NumberFormatException is caught during the
    158          * conversion then return defValue.
    159          */
    160         public static long getLong(ContentResolver resolver, String name, long defValue) {
    161             String valString = getString(resolver, name);
    162             long value;
    163             try {
    164                 value = valString != null ? Long.parseLong(valString) : defValue;
    165             } catch (NumberFormatException e) {
    166                 value = defValue;
    167             }
    168             return value;
    169         }
    170 
    171         /**
    172          * Construct the content URI for a particular name/value pair,
    173          * useful for monitoring changes with a ContentObserver.
    174          * @param name to look up in the table
    175          * @return the corresponding content URI, or null if not present
    176          */
    177         public static Uri getUriFor(String name) {
    178             return getUriFor(CONTENT_URI, name);
    179         }
    180 
    181         /**
    182          * The content:// style URL for this table
    183          */
    184         public static final Uri CONTENT_URI =
    185                 Uri.parse("content://" + AUTHORITY + "/partner");
    186 
    187 
    188         /**
    189          * Partner Table Version
    190          */
    191 
    192         public static final String DATA_STORE_VERSION = "data_store_version";
    193 
    194         /**
    195          * Google Partner Client Id
    196          */
    197         public static final String CLIENT_ID = "client_id";
    198 
    199         /**
    200          * Voice Search Client Id
    201          */
    202 
    203         public static final String VOICESEARCH_CLIENT_ID = "voicesearch_client_id";
    204 
    205         /**
    206          * Google Mobile Maps Client Id
    207          */
    208         public static final String MAPS_CLIENT_ID = "maps_client_id";
    209 
    210         /**
    211          * Google YouTube App Client Id
    212          */
    213         public static final String YOUTUBE_CLIENT_ID = "youtube_client_id";
    214 
    215         /**
    216          * Android Market Client Id
    217          */
    218         public static final String MARKET_CLIENT_ID = "market_client_id";
    219 
    220         /**
    221          * True if user has opted in to network location service.
    222          */
    223         public static final String NETWORK_LOCATION_OPT_IN = "network_location_opt_in";
    224 
    225         /**
    226          * Flag for allowing Google services to use location information.
    227          * Type: int ( 0 = disallow, 1 = allow )
    228          */
    229         public static final String USE_LOCATION_FOR_SERVICES = "use_location_for_services";
    230 
    231         /**
    232          * RLZ is a tracking string used for ROI analysis. It is similar
    233          * to client id but more powerful. RLZ data enables ROI analysis in
    234          * Google's distribution business (Toolbar, Pack, iGoogle). It
    235          * explicitly ties the revenue received from distributed software to the
    236          * expense of distribution payments.
    237          */
    238         public static final String RLZ = "rlz";
    239 
    240         /**
    241          * The Logging ID (a unique 64-bit value) as a hex string.
    242          * Used as a pseudonymous identifier for logging.
    243          */
    244         public static final String LOGGING_ID2 = "logging_id2";
    245 
    246         /**
    247          * Opaque blob of data representing Market state (installed apps, etc).
    248          * Used to hand off this data to the checkin service for upload.
    249          */
    250         public static final String MARKET_CHECKIN = "market_checkin";
    251     }
    252 }
    253