[Packagemanager] Add APIs for internal (#4991)
authorjeremy-jang <35089715+jeremy-jang@users.noreply.github.com>
Thu, 23 Mar 2023 06:48:16 +0000 (15:48 +0900)
committerGitHub <noreply@github.com>
Thu, 23 Mar 2023 06:48:16 +0000 (15:48 +0900)
* [Packagemanager] Add APIs for internal

- Tizen.PackageManager.ActivatePackage()
- Tizen.PackageManager.DeactivatePackage()

Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
* [Packagemanager] Fix return type of EnablePackage/DisablePackage

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

Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/Tizen.Applications.PackageManager/Interop/Interop.Libraries.cs
src/Tizen.Applications.PackageManager/Interop/Interop.PackageManagerInternal.cs [new file with mode: 0755]
src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs

index 83cbc6e..f486d8c 100755 (executable)
@@ -19,5 +19,6 @@ internal static partial class Interop
     internal static partial class Libraries
     {
         public const string PackageManager = "libcapi-appfw-package-manager.so.0";
+        public const string PackageManagerInternal = "libpkgmgr-client.so.0";
     }
 }
diff --git a/src/Tizen.Applications.PackageManager/Interop/Interop.PackageManagerInternal.cs b/src/Tizen.Applications.PackageManager/Interop/Interop.PackageManagerInternal.cs
new file mode 100755 (executable)
index 0000000..4a5509f
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2023 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 PackageManagerInternal
+    {
+        [DllImport(Libraries.PackageManager, EntryPoint = "pkgmgr_client_new")]
+        internal static extern IntPtr PkgmgrClientNew(int type);
+
+        [DllImport(Libraries.PackageManager, EntryPoint = "pkgmgr_client_free")]
+        internal static extern ErrorCode PkgmgrClientFree(IntPtr clientHandle);
+
+        [DllImport(Libraries.PackageManager, EntryPoint = "pkgmgr_client_activate")]
+        internal static extern ErrorCode PkgmgrClientActivate(IntPtr clientHandle, string pkgType, string pkgId);
+        
+        [DllImport(Libraries.PackageManager, EntryPoint = "pkgmgr_client_deactivate")]
+        internal static extern ErrorCode PkgmgrClientDeactivate(IntPtr clientHandle, string pkgType, string pkgId);
+    }
+}
index 36d7a25..3ad18b8 100755 (executable)
@@ -19,6 +19,7 @@ using System.Collections.Generic;
 using System.Threading.Tasks;
 using System.IO;
 using System.Linq;
+using System.ComponentModel;
 
 namespace Tizen.Applications
 {
@@ -1194,6 +1195,76 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Enable the given package.
+        /// </summary>
+        /// <param name="packageId">The ID of the package.</param>
+        /// <remarks>
+        /// This API is for inhouse app only.
+        /// </remarks>
+        /// <returns>Returns true if succeeds, otherwise false.</returns>
+        /// <privilege>http://tizen.org/privilege/packagemanager.admin</privilege>
+        /// <privlevel>platform</privlevel>
+        /// <exception cref="ArgumentException">Thrown when failed when input package ID is invalid.</exception>
+        /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory to continue the execution of the method.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
+        /// <exception cref="SystemException">Thrown when the method failed due to an internal system error.</exception>
+        /// <since_tizen> 11 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void EnablePackage(string packageId)
+        {
+            // 0 is PC_REQUEST
+            IntPtr clientHandle = Interop.PackageManagerInternal.PkgmgrClientNew(0);
+            if (clientHandle == null)
+            {
+                throw PackageManagerErrorFactory.GetException(Interop.PackageManager.ErrorCode.OutOfMemory, "Failed to create internal handle");
+            }
+
+            Interop.PackageManager.ErrorCode err = Interop.PackageManagerInternal.PkgmgrClientActivate(clientHandle, null, packageId);
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                Interop.PackageManagerInternal.PkgmgrClientFree(clientHandle);
+                throw PackageManagerErrorFactory.GetException(err, "Failed to activate the package");
+            }
+
+            Interop.PackageManagerInternal.PkgmgrClientFree(clientHandle);
+        }
+
+        /// <summary>
+        /// Disable the given package.
+        /// </summary>
+        /// <param name="packageId">The ID of the package.</param>
+        /// <remarks>
+        /// This API is for inhouse app only.
+        /// </remarks>
+        /// <returns>Returns true if succeeds, otherwise false.</returns>
+        /// <privilege>http://tizen.org/privilege/packagemanager.admin</privilege>
+        /// <privlevel>platform</privlevel>
+        /// <exception cref="ArgumentException">Thrown when failed when input package ID is invalid.</exception>
+        /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory to continue the execution of the method.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
+        /// <exception cref="SystemException">Thrown when the method failed due to an internal system error.</exception>
+        /// <since_tizen> 11 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void DisablePackage(string packageId)
+        {
+            // 0 is PC_REQUEST
+            IntPtr clientHandle = Interop.PackageManagerInternal.PkgmgrClientNew(0);
+            if (clientHandle == null)
+            {
+                throw PackageManagerErrorFactory.GetException(Interop.PackageManager.ErrorCode.OutOfMemory, "Failed to create internal handle");
+            }
+
+            Interop.PackageManager.ErrorCode err = Interop.PackageManagerInternal.PkgmgrClientDeactivate(clientHandle, null, packageId);
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                Interop.PackageManagerInternal.PkgmgrClientFree(clientHandle);
+                throw PackageManagerErrorFactory.GetException(err, "Failed to activate the package");
+            }
+
+            Interop.PackageManagerInternal.PkgmgrClientFree(clientHandle);
+        }
+
+        /// <summary>
         /// Drm nested class. This class has the PackageManager's drm related methods.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>