[Applications.PackageManager] Add ClearUserData(package, path) (#4747)
authorChangGyu Choi <uppletaste@gmail.com>
Mon, 9 Jan 2023 08:33:24 +0000 (17:33 +0900)
committerGitHub <noreply@github.com>
Mon, 9 Jan 2023 08:33:24 +0000 (17:33 +0900)
* [Tizen.Applications] Add a new PackageManager API

Adds:
 - ClearUserData(packageId, filePath)

Signed-off-by: ChangGyu Choi <uppletaste@gmail.com>
* Fix the api description

Signed-off-by: ChangGyu Choi <uppletaste@gmail.com>
* Remove a remark sentence

Signed-off-by: ChangGyu Choi <uppletaste@gmail.com>
* Update API description

Signed-off-by: ChangGyu Choi <uppletaste@gmail.com>
Signed-off-by: ChangGyu Choi <uppletaste@gmail.com>
src/Tizen.Applications.PackageManager/Interop/Interop.PackageManager.cs
src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs

index 2e38a78..5859625 100755 (executable)
@@ -141,6 +141,9 @@ internal static partial class Interop
         [DllImport(Libraries.PackageManager, EntryPoint = "package_manager_clear_data_dir")]
         internal static extern ErrorCode PackageManagerClearDataDir(string packageId);
 
+        [DllImport(Libraries.PackageManager, EntryPoint = "package_manager_clear_user_data_with_path")]
+        internal static extern ErrorCode PackageManagerClearUserDataWithPath(string packageId, String filePath);
+
         [DllImport(Libraries.PackageManager, EntryPoint = "package_manager_filter_create")]
         internal static extern ErrorCode PackageManagerFilterCreate(out IntPtr handle);
 
index 7305e44..36d7a25 100755 (executable)
@@ -353,6 +353,28 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Removes a file or directory specified with <paramref name="path"/> from user data internal storage for the application.
+        /// </summary>
+        /// <param name="packageId">ID of the package.</param>
+        /// <param name="path">The path of the file or directory in the package user data folder.</param>
+        /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory to continue the execution of the method.</exception>
+        /// <exception cref="System.IO.IOException">Thrown when the method failed due to an internal IO error.</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>
+        /// <privilege>http://tizen.org/privilege/packagemanager.admin</privilege>
+        /// <privlevel>platform</privlevel>
+        /// <since_tizen> 11 </since_tizen>
+        public static void ClearUserData(string packageId, string path)
+        {
+            Interop.PackageManager.ErrorCode err = Interop.PackageManager.PackageManagerClearUserDataWithPath(packageId, path);
+            if (err != Interop.PackageManager.ErrorCode.None)
+            {
+                Log.Warn(LogTag, string.Format("Failed to clear user data for {0} of {1}. err = {2}", path, packageId, err));
+                throw PackageManagerErrorFactory.GetException(err, "Failed to clear user data");
+            }
+        }
+
+        /// <summary>
         /// Retrieves the package information of all installed packages.
         /// </summary>
         /// <returns>Returns the list of packages.</returns>