Connectivity settings API

Connectivity settings API provides settings from various backends (currently gconf is supported). More...

Connectivity settings API provides settings from various backends (currently gconf is supported).

Depending on ConnSettingsType following items will be returned or set in gconf by various API functions

CONN_SETTINGS_GENERALGeneric connectivity settings from /system/osso/connectivity
CONN_SETTINGS_NETWORK_TYPENetwork type settings from /system/osso/connectivity/network_type, the id is the network type like WLAN or GPRS
CONN_SETTINGS_CONNECTIONConnection settings from /system/osso/connectivity/IAP, the id is the IAP id
CONN_SETTINGS_SERVICE_TYPEService type settings from /system/osso/connectivity/srv_provider, the id is the provider identifier

Example of usage:

Return IAP ids

	char **ids;
	int i;
	ids = conn_settings_list_ids(CONN_SETTINGS_CONNECTION);
	if (ids) {
	        for (i=0; ids[i]!=NULL; i++) {
		        printf("IAP: %s\n", ids[i]);
			free(ids[i]);
		}
		free(ids);
        }


Check if given IAP exists

        if (conn_settings_id_exists(CONN_SETTINGS_CONNECTION, "known-IAP"))
	        printf("IAP exists\n");
	else
	        printf("IAP is not found\n");


Return keys for a IAP id 89ebd4e9-2e86-4fda-bd15-1cdcd98e581e

	ConnSettings *ctx;
	char **keys;
	int i;
	ctx = conn_settings_open(CONN_SETTINGS_CONNECTION, "89ebd4e9-2e86-4fda-bd15-1cdcd98e581e");
	keys = conn_settings_list_keys(ctx);
	if (keys) {
	        for (i=0; keys[i]!=NULL; i++) {
		        printf("%s\n", keys[i]);
			free(keys[i]);
		}
		free(keys);
	}
	conn_settings_close(ctx);


Return GPRS RX byte count

	ConnSettings *ctx;
	ConnSettingsValue *value;
	int count = 0, ret;
	ctx = conn_settings_open(CONN_SETTINGS_NETWORK_TYPE, "GPRS");
	value = conn_settings_get(ctx, "gprs_rx_bytes");
	if (value && value->type == CONN_SETTINGS_VALUE_INT)
		printf("GPRS RX byte count = %d\n", value->value.int_val);
	conn_settings_value_destroy(value);
	// or the count can be fetched using other function
	ret = conn_settings_get_int(ctx, "gprs_rx_bytes", &count);
	if (!ret)
		printf("GPRS RX byte count = %d\n", count);
	conn_settings_close(ctx);


Return WLAN ssid

	ConnSettings *ctx;
	int ret;
	unsigned char *ssid = 0;
	unsigned int len = 0;
	ctx = conn_settings_open(CONN_SETTINGS_CONNECTION, "89ebd4e9-2e86-4fda-bd15-1cdcd98e581e");
	ret = conn_settings_get_byte_array(ctx, "wlan_ssid", &ssid, &len);
	if (ret == CONN_SETTINGS_E_NO_ERROR) {
		int i;
		if (len>0) {
			printf("wlan_ssid: ");
			for (i=0; i<len; i++)
				printf("%c", ssid[i]);
			printf("\n");
			free(ssid);
		}
	}
	conn_settings_close(ctx);


Remove IAP

	ConnSettings *ctx;
	int ret;
	ctx = conn_settings_open(CONN_SETTINGS_CONNECTION, "89ebd4e9-2e86-4fda-bd15-1cdcd98e581e");
	ret = conn_settings_remove(ctx);
	if (ret != CONN_SETTINGS_E_NO_ERROR)
		printf("Cannot remove IAP\n");
	conn_settings_close(ctx);


Set/get empty list

	ConnSettings *ctx;
	int ret;
	ConnSettingsValue **value = NULL;
	ctx = conn_settings_open(CONN_SETTINGS_CONNECTION, "89ebd4e9-2e86-4fda-bd15-1cdcd98e581e");
	ret = conn_settings_set_list(ctx, "empty_list", NULL, 0, CONN_SETTINGS_VALUE_INT);
	if (ret != CONN_SETTINGS_E_NO_ERROR)
		printf("Cannot set empty list\n");
	else {
	        ret = conn_settings_get_list(ctx, "empty_list", &value);
	        if (ret != CONN_SETTINGS_E_NO_ERROR)
		        printf("Cannot get empty list\n");
		else if (*value == NULL)
		        printf("List is empty\n");
        }
	conn_settings_close(ctx);


Set/get int list using various API functions

	ConnSettings *ctx;
	int ret, i;
	int int_list[] = { 'T','E','S','T' };
	int len = sizeof(int_list) / sizeof(int);
	ConnSettingsValue **value = NULL, *new_value;
	ctx = conn_settings_open(CONN_SETTINGS_CONNECTION, "89ebd4e9-2e86-4fda-bd15-1cdcd98e581e");
	ret = conn_settings_set_list(ctx, "int_list", int_list, len, CONN_SETTINGS_VALUE_INT);
	if (ret != CONN_SETTINGS_E_NO_ERROR)
		printf("Cannot set list\n");
	else {
	        ret = conn_settings_get_list(ctx, "int_list", &value);
	        if (ret != CONN_SETTINGS_E_NO_ERROR)
		        printf("Cannot get empty list\n");
		else if (*value == NULL)
		        printf("List is empty\n");
		else if ((*value)->type != CONN_SETTINGS_VALUE_INT)
		        printf("Invalid list type\n");
		else {
		        for (i=0; value[i]!=NULL; i++) {
				printf("[%d] = %c (%d)\n", i, value[i]->value.int_val, value[i]->value.int_val);
			}
			// change the list and put it back
			value[0]->value.int_val = 82;
			printf("\n");
			new_value = conn_settings_value_new();
			new_value->type = CONN_SETTINGS_VALUE_LIST;
			new_value->value.list_val = value;
			ret = conn_settings_set(ctx, "int_list", new_value);
			// this also clears the list values
			conn_settings_value_destroy(new_value);
			if (ret == CONN_SETTINGS_E_NO_ERROR) {
			        ret = conn_settings_get_list(ctx, "int_list", &value);
				for (i=0; value[i]!=NULL; i++) {
				        printf("[%d] = %c (%d)\n", i, value[i]->value.int_val, value[i]->value.int_val);
				}
				conn_settings_values_destroy(value);
			}
		}
        }
	conn_settings_close(ctx);