Remove default pinned app.
[profile/tv/apps/dotnet/home.git] / LibTVRefCommonTizen / Ports / AppControlPort.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
18 using System;
19 using LibTVRefCommonPortable.Utils;
20 using Tizen.Applications;
21 using System.Collections.Generic;
22
23 namespace LibTVRefCommonTizen.Ports
24 {
25     /// <summary>
26     /// Handles the Appcontrol APIs
27     /// </summary>
28     public class AppControlPort : IAppControl
29     {
30         /// <summary>
31         /// The app ID of TV reference home application
32         /// </summary>
33         // TODO : change application later
34         public static string TVHomeAppID = "org.tizen.xahome";
35
36         /// <summary>
37         /// The app ID of TV reference apps-tray application
38         /// </summary>
39         public static string TVAppsAppID = "org.tizen.xaapps";
40
41         /// <summary>
42         /// Represents the operation to be performed between TVHome and TVApps
43         /// This operation is sended from TVHomes to TVApps
44         /// </summary>
45         public static string AddAppOperation = "http://xahome.tizen.org/appcontrol/operation/add_app";
46
47         /// <summary>
48         /// Represents the operation to be performed between TVHome and TVApps
49         /// This operation is sended from TVApps to TVHome
50         /// </summary>
51         public static string AppAddedNotifyOperation = "http://xahome.tizen.org/appcontrol/operation/app_added";
52
53         public static string KeyAddedAppID = "AddedAppID";
54
55         /// <summary>
56         /// Sends the launch request
57         /// </summary>
58         /// <param name="AppId"> The app ID to explicitly launch</param>
59         public void SendLaunchRequest(string AppId)
60         {
61             try
62             {
63                 AppControl appControl = new AppControl();
64
65                 if (AppId == null || AppId.Length <= 0)
66                 {
67                     DebuggingUtils.Err("The AppID is null or blank");
68                     return;
69                 }
70
71                 appControl.ApplicationId = AppId;
72
73                 AppControl.SendLaunchRequest(appControl);
74             }
75             catch (InvalidOperationException)
76             {
77                 DebuggingUtils.Err("Failed to create AppControl");
78             }
79         }
80
81         /// <summary>
82         /// Sends the launch request
83         /// </summary>
84         /// <param name="AppId"> The app ID to explicitly launch</param>
85         /// <param name="extraData">The extra data for the app control</param>
86         public void SendLaunchRequest(string AppId, IDictionary<string, string> extraData)
87         {
88             try
89             {
90                 AppControl appControl = new AppControl();
91
92                 if (AppId == null || AppId.Length <= 0)
93                 {
94                     DebuggingUtils.Err("The AppID is null or blank");
95                     return;
96                 }
97
98                 string value;
99
100                 appControl.ApplicationId = AppId;
101                 foreach (var key in extraData.Keys)
102                 {
103                     if (extraData.TryGetValue(key, out value))
104                     {
105                         appControl.ExtraData.Add(key, value);
106                     }
107                 }
108
109                 AppControl.SendLaunchRequest(appControl);
110             }
111             catch (InvalidOperationException)
112             {
113                 DebuggingUtils.Err("Failed to create AppControl");
114             }
115         }
116
117         /// <summary>
118         /// Sends the 'Add PIN apps' operation to TV Apps
119         /// </summary>
120         public void SendAddAppRequestToApps()
121         {
122             AppControl appControl = new AppControl()
123             {
124                 ApplicationId = TVAppsAppID,
125                 Operation = AddAppOperation,
126             };
127             AppControl.SendLaunchRequest(appControl);
128         }
129
130         /// <summary>
131         /// Sends the pinned app ID to TV Home
132         /// </summary>
133         /// <param name="addedAddID">The app ID to add PIN list int the TV Home</param>
134         public void SendAppAddedNotificationToHome(string addedAddID)
135         {
136             AppControl appControl = new AppControl()
137             {
138                 ApplicationId = TVHomeAppID,
139                 Operation = AppAddedNotifyOperation,
140             };
141             appControl.ExtraData.Add(KeyAddedAppID, addedAddID);
142             AppControl.SendLaunchRequest(appControl);
143         }
144     }
145 }