138d211f0844f841db771bc9436627071532113c
[profile/tv/apps/dotnet/home.git] / LibTVRefCommonPortable / Utils / ApplicationManagerUtils.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using LibTVRefCommonPortable.Stubs;
18 using System;
19 using System.Collections.Generic;
20 using System.Threading.Tasks;
21 using Xamarin.Forms;
22
23 namespace LibTVRefCommonPortable.Utils
24 {
25     /// <summary>
26     /// A class provides application controlling functions
27     /// </summary>
28     public sealed class ApplicationManagerUtils
29     {
30         /// <summary>
31         /// A instance of platform specific application manager port.
32         /// </summary>
33         private static IApplicationManagerAPIs applicationManagerAPIs;
34
35         /// <summary>
36         /// A instance of ApplicationManagerUtils
37         /// </summary>
38         private static readonly ApplicationManagerUtils instance = new ApplicationManagerUtils();
39
40         /// <summary>
41         /// A getter of ApplicationManagerUtils instance
42         /// </summary>
43         public static ApplicationManagerUtils Instance
44         {
45             get
46             {
47                 return instance;
48             }
49         }
50
51         /// <summary>
52         /// A constructor
53         /// </summary>
54         private ApplicationManagerUtils()
55         {
56             applicationManagerAPIs = new ApplicationManagerAPITestStub();
57
58             try
59             {
60                 if (DependencyService.Get<IApplicationManagerAPIs>() != null)
61                 {
62                     applicationManagerAPIs = DependencyService.Get<IApplicationManagerAPIs>();
63                 }
64             }
65             catch (InvalidOperationException e)
66             {
67                 DebuggingUtils.Err(e.Message);
68             }
69         }
70
71         /// <summary>
72         /// A method for removing all recent applications
73         /// </summary>
74         public void DeleteAllRecentApplication()
75         {
76             applicationManagerAPIs.DeleteAllRecentApplication();
77         }
78
79         /// <summary>
80         /// A method for removing the specified recent application
81         /// </summary>
82         /// <param name="appId">An application ID</param>
83         public void DeleteRecentApplication(string appId)
84         {
85             applicationManagerAPIs.DeleteRecentApplication(appId);
86         }
87
88
89         /// <summary>
90         /// Gets the information of the recent applications
91         /// </summary>
92         /// <returns>The list of the recent applications</returns>
93         public IEnumerable<RecentApp> GetRecentApplications()
94         {
95             return applicationManagerAPIs.GetRecentApplications();
96         }
97
98         /// <summary>
99         /// Gets the information of the specified application with the app ID
100         /// </summary>
101         /// <param name="appID">The app Id to get</param>
102         /// <returns>The information of the installed application</returns>
103         public InstalledApp GetInstalledApplication(string appID)
104         {
105             return applicationManagerAPIs.GetInstalledApplication(appID);
106         }
107
108         /// <summary>
109         /// Gets the information of the installed applications asynchronously
110         /// </summary>
111         /// <returns>The list of the installed applications</returns>
112         public Task<IEnumerable<InstalledApp>> GetAllInstalledApplication()
113         {
114             return applicationManagerAPIs.GetAllInstalledApplication();
115         }
116
117         /// <summary>
118         /// Checks whether application is removable
119         /// </summary>
120         /// <param name="appID">The app ID to get</param>
121         /// <returns>If the application is removable, true; otherwise, false</returns>
122         public bool GetAppInfoRemovable(string appID)
123         {
124             return applicationManagerAPIs.GetAppInfoRemovable(appID);
125         }
126
127         /// <summary>
128         /// Gets the app ID by the app label
129         /// </summary>
130         /// <param name="appLabel">the app label to get</param>
131         /// <returns>the app ID of the app label</returns>
132         public Task<string> GetAppIDbyAppLabel(string appLabel)
133         {
134             return applicationManagerAPIs.GetAppIDbyAppLabel(appLabel);
135         }
136     }
137 }