2 * Network Configuration Module
4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <vconf-keys.h>
26 #include "wifi-power.h"
27 #include "network-dpm.h"
28 #include "network-state.h"
30 #define NETCONFIG_SIGNAL_DPM_WIFI "DPMWifi"
31 #define NETCONFIG_SIGNAL_DPM_WIFI_PROFILE "DPMWifiProfile"
33 static int dpm_policy_wifi = 1;
34 static int dpm_policy_wifi_profile = 1;
36 static void __netconfig_dpm_notify_result(const char *sig_name, const char *key)
40 GVariantBuilder *builder = NULL;
41 GDBusConnection *connection = NULL;
43 const char *prop_key = "key";
45 INFO("[Signal] %s %s", sig_name, key);
47 connection = netdbus_get_connection();
48 if (connection == NULL) {
49 ERR("Failed to get GDBus Connection");
53 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
54 g_variant_builder_add(builder, "{sv}", prop_key, g_variant_new_string(key));
55 params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
57 g_variant_builder_unref(builder);
59 reply = g_dbus_connection_emit_signal(connection,
61 NETCONFIG_NETWORK_PATH,
62 NETCONFIG_NETWORK_INTERFACE,
69 ERR("Failed to send signal [%s]", error->message);
75 INFO("Sent signal (%s), key (%s)", sig_name, key);
79 void netconfig_dpm_init(void)
81 INFO("DPM initialized");
85 void netconfig_dpm_deinit(void)
87 INFO("DPM deinitialized");
91 int netconfig_dpm_update_from_wifi(void)
93 INFO("DPM update from wifi [%d]", dpm_policy_wifi);
95 if (!dpm_policy_wifi) {
97 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
98 if (wifi_state != VCONFKEY_WIFI_OFF) {
99 int err = wifi_power_off();
101 if (err == -EINPROGRESS)
102 ERR("wifi power off : InProgress");
103 else if (err == -EALREADY)
104 ERR("wifi power off : AlreadyExists");
105 else if (err == -EPERM)
106 ERR("wifi power off : PermissionDenied");
108 ERR("wifi power off : WifiDriverFailed");
110 DBG("wifi power off : ErrorNone");
112 netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_OFF_BY_AIRPLANE, 0);
113 netconfig_send_restriction_to_net_popup("Wi-Fi unavailable",
114 "toast_popup", "wifi");
118 return dpm_policy_wifi;
121 int netconfig_dpm_update_from_wifi_profile(void)
123 INFO("DPM update from wifi profile [%d]", dpm_policy_wifi_profile);
124 return dpm_policy_wifi_profile;
127 gboolean handle_device_policy_set_wifi(
129 GDBusMethodInvocation *context,
132 INFO("DPM device policy wifi changed : [%d -> %d]",
133 dpm_policy_wifi, state);
135 dpm_policy_wifi = state;
136 netconfig_dpm_update_from_wifi();
137 __netconfig_dpm_notify_result(NETCONFIG_SIGNAL_DPM_WIFI,
138 state ? "allowed" : "disallowed");
140 network_complete_device_policy_set_wifi(object, context);
144 gboolean handle_device_policy_get_wifi(
146 GDBusMethodInvocation *context)
148 INFO("Successfully get wifi device policy [%d]",
151 network_complete_device_policy_get_wifi(object,
152 context, dpm_policy_wifi);
156 gboolean handle_device_policy_set_wifi_profile(
158 GDBusMethodInvocation *context,
161 INFO("DPM device policy wifi profile changed : [%d -> %d]",
162 dpm_policy_wifi_profile, state);
164 dpm_policy_wifi_profile = state;
165 netconfig_dpm_update_from_wifi_profile();
166 __netconfig_dpm_notify_result(NETCONFIG_SIGNAL_DPM_WIFI_PROFILE,
167 state ? "allowed" : "disallowed");
169 network_complete_device_policy_set_wifi_profile(object, context);
173 gboolean handle_device_policy_get_wifi_profile(
175 GDBusMethodInvocation *context)
177 INFO("Successfully get wifi profile device policy [%d]",
178 dpm_policy_wifi_profile);
180 network_complete_device_policy_get_wifi(object,
181 context, dpm_policy_wifi_profile);