• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2016 Google, Inc.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #include <string.h>
20 
21 #include "osi/include/properties.h"
22 
23 #if !defined(OS_GENERIC)
24 #undef PROPERTY_VALUE_MAX
25 #include <cutils/properties.h>
26 #if BUILD_SANITY_PROPERTY_VALUE_MAX != PROPERTY_VALUE_MAX
27 #error "PROPERTY_VALUE_MAX from osi/include/properties.h != the Android value"
28 #endif  // GENERIC_PROPERTY_VALUE_MAX != PROPERTY_VALUE_MAX
29 #endif  // !defined(OS_GENERIC)
30 
osi_property_get(const char * key,char * value,const char * default_value)31 int osi_property_get(const char* key, char* value, const char* default_value) {
32 #if defined(OS_GENERIC)
33   /* For linux right now just return default value, if present */
34   int len = 0;
35   if (!default_value) return len;
36 
37   len = strlen(default_value);
38   if (len >= PROPERTY_VALUE_MAX) len = PROPERTY_VALUE_MAX - 1;
39 
40   memcpy(value, default_value, len);
41   value[len] = '\0';
42   return len;
43 #else
44   return property_get(key, value, default_value);
45 #endif  // defined(OS_GENERIC)
46 }
47 
osi_property_set(const char * key,const char * value)48 int osi_property_set(const char* key, const char* value) {
49 #if defined(OS_GENERIC)
50   return -1;
51 #else
52   return property_set(key, value);
53 #endif  // defined(OS_GENERIC)
54 }
55 
osi_property_get_int32(const char * key,int32_t default_value)56 int32_t osi_property_get_int32(const char* key, int32_t default_value) {
57 #if defined(OS_GENERIC)
58   return default_value;
59 #else
60   return property_get_int32(key, default_value);
61 #endif  // defined(OS_GENERIC)
62 }
63 
osi_property_get_bool(const char * key,bool default_value)64 bool osi_property_get_bool(const char* key, bool default_value) {
65 #if defined(OS_GENERIC)
66   return default_value;
67 #else
68   return property_get_bool(key, default_value);
69 #endif  // defined(OS_GENERIC)
70 }