Revert "Add Test cases for app shortcut, managedapps"
[profile/tv/apps/dotnet/home.git] / LibTVRefCommonPortable / Utils / ApplicationManagerUtils.cs
1 
2 using System;
3 using System.Collections.Generic;
4 using System.Threading.Tasks;
5 using Xamarin.Forms;
6
7 namespace LibTVRefCommonPortable.Utils
8 {
9     /// <summary>
10     /// A class provides application controlling functions
11     /// </summary>
12     public sealed class ApplicationManagerUtils
13     {
14         /// <summary>
15         /// A instance of platform specific application manager port.
16         /// </summary>
17         private static IApplicationManagerAPIs applicationManagerAPIs;
18
19         /// <summary>
20         /// A instance of ApplicationManagerUtils
21         /// </summary>
22         private static readonly ApplicationManagerUtils instance = new ApplicationManagerUtils();
23
24         /// <summary>
25         /// A getter of ApplicationManagerUtils instance
26         /// </summary>
27         public static ApplicationManagerUtils Instance
28         {
29             get
30             {
31                 return instance;
32             }
33         }
34
35         /// <summary>
36         /// A unit testing stub of IApplicationManagerAPIs.
37         /// </summary>
38         private class TestingStub : IApplicationManagerAPIs
39         {
40             public void DeleteAllRecentApplication()
41             {
42                 throw new NotImplementedException();
43             }
44
45             public void DeleteRecentApplication(string appId)
46             {
47                 throw new NotImplementedException();
48             }
49
50             public Task<Dictionary<string, string[]>> GetAllInstalledApplication()
51             {
52                 throw new NotImplementedException();
53             }
54
55             public Task<string> GetAppIDbyAppLabel(string appLabel)
56             {
57                 throw new NotImplementedException();
58             }
59
60             public bool GetAppInfoRemovable(string appID)
61             {
62                 throw new NotImplementedException();
63             }
64
65             public Dictionary<string, string> GetInstalledApplication(string applicationId)
66             {
67                 throw new NotImplementedException();
68             }
69
70             public IEnumerable<RecentApp> GetRecentApplications()
71             {
72                 IList<RecentApp> testData = new List<RecentApp>();
73
74                 testData.Add(new RecentApp
75                 {
76                     InstanceID = "recentapp1",
77                     InstanceLabel = "recentapp1",
78                     AppID = "org.tizen.recentapp1",
79                     Applabel = "recentapp1",
80                     IconPath = "/test/recentapp1",
81                     LaunchedTime = new DateTime(2014, 11, 12),
82                     Uri = "uri/recentapp1",
83                     ScreenShot = "screenshot/recentapp1",
84                 });
85                 testData.Add(new RecentApp
86                 {
87                     InstanceID = "recentapp2.noscreenshot",
88                     InstanceLabel = "recentapp2.noscreenshot",
89                     AppID = "org.tizen.recentapp2.noscreenshot",
90                     Applabel = "recentapp2.noscreenshot",
91                     IconPath = "/test/recentapp2",
92                     LaunchedTime = new DateTime(2014, 11, 12),
93                     Uri = "uri/recentapp2",
94                 });
95                 testData.Add(new RecentApp
96                 {
97                     InstanceID = "invalid.recentapp3.nolabel",
98                     AppID = "invalid.org.tizen.recentapp3.nolabel",
99                     IconPath = "/test/recentapp3",
100                     LaunchedTime = new DateTime(2014, 11, 12),
101                     Uri = "uri/recentapp3",
102                     ScreenShot = "screenshot/recentapp3",
103                 });
104                 testData.Add(new RecentApp
105                 {
106                     InstanceID = "invalid.recentapp4.notime",
107                     AppID = "invalid.org.tizen.recentapp4.notime",
108                     Applabel = "recentapp4.notime",
109                     IconPath = "/test/recentapp4",
110                     Uri = "uri/recentapp4",
111                     ScreenShot = "screenshot/recentapp4",
112                 });
113                 testData.Add(new RecentApp
114                 {
115                     InstanceID = "recentapp5",
116                     InstanceLabel = "recentapp5",
117                     AppID = "org.tizen.recentapp5",
118                     Applabel = "recentapp5",
119                     IconPath = "/test/recentapp5",
120                     LaunchedTime = new DateTime(2017, 05, 02),
121                     Uri = "uri/recentapp5",
122                     ScreenShot = "screenshot/recentapp5",
123                 });
124                 testData.Add(new RecentApp
125                 {
126                     InstanceID = "recentapp6",
127                     InstanceLabel = "recentapp6",
128                     AppID = "org.tizen.recentapp6",
129                     Applabel = "recentapp6",
130                     IconPath = "/test/recentapp6",
131                     LaunchedTime = new DateTime(2017, 02, 26),
132                     Uri = "uri/recentapp6",
133                     ScreenShot = "screenshot/recentapp6",
134                 });
135                 testData.Add(new RecentApp
136                 {
137                     InstanceID = "recentapp7",
138                     InstanceLabel = "recentapp7",
139                     AppID = "org.tizen.recentapp7",
140                     Applabel = "recentapp7",
141                     IconPath = "/test/recentapp7",
142                     LaunchedTime = new DateTime(2016, 04, 25),
143                     Uri = "uri/recentapp7",
144                     ScreenShot = "screenshot/recentapp7",
145                 });
146
147                 return testData;
148             }
149         }
150
151         /// <summary>
152         /// A constructor
153         /// </summary>
154         private ApplicationManagerUtils()
155         {
156             applicationManagerAPIs = new TestingStub();
157
158             try
159             {
160                 if (DependencyService.Get<IApplicationManagerAPIs>() != null)
161                 {
162                     applicationManagerAPIs = DependencyService.Get<IApplicationManagerAPIs>();
163                 }
164             }
165             catch (InvalidOperationException e)
166             {
167                 DebuggingUtils.Err(e.Message);
168             }
169         }
170
171         /// <summary>
172         /// A method for removing all recent applications
173         /// </summary>
174         public void DeleteAllRecentApplication()
175         {
176             applicationManagerAPIs.DeleteAllRecentApplication();
177         }
178
179         /// <summary>
180         /// A method for removing the specified recent application
181         /// </summary>
182         /// <param name="appId">An application ID</param>
183         public void DeleteRecentApplication(string appId)
184         {
185             applicationManagerAPIs.DeleteRecentApplication(appId);
186         }
187
188
189         /// <summary>
190         /// Gets the information of the recent applications
191         /// </summary>
192         /// <returns>The list of the recent applications</returns>
193         public IEnumerable<RecentApp> GetRecentApplications()
194         {
195             return applicationManagerAPIs.GetRecentApplications();
196         }
197
198         /// <summary>
199         /// Gets the information of the specified application with the app ID
200         /// </summary>
201         /// <param name="appID">The app Id to get</param>
202         /// <returns>The information of the installed application</returns>
203         public Dictionary<string, string> GetInstalledApplication(string appID)
204         {
205             return applicationManagerAPIs.GetInstalledApplication(appID);
206         }
207
208         /// <summary>
209         /// Gets the information of the installed applications asynchronously
210         /// </summary>
211         /// <returns>The list of the installed applications</returns>
212         public Task<Dictionary<string, string[]>> GetAllInstalledApplication()
213         {
214             return applicationManagerAPIs.GetAllInstalledApplication();
215         }
216
217         /// <summary>
218         /// Checks whether application is removable
219         /// </summary>
220         /// <param name="appID">The app ID to get</param>
221         /// <returns>If the application is removable, true; otherwise, false</returns>
222         public bool GetAppInfoRemovable(string appID)
223         {
224             return applicationManagerAPIs.GetAppInfoRemovable(appID);
225         }
226
227         /// <summary>
228         /// Gets the app ID by the app label
229         /// </summary>
230         /// <param name="appLabel">the app label to get</param>
231         /// <returns>the app ID of the app label</returns>
232         public Task<string> GetAppIDbyAppLabel(string appLabel)
233         {
234             return applicationManagerAPIs.GetAppIDbyAppLabel(appLabel);
235         }
236     }
237 }