From 36fb2d2784874c73d07c4383a09cde5603deb629 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 30 Jun 2015 14:01:49 +0900 Subject: [PATCH] modify package manager tutorial Change-Id: Ie02823e46bc413030f0a72c18c984d79bb10d9b2 Signed-off-by: Junghyun Yeon --- .../native/app_framework/package_tutorial_n.htm | 149 ++++++++++++++------- 1 file changed, 102 insertions(+), 47 deletions(-) mode change 100644 => 100755 org.tizen.tutorials/html/native/app_framework/package_tutorial_n.htm diff --git a/org.tizen.tutorials/html/native/app_framework/package_tutorial_n.htm b/org.tizen.tutorials/html/native/app_framework/package_tutorial_n.htm old mode 100644 new mode 100755 index 8667223..7f96c38 --- a/org.tizen.tutorials/html/native/app_framework/package_tutorial_n.htm +++ b/org.tizen.tutorials/html/native/app_framework/package_tutorial_n.htm @@ -41,7 +41,7 @@

Package Manager: Installing and Uninstalling Applications

-

This tutorial demonstrates how you can retrieve package information and manage packages.

+

This tutorial demonstrates how you can manage installed packages with its information.

Warm-up

Become familiar with the Package Manager API basics by learning about:

@@ -64,24 +64,9 @@
 #include <package_manager.h>
 
-
  • The http://tizen.org/privilege/packagemanager.info, http://tizen.org/privilege/packagemanager.install, and http://tizen.org/privilege/packagemanager.setting privileges are required for the Package Manager API.

    -

    Add the privileges to the tizen-manifest.xml file.

  • -
  • Use the - package_manager_foreach_package_info() function: - -
    -package_manager_foreach_package_info(package_info_cb, NULL)
    -
    - -

    The function takes the following parameters:

    -
      -
    • [in] callback: Callback function to be invoked
    • -
    • [in] user_data: User data to be passed to the callback function
    • -
    • [out] 0 on success, otherwise a negative error value
    • -
  • - -
  • Use the package_manager_package_info_cb callback to retrieve all installed packages and print package information. Finally, destroy the package info handler.

    - +
  • The http://tizen.org/privilege/packagemanager.info privilege is required to get package information.

    +

    Add this privilege to the tizen-manifest.xml file.

  • +
  • Prepare callback function package_info_cb which will be invoked for each package information retrieved
  •  void package_info_cb(package_info_h package_info, void *user_data)
     {
    @@ -124,7 +109,25 @@ void package_info_cb(package_info_h package_info, void *user_data)
        free(type);
     }
     
    +
  • Use the + package_manager_foreach_package_info() function: This function will retrieve all package information and invoke callback for each information retrieved + +
    +package_manager_foreach_package_info(package_manager_package_info_cb callback, void *user_data)
    +
    + +

    The function takes the following parameters:

    +
      +
    • [in] callback: Callback function to be invoked for each package information retrieved
    • +
    • [in] user_data: User data to be passed to the callback function
    • +
    • [out] 0 on success, otherwise a negative error value
    • +
  • + +
  • Call package_manager_foreach_package_info with passing callback and userdata

    + +
    +<<<<<<< Updated upstream
     ret = package_manager_foreach_package_info(package_info_cb, NULL);
     if (ret != PACKAGE_MANAGER_ERROR_NONE) 
     {
    @@ -142,25 +145,60 @@ if (ret != PACKAGE_MANAGER_ERROR_NONE)
     
     #include <package_manager.h>
     
  • -
  • The http://tizen.org/privilege/packagemanager.info, http://tizen.org/privilege/packagemanager.install, and http://tizen.org/privilege/packagemanager.setting privileges are required for the Package Manager API.

    -

    Add the privileges to the tizen-manifest.xml file.

  • +
  • The http://tizen.org/privilege/packagemanager.info privilege is required for this Package Manager API.

    +

    Add the privilege to the tizen-manifest.xml file.

  • Use the package_manager_get_package_info() function: +
    +int package_manager_get_package_info(const char *package_id, package_info_h *package_info)
    +
    +

    The function takes the following parameters:

    +
      +
    • [in] package_id: ID of the package
    • +
    • [in] package_info: Package information for the given package ID.
    • +
    • [out] 0 on success, otherwise a negative error value
    • +
  • +
  • After getting package_info_h handle, use package_info_get_ functions to retrieve specific information
    +char *version = NULL;
    +char *label = NULL;
    +char *type = NULL;
     package_info_h package_info = NULL;
     package_manager_get_package_info("PACKAGE-ID", &package_info);
     
    +package_info_get_version(package_info, &version);
    +package_info_get_label(package_info, &label);
    +package_info_get_type(package_info, &type);
    +
    +dlog_print(DLOG_INFO, TAG, "label \t= [%s]\n", label);
    +dlog_print(DLOG_INFO, TAG, "icon \t= [%s]\n", icon);
    +dlog_print(DLOG_INFO, TAG, "version \t= [%s]\n", version);
    +
    +free(label);
    +free(icon);
    +free(version);
    +
     // Use package information
     package_info_destroy(package_info);
     
    -

    The function takes the following parameters:

    -
      -
    • [in] package_id: ID of the package
    • -
    • [in] package_info: Package information for the given package ID
    • -
    • [out] 0 on success, otherwise a negative error value
    • -
  • + +
  • You can get package information with functions listed below: +
    +package_info_get_label(package_info_h package_info, char **label)
    +package_info_get_icon(package_info_h package_info, char **path)
    +package_info_get_version(package_info_h package_info, char **version)
    +package_info_get_type(package_info_h package_info, char **type)
    +package_info_get_installed_storage(package_info_h package_info, package_info_installed_storage_type_e *storage)
    +package_info_get_root_path(package_info_h package_info, char **path)
    +package_info_is_system_package(package_info_h package_info, bool *system)
    +package_info_is_removable_package(package_info_h package_info, bool *removable)
    +package_info_is_preload_package(package_info_h package_info, bool *preload)
    +package_info_is_accessible(package_info_h package_info, bool *accessible)
    +
  • +
  • Package Manager handle shoule be released with package_info_destroy function.
  • +

    Listening to Package Events

    @@ -172,14 +210,17 @@ package_info_destroy(package_info);
     #include <package_manager.h>
     
    -
  • The http://tizen.org/privilege/packagemanager.info, http://tizen.org/privilege/packagemanager.install, and http://tizen.org/privilege/packagemanager.setting privileges are required for the Package Manager API.

    -

    Add the privileges to the tizen-manifest.xml file.

  • +
  • The http://tizen.org/privilege/packagemanager.info privilege is required for this Package Manager API.

    +

    Add privilege to the tizen-manifest.xml file.

  • Create the package manager (package_manager_h) using the package_manager_create() function:

    +
    +package_manager_create(package_manager_h * manager)
    package_manager_h manager;
     package_manager_create(&manager);
    +

    The function takes the following parameters:

    • [in] manager: Package manager handle that is newly created on success
    • @@ -189,29 +230,25 @@ package_manager_create(&manager);
    • -

      Set the status when the package is installed, uninstalled, or updated:

      - +

      Set the package event which you want to listen by invoking package_manager_set_event_status:

      +
      package_manager_set_event_status(package_manager_h manager, int status_type)
      package_manager_set_event_status(manager, PACKAGE_MANAGER_STATUS_TYPE_ALL);

      The function takes the following parameters:

      • [in] manager: Package manager handle
      • -
      • [in] status_type: Status of the package
      • -
      • [out] 0 on success, otherwise a negative error value
      • -
      -
    • - -
    • -

      Register a callback function to be invoked when the package is installed, uninstalled, or updated:

      -
      -package_manager_set_event_cb(manager, event_cb, NULL);
      -
      - -

      The function takes the following parameters:

      -
        -
      • [in] manager: Package manager handle
      • -
      • [in] callback: Callback function to be registered
      • -
      • [in] user_data: User data to be passed to the callback function
      • +
      • [in] status_type: Status of the package
        + There are several event types want to listen +
        +PACKAGE_MANAGER_STATUS_TYPE_ALL : All status
        +PACKAGE_MANAGER_STATUS_TYPE_INSTALL :  Install package status
        +PACKAGE_MANAGER_STATUS_TYPE_UNINSTALL : Uninstall package status
        +PACKAGE_MANAGER_STATUS_TYPE_UPGRADE : Upgrade package status
        +PACKAGE_MANAGER_STATUS_TYPE_MOVE : Move package status
        +PACKAGE_MANAGER_STATUS_TYPE_CLEAR_DATA : Clear data status
        +PACKAGE_MANAGER_STATUS_TYPE_INSTALL_PROGRESS : Install progress status
        +PACKAGE_MANAGER_STATUS_TYPE_GET_SIZE : Get size status
        +
      • [out] 0 on success, otherwise a negative error value
    • @@ -241,6 +278,24 @@ package_manager_set_event_cb(manager, event_cb, NULL); } + +
    • +

      Register a callback function to be invoked when the event you registered has happened:

      +
      +int package_manager_set_event_cb(package_manager_h manager, package_manager_event_cb callback, void *user_data)
      +
      +package_manager_set_event_cb(manager, event_cb, NULL);
      +
      + +

      The function takes the following parameters:

      +
        +
      • [in] manager: Package manager handle
      • +
      • [in] callback: Callback function to be registered
      • +
      • [in] user_data: User data to be passed to the callback function
      • +
      • [out] 0 on success, otherwise a negative error value
      • +
      +
    • +
    • Free the package manager:

      -- 2.7.4