[Tizen.Applications] Fix static analysis issues (#5389)
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.RemoteView / Tizen.Applications / RemoteView.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 ElmSharp;
18 using System;
19 using System.Runtime.InteropServices;
20
21 namespace Tizen.Applications
22 {
23     /// <summary>
24     /// Represents the proxy class for the widget application.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     [Obsolete("Deprecated since API10. Will be removed in API12.")]
28     public class RemoteView
29     {
30         /// <summary>
31         /// The event types to send.
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         [Obsolete("Deprecated since API10. Will be removed in API12.")]
35         public enum Event
36         {
37             /// <summary>
38             /// Type for feeding the mouse-up event to the widget application.
39             /// </summary>
40             FeedMouseUp,
41
42             /// <summary>
43             /// Type for canceling the click event procedure.
44             /// </summary>
45             CancelClick
46         }
47
48         /// <summary>
49         /// Layout object including preview image, overlay text, loading text, and remote screen image.
50         /// </summary>
51         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
52         /// <since_tizen> 3 </since_tizen>
53         [Obsolete("Deprecated since API10. Will be removed in API12.")]
54         public Layout Layout { get; internal set; }
55
56         /// <summary>
57         /// The widget ID.
58         /// </summary>
59         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
60         /// <since_tizen> 3 </since_tizen>
61         [Obsolete("Deprecated since API10. Will be removed in API12.")]
62         public string Id
63         {
64             get
65             {
66                 IntPtr ptr = Interop.WidgetViewerEvas.GetWidgetId(Layout);
67
68                 return Marshal.PtrToStringAnsi(ptr);
69             }
70         }
71
72         /// <summary>
73         /// The update period.
74         /// </summary>
75         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
76         /// <since_tizen> 3 </since_tizen>
77         [Obsolete("Deprecated since API10. Will be removed in API12.")]
78         public double Period
79         {
80             get
81             {
82                 return Interop.WidgetViewerEvas.GetPeriod(Layout);
83             }
84         }
85
86         /// <summary>
87         /// Contents of the widget.
88         /// </summary>
89         /// <remarks>
90         /// This string can be used for creating contents of the widget again after rebooting a device or it can be recovered from a crash (abnormal status).
91         /// </remarks>
92         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
93         /// <since_tizen> 3 </since_tizen>
94         [Obsolete("Deprecated since API10. Will be removed in API12.")]
95         public string Content
96         {
97             get
98             {
99                 IntPtr ptr = Interop.WidgetViewerEvas.GetContentInfo(Layout);
100
101                 return Marshal.PtrToStringAnsi(ptr);
102             }
103         }
104
105         /// <summary>
106         /// Summarized string of the widget content for accessibility.
107         /// </summary>
108         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
109         /// <since_tizen> 3 </since_tizen>
110         [Obsolete("Deprecated since API10. Will be removed in API12.")]
111         public string Title
112         {
113             get
114             {
115                 IntPtr ptr = Interop.WidgetViewerEvas.GetTitleString(Layout);
116
117                 return Marshal.PtrToStringAnsi(ptr);
118             }
119         }
120
121         internal RemoteView()
122         {
123         }
124
125         internal static void CheckException(Interop.WidgetViewerEvas.ErrorCode err)
126         {
127             switch (err)
128             {
129                 case Interop.WidgetViewerEvas.ErrorCode.Fault:
130                     throw new InvalidOperationException("Fault at unmanaged code");
131
132                 case Interop.WidgetViewerEvas.ErrorCode.PermissionDenied:
133                     throw new UnauthorizedAccessException();
134
135                 case Interop.WidgetViewerEvas.ErrorCode.NotSupported:
136                     throw new NotSupportedException();
137
138                 case Interop.WidgetViewerEvas.ErrorCode.InvalidParameter:
139                     throw new InvalidOperationException("Invalid parameter error at unmanaged code");
140
141                 case Interop.WidgetViewerEvas.ErrorCode.AlreadyExist:
142                     throw new InvalidOperationException("Already exist");
143
144                 case Interop.WidgetViewerEvas.ErrorCode.MaxExceeded:
145                     throw new InvalidOperationException("Max exceeded");
146
147                 case Interop.WidgetViewerEvas.ErrorCode.Disabled:
148                     throw new InvalidOperationException("Disabled");
149
150                 default:
151                     throw new InvalidOperationException("Invalid Operation");
152             }
153         }
154
155         /// <summary>
156         /// Pauses all the connected widget applications.
157         /// </summary>
158         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
159         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
160         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
161         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
162         /// <since_tizen> 3 </since_tizen>
163         [Obsolete("Deprecated since API10. Will be removed in API12.")]
164         public static void PauseAll()
165         {
166             CheckException(Interop.WidgetViewerEvas.NotifyPausedStatusOfViewer());
167         }
168
169         /// <summary>
170         /// Resumes all the connected widget applications.
171         /// </summary>
172         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
173         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
174         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
175         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
176         /// <since_tizen> 3 </since_tizen>
177         [Obsolete("Deprecated since API10. Will be removed in API12.")]
178         public static void ResumeAll()
179         {
180             CheckException(Interop.WidgetViewerEvas.NotifyResumedStatusOfViewer());
181         }
182
183         /// <summary>
184         /// Pauses the widget application which is connected on this proxy.
185         /// </summary>
186         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
187         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
188         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
189         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
190         /// <since_tizen> 3 </since_tizen>
191         [Obsolete("Deprecated since API10. Will be removed in API12.")]
192         public void Pause()
193         {
194             CheckException(Interop.WidgetViewerEvas.PauseWidget(Layout));
195         }
196
197         /// <summary>
198         /// Resumes the widget application which is connected on this proxy.
199         /// </summary>
200         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
201         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
202         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
203         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
204         /// <since_tizen> 3 </since_tizen>
205         [Obsolete("Deprecated since API10. Will be removed in API12.")]
206         public void Resume()
207         {
208             CheckException(Interop.WidgetViewerEvas.ResumeWidget(Layout));
209         }
210
211         /// <summary>
212         /// Sends the event to the widget application which is connected on this proxy.
213         /// </summary>
214         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
215         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
216         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
217         /// <since_tizen> 3 </since_tizen>
218         [Obsolete("Deprecated since API10. Will be removed in API12.")]
219         public void SendEvent(Event ev)
220         {
221             switch (ev)
222             {
223                 case Event.FeedMouseUp:
224                     Interop.WidgetViewerEvas.FeedMouseUpEvent(Layout);
225                     break;
226
227                 case Event.CancelClick:
228                     Interop.WidgetViewerEvas.CancelClickEvent(Layout);
229                     break;
230
231                 default:
232                     throw new NotSupportedException("Not supported event type");
233             }
234
235             int err = Internals.Errors.ErrorFacts.GetLastResult();
236             CheckException((Interop.WidgetViewerEvas.ErrorCode)err);
237         }
238
239         internal void HideLoadingMessage()
240         {
241             Interop.WidgetViewerEvas.DisableLoading(Layout);
242             int err = Internals.Errors.ErrorFacts.GetLastResult();
243             CheckException((Interop.WidgetViewerEvas.ErrorCode)err);
244         }
245
246         internal void HidePreviewImage()
247         {
248             Interop.WidgetViewerEvas.DisablePreview(Layout);
249             int err = Internals.Errors.ErrorFacts.GetLastResult();
250             CheckException((Interop.WidgetViewerEvas.ErrorCode)err);
251         }
252
253         internal void HideOverlayText()
254         {
255             Interop.WidgetViewerEvas.DisableOverlayText(Layout);
256             int err = Internals.Errors.ErrorFacts.GetLastResult();
257             CheckException((Interop.WidgetViewerEvas.ErrorCode)err);
258         }
259
260     }
261 }