[Applications][TCSACR-441] Add new APIs for resource control (#3414)
authorjeremy-jang <35089715+jeremy-jang@users.noreply.github.com>
Fri, 10 Sep 2021 05:01:55 +0000 (14:01 +0900)
committerGitHub <noreply@github.com>
Fri, 10 Sep 2021 05:01:55 +0000 (14:01 +0900)
* [Applications] Add new APIs for resource control

Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
* [Applications] Fix namings

Use full name instead of abbreviations.

Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
* Fix ResourceControl

- Fix class summary of doxygen comment.
- Set default value of min/maxResourceVersion as null.

Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
Co-authored-by: pjh9216 <jh9216.park@samsung.com>
src/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs
src/Tizen.Applications.Common/Tizen.Applications/ApplicationInfo.cs
src/Tizen.Applications.Common/Tizen.Applications/ResourceControl.cs [new file with mode: 0644]

index 526141e..6758ac1 100755 (executable)
@@ -100,6 +100,9 @@ internal static partial class Interop
         internal delegate bool AppInfoCategoryCallback(string category, IntPtr userData);
         //bool (*app_info_category_cb) (const char *category, void *user_data)
 
+        internal delegate bool AppInfoResControlCallback(string resType, string minResVersion, string maxResVersion, string autoClose, IntPtr userUdata);
+        //bool (*app_info_res_control_cb) (const char *res_type, const char *min_res_version, const char *max_res_version, const char *auto_close, 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)
@@ -348,6 +351,9 @@ internal static partial class Interop
         internal static extern ErrorCode AppInfoMetadataFilterForeach(IntPtr handle, AppInfoFilterCallback callback, IntPtr userData);
         //int app_info_metadata_filter_foreach (app_info_metadata_filter_h handle, app_info_filter_cb callback, void *user_data)
 
+        [DllImport(Libraries.AppManager, EntryPoint = "app_info_foreach_res_control")]
+        internal static extern ErrorCode AppInfoForeachResControl(IntPtr handle, AppInfoResControlCallback callback, IntPtr userData);
+
         [NativeStruct("struct rua_rec", Include="rua.h", PkgConfig="rua")]
         [StructLayout(LayoutKind.Sequential)]
         internal struct RuaRec
index f0110aa..33ac219 100644 (file)
@@ -422,6 +422,35 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Gets the resource controls.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public IEnumerable<ResourceControl> ResourceControls
+        {
+            get
+            {
+                List<ResourceControl> resourceControls = new List<ResourceControl>();
+                Interop.ApplicationManager.AppInfoResControlCallback cb = (string resType, string minResourceVersion, string maxResourceVersion, string isAutoClose, IntPtr userData) =>
+                {
+                    resourceControls.Add(new ResourceControl(resType, minResourceVersion, maxResourceVersion, isAutoClose == "true"));
+                    return true;
+                };
+
+                IntPtr infoHandle = GetInfoHandle();
+                if (infoHandle != null)
+                {
+                    err = Interop.ApplicationManager.AppInfoForeachResControl(infoHandle, cb, IntPtr.Zero);
+                    if (err != Interop.ApplicationManager.ErrorCode.None)
+                    {
+                        Log.Warn(LogTag, "Failed to get the resource controls of " + _applicationId + ". err = " + err);
+                    }
+                }
+
+                return resourceControls;
+            }
+        }
+
+        /// <summary>
         /// Gets the localized label of the application for the given locale.
         /// </summary>
         /// <param name="locale">Locale.</param>
diff --git a/src/Tizen.Applications.Common/Tizen.Applications/ResourceControl.cs b/src/Tizen.Applications.Common/Tizen.Applications/ResourceControl.cs
new file mode 100644 (file)
index 0000000..318fbcd
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Tizen.Applications
+{
+    /// <summary>
+    /// Represents the resource control information.
+    /// </summary>
+    /// <since_tizen> 9 </since_tizen>
+    public class ResourceControl
+    {
+        internal ResourceControl(string resourceType, string minResourceVersion, string maxResourceVersion, bool isAutoClose)
+        {
+            ResourceType = resourceType;
+            MinResourceVersion = minResourceVersion ?? null;
+            MaxResourceVersion = maxResourceVersion ?? null;
+            IsAutoClose = isAutoClose;
+        }
+
+        /// <summary>
+        /// The resource type.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public string ResourceType { get; }
+
+        /// <summary>
+        /// The minimum version of required resource package.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public string MinResourceVersion { get; }
+
+        /// <summary>
+        /// The maximum version of required resource package.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public string MaxResourceVersion { get; }
+
+        /// <summary>
+        /// The auto close property.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public bool IsAutoClose { get; }
+    }
+}