#include <ITapiModem.h>
#include <ITapiSim.h>
#include <ITapiSim_product.h>
+#include <device.h>
#include "common/logger.h"
#include "common/platform_exception.h"
#define SEED_LENGTH 16
#define CRYPT_KEY_SIZE 8
+#define TAPI_HANDLE_MAX 2
+#define DEFAULT_PROPERTY_COUNT 1
+
#ifdef FEATURE_OPTIONAL_WI_FI
#include <wifi.h>
#endif
namespace extension {
namespace systeminfo {
+namespace {
+const int MEMORY_TO_BYTE = 1024;
+}
using namespace common;
//Callback functions declarations
unsigned short to_process_;
std::mutex sim_to_process_mutex_;
std::mutex sim_info_mutex_;
+ long sim_count_;
void ResetSimHolder(picojson::object* out);
void FetchSimState(TapiHandle *tapi_handle);
SimDetailsManager();
void GatherSimInformation(TapiHandle* handle, picojson::object* out);
+ long GetSimCount(TapiHandle **tapi_handle);
void TryReturn();
void set_operator_name(const std::string& name)
iccid_(""),
spn_(""),
sim_result_obj_(nullptr),
- to_process_(0)
+ to_process_(0),
+ sim_count_(0)
{
}
}
}
+long SimDetailsManager::GetSimCount(TapiHandle **tapi_handle){
+ if (0 != sim_count_){
+ LOGD("Sim counted already");
+ } else {
+ LOGD("Gathering sim count");
+ char **cp_list = tel_get_cp_name_list();
+ if (cp_list != NULL) {
+ while (cp_list[sim_count_]) {
+ tapi_handle[sim_count_] = tel_init(cp_list[sim_count_]);
+ if (tapi_handle[sim_count_] == NULL) {
+ LOGE("Failed to connect with tapi, handle is null");
+ break;
+ }
+ sim_count_++;
+ LOGD("%d modem: %s", sim_count_, cp_list[sim_count_]);
+ }
+ } else {
+ LOGE("Failed to get cp list");
+ sim_count_ = TAPI_HANDLE_MAX;
+ }
+ g_strfreev(cp_list);
+ }
+ return sim_count_;
+}
+
void SimDetailsManager::TryReturn(){
if (0 == to_process_){
LOGD("Returning property to JS");
void OnPeripheralChangedCallback(keynode_t* node, void* event_ptr);
TapiHandle* GetTapiHandle();
+ TapiHandle** GetTapiHandles();
connection_h GetConnectionHandle();
private:
static void RegisterVconfCallback(const char *in_key, vconf_callback_fn cb);
static void UnregisterVconfCallback(const char *in_key, vconf_callback_fn cb);
void RegisterIpChangeCallback();
void UnregisterIpChangeCallback();
+ void InitTapiHandles();
SystemInfoDeviceOrientationPtr m_orientation;
guint m_cpu_event_id;
SysteminfoUtilsCallback m_cellular_network_listener;
SysteminfoUtilsCallback m_peripheral_listener;
- TapiHandle *m_tapi_handle;
+ TapiHandle *m_tapi_handles[TAPI_HANDLE_MAX+1];
//for ip change callback
connection_h m_connection_handle;
};
m_wifi_network_listener(nullptr),
m_cellular_network_listener(nullptr),
m_peripheral_listener(nullptr),
- m_tapi_handle(nullptr),
m_connection_handle(nullptr)
{
LOGD("Entered");
UnregisterWifiNetworkListener();
UnregisterCellularNetworkListener();
UnregisterPeripheralListener();
- if (nullptr != m_tapi_handle) {
- tel_deinit(m_tapi_handle);
+
+ unsigned int i = 0;
+ while(m_tapi_handles[i]) {
+ tel_deinit(m_tapi_handles[i]);
+ i++;
}
if (nullptr != m_connection_handle) {
connection_destroy(m_connection_handle);
}
}
-TapiHandle* SystemInfoListeners::GetTapiHandle()
+void SystemInfoListeners::InitTapiHandles()
{
- if (nullptr == m_tapi_handle){
- m_tapi_handle = tel_init(0);
- if (nullptr == m_tapi_handle) {
- LOGE("Failed to connect with tapi, handle is null");
+ LOGD("Entered");
+ int sim_count = 0;
+ if (nullptr == m_tapi_handles){
+ char **cp_list = tel_get_cp_name_list();
+ *m_tapi_handles = nullptr;
+ if (nullptr != cp_list) {
+ while (cp_list[sim_count]) {
+ m_tapi_handles[sim_count] = tel_init(cp_list[sim_count]);
+ if (nullptr == m_tapi_handles[sim_count]) {
+ LOGE("Failed to connect with tapi, handle is null");
+ break;
+ }
+ sim_count++;
+ LOGD("%d modem: %s", sim_count, cp_list[sim_count]);
+ }
+ } else {
+ LOGE("Failed to get cp list");
+ sim_count = TAPI_HANDLE_MAX;
}
+ g_strfreev(cp_list);
}
- return m_tapi_handle;
}
+TapiHandle* SystemInfoListeners::GetTapiHandle()
+{
+
+ LOGD("Entered");
+ InitTapiHandles();
+ return m_tapi_handles[0];
+}
+
+TapiHandle** SystemInfoListeners::GetTapiHandles()
+{
+ InitTapiHandles();
+ return m_tapi_handles;
+}
connection_h SystemInfoListeners::GetConnectionHandle()
{
return value;
}
+long long SysteminfoUtils::GetTotalMemory()
+{
+ LOGD("Entered");
+
+ unsigned int value = 0;
+
+ int ret = device_memory_get_total(&value);
+ if (ret != DEVICE_ERROR_NONE) {
+ std::string log_msg = "Failed to get total memory: " + std::to_string(ret);
+ LOGE("%s", log_msg.c_str());
+ throw UnknownException(log_msg.c_str());
+ }
+
+ return static_cast<long long>(value*MEMORY_TO_BYTE);
+}
+
+long long SysteminfoUtils::GetAvailableMemory()
+{
+ LOGD("Entered");
+
+ unsigned int value = 0;
+
+ int ret = device_memory_get_available(&value);
+ if (ret != DEVICE_ERROR_NONE) {
+ std::string log_msg = "Failed to get total memory: " + std::to_string(ret);
+ LOGE("%s", log_msg.c_str());
+ throw UnknownException(log_msg.c_str());
+ }
+
+ return static_cast<long long>(value*MEMORY_TO_BYTE);
+}
+
+unsigned long SysteminfoUtils::GetCount(const std::string& property)
+{
+ LOGD("Enter");
+
+ unsigned long count = 0;
+
+ if ("BATTERY" == property || "CPU" == property || "STORAGE" == property ||
+ "DISPLAY" == property || "DEVICE_ORIENTATION" == property ||
+ "BUILD" == property || "LOCALE" == property || "NETWORK" == property ||
+ "WIFI_NETWORK" == property || "CELLULAR_NETWORK" == property ||
+ "PERIPHERAL" == property) {
+ count = DEFAULT_PROPERTY_COUNT;
+ } else if ("SIM" == property) {
+ count = sim_mgr.GetSimCount(system_info_listeners.GetTapiHandles());
+ } else {
+ LOGD("Property with given id is not supported");
+ throw NotSupportedException("Property with given id is not supported");
+ }
+ return count;
+}
+
picojson::value SysteminfoUtils::GetPropertyValue(const std::string& property)
{
LOGD("Entered getPropertyValue");
}
//TODO maybe make two functions later onGSourceFunc
void SysteminfoUtils::ReportCpu(picojson::object& out) {
- LOGD("enter");
+ LOGD("Entered");
static CpuInfo cpu_info;
FILE *fp = nullptr;
fp = fopen("/proc/stat", "r");
//all flags are hardcoded for Kiran on top of this file
std::string SystemInfoDeviceCapability::GenerateDuid()
{
- LOGD("Enter");
+ LOGD("Entered");
bool supported = false;
std::string duid = "";
std::string SystemInfoDeviceCapability::GenerateId(char* pDeviceString)
{
- LOGD("Enter");
+ LOGD("Entered");
unsigned long long value = 0;
byte result[8] {0,};
void SystemInfoDeviceCapability::GenerateCrc64(char* device_string, unsigned long long int* value)
{
- LOGD("Enter");
+ LOGD("Entered");
byte first_crypt[SEED_LENGTH + 1] = {0,};
std::string SystemInfoDeviceCapability::Base32Encode(byte* value)
{
- LOGD("Enter");
+ LOGD("Entered");
byte* encoding_pointer = nullptr;
byte* src_pointer = nullptr;
class SysteminfoUtils {
public:
+ static long long GetTotalMemory();
+ static long long GetAvailableMemory();
+ static unsigned long GetCount(const std::string& property);
static picojson::value GetPropertyValue(const std::string& prop);
static void RegisterBatteryListener(const SysteminfoUtilsCallback& callback);
SystemInfo.prototype.getCapability = function() {
var args = AV.validateMethod(arguments, [
- {
- name : 'key',
- type : AV.Types.STRING
- }
- ]);
+ {
+ name : 'key',
+ type : AV.Types.STRING
+ }
+ ]);
var result = _callSync('SystemInfo_getCapability', {key: args.key});
if (C.isFailure(result)) {
SystemInfo.prototype.getPropertyValue = function() {
var args = AV.validateMethod(arguments, [
- {
- name : 'property',
- type : AV.Types.ENUM,
- values : T.getValues(SystemInfoPropertyId)
- },
- {
- name : 'successCallback',
- type : AV.Types.FUNCTION
- },
- {
- name : 'errorCallback',
- type : AV.Types.FUNCTION,
- optional : true,
- nullable : true
- }
- ]);
+ {
+ name : 'property',
+ type : AV.Types.ENUM,
+ values : T.getValues(SystemInfoPropertyId)
+ },
+ {
+ name : 'successCallback',
+ type : AV.Types.FUNCTION
+ },
+ {
+ name : 'errorCallback',
+ type : AV.Types.FUNCTION,
+ optional : true,
+ nullable : true
+ }
+ ]);
var propObject = _propertyContainer[args.property];
if (!propObject) {
SystemInfo.prototype.addPropertyValueChangeListener = function() {
var args = AV.validateMethod(arguments, [
- {
- name : 'property',
- type : AV.Types.ENUM,
- values : T.getValues(SystemInfoPropertyId)
- },
- {
- name : 'successCallback',
- type : AV.Types.FUNCTION
- },
- {
- name : 'options',
- type : AV.Types.DICTIONARY,
- optional : true,
- nullable : true
- },
- {
- name : 'errorCallback',
- type : AV.Types.FUNCTION,
- optional : true,
- nullable : true
- }
- ]);
+ {
+ name : 'property',
+ type : AV.Types.ENUM,
+ values : T.getValues(SystemInfoPropertyId)
+ },
+ {
+ name : 'successCallback',
+ type : AV.Types.FUNCTION
+ },
+ {
+ name : 'options',
+ type : AV.Types.DICTIONARY,
+ optional : true,
+ nullable : true
+ },
+ {
+ name : 'errorCallback',
+ type : AV.Types.FUNCTION,
+ optional : true,
+ nullable : true
+ }
+ ]);
var listener = {
callback : args.successCallback,
SystemInfo.prototype.removePropertyValueChangeListener = function() {
var args = AV.validateMethod(arguments, [
- {
- name : 'watchId',
- type : AV.Types.UNSIGNED_LONG
- }
- ]);
+ {
+ name : 'watchId',
+ type : AV.Types.UNSIGNED_LONG
+ }
+ ]);
_unregisterListener(args.watchId, false);
};
+SystemInfo.prototype.getTotalMemory = function() {
+ var result = _callSync('SystemInfo_getTotalMemory', {});
+ if (C.isFailure(result)) {
+ throw C.getErrorObject(result);
+ }
+ return C.getResultObject(result).totalMemory;
+};
+
+SystemInfo.prototype.getAvailableMemory = function() {
+ var result = _callSync('SystemInfo_getAvailableMemory', {});
+ if (C.isFailure(result)) {
+ throw C.getErrorObject(result);
+ }
+ return C.getResultObject(result).availableMemory;
+};
+
+SystemInfo.prototype.getCount = function() {
+ var args = AV.validateMethod(arguments, [
+ {
+ name : 'key',
+ type : AV.Types.STRING
+ }
+ ]);
+
+ var result = _callSync('SystemInfo_getCount', {key: args.key});
+ if (C.isFailure(result)) {
+ throw C.getErrorObject(result);
+ }
+ var res = C.getResultObject(result);
+ return Number(res.count);
+};
+
//Exports
-var systeminfoObject = new SystemInfo();
-//exports.getTotalMemory = systeminfoObject.getTotalMemory;
-//exports.getAvailableMemory = systeminfoObject.getAvailableMemory;
-exports.getCapabilities = systeminfoObject.getCapabilities;
-exports.getCapability = systeminfoObject.getCapability;
-//exports.getCount = systeminfoObject.getCount;
-exports.getPropertyValue = systeminfoObject.getPropertyValue;
-//exports.getPropertyValueArray = systeminfoObject.getPropertyValueArray;
-exports.addPropertyValueChangeListener = systeminfoObject.addPropertyValueChangeListener;
-//exports.addPropertyValueArrayChangeListener = systeminfoObject.addPropertyValueArrayChangeListener;
-exports.removePropertyValueChangeListener = systeminfoObject.removePropertyValueChangeListener;
+exports = new SystemInfo();
REGISTER_SYNC("SystemInfo_getCapability", GetCapability);
REGISTER_SYNC("SystemInfo_addPropertyValueChangeListener", AddPropertyValueChangeListener);
REGISTER_SYNC("SystemInfo_removePropertyValueChangeListener", RemovePropertyValueChangeListener);
+ REGISTER_SYNC("SystemInfo_getTotalMemory", GetTotalMemory);
+ REGISTER_SYNC("SystemInfo_getAvailableMemory", GetAvailableMemory);
+ REGISTER_SYNC("SystemInfo_getCount", GetCount);
#undef REGISTER_SYNC
#define REGISTER_ASYNC(c,x) \
RegisterHandler(c, std::bind(&SysteminfoInstance::x, this, _1, _2));
}
+void SysteminfoInstance::GetTotalMemory(const picojson::value& args, picojson::object& out) {
+ LoggerD("");
+ picojson::value result = picojson::value(picojson::object());
+ picojson::object& result_obj = result.get<picojson::object>();
+
+ result_obj.insert(std::make_pair("totalMemory",
+ static_cast<double>(SysteminfoUtils::GetTotalMemory()) ));
+
+ ReportSuccess(result, out);
+ LoggerD("Success");
+}
+
+void SysteminfoInstance::GetAvailableMemory(const picojson::value& args, picojson::object& out) {
+ LoggerD("");
+ picojson::value result = picojson::value(picojson::object());
+ picojson::object& result_obj = result.get<picojson::object>();
+
+ result_obj.insert(std::make_pair("availableMemory",
+ static_cast<double>(SysteminfoUtils::GetAvailableMemory()) ));
+
+ ReportSuccess(result, out);
+ LoggerD("Success");
+}
+
+void SysteminfoInstance::GetCount(const picojson::value& args, picojson::object& out) {
+
+ const std::string& key = args.get("key").get<std::string>();
+ LoggerD("Getting capability with key: %s ", key.c_str());
+
+ picojson::value result = picojson::value(picojson::object());
+ picojson::object& result_obj = result.get<picojson::object>();
+ result_obj.insert(std::make_pair("count",
+ static_cast<double>(SysteminfoUtils::GetCount(key)) ));
+
+ ReportSuccess(result, out);
+ LoggerD("Success");
+}
+
void SysteminfoInstance::RemovePropertyValueChangeListener(const picojson::value& args, picojson::object& out) {
LoggerD("");
private:
SysteminfoInstance();
virtual ~SysteminfoInstance();
+
void GetCapabilities(const picojson::value& args, picojson::object& out);
void GetCapability(const picojson::value& args, picojson::object& out);
void GetPropertyValue(const picojson::value& args, picojson::object& out);
void AddPropertyValueChangeListener(const picojson::value& args, picojson::object& out);
void RemovePropertyValueChangeListener(const picojson::value& args, picojson::object& out);
+ void GetTotalMemory(const picojson::value& args, picojson::object& out);
+ void GetAvailableMemory(const picojson::value& args, picojson::object& out);
+ void GetCount(const picojson::value& args, picojson::object& out);
};
} // namespace systeminfo