Add new API for getting filtered count
authorjongmyeongko <jongmyeong.ko@samsung.com>
Wed, 8 Mar 2017 14:48:21 +0000 (23:48 +0900)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Fri, 17 Mar 2017 00:56:00 +0000 (17:56 -0700)
usage)
var filter = new PackageFilter();
filter.Filters.Add(PackasgeFilter.Keys.Removalble, true);
var pkgList1 = PackageManager.GetPackage(filter);
var pkgList2 = PackageManager.GetPackage(filter);
int count = filter.GetCount(); // get count from latest filtered result.
int count = filter.GetCount(pkgList1); // get count from the given filtered result.

Change-Id: Idd111de78964bd1bc81e4703945b4cc8d1fb8987
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
src/Tizen.Applications.PackageManager/Interop/Interop.PackageManager.cs
src/Tizen.Applications.PackageManager/Tizen.Applications/PackageFilter.cs
src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs

index e8fac2d..a58b128 100644 (file)
@@ -46,7 +46,8 @@ internal static partial class Interop
             IoError = Tizen.Internals.Errors.ErrorCode.IoError,
             NoSuchPackage = -0x01150000 | 0x71,
             SystemError = -0x01150000 | 0x72,
-            PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied
+            PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
+            InvalidOperation = Tizen.Internals.Errors.ErrorCode.InvalidOperation
         }
 
         // Any change here might require changes in Tizen.Applications.PackageEventState enum
index 8ebff43..2a4c57e 100755 (executable)
@@ -15,6 +15,7 @@
  */
 
 using System.Collections.Generic;
+using System.Linq;
 
 namespace Tizen.Applications
 {
@@ -24,6 +25,7 @@ namespace Tizen.Applications
     public class PackageFilter
     {
         private IDictionary<string, bool> _filter;
+        private int _filteredCount = -1;
 
         /// <summary>
         /// Default constructor with empty filter list. All installed applications will satisfy this filter unless updated with more specific filters.
@@ -53,6 +55,45 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Gets the filtered item count from the given filtered result which was retrieved using GetPackages method, previously.
+        /// </summary>
+        /// <param name="filteredList">filtered list</param>
+        /// <exception cref="ArgumentException">Thrown when failed when input filtered list is invalid</exception>
+        public int GetCount(IEnumerable<Package> filteredList)
+        {
+            if (filteredList == null)
+            {
+                throw PackageManagerErrorFactory.GetException(Interop.PackageManager.ErrorCode.InvalidParameter, "the parameter is null");
+            }
+            return filteredList.Count();
+        }
+
+        /// <summary>
+        /// Gets the filtered count from the latest result of GetPackages method call.
+        /// </summary>
+        /// <remarks>
+        /// For the valid result, the method, Getpackages(PackageFilter filter), should be called once before.
+        /// The return value of this API can be same with GetCount(filteredList) if the filteredList is the result of the latest GetPackages method call.
+        /// </remarks>
+        /// <exception cref="InvalidOperationException">Thrown when failed when there is no valid fitered result</exception>
+        public int GetCount()
+        {
+            if (_filteredCount < 0)
+            {
+                throw PackageManagerErrorFactory.GetException(Interop.PackageManager.ErrorCode.InvalidOperation, "there is no valid filtered result");
+            }
+            return _filteredCount;
+        }
+
+        internal int FilteredCount
+        {
+            set
+            {
+                _filteredCount = value;
+            }
+        }
+
+        /// <summary>
         /// This class contains possible keys for filter to be used in the GetPackages method.
         /// </summary>
         public static class Keys
index 738e3c3..950d2d5 100644 (file)
@@ -329,6 +329,12 @@ namespace Tizen.Applications
             {
                 Log.Warn(LogTag, string.Format("Failed to destroy package filter handle. err = {0}", err));
             }
+
+            if (filter != null)
+            {
+                filter.FilteredCount = packageList.Count;
+            }
+
             return packageList;
         }