--- /dev/null
+/*
+ * 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);
+ }
+}
using System.Threading.Tasks;
using System.IO;
using System.Linq;
+using System.ComponentModel;
namespace Tizen.Applications
{
return PackageArchive.GetPackageArchive(archivePath);
}
+ /// <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>