1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 #include "tensorflow/lite/experimental/acceleration/compatibility/android_info.h" 16 17 #include <string> 18 19 #include "absl/status/status.h" 20 21 #ifdef __ANDROID__ 22 #include <sys/system_properties.h> 23 #endif // __ANDROID__ 24 25 namespace { GetPropertyValue(const std::string & property)26std::string GetPropertyValue(const std::string& property) { 27 #ifdef __ANDROID__ 28 char value[PROP_VALUE_MAX]; 29 __system_property_get(property.c_str(), value); 30 return std::string(value); 31 #else // !__ANDROID__ 32 return std::string(); 33 #endif // __ANDROID__ 34 } 35 } // namespace 36 37 namespace tflite { 38 namespace acceleration { 39 RequestAndroidInfo(AndroidInfo * info_out)40absl::Status RequestAndroidInfo(AndroidInfo* info_out) { 41 if (!info_out) { 42 return absl::InvalidArgumentError("info_out may not be null"); 43 } 44 info_out->android_sdk_version = GetPropertyValue("ro.build.version.sdk"); 45 info_out->device = GetPropertyValue("ro.product.device"); 46 info_out->model = GetPropertyValue("ro.product.model"); 47 info_out->manufacturer = GetPropertyValue("ro.product.manufacturer"); 48 return absl::OkStatus(); 49 } 50 51 } // namespace acceleration 52 } // namespace tflite 53