diff --git a/docs/application/native/api/common/9.0/group__CAPI__APPLICATION__MANAGER__MODULE.html b/docs/application/native/api/common/9.0/group__CAPI__APPLICATION__MANAGER__MODULE.html index 767e9d1fd8..0e35f307ff 100644 --- a/docs/application/native/api/common/9.0/group__CAPI__APPLICATION__MANAGER__MODULE.html +++ b/docs/application/native/api/common/9.0/group__CAPI__APPLICATION__MANAGER__MODULE.html @@ -101,6 +101,220 @@

Overview

The Application Manager API provides information about applications. There are several different sorts of queries. Two iterator functions step through a list of applications. One is used in running applications(app_manager_foreach_app_context()), and the other is used in available ("installed") but not necessarily running applications(app_manager_foreach_app_info()). Each will call a callback function, passing the package name of each application found. A query function will respond whether the application represented by a particular package name is running. Other query functions return static information about an application, such as a name, a type, an icon path, or a version. The API provides functions to manage applications also. By using them, it is possible to resume(app_manager_resume_app) applications.

+

+Getting Information About Running Applications

+

You can retrieve information about currently running applications using the foreach function:

+
 #include <app_manager.h>
+ #include <dlog.h>
+
+ static bool
+ app_context_cb(app_context_h app_context, void *user_data)
+ {
+     char *app_id = NULL;
+     char *package = NULL;
+     pid_t pid;
+     
+     // Get application ID
+     app_context_get_app_id(app_context, &app_id);
+     if (app_id) {
+         dlog_print(DLOG_INFO, "APP_MANAGER", "Running App ID: %s", app_id);
+         free(app_id);
+     }
+     
+     // Get package ID
+     app_context_get_package_id(app_context, &package);
+     if (package) {
+         dlog_print(DLOG_INFO, "APP_MANAGER", "Package ID: %s", package);
+         free(package);
+     }
+     
+     // Get process ID
+     app_context_get_pid(app_context, &pid);
+     dlog_print(DLOG_INFO, "APP_MANAGER", "PID: %d", pid);
+     
+     return true; // Continue iteration
+ }
+
+ void
+ list_running_apps(void)
+ {
+     int ret = app_manager_foreach_app_context(app_context_cb, NULL);
+     if (ret != APP_MANAGER_ERROR_NONE) {
+         dlog_print(DLOG_ERROR, "APP_MANAGER", "Failed to get running apps");
+     }
+ }
+

+Getting Information About Installed Applications

+

You can retrieve information about all installed applications:

+
 static bool
+ app_info_cb(app_info_h app_info, void *user_data)
+ {
+     char *app_id = NULL;
+     char *label = NULL;
+     char *icon_path = NULL;
+     char *version = NULL;
+     bool nodisplay = false;
+     
+     // Get application ID
+     app_info_get_app_id(app_info, &app_id);
+     
+     // Get application label
+     app_info_get_label(app_info, &label);
+     
+     // Get icon path
+     app_info_get_icon(app_info, &icon_path);
+     
+     // Get version
+     app_info_get_version(app_info, &version);
+     
+     // Check if app should be displayed
+     app_info_is_nodisplay(app_info, &nodisplay);
+     
+     if (!nodisplay) {
+         dlog_print(DLOG_INFO, "APP_MANAGER", "App: %s (%s) v%s", 
+                    label ? label : "Unknown", 
+                    app_id ? app_id : "Unknown", 
+                    version ? version : "Unknown");
+     }
+     
+     if (app_id) free(app_id);
+     if (label) free(label);
+     if (icon_path) free(icon_path);
+     if (version) free(version);
+     
+     return true;
+ }
+
+ void
+ list_installed_apps(void)
+ {
+     int ret = app_manager_foreach_app_info(app_info_cb, NULL);
+     if (ret != APP_MANAGER_ERROR_NONE) {
+         dlog_print(DLOG_ERROR, "APP_MANAGER", "Failed to get installed apps");
+     }
+ }
+

+Checking Application Status

+

You can check if a specific application is running and get its information:

+
 void
+ check_app_status(const char *app_id)
+ {
+     bool running = false;
+     int ret;
+     
+     // Check if application is running
+     ret = app_manager_is_running(app_id, &running);
+     if (ret == APP_MANAGER_ERROR_NONE) {
+         if (running) {
+             dlog_print(DLOG_INFO, "APP_MANAGER", "%s is running", app_id);
+             
+             // Get application context
+             app_context_h app_context = NULL;
+             ret = app_manager_get_app_context(app_id, &app_context);
+             if (ret == APP_MANAGER_ERROR_NONE && app_context) {
+                 pid_t pid;
+                 app_context_get_pid(app_context, &pid);
+                 dlog_print(DLOG_INFO, "APP_MANAGER", "PID: %d", pid);
+                 
+                 app_context_destroy(app_context);
+             }
+         } else {
+             dlog_print(DLOG_INFO, "APP_MANAGER", "%s is not running", app_id);
+         }
+     }
+     
+     // Get application information
+     app_info_h app_info = NULL;
+     ret = app_manager_get_app_info(app_id, &app_info);
+     if (ret == APP_MANAGER_ERROR_NONE && app_info) {
+         char *label = NULL;
+         app_info_get_label(app_info, &label);
+         if (label) {
+             dlog_print(DLOG_INFO, "APP_MANAGER", "App name: %s", label);
+             free(label);
+         }
+         app_info_destroy(app_info);
+     }
+ }
+

+Monitoring Application Launch and Termination

+

You can register a callback to be notified when applications are launched or terminated:

+
 static void
+ app_context_event_cb(app_context_h app_context, app_context_event_e event, void *user_data)
+ {
+     char *app_id = NULL;
+     pid_t pid;
+     
+     app_context_get_app_id(app_context, &app_id);
+     app_context_get_pid(app_context, &pid);
+     
+     if (event == APP_CONTEXT_EVENT_LAUNCHED) {
+         dlog_print(DLOG_INFO, "APP_MANAGER", "App launched: %s (PID: %d)", 
+                    app_id ? app_id : "Unknown", pid);
+     } else if (event == APP_CONTEXT_EVENT_TERMINATED) {
+         dlog_print(DLOG_INFO, "APP_MANAGER", "App terminated: %s (PID: %d)", 
+                    app_id ? app_id : "Unknown", pid);
+     }
+     
+     if (app_id) free(app_id);
+ }
+
+ void
+ start_monitoring(void)
+ {
+     int ret = app_manager_set_app_context_event_cb(app_context_event_cb, NULL);
+     if (ret != APP_MANAGER_ERROR_NONE) {
+         dlog_print(DLOG_ERROR, "APP_MANAGER", "Failed to set event callback");
+     }
+ }
+
+ void
+ stop_monitoring(void)
+ {
+     app_manager_unset_app_context_event_cb();
+ }
+

+Managing Applications

+

You can resume or terminate background applications:

+
 void
+ resume_application(const char *app_id)
+ {
+     app_context_h app_context = NULL;
+     int ret;
+     
+     // Get application context
+     ret = app_manager_get_app_context(app_id, &app_context);
+     if (ret == APP_MANAGER_ERROR_NONE && app_context) {
+         // Resume the application
+         ret = app_manager_resume_app(app_context);
+         if (ret == APP_MANAGER_ERROR_NONE) {
+             dlog_print(DLOG_INFO, "APP_MANAGER", "Successfully resumed %s", app_id);
+         } else {
+             dlog_print(DLOG_ERROR, "APP_MANAGER", "Failed to resume app");
+         }
+         app_context_destroy(app_context);
+     }
+ }
+
+ void
+ terminate_background_app(const char *app_id)
+ {
+     app_context_h app_context = NULL;
+     int ret;
+     
+     ret = app_manager_get_app_context(app_id, &app_context);
+     if (ret == APP_MANAGER_ERROR_NONE && app_context) {
+         // Request to terminate background app
+         ret = app_manager_request_terminate_bg_app(app_context);
+         if (ret == APP_MANAGER_ERROR_NONE) {
+             dlog_print(DLOG_INFO, "APP_MANAGER", "Requested termination of %s", app_id);
+         } else {
+             dlog_print(DLOG_ERROR, "APP_MANAGER", "Failed to terminate app");
+         }
+         app_context_destroy(app_context);
+     }
+ }
+
diff --git a/docs/application/native/api/common/9.0/group__CAPI__APP__COMMON__MODULE.html b/docs/application/native/api/common/9.0/group__CAPI__APP__COMMON__MODULE.html index 41a849a72f..d25288aece 100644 --- a/docs/application/native/api/common/9.0/group__CAPI__APP__COMMON__MODULE.html +++ b/docs/application/native/api/common/9.0/group__CAPI__APP__COMMON__MODULE.html @@ -133,6 +133,222 @@

  • Get the current orientation of the device
  • Get the Internal/External root folders which are shared among all applications
  • +

    +Getting Application Information

    +

    You can retrieve basic information about the application such as ID, name, and version:

    +
     #include <app_common.h>
    + #include <dlog.h>
    +
    + void
    + get_app_information(void)
    + {
    +     char *app_id = NULL;
    +     char *app_name = NULL;
    +     char *app_version = NULL;
    +     int ret;
    +     
    +     // Get application ID
    +     ret = app_get_id(&app_id);
    +     if (ret == APP_ERROR_NONE && app_id) {
    +         dlog_print(DLOG_INFO, "APP_COMMON", "Application ID: %s", app_id);
    +         free(app_id);
    +     }
    +     
    +     // Get application name
    +     ret = app_get_name(&app_name);
    +     if (ret == APP_ERROR_NONE && app_name) {
    +         dlog_print(DLOG_INFO, "APP_COMMON", "Application Name: %s", app_name);
    +         free(app_name);
    +     }
    +     
    +     // Get application version
    +     ret = app_get_version(&app_version);
    +     if (ret == APP_ERROR_NONE && app_version) {
    +         dlog_print(DLOG_INFO, "APP_COMMON", "Application Version: %s", app_version);
    +         free(app_version);
    +     }
    + }
    +

    +Getting Application Directories

    +

    Applications can access various directories for storing data, resources, and cache files:

    +
     void
    + get_app_directories(void)
    + {
    +     char *data_path = NULL;
    +     char *cache_path = NULL;
    +     char *resource_path = NULL;
    +     char *shared_data_path = NULL;
    +     char *shared_resource_path = NULL;
    +     
    +     // Get data directory (read/write)
    +     data_path = app_get_data_path();
    +     if (data_path) {
    +         dlog_print(DLOG_INFO, "APP_COMMON", "Data path: %s", data_path);
    +         free(data_path);
    +     }
    +     
    +     // Get cache directory (read/write, can be cleared by system)
    +     cache_path = app_get_cache_path();
    +     if (cache_path) {
    +         dlog_print(DLOG_INFO, "APP_COMMON", "Cache path: %s", cache_path);
    +         free(cache_path);
    +     }
    +     
    +     // Get resource directory (read-only)
    +     resource_path = app_get_resource_path();
    +     if (resource_path) {
    +         dlog_print(DLOG_INFO, "APP_COMMON", "Resource path: %s", resource_path);
    +         free(resource_path);
    +     }
    +     
    +     // Get shared data directory (requires privilege)
    +     shared_data_path = app_get_shared_data_path();
    +     if (shared_data_path) {
    +         dlog_print(DLOG_INFO, "APP_COMMON", "Shared data path: %s", shared_data_path);
    +         free(shared_data_path);
    +     }
    +     
    +     // Get shared resource directory
    +     shared_resource_path = app_get_shared_resource_path();
    +     if (shared_resource_path) {
    +         dlog_print(DLOG_INFO, "APP_COMMON", "Shared resource path: %s", shared_resource_path);
    +         free(shared_resource_path);
    +     }
    + }
    +

    +Handling System Events

    +

    Applications can register callbacks to handle various system events such as low memory, low battery, language changes, etc:

    +
     static void
    + on_low_memory(app_event_info_h event_info, void *user_data)
    + {
    +     app_event_low_memory_status_e status;
    +     
    +     if (app_event_get_low_memory_status(event_info, &status) == APP_ERROR_NONE) {
    +         switch (status) {
    +         case APP_EVENT_LOW_MEMORY_NORMAL:
    +             dlog_print(DLOG_INFO, "APP_COMMON", "Memory status: Normal");
    +             break;
    +         case APP_EVENT_LOW_MEMORY_SOFT_WARNING:
    +             dlog_print(DLOG_WARN, "APP_COMMON", "Memory status: Soft warning");
    +             // Free some cached data
    +             break;
    +         case APP_EVENT_LOW_MEMORY_HARD_WARNING:
    +             dlog_print(DLOG_ERROR, "APP_COMMON", "Memory status: Hard warning");
    +             // Free as much memory as possible
    +             break;
    +         }
    +     }
    + }
    +
    + static void
    + on_low_battery(app_event_info_h event_info, void *user_data)
    + {
    +     app_event_low_battery_status_e status;
    +     
    +     if (app_event_get_low_battery_status(event_info, &status) == APP_ERROR_NONE) {
    +         switch (status) {
    +         case APP_EVENT_LOW_BATTERY_POWER_OFF:
    +             dlog_print(DLOG_ERROR, "APP_COMMON", "Battery critical: Power off imminent");
    +             // Save all data immediately
    +             break;
    +         case APP_EVENT_LOW_BATTERY_CRITICAL_LOW:
    +             dlog_print(DLOG_WARN, "APP_COMMON", "Battery critical low");
    +             // Reduce power consumption
    +             break;
    +         }
    +     }
    + }
    +
    + static void
    + on_language_changed(app_event_info_h event_info, void *user_data)
    + {
    +     char *language = NULL;
    +     
    +     if (app_event_get_language(event_info, &language) == APP_ERROR_NONE && language) {
    +         dlog_print(DLOG_INFO, "APP_COMMON", "Language changed to: %s", language);
    +         // Reload localized resources
    +         free(language);
    +     }
    + }
    +
    + static void
    + on_device_orientation_changed(app_event_info_h event_info, void *user_data)
    + {
    +     app_device_orientation_e orientation;
    +     
    +     if (app_event_get_device_orientation(event_info, &orientation) == APP_ERROR_NONE) {
    +         switch (orientation) {
    +         case APP_DEVICE_ORIENTATION_0:
    +             dlog_print(DLOG_INFO, "APP_COMMON", "Orientation: 0 degrees");
    +             break;
    +         case APP_DEVICE_ORIENTATION_90:
    +             dlog_print(DLOG_INFO, "APP_COMMON", "Orientation: 90 degrees");
    +             break;
    +         case APP_DEVICE_ORIENTATION_180:
    +             dlog_print(DLOG_INFO, "APP_COMMON", "Orientation: 180 degrees");
    +             break;
    +         case APP_DEVICE_ORIENTATION_270:
    +             dlog_print(DLOG_INFO, "APP_COMMON", "Orientation: 270 degrees");
    +             break;
    +         }
    +     }
    + }
    +

    +Getting Display State

    +

    Applications can check the current display state:

    +
     void
    + check_display_state(void)
    + {
    +     app_display_state_e display_state;
    +     int ret;
    +     
    +     ret = app_get_display_state(&display_state);
    +     if (ret == APP_ERROR_NONE) {
    +         if (display_state == APP_DISPLAY_STATE_ON) {
    +             dlog_print(DLOG_INFO, "APP_COMMON", "Display is ON");
    +         } else {
    +             dlog_print(DLOG_INFO, "APP_COMMON", "Display is OFF");
    +         }
    +     } else if (ret == APP_ERROR_NOT_SUPPORTED) {
    +         dlog_print(DLOG_WARN, "APP_COMMON", "Display state not supported on this device");
    +     }
    + }
    +

    +Managing Watchdog Timer

    +

    Applications can control the watchdog timer to prevent ANR (Application Not Responding) errors during long operations:

    +
     void
    + perform_long_operation(void)
    + {
    +     // Disable watchdog timer before long operation
    +     if (app_watchdog_timer_disable() == APP_ERROR_NONE) {
    +         dlog_print(DLOG_INFO, "APP_COMMON", "Watchdog timer disabled");
    +     }
    +     
    +     // Perform long operation
    +     // ...
    +     
    +     // Re-enable watchdog timer after operation
    +     if (app_watchdog_timer_enable() == APP_ERROR_NONE) {
    +         dlog_print(DLOG_INFO, "APP_COMMON", "Watchdog timer enabled");
    +     }
    + }
    +
    + void
    + perform_operation_with_periodic_kick(void)
    + {
    +     int i;
    +     
    +     for (i = 0; i < 100; i++) {
    +         // Perform some work
    +         // ...
    +         
    +         // Periodically kick watchdog to reset timer
    +         if (i % 10 == 0) {
    +             app_watchdog_timer_kick();
    +         }
    +     }
    + }
    +

    Functions

    diff --git a/docs/application/native/api/common/9.0/group__CAPI__SERVICE__APP__MODULE.html b/docs/application/native/api/common/9.0/group__CAPI__SERVICE__APP__MODULE.html index 083bbe12d0..8dd9c405ba 100644 --- a/docs/application/native/api/common/9.0/group__CAPI__SERVICE__APP__MODULE.html +++ b/docs/application/native/api/common/9.0/group__CAPI__SERVICE__APP__MODULE.html @@ -106,6 +106,143 @@

  • Registering callbacks for application state change events.
  • Registering callbacks for basic system events.
  • +

    +How to Use Service Application API

    +

    A service application is a Tizen native application without a graphical user interface that runs in the background. The following example demonstrates a basic service application structure:

    +
     #include <service_app.h>
    + #include <dlog.h>
    +
    + typedef struct {
    +     // Application data structure
    +     int some_data;
    + } appdata_s;
    +
    + static bool
    + service_app_create(void *user_data)
    + {
    +     // Initialize application resources
    +     appdata_s *ad = (appdata_s *)user_data;
    +     
    +     // Initialize data
    +     ad->some_data = 0;
    +     
    +     dlog_print(DLOG_INFO, "SERVICE_APP", "Service application created");
    +     
    +     return true;
    + }
    +
    + static void
    + service_app_terminate(void *user_data)
    + {
    +     // Release all resources
    +     appdata_s *ad = (appdata_s *)user_data;
    +     
    +     dlog_print(DLOG_INFO, "SERVICE_APP", "Service application terminated");
    + }
    +
    + static void
    + service_app_control(app_control_h app_control, void *user_data)
    + {
    +     // Handle the launch request
    +     appdata_s *ad = (appdata_s *)user_data;
    +     char *operation = NULL;
    +     
    +     app_control_get_operation(app_control, &operation);
    +     
    +     if (operation) {
    +         dlog_print(DLOG_INFO, "SERVICE_APP", "Operation: %s", operation);
    +         free(operation);
    +     }
    + }
    +
    + int
    + main(int argc, char *argv[])
    + {
    +     appdata_s ad = {0,};
    +     service_app_lifecycle_callback_s event_callback;
    +     
    +     event_callback.create = service_app_create;
    +     event_callback.terminate = service_app_terminate;
    +     event_callback.app_control = service_app_control;
    +     
    +     return service_app_main(argc, argv, &event_callback, &ad);
    + }
    +

    +Handling System Events

    +

    Service applications can register event handlers for various system events such as low memory, low battery, language changes, and region format changes:

    +
     static void
    + service_app_low_memory(app_event_info_h event_info, void *user_data)
    + {
    +     // Handle low memory event
    +     // Free cached data and reduce memory usage
    +     dlog_print(DLOG_WARN, "SERVICE_APP", "Low memory event occurred");
    + }
    +
    + static void
    + service_app_low_battery(app_event_info_h event_info, void *user_data)
    + {
    +     // Handle low battery event
    +     // Reduce power consumption
    +     dlog_print(DLOG_WARN, "SERVICE_APP", "Low battery event occurred");
    + }
    +
    + static void
    + service_app_language_changed(app_event_info_h event_info, void *user_data)
    + {
    +     // Handle language change event
    +     // Reload localized resources, update UI text, etc.
    +     dlog_print(DLOG_INFO, "SERVICE_APP", "Language changed event occurred");
    + }
    +
    + static bool
    + service_app_create(void *user_data)
    + {
    +     app_event_handler_h handler;
    +     
    +     // Register event handlers
    +     service_app_add_event_handler(&handler, APP_EVENT_LOW_MEMORY, 
    +                                   service_app_low_memory, user_data);
    +     service_app_add_event_handler(&handler, APP_EVENT_LOW_BATTERY, 
    +                                   service_app_low_battery, user_data);
    +     service_app_add_event_handler(&handler, APP_EVENT_LANGUAGE_CHANGED, 
    +                                   service_app_language_changed, user_data);
    +     
    +     return true;
    + }
    +

    +Handling App Control

    +

    Service applications can receive and process app control requests from other applications:

    +
     static void
    + service_app_control(app_control_h app_control, void *user_data)
    + {
    +     char *operation = NULL;
    +     char *uri = NULL;
    +     char *extra_data = NULL;
    +     
    +     // Get operation
    +     app_control_get_operation(app_control, &operation);
    +     
    +     if (operation) {
    +         dlog_print(DLOG_INFO, "SERVICE_APP", "Operation: %s", operation);
    +         
    +         // Get URI if available
    +         app_control_get_uri(app_control, &uri);
    +         if (uri) {
    +             dlog_print(DLOG_INFO, "SERVICE_APP", "URI: %s", uri);
    +             free(uri);
    +         }
    +         
    +         // Get extra data
    +         app_control_get_extra_data(app_control, "my_key", &extra_data);
    +         if (extra_data) {
    +             dlog_print(DLOG_INFO, "SERVICE_APP", "Extra data: %s", extra_data);
    +             free(extra_data);
    +         }
    +         
    +         free(operation);
    +     }
    + }
    +

    Functions

    Functions