403d8eb94e4a6d00a541e1313bc591fc598f4279
[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
22 namespace LibTVRefCommonTizen.Ports
23 {
24     /// <summary>
25     /// Handles the Appcontrol APIs
26     /// </summary>
27     public class AppControlPort : IAppControl
28     {
29         /// <summary>
30         /// The app ID of TV reference home application
31         /// </summary>
32         // TODO : change application later
33         public static string TVHomeAppID = "org.tizen.xahome";
34
35         /// <summary>
36         /// The app ID of TV reference apps-tray application
37         /// </summary>
38         public static string TVAppsAppID = "org.tizen.xaapps";
39
40         /// <summary>
41         /// Represents the operation to be performed between TVHome and TVApps
42         /// This operation is sended from TVHomes to TVApps
43         /// </summary>
44         public static string AddAppOperation = "http://xahome.tizen.org/appcontrol/operation/add_app";
45
46         /// <summary>
47         /// Represents the operation to be performed between TVHome and TVApps
48         /// This operation is sended from TVApps to TVHome
49         /// </summary>
50         public static string AppAddedNotifyOperation = "http://xahome.tizen.org/appcontrol/operation/app_added";
51
52         public static string KeyAddedAppID = "AddedAppID";
53
54         /// <summary>
55         /// Sends the launch request
56         /// </summary>
57         /// <param name="AppId"> The app ID to explicitly launch</param>
58         public void SendLaunchRequest(string AppId)
59         {
60             try
61             {
62                 AppControl appControl = new AppControl();
63
64                 if (AppId == null || AppId.Length <= 0)
65                 {
66                     DebuggingUtils.Err("The AppID is null or blank");
67                     return;
68                 }
69
70                 appControl.ApplicationId = AppId;
71
72                 AppControl.SendLaunchRequest(appControl);
73             }
74             catch (InvalidOperationException)
75             {
76                 DebuggingUtils.Err("Failed to create AppControl");
77             }
78         }
79
80         /// <summary>
81         /// Sends the 'Add PIN apps' operation to TV Apps
82         /// </summary>
83         public void SendAddAppRequestToApps()
84         {
85             AppControl appControl = new AppControl()
86             {
87                 ApplicationId = TVAppsAppID,
88                 Operation = AddAppOperation,
89             };
90             AppControl.SendLaunchRequest(appControl);
91         }
92
93         /// <summary>
94         /// Sends the pinned app ID to TV Home
95         /// </summary>
96         /// <param name="addedAddID">The app ID to add PIN list int the TV Home</param>
97         public void SendAppAddedNotificationToHome(string addedAddID)
98         {
99             AppControl appControl = new AppControl()
100             {
101                 ApplicationId = TVHomeAppID,
102                 Operation = AppAddedNotifyOperation,
103             };
104             appControl.ExtraData.Add(KeyAddedAppID, addedAddID);
105             AppControl.SendLaunchRequest(appControl);
106         }
107     }
108 }