var Converter_ = xwalk.utils.converter;
var native_ = new xwalk.utils.NativeManager(extension);
+// index of default property for sim-related callbacks
+var defaultListenerIndex = 0;
+
//enumeration SystemInfoPropertyId ////////////////////////////////////////////////////
var SystemInfoPropertyId = {
BATTERY : 'BATTERY',
for (var watchId in callbacks) {
if (callbacks.hasOwnProperty(watchId)) {
var listener = callbacks[watchId];
+ if (!listener.isArrayType && eventObj.changedPropertyIndex != defaultListenerIndex) {
+ // if this is not arrayListener, ignore events of non-default SIM
+ return;
+ }
+
var propObj = !listener.isArrayType ?
_createProperty(property, eventObj.result.array[0]) :
_createPropertyArray(property, eventObj.result);
const int kDefaultPropertyCount = 1;
const int BASE_GATHERING_INTERVAL = 100;
const double kPropertyWatcherTime = 1;
+// index of default property for sim-related callbacks
+const int kDefaultListenerIndex = 0;
const std::string kPropertyIdString = "propertyId";
const std::string kListenerIdString = "listenerId";
+const std::string kChangedPropertyIndexString = "changedPropertyIndex";
const std::string kListenerConstValue = "SysteminfoCommonListenerLabel";
const std::string kPropertyIdBattery = "BATTERY";
static void OnCellularNetworkValueChangedCb(keynode_t *node, void *event_ptr) {
LoggerD("Enter");
SysteminfoManager* manager = static_cast<SysteminfoManager*>(event_ptr);
- manager->CallListenerCallback(kPropertyIdCellularNetwork);
+ manager->CallListenerCallback(kPropertyIdCellularNetwork, kDefaultListenerIndex);
}
static void OnTapiValueChangedCb(TapiHandle *handle, const char *noti_id,
LoggerD("Enter");
LoggerD("Changed key: %s", noti_id);
SysteminfoManager* manager = static_cast<SysteminfoManager*>(user_data);
- manager->CallListenerCallback(kPropertyIdCellularNetwork);
+ int index = manager->GetChangedTapiIndex(handle);
+ LoggerD("Changed SIM index is: %d", index);
+ manager->CallListenerCallback(kPropertyIdCellularNetwork, index);
}
static void OnPeripheralChangedCb(keynode_t* node, void* event_ptr) {
return tapi_handles_;
}
+int SysteminfoManager::GetChangedTapiIndex(TapiHandle* tapi) {
+ LoggerD("Enter");
+ TapiHandle** handles = GetTapiHandles();
+ for (int i = 0; i < sim_count_; ++i) {
+ if (handles[i] == tapi) {
+ return i;
+ }
+ }
+ return -1;
+}
+
void SysteminfoManager::InitCameraTypes() {
LoggerD("Enter");
bool supported = false;
}
void SysteminfoManager::PostListenerResponse(const std::string& property_id,
- const picojson::value& result) {
+ const picojson::value& result,
+ int property_index) {
LoggerD("Entered");
const std::shared_ptr<picojson::value>& response =
std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
response->get<picojson::object>()[kPropertyIdString] = picojson::value(property_id);
response->get<picojson::object>()[kListenerIdString] = picojson::value(kListenerConstValue);
+ // Added pushing index of property to handle only default for signle-property listeners in js
+ response->get<picojson::object>()[kChangedPropertyIndexString] =
+ picojson::value(static_cast<double>(property_index));
ReportSuccess(result,response->get<picojson::object>());
Instance::PostMessage(instance_, response->serialize().c_str());
}
-void SysteminfoManager::CallListenerCallback(const std::string& property_id) {
+void SysteminfoManager::CallListenerCallback(const std::string& property_id,
+ int property_index) {
LoggerD("Enter");
if(IsListenerRegistered(property_id)) {
LoggerD("listener for %s property is registered, calling it", property_id.c_str());
PlatformResult ret = GetPropertiesManager().GetPropertyValue(
property_id, true, &result);
if (ret.IsSuccess()) {
- PostListenerResponse(property_id, result);
+ PostListenerResponse(property_id, result, property_index);
}
} else {
LoggerD("listener for %s property is not registered, ignoring", property_id.c_str());
int GetSensorHandle();
TapiHandle* GetTapiHandle();
TapiHandle** GetTapiHandles();
+ int GetChangedTapiIndex(TapiHandle* tapi);
common::PlatformResult GetConnectionHandle(connection_h& handle);
SysteminfoInstance* GetInstance() { return instance_;};
int GetCameraTypesCount();
bool IsListenerRegistered(const std::string& property_id);
- void CallListenerCallback(const std::string& property_id);
+ void CallListenerCallback(const std::string& property_id, int property_index = 0);
void CallCpuListenerCallback();
void CallStorageListenerCallback();
private:
- void PostListenerResponse(const std::string& property_id, const picojson::value& result);
+ void PostListenerResponse(const std::string& property_id, const picojson::value& result,
+ int property_index = 0);
common::PlatformResult ConnectSensor(int* result);
void DisconnectSensor(int handle_orientation);
void InitTapiHandles();