notification : add set_contents_for_noti in add_notification and launch_battery_disch... 03/110203/5 accepted/tizen/mobile/20170113.225620 accepted/tizen/tv/20170113.225636 accepted/tizen/wearable/20170113.225653 submit/tizen/20170113.124338
authorlokilee73 <changjoo.lee@samsung.com>
Fri, 13 Jan 2017 07:50:02 +0000 (16:50 +0900)
committerlokilee73 <changjoo.lee@samsung.com>
Fri, 13 Jan 2017 12:18:10 +0000 (21:18 +0900)
set_contents_for_noti is made to handle text in notification with variables.
launch_battery_discharge_active_notification is made for low battery noti without USB or Charger.

Change-Id: I16ce74f6e8c1dfb8d6d041afea13f49671e57908
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
src/launcher/launcher.c
src/launcher/noti.c

index 6276388..5c492fb 100755 (executable)
@@ -134,13 +134,13 @@ static DBusMessage *battery_critical_noti_on(E_DBus_Object *obj, DBusMessage *ms
 static DBusMessage *battery_low_actnoti_on(E_DBus_Object *obj, DBusMessage *msg)
 {
        set_timer_to_terminate();
-       return activate_notification_no_param(obj, msg, BATTERY_LOW_ACT);
+       return activate_notification_single_param(obj, msg, BATTERY_LOW_ACT);
 }
 
 static DBusMessage *battery_critical_actnoti_on(E_DBus_Object *obj, DBusMessage *msg)
 {
        set_timer_to_terminate();
-       return activate_notification_no_param(obj, msg, BATTERY_CRITICAL_ACT);
+       return activate_notification_single_param(obj, msg, BATTERY_CRITICAL_ACT);
 }
 
 static DBusMessage *battery_low_actnoti_usb_on(E_DBus_Object *obj, DBusMessage *msg)
@@ -250,8 +250,8 @@ dbus_noti_methods[] = {
        { "UsbDeviceNotiUpdate"         , "isss"        , "i"   , usb_device_noti_update        },
        { "UsbDeviceNotiOff"            , "i"           , "i"   , noti_off                      },
        /* usb connection */
-       { "MediaDeviceNotiOn"           , NULL          , "i"   , media_device_noti_on          },
-       { "MediaDeviceNotiOff"          , "i"           , "i"   , noti_off                      },
+       { "MediaDeviceNotiOn"           , NULL          , "i"   , media_device_noti_on  },
+       { "MediaDeviceNotiOff"          , "i"           , "i"   , noti_off      },
        /* Battery Event noti*/
        { "BatteryFullNotiOn"           , NULL          , "i"   , battery_full_noti_on          },
        { "BatteryFullNotiOff"          , "i"           , "i"   , noti_off                      },
@@ -260,12 +260,12 @@ dbus_noti_methods[] = {
        { "BatteryCriticalNotiOn"       , NULL          , "i"   , battery_critical_noti_on      },
        { "BatteryLowCriticalNotiOff"   , "i"           , "i"   , noti_off      },
        /* Battery Active noti*/
-       { "BatteryLowActNotiOn"         , NULL          , "i"   , battery_low_actnoti_on        },
-       { "BatteryCriticalActNotiOn"    , NULL          , "i"   , battery_critical_actnoti_on   },
-       { "BatteryLowActNotiUsbOn"      , NULL          , "i"   , battery_low_actnoti_usb_on    },
-       { "BatteryCriticalActNotiUsbOn" , NULL          , "i"   , battery_critical_actnoti_usb_on       },
-       { "BatteryLowActNotiChgOn"      , NULL          , "i"   , battery_low_actnoti_chg_on    },
-       { "BatteryCriticalActNotiChgOn" , NULL          , "i"   , battery_critical_actnoti_chg_on       },
+       { "BatteryLowActNotiOn"         , "s"           , "i"   , battery_low_actnoti_on        },
+       { "BatteryCriticalActNotiOn",   "s"             , "i"   , battery_critical_actnoti_on   },
+       { "BatteryLowActNotiUsbOn"      , NULL          , "i"   , battery_low_actnoti_usb_on    },
+       { "BatteryCriticalActNotiUsbOn" , NULL  , "i"   , battery_critical_actnoti_usb_on       },
+       { "BatteryLowActNotiChgOn"      , NULL          , "i"   , battery_low_actnoti_chg_on    },
+       { "BatteryCriticalActNotiChgOn" , NULL  , "i"   , battery_critical_actnoti_chg_on       },
        /* Temperature */
        { "TempCooldownNotiOn"          , NULL          , "i"   , cooldown_noti_on              },
        { "TempCooldownNotiOff"         , "i"           , "i"   , noti_off                      },
index dd07a15..8df372b 100755 (executable)
@@ -70,14 +70,37 @@ static void set_language(void)
        free(lang);
 }
 
+notification_error_e set_contents_for_lowbat_noti(char *title, notification_h noti, char *content, char *sig, va_list args)
+{
+       int var = 0;
+       notification_error_e noti_err = NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       if (strncmp(sig, "i", 1))
+               return noti_err;
+
+       var = va_arg(args, int);
+       noti_err = notification_set_text(noti,
+                       NOTIFICATION_TEXT_TYPE_CONTENT,
+                       _(content),
+                       content,
+                       NOTIFICATION_VARIABLE_TYPE_INT,
+                       var,
+                       NOTIFICATION_VARIABLE_TYPE_NONE);
+
+       return noti_err;
+}
+
 static int add_notification(
                int type, int layout,
                char *title, char *content,
                char *icon, char *icon_indi,
                bundle *b, int prop,
-               int applist)
+               int applist,
+               notification_error_e (func)(char *, notification_h, char *, char *, va_list),
+               char *sig, ...)
 {
        int priv_id;
+       va_list args;
        notification_h noti = NULL;
        notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
 
@@ -126,11 +149,18 @@ static int add_notification(
        }
 
        if (content) {
+               if (!func) {
                noti_err = notification_set_text(noti,
                                NOTIFICATION_TEXT_TYPE_CONTENT,
                                _(content),
                                content,
                                NOTIFICATION_VARIABLE_TYPE_NONE);
+               } else {
+                       va_start(args, sig);
+                       noti_err = func(title, noti, content, sig, args);
+                       va_end(args);
+               }
+
                if (noti_err != NOTIFICATION_ERROR_NONE) {
                        _E("FAIL: notification_set_text()");
                        priv_id = -ENOMEM;
@@ -223,7 +253,9 @@ static int launch_datausage_warning_notification(void)
                                NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY
                                | NOTIFICATION_DISPLAY_APP_TICKER
                                | NOTIFICATION_DISPLAY_APP_LOCK
-                               | NOTIFICATION_DISPLAY_APP_INDICATOR);
+                               | NOTIFICATION_DISPLAY_APP_INDICATOR,
+                               NULL,
+                               NULL);
 
        if (b)
                bundle_free(b);
@@ -250,7 +282,9 @@ static int launch_datausage_disabled_notification(void)
                                NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY
                                | NOTIFICATION_DISPLAY_APP_TICKER
                                | NOTIFICATION_DISPLAY_APP_LOCK
-                               | NOTIFICATION_DISPLAY_APP_INDICATOR);
+                               | NOTIFICATION_DISPLAY_APP_INDICATOR,
+                               NULL,
+                               NULL);
 
        if (b)
                bundle_free(b);
@@ -274,7 +308,9 @@ static int launch_led_torch_notification(void)
                                NULL,
                                b,
                                NOTIFICATION_PROP_VOLATILE_DISPLAY,
-                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
+                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY,
+                               NULL,
+                               NULL);
 
        if (b)
                bundle_free(b);
@@ -344,7 +380,9 @@ static int launch_ode_progress_notification(void *data)
                                b,
                                NOTIFICATION_PROP_VOLATILE_DISPLAY,
                                NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY
-                               | NOTIFICATION_DISPLAY_APP_INDICATOR);
+                               | NOTIFICATION_DISPLAY_APP_INDICATOR,
+                               NULL,
+                               NULL);
 
        if (b)
                bundle_free(b);
@@ -391,7 +429,9 @@ static int launch_ode_error_notification(void *data1, void *data2, void *data3)
                                b,
                                NOTIFICATION_PROP_VOLATILE_DISPLAY,
                                NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY
-                               | NOTIFICATION_DISPLAY_APP_INDICATOR);
+                               | NOTIFICATION_DISPLAY_APP_INDICATOR,
+                               NULL,
+                               NULL);
 
        if (b)
                bundle_free(b);
@@ -419,7 +459,9 @@ static int launch_tima_lkm_prevention_notification(void)
                                NULL,
                                b,
                                NOTIFICATION_PROP_VOLATILE_DISPLAY,
-                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
+                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY,
+                               NULL,
+                               NULL);
 
        if (b)
                bundle_free(b);
@@ -447,7 +489,9 @@ static int launch_tima_pkm_detection_notification(void)
                                NULL,
                                b,
                                NOTIFICATION_PROP_VOLATILE_DISPLAY,
-                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
+                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY,
+                               NULL,
+                               NULL);
 
        if (b)
                bundle_free(b);
@@ -498,7 +542,9 @@ static int launch_usb_storage_notification(void *data, int type)
                                NULL,
                                b,
                                NOTIFICATION_PROP_VOLATILE_DISPLAY,
-                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
+                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY,
+                               NULL,
+                               NULL);
 
        if (b)
                bundle_free(b);
@@ -524,7 +570,9 @@ static int launch_temp_cooldown_notification(int type)
                                NULL,
                                b,
                                NOTIFICATION_PROP_VOLATILE_DISPLAY,
-                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
+                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY,
+                               NULL,
+                               NULL);
 
        if (b)
                bundle_free(b);
@@ -569,13 +617,50 @@ static int launch_usb_device_notification(char *dev, char *name)
                                NULL,
                                b,
                                NOTIFICATION_PROP_VOLATILE_DISPLAY,
-                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
+                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY,
+                               NULL,
+                               NULL);
 
        if (b)
                bundle_free(b);
        return ret;
 }
 
+static int launch_battery_discharge_active_notification(void *data, int type)
+{
+       int ret;
+       bundle *b;
+       char *title = NULL;
+       int capacity = atoi(data);
+
+       b = bundle_create();
+       if (b)
+               appsvc_set_pkgname(b, SYSTEM_SIGNAL_SENDER);
+
+       if (type == BATTERY_LOW_ACT)
+               title = "IDS_QP_HEADER_BATTERY_LOW_ABB";
+       else if (type == BATTERY_CRITICAL_ACT)
+               title = "IDS_QP_HEADER_BATTERY_CRITICALLY_LOW_ABB";
+
+       ret =  add_notification(NOTIFICATION_TYPE_NOTI,
+                       NOTIFICATION_LY_ONGOING_EVENT,
+                       title,
+                       "IDS_QP_POP_YOUR_DEVICE_HAS_PDP_BATTERY_POWER_REMAINING_CONNECT_A_CHARGER_ABB",
+                       BATT_LOW_INDI_ICON,
+                       NULL,
+                       b,
+                       NOTIFICATION_PROP_VOLATILE_DISPLAY,
+                       NOTIFICATION_DISPLAY_APP_ACTIVE,
+                       set_contents_for_lowbat_noti,
+                       "i",
+                       capacity);
+
+       if (b)
+               bundle_free(b);
+
+       return ret;
+}
+
 static int launch_ticker_notification(void *data)
 {
        char *content, *input;
@@ -620,8 +705,10 @@ static int launch_battery_notification(int type)
                                NULL,
                                NULL,
                                NOTIFICATION_PROP_DISABLE_APP_LAUNCH,
-                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
-       } else  if (type == BATTERY_LOW) {
+                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY,
+                               NULL,
+                               NULL);
+       } else if (type == BATTERY_LOW) {
                ret =  add_notification(NOTIFICATION_TYPE_ONGOING,
                                NOTIFICATION_LY_ONGOING_EVENT,
                                "IDS_QP_HEADER_BATTERY_LOW_ABB",
@@ -630,7 +717,9 @@ static int launch_battery_notification(int type)
                                NULL,
                                NULL,
                                NOTIFICATION_PROP_DISABLE_APP_LAUNCH,
-                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
+                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY,
+                               NULL,
+                               NULL);
        } else if (type == BATTERY_CRITICAL) {
                ret =  add_notification(NOTIFICATION_TYPE_ONGOING,
                                NOTIFICATION_LY_ONGOING_EVENT,
@@ -640,7 +729,9 @@ static int launch_battery_notification(int type)
                                NULL,
                                NULL,
                                NOTIFICATION_PROP_DISABLE_APP_LAUNCH,
-                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
+                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY,
+                               NULL,
+                               NULL);
        } else
                _E("Unknown type(%d)", type);
 
@@ -651,28 +742,7 @@ static int launch_battery_active_notification(int type)
 {
        int ret = -EINVAL;
 
-       if (type == BATTERY_LOW_ACT) {
-               ret =  add_notification(NOTIFICATION_TYPE_NOTI,
-                               NOTIFICATION_LY_ONGOING_EVENT,
-                               "IDS_QP_HEADER_BATTERY_LOW_ABB",
-                               "IDS_QP_SBODY_CONNECT_A_CHARGER_ABB",
-                               BATT_LOW_INDI_ICON,
-                               NULL,
-                               NULL,
-                               NOTIFICATION_PROP_VOLATILE_DISPLAY,
-                               NOTIFICATION_DISPLAY_APP_ACTIVE);
-       } else if (type == BATTERY_CRITICAL_ACT) {
-               ret =  add_notification(NOTIFICATION_TYPE_NOTI,
-                               NOTIFICATION_LY_ONGOING_EVENT,
-                               "IDS_QP_HEADER_BATTERY_CRITICALLY_LOW_ABB",
-                               "IDS_QP_SBODY_CONNECT_A_CHARGER_ABB",
-                               BATT_LOW_INDI_ICON,
-                               NULL,
-                               NULL,
-                               NOTIFICATION_PROP_VOLATILE_DISPLAY,
-                               NOTIFICATION_DISPLAY_APP_ACTIVE);
-       }
-       else if (type == BATTERY_LOW_USB_ACT) {
+       if (type == BATTERY_LOW_USB_ACT) {
                ret =  add_notification(NOTIFICATION_TYPE_NOTI,
                                NOTIFICATION_LY_ONGOING_EVENT,
                                "IDS_QP_HEADER_BATTERY_LOW_ABB",
@@ -681,7 +751,9 @@ static int launch_battery_active_notification(int type)
                                NULL,
                                NULL,
                                NOTIFICATION_PROP_VOLATILE_DISPLAY,
-                               NOTIFICATION_DISPLAY_APP_ACTIVE);
+                               NOTIFICATION_DISPLAY_APP_ACTIVE,
+                               NULL,
+                               NULL);
        } else if (type == BATTERY_CRITICAL_USB_ACT) {
                ret =  add_notification(NOTIFICATION_TYPE_NOTI,
                                NOTIFICATION_LY_ONGOING_EVENT,
@@ -691,7 +763,9 @@ static int launch_battery_active_notification(int type)
                                NULL,
                                NULL,
                                NOTIFICATION_PROP_VOLATILE_DISPLAY,
-                               NOTIFICATION_DISPLAY_APP_ACTIVE);
+                               NOTIFICATION_DISPLAY_APP_ACTIVE,
+                               NULL,
+                               NULL);
        } else if (type == BATTERY_LOW_CHG_ACT) {
                ret =  add_notification(NOTIFICATION_TYPE_NOTI,
                                NOTIFICATION_LY_ONGOING_EVENT,
@@ -701,7 +775,9 @@ static int launch_battery_active_notification(int type)
                                NULL,
                                NULL,
                                NOTIFICATION_PROP_VOLATILE_DISPLAY,
-                               NOTIFICATION_DISPLAY_APP_ACTIVE);
+                               NOTIFICATION_DISPLAY_APP_ACTIVE,
+                               NULL,
+                               NULL);
        } else if (type == BATTERY_CRITICAL_CHG_ACT) {
                ret =  add_notification(NOTIFICATION_TYPE_NOTI,
                                NOTIFICATION_LY_ONGOING_EVENT,
@@ -711,7 +787,9 @@ static int launch_battery_active_notification(int type)
                                NULL,
                                NULL,
                                NOTIFICATION_PROP_VOLATILE_DISPLAY,
-                               NOTIFICATION_DISPLAY_APP_ACTIVE);
+                               NOTIFICATION_DISPLAY_APP_ACTIVE,
+                               NULL,
+                               NULL);
        } else
                _E("Unknown type(%d)", type);
 
@@ -731,7 +809,9 @@ static int launch_media_device_notification(void)
                                NULL,
                                NOTIFICATION_PROP_DISABLE_APP_LAUNCH |
                                NOTIFICATION_PROP_DISABLE_AUTO_DELETE,
-                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
+                               NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY,
+                               NULL,
+                               NULL);
 
        return ret;
 }
@@ -753,8 +833,6 @@ static int launch_notification_no_param_by_type(int type)
        case BATTERY_LOW:
        case BATTERY_CRITICAL:
                return launch_battery_notification(type);
-       case BATTERY_LOW_ACT:
-       case BATTERY_CRITICAL_ACT:
        case BATTERY_LOW_USB_ACT:
        case BATTERY_CRITICAL_USB_ACT:
        case BATTERY_LOW_CHG_ACT:
@@ -782,6 +860,9 @@ static int launch_notification_single_param_by_type(int type, void *data)
        case USB_STORAGE:
        case USB_STORAGE_RO:
                return launch_usb_storage_notification(data, type);
+       case BATTERY_LOW_ACT:
+       case BATTERY_CRITICAL_ACT:
+               return launch_battery_discharge_active_notification(data, type);
        default:
                _E("Noti type is unknown");
                return -EINVAL;
@@ -884,7 +965,7 @@ DBusMessage *activate_notification_double_param(E_DBus_Object *obj, DBusMessage
 
        priv_id = launch_notification_double_param_by_type(type, str1, str2);
        if (priv_id < 0)
-               _E("FAIL: launch_noti_single_param_by_type()");
+               _E("FAIL: launch_notification_double_param_by_type()");
 
 out:
        reply = dbus_message_new_method_return(msg);