From: jeremy-jang <35089715+jeremy-jang@users.noreply.github.com> Date: Thu, 23 Mar 2023 06:48:16 +0000 (+0900) Subject: [Packagemanager] Add APIs for internal (#4991) X-Git-Tag: submit/tizen/20230323.150933~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cb5ae7dc8ad140a006f7725ff47a6f37934a3341;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Packagemanager] Add APIs for internal (#4991) * [Packagemanager] Add APIs for internal - Tizen.PackageManager.ActivatePackage() - Tizen.PackageManager.DeactivatePackage() Signed-off-by: Sangyoon Jang * [Packagemanager] Fix return type of EnablePackage/DisablePackage Signed-off-by: Sangyoon Jang --------- Signed-off-by: Sangyoon Jang --- diff --git a/src/Tizen.Applications.PackageManager/Interop/Interop.Libraries.cs b/src/Tizen.Applications.PackageManager/Interop/Interop.Libraries.cs index 83cbc6e76..f486d8c02 100755 --- a/src/Tizen.Applications.PackageManager/Interop/Interop.Libraries.cs +++ b/src/Tizen.Applications.PackageManager/Interop/Interop.Libraries.cs @@ -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 index 000000000..4a5509f4a --- /dev/null +++ b/src/Tizen.Applications.PackageManager/Interop/Interop.PackageManagerInternal.cs @@ -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); + } +} diff --git a/src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs b/src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs index 36d7a256a..3ad18b83e 100755 --- a/src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs +++ b/src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using System.IO; using System.Linq; +using System.ComponentModel; namespace Tizen.Applications { @@ -1193,6 +1194,76 @@ namespace Tizen.Applications return PackageArchive.GetPackageArchive(archivePath); } + /// + /// Enable the given package. + /// + /// The ID of the package. + /// + /// This API is for inhouse app only. + /// + /// Returns true if succeeds, otherwise false. + /// http://tizen.org/privilege/packagemanager.admin + /// platform + /// Thrown when failed when input package ID is invalid. + /// Thrown when there is not enough memory to continue the execution of the method. + /// Thrown when an application does not have the privilege to access this method. + /// Thrown when the method failed due to an internal system error. + /// 11 + [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); + } + + /// + /// Disable the given package. + /// + /// The ID of the package. + /// + /// This API is for inhouse app only. + /// + /// Returns true if succeeds, otherwise false. + /// http://tizen.org/privilege/packagemanager.admin + /// platform + /// Thrown when failed when input package ID is invalid. + /// Thrown when there is not enough memory to continue the execution of the method. + /// Thrown when an application does not have the privilege to access this method. + /// Thrown when the method failed due to an internal system error. + /// 11 + [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); + } + /// /// Drm nested class. This class has the PackageManager's drm related methods. ///