[Tizen.Applications.PackageManager] Add API for package archive info (#739)
authorilho159kim <dlfgh951@naver.com>
Fri, 22 Mar 2019 05:50:31 +0000 (14:50 +0900)
committerpjh9216 <jh9216.park@samsung.com>
Fri, 22 Mar 2019 05:50:31 +0000 (14:50 +0900)
* [Tizen.Applications.PackageManager] Add API for package archive info

* Fix spelling error

* Delete unused exception

* Add remarks for PackageManager's GetPackageArchive

* Modify GetPackageArchive API's remarks

* Add documentation for PackageFilter's param

src/Tizen.Applications.PackageManager/Interop/Interop.PackageArchive.cs [new file with mode: 0644]
src/Tizen.Applications.PackageManager/Tizen.Applications/PackageArchive.cs [new file with mode: 0644]
src/Tizen.Applications.PackageManager/Tizen.Applications/PackageFilter.cs
src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs

diff --git a/src/Tizen.Applications.PackageManager/Interop/Interop.PackageArchive.cs b/src/Tizen.Applications.PackageManager/Interop/Interop.PackageArchive.cs
new file mode 100644 (file)
index 0000000..e2af2fa
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+using ErrorCode = Interop.PackageManager.ErrorCode;
+
+internal static partial class Interop
+{
+    internal static partial class PackageArchive
+    {
+        [DllImport(Libraries.PackageManager, EntryPoint = "package_archive_info_create")]
+        internal static extern ErrorCode PackageArchiveInfoCreate(string path, out IntPtr handle);
+
+        [DllImport(Libraries.PackageManager, EntryPoint = "package_archive_info_destroy")]
+        internal static extern ErrorCode PackageArchiveInfoDestroy(IntPtr handle);
+
+        [DllImport(Libraries.PackageManager, EntryPoint = "package_archive_info_get_package")]
+        internal static extern ErrorCode PackageArchiveInfoGetPackage(IntPtr handle, out string package);
+
+        [DllImport(Libraries.PackageManager, EntryPoint = "package_archive_info_get_type")]
+        internal static extern ErrorCode PackageArchiveInfoGetType(IntPtr handle, out string type);
+
+        [DllImport(Libraries.PackageManager, EntryPoint = "package_archive_info_get_version")]
+        internal static extern ErrorCode PackageArchiveInfoGetVersion(IntPtr handle, out string version);
+
+        [DllImport(Libraries.PackageManager, EntryPoint = "package_archive_info_get_api_version")]
+        internal static extern ErrorCode PackageArchiveInfoGetApiVersion(IntPtr handle, out string apiVersion);
+
+        [DllImport(Libraries.PackageManager, EntryPoint = "package_archive_info_get_description")]
+        internal static extern ErrorCode PackageArchiveInfoGetDescription(IntPtr handle, out string description);
+
+        [DllImport(Libraries.PackageManager, EntryPoint = "package_archive_info_get_label")]
+        internal static extern ErrorCode PackageArchiveInfoGetLabel(IntPtr handle, out string label);
+
+        [DllImport(Libraries.PackageManager, EntryPoint = "package_archive_info_get_author")]
+        internal static extern ErrorCode PackageArchiveInfoGetAuthor(IntPtr handle, out string author);
+
+        [DllImport(Libraries.PackageManager, EntryPoint = "package_archive_info_get_icon")]
+        internal static extern ErrorCode PackageArchiveInfoGetIcon(IntPtr handle, out IntPtr icon, out int iconSize);
+    }
+}
diff --git a/src/Tizen.Applications.PackageManager/Tizen.Applications/PackageArchive.cs b/src/Tizen.Applications.PackageManager/Tizen.Applications/PackageArchive.cs
new file mode 100644 (file)
index 0000000..b7c45b9
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Tizen.Applications
+{
+    /// <summary>
+    /// This class provides the methods and properties to get information about the package archive.
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    public class PackageArchive
+    {
+        private const string LogTag = "Tizen.Applications";
+
+        private string _path = string.Empty;
+        private string _id = string.Empty;
+        private string _type = string.Empty;
+        private string _version = string.Empty;
+        private string _apiVersion = string.Empty;
+        private string _description = string.Empty;
+        private string _label = string.Empty;
+        private string _author = string.Empty;
+        private IntPtr _icon = IntPtr.Zero;
+        private int _iconSize = 0;
+
+        private PackageArchive(string archivePath)
+        {
+            _path = archivePath;
+        }
+
+        /// <summary>
+        /// The package ID.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Id { get { return _id; } }
+
+        /// <summary>
+        /// Type of the package.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Type { get { return _type; } }
+
+        /// <summary>
+        /// Version of the package.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Version { get { return _version; } }
+
+        /// <summary>
+        /// Api version of the package.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string ApiVersion { get { return _apiVersion; } }
+
+        /// <summary>
+        /// Description of the package.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Description { get { return _description; } }
+
+        /// <summary>
+        /// Label of the package.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Label { get { return _label; } }
+
+        /// <summary>
+        /// Author of the package.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Author { get { return _author; } }
+
+        /// <summary>
+        /// Icon of the package.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public byte[] Icon
+        {
+            get
+            {
+                byte[] byteArray = new byte[_iconSize];
+                Marshal.Copy(_icon, byteArray, 0, _iconSize);
+                return byteArray;
+            }
+        }
+
+        // This method assumes that given arguments are already validated and have valid values.
+        internal static PackageArchive CreatePackageArchive(IntPtr handle, string archivePath)
+        {
+            PackageArchive packageArchive = new PackageArchive(archivePath);
+
+            var err = Interop.PackageManager.ErrorCode.None;
+            err = Interop.PackageArchive.PackageArchiveInfoGetPackage(handle, out packageArchive._id);
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                Log.Warn(LogTag, "Failed to get package id from " + archivePath);
+            }
+            err = Interop.PackageArchive.PackageArchiveInfoGetType(handle, out packageArchive._type);
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                Log.Warn(LogTag, "Failed to get package type from " + archivePath);
+            }
+            err = Interop.PackageArchive.PackageArchiveInfoGetVersion(handle, out packageArchive._version);
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                Log.Warn(LogTag, "Failed to get package version from " + archivePath);
+            }
+            err = Interop.PackageArchive.PackageArchiveInfoGetApiVersion(handle, out packageArchive._apiVersion);
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                Log.Warn(LogTag, "Failed to get package api version from " + archivePath);
+            }
+            err = Interop.PackageArchive.PackageArchiveInfoGetDescription(handle, out packageArchive._description);
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                Log.Warn(LogTag, "Failed to get package description from " + archivePath);
+            }
+            err = Interop.PackageArchive.PackageArchiveInfoGetLabel(handle, out packageArchive._label);
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                Log.Warn(LogTag, "Failed to get package label from " + archivePath);
+            }
+            err = Interop.PackageArchive.PackageArchiveInfoGetAuthor(handle, out packageArchive._author);
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                Log.Warn(LogTag, "Failed to get package author from " + archivePath);
+            }
+            err = Interop.PackageArchive.PackageArchiveInfoGetIcon(handle, out packageArchive._icon, out packageArchive._iconSize);
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                Log.Warn(LogTag, "Failed to get package author from " + archivePath);
+            }
+
+            return packageArchive;
+        }
+
+        internal static PackageArchive GetPackageArchive(string archivePath)
+        {
+            IntPtr packageArchiveInfoHandle;
+            Interop.PackageManager.ErrorCode err = Interop.PackageArchive.PackageArchiveInfoCreate(archivePath, out packageArchiveInfoHandle);
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                throw PackageManagerErrorFactory.GetException(err, string.Format("Failed to create native handle for package archive info of {0}", archivePath));
+            }
+
+            PackageArchive packageArchive = CreatePackageArchive(packageArchiveInfoHandle, archivePath);
+
+            err = Interop.PackageArchive.PackageArchiveInfoDestroy(packageArchiveInfoHandle);
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                Log.Warn(LogTag, string.Format("Failed to destroy native handle for package archive info of {0}. err = {1}", archivePath, err));
+            }
+            return packageArchive;
+        }
+    }
+}
index cd5ff8a..47061c9 100755 (executable)
@@ -38,6 +38,7 @@ namespace Tizen.Applications
         /// <summary>
         /// The constructor with specific filters. Using this will filter out the installed packages which do not meet the filter criteria.
         /// </summary>
+        /// <param name="filter">Package filters.</param>
         /// <since_tizen> 3 </since_tizen>
         public PackageFilter(IDictionary<string, bool> filter)
         {
index c160e94..94f41ab 100644 (file)
@@ -439,7 +439,7 @@ namespace Tizen.Applications
         /// <param name="packagePath">Absolute path for the package to be installed.</param>
         /// <param name="eventCallback">The event callback will be invoked only for the current request.</param>
         /// <param name="installMode">Optional parameter to indicate special installation mode.</param>
-        /// <returns>Returns true if installtion request is successful, false otherwise.</returns>
+        /// <returns>Returns true if installation request is successful, false otherwise.</returns>
         /// <remarks>
         /// The 'true' means that the request for installation is successful.
         /// To check the result of installation, the caller should check the progress using the InstallProgressChanged event or eventCallback.
@@ -458,7 +458,7 @@ namespace Tizen.Applications
         /// <param name="packagePath">Absolute path for the package to be installed.</param>
         /// <param name="type">Package type for the package to be installed.</param>
         /// <param name="installMode">Optional parameter to indicate special installation mode.</param>
-        /// <returns>Returns true if installtion request is successful, false otherwise.</returns>
+        /// <returns>Returns true if installation request is successful, false otherwise.</returns>
         /// <remarks>
         /// The 'true' means that the request for installation is successful.
         /// To check the result of installation, the caller should check the progress using the InstallProgressChanged event.
@@ -477,7 +477,7 @@ namespace Tizen.Applications
         /// <param name="packagePath">Absolute path for the package to be installed.</param>
         /// <param name="expansionPackagePath">Absolute path for the expansion package to be installed.</param>
         /// <param name="installMode">Optional parameter to indicate special installation mode.</param>
-        /// <returns>Returns true if installtion request is successful, false otherwise.</returns>
+        /// <returns>Returns true if installation request is successful, false otherwise.</returns>
         /// <remarks>
         /// The 'true' means that the request for installation is successful.
         /// To check the result of installation, the caller should check the progress using the InstallProgressChanged event.
@@ -497,7 +497,7 @@ namespace Tizen.Applications
         /// <param name="type">Package type for the package to be installed.</param>
         /// <param name="eventCallback">The event callback will be invoked only for the current request.</param>
         /// <param name="installMode">Optional parameter to indicate special installation mode.</param>
-        /// <returns>Returns true if installtion request is successful, false otherwise.</returns>
+        /// <returns>Returns true if installation request is successful, false otherwise.</returns>
         /// <remarks>
         /// The 'true' means that the request for installation is successful.
         /// To check the result of installation, the caller should check the progress using the InstallProgressChanged event or eventCallback.
@@ -517,7 +517,7 @@ namespace Tizen.Applications
         /// <param name="expansionPackagePath">Absolute path for the expansion package to be installed.</param>
         /// <param name="eventCallback">The event callback will be invoked only for the current request.</param>
         /// <param name="installMode">Optional parameter to indicate special installation mode.</param>
-        /// <returns>Returns true if installtion request is successful, false otherwise.</returns>
+        /// <returns>Returns true if installation request is successful, false otherwise.</returns>
         /// <remarks>
         /// The 'true' means that the request for installation is successful.
         /// To check the result of installation, the caller should check the progress using the InstallProgressChanged event or eventCallback.
@@ -537,7 +537,7 @@ namespace Tizen.Applications
         /// <param name="expansionPackagePath">Absolute path for the expansion package to be installed.</param>
         /// <param name="type">Package type for the package to be installed.</param>
         /// <param name="installMode">Optional parameter to indicate special installation mode.</param>
-        /// <returns>Returns true if installtion request is successful, false otherwise.</returns>
+        /// <returns>Returns true if installation request is successful, false otherwise.</returns>
         /// <remarks>
         /// The 'true' means that the request for installation is successful.
         /// To check the result of installation, the caller should check the progress using the InstallProgressChanged event.
@@ -558,7 +558,7 @@ namespace Tizen.Applications
         /// <param name="type">Package type for the package to be installed.</param>
         /// <param name="eventCallback">The event callback will be invoked only for the current request.</param>
         /// <param name="installMode">Optional parameter to indicate special installation mode.</param>
-        /// <returns>Returns true if installtion request is successful, false otherwise.</returns>
+        /// <returns>Returns true if installation request is successful, false otherwise.</returns>
         /// <remarks>
         /// The 'true' means that the request for installation is successful.
         /// To check the result of installation, the caller should check the progress using the InstallProgressChanged event or eventCallback.
@@ -678,7 +678,7 @@ namespace Tizen.Applications
         /// </summary>
         /// <param name="packageId">ID of the package to be uninstalled.</param>
         /// <param name="type">Optional - Package type for the package to be uninstalled.</param>
-        /// <returns>Returns true if the uninstalltion request is successful, false otherwise.</returns>
+        /// <returns>Returns true if the uninstallation request is successful, false otherwise.</returns>
         /// <remarks>
         /// The 'true' means that the request for uninstallation is successful.
         /// To check the result of uninstallation, the caller should check the progress using the UninstallProgressChanged event.
@@ -996,6 +996,22 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Gets the package archive's information for the given archive path.
+        /// </summary>
+        /// <param name="archivePath">The path of the package archive.</param>
+        /// <remarks>
+        /// Regular 3rd party apps do not need to use this API
+        /// </remarks>
+        /// <returns>Returns the package archive information for the given archive path.</returns>
+        /// <exception cref="ArgumentException">Thrown when the failed input package ID is invalid.</exception>
+        /// <exception cref="System.IO.IOException">Thrown when the method fails due to an internal I/O error.</exception>
+        /// <since_tizen> 6 </since_tizen>
+        public static PackageArchive GetPackageArchive(string archivePath)
+        {
+            return PackageArchive.GetPackageArchive(archivePath);
+        }
+
+        /// <summary>
         /// Drm nested class. This class has the PackageManager's drm related methods.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>