[Application] Add more method in ApplicationInfo class (#732)
authorilho159kim <dlfgh951@naver.com>
Fri, 22 Mar 2019 05:50:13 +0000 (14:50 +0900)
committerpjh9216 <jh9216.park@samsung.com>
Fri, 22 Mar 2019 05:50:13 +0000 (14:50 +0900)
* Add missing Application API

* Fix ambiguous name

* Change enum member's name

* Modify Categories API's reference tags

* Add additional Explanation for categories API's summary

* Delete unused file

* Change ComponentType property's return value

- Remapping ComponentType to ApplicationType

* Add Package's new GetApplications method

This method use ApplicationComponentType

* Modify GetApplications method using ApplicationComponentType

src/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs
src/Tizen.Applications.Common/Tizen.Applications/ApplicationComponentType.cs [new file with mode: 0644]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationInfo.cs
src/Tizen.Applications.Common/Tizen.Applications/ApplicationType.cs
src/Tizen.Applications.PackageManager/Tizen.Applications/Package.cs

index 0879a32..11a879c 100644 (file)
@@ -61,6 +61,14 @@ internal static partial class Interop
             Failed = 2
         }
 
+        internal enum AppInfoAppComponentType
+        {
+            UiApp = 0,
+            ServiceApp = 1,
+            WidgetApp = 2,
+            WatchApp = 3
+        }
+
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate void AppManagerEventCallback(string appType, string appId, AppManagerEventType eventType, AppManagerEventState eventState, IntPtr eventHandle, IntPtr userData);
         //void(* app_manager_event_cb)(const char *type, const char *app_id, app_manager_event_type_e event_type, app_manager_event_state_e event_state, app_manager_event_h handle, void *user_data)
@@ -86,6 +94,10 @@ internal static partial class Interop
         internal delegate bool AppInfoMetadataCallback(string key, string value, IntPtr userData);
         //bool(* app_info_metadata_cb )(const char *metadata_key, const char *metadata_value, void *user_data)
 
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate bool AppInfoCategoryCallback(string category, IntPtr userData);
+        //bool (*app_info_category_cb) (const char *category, void *user_data)
+
         [DllImport(Libraries.AppManager, EntryPoint = "app_manager_set_app_context_event_cb")]
         internal static extern ErrorCode AppManagerSetAppContextEvent(AppManagerAppContextEventCallback callback, IntPtr userData);
         //int app_manager_set_app_context_event_cb( app_manager_app_context_event_cb callback, void * user_data)
@@ -246,6 +258,10 @@ internal static partial class Interop
         internal static extern ErrorCode AppInfoGetType(IntPtr handle, out string type);
         //int app_info_get_type (app_info_h app_info, char **type)
 
+        [DllImport(Libraries.AppManager, EntryPoint = "app_info_get_app_component_type")]
+        internal static extern ErrorCode AppInfoGetAppComponentType(IntPtr handle, out AppInfoAppComponentType type);
+        //int app_info_get_app_component_type(app_info_h app_info, app_info_app_component_type_e *type)
+
         [DllImport(Libraries.AppManager, EntryPoint = "app_info_foreach_metadata")]
         internal static extern ErrorCode AppInfoForeachMetadata(IntPtr handle, AppInfoMetadataCallback callback, IntPtr userData);
         //int app_info_foreach_metadata(app_info_h app_info, app_info_metadata_cb callback, void *user_data)
@@ -274,6 +290,10 @@ internal static partial class Interop
         internal static extern ErrorCode AppInfoClone(out IntPtr destination, IntPtr source);
         //int app_info_clone(app_info_h * clone, app_info_h app_info)
 
+        [DllImport(Libraries.AppManager, EntryPoint = "app_info_foreach_category")]
+        internal static extern ErrorCode AppInfoForeachCategory(IntPtr handle, AppInfoCategoryCallback callback, IntPtr userData);
+        //int app_info_foreach_category(app_info_h app_info, app_info_category_cb callback, void *user_data)
+
         [DllImport(Libraries.AppManager, EntryPoint = "app_info_filter_create")]
         internal static extern ErrorCode AppInfoFilterCreate(out IntPtr handle);
         //int app_info_filter_create(app_info_filter_h * handle)
diff --git a/src/Tizen.Applications.Common/Tizen.Applications/ApplicationComponentType.cs b/src/Tizen.Applications.Common/Tizen.Applications/ApplicationComponentType.cs
new file mode 100644 (file)
index 0000000..bb96bd1
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Tizen.Applications
+{
+    /// <summary>
+    /// Enumeration for application component type.
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    public enum ApplicationComponentType
+    {
+        /// <summary>
+        /// Component type is ui application.
+        /// </summary>
+        UIApplication = 0,
+
+        /// <summary>
+        /// Component type is service application.
+        /// </summary>
+        ServiceApplication,
+
+        /// <summary>
+        /// Component type is widget application.
+        /// </summary>
+        WidgetApplication,
+
+        /// <summary>
+        /// Component type is watch application.
+        /// </summary>
+        WatchApplication,
+    }
+}
index b26f480..f0110aa 100644 (file)
@@ -194,6 +194,28 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Gets the application component type.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public ApplicationComponentType ComponentType
+        {
+            get
+            {
+                IntPtr infoHandle = GetInfoHandle();
+                Interop.ApplicationManager.AppInfoAppComponentType componentType = 0;
+                if (infoHandle != IntPtr.Zero)
+                {
+                    err = Interop.ApplicationManager.AppInfoGetAppComponentType(infoHandle, out componentType);
+                    if (err != Interop.ApplicationManager.ErrorCode.None)
+                    {
+                        Log.Warn(LogTag, "Failed to get the application component type of " + _applicationId + ". err = " + err);
+                    }
+                }
+                return (ApplicationComponentType)componentType;
+            }
+        }
+
+        /// <summary>
         /// Gets the application's metadata.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
@@ -294,6 +316,37 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Gets the application's category values specified in the tizen-manifest
+        /// </summary>
+        /// <privilege>http://tizen.org/privilege/packagemanager.admin</privilege>
+        /// <privlevel>platform</privlevel>
+        /// <since_tizen> 6 </since_tizen>
+        public IEnumerable<string> Categories
+        {
+            get
+            {
+                List<string> categories = new List<string>();
+
+                Interop.ApplicationManager.AppInfoCategoryCallback cb = (string category, IntPtr userData) =>
+                {
+                    categories.Add(category);
+                    return true;
+                };
+
+                IntPtr infoHandle = GetInfoHandle();
+                if (infoHandle != IntPtr.Zero)
+                {
+                    err = Interop.ApplicationManager.AppInfoForeachCategory(infoHandle, cb, IntPtr.Zero);
+                    if (err != Interop.ApplicationManager.ErrorCode.None)
+                    {
+                        Log.Warn(LogTag, "Failed to get application category of " + _applicationId + ". err = " + err);
+                    }
+                }
+                return categories;
+            }
+        }
+
+        /// <summary>
         /// Gets the shared data path.
         /// </summary>
         /// <remarks>
index 153b566..288b6d9 100644 (file)
@@ -33,6 +33,14 @@ namespace Tizen.Applications
         /// <summary>
         /// Service applications.
         /// </summary>
-        Service = 2
+        Service = 2,
+        /// <summary>
+        /// Service applications.
+        /// </summary>
+        Widget = 3,
+        /// <summary>
+        /// Service applications.
+        /// </summary>
+        Watch = 4
     }
 }
index 4cda57f..2bc73f3 100644 (file)
@@ -192,6 +192,17 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Retrieves all the application IDs of this package.
+        /// </summary>
+        /// <param name="componentType">Optional: AppType enumeration value.</param>
+        /// <returns>Returns a dictionary containing all the application information for a given application type.</returns>
+        /// <since_tizen> 6 </since_tizen>
+        public IEnumerable<ApplicationInfo> GetApplications(ApplicationComponentType componentType)
+        {
+            return GetApplications(ToApplicationType(componentType));
+        }
+
+        /// <summary>
         /// Gets the package size information.
         /// </summary>
         /// <returns>Package size information.</returns>
@@ -379,5 +390,20 @@ namespace Tizen.Applications
             }
             return privileges;
         }
+
+        private ApplicationType ToApplicationType(ApplicationComponentType componentType)
+        {
+            ApplicationType applicationType = 0;
+            if (componentType == Tizen.Applications.ApplicationComponentType.UIApplication)
+                applicationType = Tizen.Applications.ApplicationType.Ui;
+            else if (componentType == Tizen.Applications.ApplicationComponentType.ServiceApplication)
+                applicationType = Tizen.Applications.ApplicationType.Service;
+            else if (componentType == Tizen.Applications.ApplicationComponentType.WidgetApplication)
+                applicationType = Tizen.Applications.ApplicationType.Widget;
+            else if (componentType == Tizen.Applications.ApplicationComponentType.WatchApplication)
+                applicationType = Tizen.Applications.ApplicationType.Watch;
+
+            return applicationType;
+        }
     }
 }