Implement ApplicationManagerUtils in PCL
authorGeunsun, Lee <gs86.lee@samsung.com>
Thu, 6 Apr 2017 10:59:42 +0000 (19:59 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:52 +0000 (18:34 +0900)
Change-Id: If60a660d6a6257679110086ee25d7c365c5f99ca

LibTVRefCommonPortable/DataModels/RecentShortcutInfo.cs
LibTVRefCommonPortable/LibTVRefCommonPortable.csproj
LibTVRefCommonPortable/Models/AppShortcutController.cs
LibTVRefCommonPortable/Models/RecentShortcutController.cs
LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs [new file with mode: 0644]
LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs
LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs
TVApps/TVApps/ViewModels/AppsHolder.cs

index 255d3f5..96b2750 100755 (executable)
@@ -24,7 +24,7 @@ namespace LibTVRefCommonPortable.DataModels
     public class RecentShortcutInfo : ShortcutInfo
     {
         /// <summary>
-        /// A application ID
+        /// An application ID
         /// </summary>
         public string AppID { get; set; }
         /// <summary>
index 1b1f96c..f682b4a 100755 (executable)
@@ -51,6 +51,7 @@
     <Compile Include="Models\RecentShortcutController.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Utils\AppControlUtils.cs" />
+    <Compile Include="Utils\ApplicationManagerUtils.cs" />
     <Compile Include="Utils\AppShortcutStorage.cs" />
     <Compile Include="Utils\DateUtils.cs" />
     <Compile Include="Utils\DebuggingUtils.cs" />
index 2db6bae..e0a38ff 100755 (executable)
@@ -45,10 +45,9 @@ namespace LibTVRefCommonPortable.Models
         /// <returns>A installed app list.</returns>
         public async Task<IEnumerable<AppShortcutInfo>> GetInstalledApps()
         {
-            IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
             List<AppShortcutInfo> appShortcutInfoList = new List<AppShortcutInfo>();
 
-            var installedAppList = await applicationManagerPort.GetAllInstalledApplication();
+            var installedAppList = await ApplicationManagerUtils.GetAllInstalledApplication();
 
             foreach (KeyValuePair<string, string[]> item in installedAppList)
             {
@@ -64,6 +63,7 @@ namespace LibTVRefCommonPortable.Models
 
                 var appShortcutInfo = new AppShortcutInfo()
                 {
+                    IsRemovable = ApplicationManagerUtils.GetAppInfoRemovable(item.Key),
                     // TODO : Fill these correctly by using Tizen Device APIs
                     Installed = DateUtils.GetRandomDate(),
                     LastUsed = DateUtils.GetRandomDate(),
@@ -160,14 +160,13 @@ namespace LibTVRefCommonPortable.Models
         /// <returns>A Pinned App Shortcut list.</returns>
         private async Task<List<ShortcutInfo>> GetPinnedApps()
         {
-            IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
             IEnumerable<AppShortcutInfo> pinned_apps_info = await AppShortcutStorage.Read();
 
             List<ShortcutInfo> returnPinnedAppsInfo = new List<ShortcutInfo>();
 
             foreach (AppShortcutInfo appShortcutInfo in pinned_apps_info)
             {
-                Dictionary<string, string> appInfo = applicationManagerPort.GetInstalledApplication(appShortcutInfo.AppID);
+                Dictionary<string, string> appInfo = ApplicationManagerUtils.GetInstalledApplication(appShortcutInfo.AppID);
 
                 if (appInfo == null)
                 {
index 6678270..a3a7ca0 100755 (executable)
@@ -70,10 +70,9 @@ namespace LibTVRefCommonPortable.Models
         /// <returns>A Recent Shortcut list.</returns>
         public IEnumerable<RecentShortcutInfo> GetList()
         {
-            IApplicationManagerAPIs applicationManagerPort = DependencyService.Get<IApplicationManagerAPIs>();
             List<RecentShortcutInfo> recentShortcutInfoList = new List<RecentShortcutInfo>();
 
-            var recentApps = applicationManagerPort.GetRecentApplications();
+            var recentApps = ApplicationManagerUtils.GetRecentApplications();
             foreach (var item in recentApps)
             {
                 var defaultStateDescription = new StateDescription()
diff --git a/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs b/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs
new file mode 100644 (file)
index 0000000..a69a27b
--- /dev/null
@@ -0,0 +1,75 @@
+
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Xamarin.Forms;
+
+namespace LibTVRefCommonPortable.Utils
+{
+    public sealed class ApplicationManagerUtils
+    {
+        /// <summary>
+        /// A constructor
+        /// </summary>
+        public ApplicationManagerUtils()
+        {
+        }
+
+        /// <summary>
+        /// Gets the information of the recent applications
+        /// </summary>
+        /// <returns>The list of the recent applications</returns>
+        public static IEnumerable<RecentApp> GetRecentApplications()
+        {
+            if (DependencyService.Get<IApplicationManagerAPIs>() == null)
+            {
+                return null;
+            }
+
+            return DependencyService.Get<IApplicationManagerAPIs>().GetRecentApplications();
+        }
+
+        /// <summary>
+        /// Gets the information of the specified application with the app ID
+        /// </summary>
+        /// <param name="appID">The app Id to get</param>
+        /// <returns>The information of the installed application</returns>
+        public static Dictionary<string, string> GetInstalledApplication(string appID)
+        {
+            if (DependencyService.Get<IApplicationManagerAPIs>() == null)
+            {
+                return null;
+            }
+
+            return DependencyService.Get<IApplicationManagerAPIs>().GetInstalledApplication(appID);
+        }
+
+        /// <summary>
+        /// Gets the information of the installed applications asynchronously
+        /// </summary>
+        /// <returns>The list of the installed applications</returns>
+        public static Task<Dictionary<string, string[]>> GetAllInstalledApplication()
+        {
+            if (DependencyService.Get<IApplicationManagerAPIs>() == null)
+            {
+                return null;
+            }
+
+            return DependencyService.Get<IApplicationManagerAPIs>().GetAllInstalledApplication();
+        }
+
+        /// <summary>
+        /// Checks whether application is removable
+        /// </summary>
+        /// <param name="appID">The app ID to get</param>
+        /// <returns>If the application is removable, true; otherwise, false</returns>
+        public static bool GetAppInfoRemovable(string appID)
+        {
+            if (DependencyService.Get<IApplicationManagerAPIs>() == null)
+            {
+                return false;
+            }
+
+            return DependencyService.Get<IApplicationManagerAPIs>().GetAppInfoRemovable(appID);
+        }
+    }
+}
index cf65a8e..39ac943 100755 (executable)
@@ -85,14 +85,21 @@ namespace LibTVRefCommonPortable.Utils
         /// <returns>A installed application information</returns>
         Dictionary<string, string> GetInstalledApplication(string applicationId);
 
-       /// <summary>
-       /// A method for removing all recent applications
-       /// </summary>
+        /// <summary>
+        /// A method for removing all recent applications
+        /// </summary>
         void DeleteAllRecentApplication();
 
-       /// <summary>
-       /// A method for removing the specified recent application
-       /// </summary>
+        /// <summary>
+        /// A method for removing the specified recent application
+        /// </summary>
         void DeleteRecentApplication(string appId);
+
+        /// <summary>
+        /// Checks whether application is removable
+        /// </summary>
+        /// <param name="appID">The app ID to get</param>
+        /// <returns>If the application is removable, true; otherwise, false</returns>
+        bool GetAppInfoRemovable(string appID);
     }
 }
index 8182734..014050c 100755 (executable)
@@ -150,7 +150,7 @@ namespace LibTVRefCommonTizen.Ports
             }
             catch (Exception exception)
             {
-                DbgPort.E("Exception " + appID + " :" + exception.Message);
+                DbgPort.E("Failed to get the installed application(" + appID + ") :" + exception.Message);
                 return null;
             }
 
@@ -203,9 +203,36 @@ namespace LibTVRefCommonTizen.Ports
             }
             catch (Exception exception)
             {
-                DbgPort.E(exception.Message);
+                DbgPort.E("Failed to get the all installed applications : " + exception.Message);
                 return null;
             }
         }
+
+        /// <summary>
+        /// Checks whether application is removable
+        /// </summary>
+        /// <param name="appID">The app ID to get</param>
+        /// <returns>If the application is removable, true; otherwise, false</returns>
+        public bool GetAppInfoRemovable(string appID)
+        {
+            ApplicationInfo appInfo = null;
+
+            try
+            {
+                appInfo = ApplicationManager.GetInstalledApplication(appID);
+                if (appInfo == null)
+                {
+                    DbgPort.D("Failed to get the installed application(" + appID +")");
+                    return false;
+                }
+
+                return !appInfo.IsPreload;
+            }
+            catch (Exception exception)
+            {
+                DbgPort.E("Failed to get the installed application(" + appID + ") :" + exception.Message);
+                return false;
+            }
+        }
     }
 }
\ No newline at end of file
index 88e9685..c9fb8c2 100644 (file)
@@ -251,6 +251,12 @@ namespace TVApps.ViewModels
         {
             DebuggingUtils.Dbg("Delete, " + appID);
 
+            if (!ApplicationManagerUtils.GetAppInfoRemovable(appID))
+            {
+                DebuggingUtils.Dbg("This app is not removable : " + appID);
+                return;
+            }
+
             // TODO : popup
 
             // if the app to be deleted is pinned, remove the app in the pinned apps list
@@ -262,8 +268,8 @@ namespace TVApps.ViewModels
                 return;
             }
 
-            List<string> removableAppsList = PackageManagerUtils.GetApplicationsByPkgID(pkgID);
-            if (removableAppsList == null || removableAppsList.Count == 0)
+            List<string> appsList = PackageManagerUtils.GetApplicationsByPkgID(pkgID);
+            if (appsList == null || appsList.Count == 0)
             {
                 DebuggingUtils.Err("Failed to get the apps list by package ID(" + pkgID + ")");
 
@@ -287,7 +293,7 @@ namespace TVApps.ViewModels
                     DebuggingUtils.Dbg("- " + item.AppID);
                 }
 
-                RemovePinnedApp(removableAppsList);
+                RemovePinnedApp(appsList);
                 RefreshApps();
             }
         }
@@ -348,6 +354,11 @@ namespace TVApps.ViewModels
 
                         break;
                     case AppsStatus.Delete:
+                        if (!item.IsRemovable)
+                        {
+                            item.IsDim = true;
+                        }
+
                         item.IsChecked = false;
                         break;
                 }