6365ea0c83b49cf0ae410c13b5dfb7b3a2cc26f4
[platform/core/csapi/tizenfx.git] / src / Tizen.System.Feedback / Feedback / Feedback.cs
1 /*
2 * Copyright (c) 2018 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 System;
18 using System.Collections.Generic;
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
21
22
23 namespace Tizen.System
24 {
25     /// <summary>
26     /// The Feedback API provides functions to control haptic and sound.
27     /// The Feedback API provides the way to play and stop feedback, and get the information whether a specific pattern is supported.
28     /// Below is the supported pattern string:
29     /// Tap
30     /// SoftInputPanel
31     /// Key0
32     /// Key1
33     /// Key2
34     /// Key3
35     /// Key4
36     /// Key5
37     /// Key6
38     /// Key7
39     /// Key8
40     /// Key9
41     /// KeyStar
42     /// KeySharp
43     /// KeyBack
44     /// Hold
45     /// HardwareKeyPressed
46     /// HardwareKeyHold
47     /// Message
48     /// Email
49     /// WakeUp
50     /// Schedule
51     /// Timer
52     /// General
53     /// PowerOn
54     /// PowerOff
55     /// ChargerConnected
56     /// ChargingError
57     /// FullyCharged
58     /// LowBattery
59     /// Lock
60     /// UnLock
61     /// VibrationModeAbled
62     /// SilentModeDisabled
63     /// BluetoothDeviceConnected
64     /// BluetoothDeviceDisconnected
65     /// ListReorder
66     /// ListSlider
67     /// VolumeKeyPressed
68     /// </summary>
69     /// <privilege>
70     /// For controlling the haptic device:
71     /// http://tizen.org/privilege/haptic
72     /// For controlling the sound, privilege is not needed.
73     /// </privilege>
74     /// <example>
75     /// <code>
76     /// Feedback feedback = new Feedback();
77     /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
78     /// </code>
79     /// </example>
80     /// <since_tizen> 3 </since_tizen>
81     public class Feedback
82     {
83         private const string LogTag = "Tizen.System.Feedback";
84
85         private readonly Dictionary<string, int> Pattern = new Dictionary<string, int>
86         {
87             {"Tap", 0},
88             {"SoftInputPanel", 1},
89             {"SipBackspace", 2},
90             {"SipFunction", 3},
91             {"SipFjkey", 4},
92             {"MaxCharacter", 5},
93             {"Key0", 6},
94             {"Key1", 7},
95             {"Key2", 8},
96             {"Key3", 9},
97             {"Key4", 10},
98             {"Key5", 11},
99             {"Key6", 12},
100             {"Key7", 13},
101             {"Key8", 14},
102             {"Key9", 15},
103             {"KeyStar", 16},
104             {"KeySharp", 17},
105             {"KeyBack", 18},
106             {"Hold", 19},
107             {"MultiTap", 20},
108             {"HardwareKeyPressed", 21},
109             {"HardwareKeyHold", 22},
110             {"Message", 23},
111             {"MessageOnCall", 24},
112             {"Email", 25},
113             {"EmailOnCall", 26},
114             {"WakeUp", 27},
115             {"WakeUpOnCall", 28},
116             {"Schedule", 29},
117             {"ScheduleOnCall", 30},
118             {"Timer", 31},
119             {"TimerOnCall", 32},
120             {"General", 33},
121             {"GeneralOnCall", 34},
122             {"SmartAlert", 35},
123             {"PowerOn", 36},
124             {"PowerOff", 37},
125             {"ChargerConnected", 38},
126             {"ChargerconnOnCall", 39},
127             {"ChargingError", 40},
128             {"ChargingErrorOnCall", 41},
129             {"FullyCharged", 42},
130             {"FullchargedOnCall", 43},
131             {"LowBattery", 44},
132             {"LowBattOnCall", 45},
133             {"Lock", 46},
134             {"UnLock", 47},
135             {"GeometricLock", 50},
136             {"Callconnect", 51},
137             {"Discallconnect", 52},
138             {"OutgoingCall", 53},
139             {"Minuteminder", 54},
140             {"VibrationModeAbled", 55},
141             {"SilentModeDisabled", 56},
142             {"BluetoothDeviceConnected", 57},
143             {"BluetoothDeviceDisconnected", 58},
144             {"BtPairing", 59},
145             {"BtWaiting", 60},
146             {"ScreenCapture", 61},
147             {"ListReorder", 62},
148             {"ListSlider", 63},
149             {"VolumeKeyPressed", 64},
150             {"UvProcessing", 95},
151             {"ShealthStart", 96},
152             {"ShealthPause", 97},
153             {"ShealthStop", 98},
154             {"3rdApplication", 99},
155             {"Tick", 100},
156             {"TransitionCircular", 101},
157             {"TransitionPop", 102},
158             {"Process", 103},
159             {"MoveList", 104},
160             {"Dismiss", 105},
161             {"ClockSecondHand", 106},
162             {"SystemShort", 107},
163             {"SystemError", 108},
164             {"SpiralDown", 109},
165             {"MoveList2", 110},
166             {"SpiralUp", 111},
167             {"SystemLong", 112},
168             {"SystemMid", 113},
169             {"Silence", 114},
170             {"InactiveTension", 115},
171             {"InactiveFine", 116},
172             {"EndEffect", 117},
173             {"ShealthNotice", 118},
174             {"ShealthGentleAlert", 119},
175             {"EndEffectFine", 120},
176             {"ClickValue", 121},
177             {"ClickFineTrain1", 122},
178             {"ClickFine", 123},
179             {"ClickSlider", 124},
180             {"ClickMedium", 125},
181             {"ClickStrong", 126},
182             {"TurnRight", 127},
183             {"TurnLeft", 128},
184             {"Function", 129},
185             {"VoiceStart", 130},
186             {"VoiceStop", 131},
187             {"Communication", 132},
188             {"MessageStrongBuzz", 133},
189             {"EmailStrongBuzz", 134},
190             {"GeneralStrongBuzz", 135},
191             {"CommunicationStrongBuzz", 136},
192             {"ScheduleStrongBuzz", 137},
193             {"WakeupStrongBuzz", 138},
194             {"TimerStrongBuzz", 139},
195             {"RingerStrongBuzz", 140},
196             {"Heartbeat", 141},
197             {"HeartbeatFast", 142},
198             {"SettingOn", 143},
199             {"SettingOff", 144},
200             {"Connect", 145},
201             {"Disconnect", 146},
202             {"FindMyGear", 147},
203             {"Notification1", 148},
204             {"Notification1StrongBuzz", 149},
205             {"Notification2", 150},
206             {"Notification2StrongBuzz", 151},
207             {"Notification3", 152},
208             {"Notification3StrongBuzz", 153},
209             {"Notification4", 154},
210             {"Notification4StrongBuzz", 155},
211             {"Notification5", 156},
212             {"Notification5StrongBuzz", 157},
213             {"Notification6", 158},
214             {"Notification6StrongBuzz", 159},
215             {"Notification7", 160},
216             {"Notification7StrongBuzz", 161},
217             {"Notification8", 162},
218             {"Notification8StrongBuzz", 163},
219             {"Notification9", 164},
220             {"Notification9StrongBuzz", 165},
221             {"Notification10", 166},
222             {"Notification10StrongBuzz", 167},
223             {"Ring1", 168},
224             {"Ring1StrongBuzz", 169},
225             {"Ring2", 170},
226             {"Ring2StrongBuzz", 171},
227             {"Ring3", 172},
228             {"Ring3StrongBuzz", 173},
229             {"Ring4", 174},
230             {"Ring4StrongBuzz", 175},
231             {"Ring5", 176},
232             {"Ring5StrongBuzz", 177},
233             {"Ring6", 178},
234             {"Ring6StrongBuzz", 179},
235             {"Ring7", 180},
236             {"Ring7StrongBuzz", 181},
237             {"Ring8", 182},
238             {"Ring8StrongBuzz", 183},
239             {"Ring9", 184},
240             {"Ring9StrongBuzz", 185},
241             {"Ring10", 186},
242             {"Ring10StrongBuzz", 187},
243             {"Alarm1", 188},
244             {"Alarm1StrongBuzz", 189},
245             {"Alarm2", 190},
246             {"Alarm2StrongBuzz", 191},
247             {"Alarm3", 192},
248             {"Alarm3StrongBuzz", 193},
249             {"Alarm4", 194},
250             {"Alarm4StrongBuzz", 195},
251             {"Alarm5", 196},
252             {"Alarm5StrongBuzz", 197},
253             {"Alarm6", 198},
254             {"Alarm6StrongBuzz", 199},
255             {"Alarm7", 200},
256             {"Alarm7StrongBuzz", 201},
257             {"Alarm8", 202},
258             {"Alarm8StrongBuzz", 203},
259             {"Alarm9", 204},
260             {"Alarm9StrongBuzz", 205},
261             {"Alarm10", 206},
262             {"Alarm10StrongBuzz", 207},
263             {"Picker", 208},
264             {"PickerFinish", 209},
265             {"OnOffSwitch", 210},
266             {"Reorder", 211},
267             {"CursorMove", 212},
268             {"Mms", 10000},
269             {"HourlyAlert", 10001},
270             {"SafetyAlert", 10002},
271             {"AccidentDetect", 10003},
272             {"SendSosMessage", 10004},
273             {"EndSosMessage", 10005},
274             {"EmergencyBuzzer", 10006},
275             {"SafetyLowPower", 10007},
276             {"Cmas", 10008},
277             {"Ringer", 10009},
278             {"Notification", 10010},
279             {"Info", 10011},
280             {"Warning", 10012},
281             {"Error", 10013},
282             {"Emergency", 10014},
283             {"InternalWakeup", 10015},
284             {"InternalTimer", 10016},
285             {"TemperatureWarning", 10017},
286             {"CooldownWarning1", 10018},
287             {"CooldownWarning2", 10019},
288             {"SpeedUp", 10020},
289             {"SlowDown", 10021},
290             {"KeepThisPace", 10022},
291             {"GoalAchieved", 10023},
292             {"ExerciseCount", 10024},
293             {"StartCue", 10025},
294             {"HealthPace", 10026},
295             {"InactiveTime", 10027},
296             {"CmasCa", 10028},
297             {"NfcSuccess", 10029},
298             {"MeasuringSuccess", 10030},
299             {"MeasuringFailure", 10031},
300             {"Meditation", 10032},
301             {"MeditationInternal", 10033},
302             {"FallDetection1", 10034},
303             {"FallDetection2", 10035},
304             {"SmartGesture", 10036},
305             {"BreathingExhale", 12000},
306             {"Bos", 12001},
307             {"Eos", 12002},
308             {"Uds", 12003},
309             {"Basic", 40001},
310             {"ToggleOn", 40002},
311             {"ToggleOff", 40003},
312             {"LongPressOn", 40004},
313             {"LongPressOff", 40005},
314             {"Invalid", 40006},
315             {"Confirm", 40007},
316             {"PopUp", 40008},
317             {"PreheatEnding", 40009},
318             {"TaskEnding", 40010},
319             {"Scroll", 40011},
320             {"PageTurn", 40012},
321             {"OpStart", 40013},
322             {"OpPause", 40014},
323             {"OpStop", 40015},
324             {"Default", 40016},
325             {"DefaultLevel1", 40017},
326             {"Level1", 40018},
327             {"Level2", 40019},
328             {"Level3", 40020},
329             {"Level4", 40021},
330             {"Level5", 40022},
331             {"Level6", 40023},
332             {"Level7", 40024},
333             {"Level8", 40025},
334             {"Level9", 40026},
335             {"Level10", 40027},
336             {"TimerEnding", 40028},
337             {"BurnerDetected", 40029},
338             {"BurnerMoved", 40030},
339             {"Connected", 40031},
340             {"Disconnected", 40032},
341             {"Welcome", 40033},
342             {"AutoDoorOpen", 40034},
343         };
344
345         /// <summary>
346         /// Constructor of Feedback class
347         /// </summary>
348         /// <since_tizen> 3 </since_tizen>
349         /// <feature>
350         /// http://tizen.org/feature/feedback.vibration for FeedbackType.Vibration
351         /// </feature>
352         /// <exception cref="NotSupportedException">Thrown when failed because the devices (vibration and sound) are not supported.</exception>
353         /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
354         /// <privilege>http://tizen.org/privilege/haptic</privilege>
355         /// <example>
356         /// <code>
357         /// Feedback feedback = new Feedback();
358         /// </code>
359         /// </example>
360         public Feedback()
361         {
362             Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Initialize();
363             if (res != Interop.Feedback.FeedbackError.None)
364             {
365                 Log.Warn(LogTag, string.Format("Failed to initialize feedback. err = {0}", res));
366                 switch (res)
367                 {
368                     case Interop.Feedback.FeedbackError.NotSupported:
369                         throw new NotSupportedException("Device is not supported");
370                     default:
371                         throw new InvalidOperationException("Failed to initialize");
372                 }
373             }
374         }
375
376         /// <summary>
377         /// Finalizes an instance of the Feedback class.
378         /// </summary>
379         ~Feedback()
380         {
381             Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Deinitialize();
382             if (res != Interop.Feedback.FeedbackError.None)
383             {
384                 Log.Warn(LogTag, string.Format("Failed to deinitialize feedback. err = {0}", res));
385             }
386         }
387
388         /// <summary>
389         /// Gets the supported information about a specific type and pattern.
390         /// </summary>
391         /// <remarks>
392         /// Now, IsSupportedPattern is not working for FeedbackType.All.
393         /// This API is working for FeedbackType.Sound and FeedbackType.Vibration only.
394         /// If you use FeedbackType.All for type parameter, this API will throw ArgumentException.
395         /// To get the supported information for Vibration type, the application should have http://tizen.org/privilege/haptic privilege.
396         /// </remarks>
397         /// <since_tizen> 3 </since_tizen>
398         /// <param name="type">The feedback type.</param>
399         /// <param name="pattern">The feedback pattern string.</param>
400         /// <feature>
401         /// http://tizen.org/feature/feedback.vibration for FeedbackType.Vibration
402         /// </feature>
403         /// <returns>Information whether a pattern is supported.</returns>
404         /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
405         /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
406         /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
407         /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted (No privilege).</exception>
408         /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
409         /// <privilege>http://tizen.org/privilege/haptic</privilege>
410         /// <example>
411         /// <code>
412             /// Feedback feedback = new Feedback();
413         /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
414         /// </code>
415         /// </example>
416         public bool IsSupportedPattern(FeedbackType type, String pattern)
417         {
418             bool supported = false;
419             int number;
420             Interop.Feedback.FeedbackError res;
421
422             if (!Pattern.TryGetValue(pattern, out number))
423                 throw new ArgumentException($"Not supported pattern string : {pattern}", nameof(pattern));
424
425             res = (Interop.Feedback.FeedbackError)Interop.Feedback.IsSupportedPattern((Interop.Feedback.FeedbackType)type, number, out supported);
426
427             if (res != Interop.Feedback.FeedbackError.None)
428             {
429                 Log.Warn(LogTag, string.Format("Failed to get supported information. err = {0}", res));
430                 switch (res)
431                 {
432                     case Interop.Feedback.FeedbackError.NotInitialized:
433                         throw new Exception("Not initialized");
434                     case Interop.Feedback.FeedbackError.InvalidParameter:
435                         throw new ArgumentException("Invalid Arguments");
436                     case Interop.Feedback.FeedbackError.NotSupported:
437                         throw new NotSupportedException("Device is not supported");
438                     case Interop.Feedback.FeedbackError.PermissionDenied:
439                         throw new UnauthorizedAccessException("Access is not granted");
440                     case Interop.Feedback.FeedbackError.OperationFailed:
441                     default:
442                         throw new InvalidOperationException("Failed to get supported information");
443                 }
444             }
445             return supported;
446         }
447
448         /// <summary>
449         /// Plays a specific feedback pattern.
450         /// </summary>
451         /// <remarks>
452         /// To play Vibration type, app should have http://tizen.org/privilege/haptic privilege.
453         /// </remarks>
454         /// <since_tizen> 3 </since_tizen>
455         /// <param name="type">The feedback type.</param>
456         /// <param name="pattern">The feedback pattern string.</param>
457         /// <feature>
458         /// http://tizen.org/feature/feedback.vibration for FeedbackType.Vibration
459         /// </feature>
460         /// <exception cref="Exception">Thrown when failed because feedback is not initialized.</exception>
461         /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
462         /// <exception cref="NotSupportedException">Thrown when failed because the device (haptic, sound) or a specific pattern is not supported.</exception>
463         /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted(No privilege)</exception>
464         /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
465         /// <privilege>http://tizen.org/privilege/haptic</privilege>
466         /// <example>
467         /// <code>
468         /// Feedback feedback = new Feedback();
469         /// feedback.Play(FeedbackType.All, "Tap");
470         /// </code>
471         /// </example>
472         public void Play(FeedbackType type, String pattern)
473         {
474             int number;
475             Interop.Feedback.FeedbackError res;
476
477             if (!Pattern.TryGetValue(pattern, out number))
478                 throw new ArgumentException($"Not supported pattern string : {pattern}", nameof(pattern));
479
480             if (type == FeedbackType.All)
481                 res = (Interop.Feedback.FeedbackError)Interop.Feedback.Play(number);
482             else
483                 res = (Interop.Feedback.FeedbackError)Interop.Feedback.PlayType((Interop.Feedback.FeedbackType)type, number);
484
485             if (res != Interop.Feedback.FeedbackError.None)
486             {
487                 Log.Warn(LogTag, string.Format("Failed to play feedback. err = {0}", res));
488                 switch (res)
489                 {
490                     case Interop.Feedback.FeedbackError.NotInitialized:
491                         throw new Exception("Not initialized");
492                     case Interop.Feedback.FeedbackError.InvalidParameter:
493                         throw new ArgumentException("Invalid Arguments");
494                     case Interop.Feedback.FeedbackError.NotSupported:
495                         throw new NotSupportedException("Not supported");
496                     case Interop.Feedback.FeedbackError.PermissionDenied:
497                         throw new UnauthorizedAccessException("Access is not granted");
498                     case Interop.Feedback.FeedbackError.OperationFailed:
499                     default:
500                         throw new InvalidOperationException("Failed to play pattern");
501                 }
502             }
503         }
504
505         /// <summary>
506         /// Stops to play the feedback.
507         /// </summary>
508         /// <remarks>
509         /// To stop vibration, the application should have http://tizen.org/privilege/haptic privilege.
510         /// </remarks>
511         /// <since_tizen> 3 </since_tizen>
512         /// <feature>
513         /// http://tizen.org/feature/feedback.vibration
514         /// </feature>
515         /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
516         /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament</exception>
517         /// <exception cref="NotSupportedException">Thrown when failed because the device (haptic, sound) or a specific pattern is not supported.</exception>
518         /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted (No privilege).</exception>
519         /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
520         /// <privilege>http://tizen.org/privilege/haptic</privilege>
521         /// <example>
522         /// <code>
523         /// Feedback Feedback1 = new Feedback();
524         /// Feedback1.Stop();
525         /// </code>
526         /// </example>
527         public void Stop()
528         {
529             Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Stop();
530
531             if (res != Interop.Feedback.FeedbackError.None)
532             {
533                 Log.Warn(LogTag, string.Format("Failed to stop feedback. err = {0}", res));
534                 switch (res)
535                 {
536                     case Interop.Feedback.FeedbackError.NotInitialized:
537                         throw new Exception("Not initialized");
538                     case Interop.Feedback.FeedbackError.InvalidParameter:
539                         throw new ArgumentException("Invalid Arguments");
540                     case Interop.Feedback.FeedbackError.NotSupported:
541                         throw new NotSupportedException("Not supported");
542                     case Interop.Feedback.FeedbackError.PermissionDenied:
543                         throw new UnauthorizedAccessException("Access is not granted");
544                     case Interop.Feedback.FeedbackError.OperationFailed:
545                     default:
546                         throw new InvalidOperationException("Failed to stop pattern");
547                 }
548             }
549         }
550
551         /// <summary>
552         /// Gets the count of theme can be used according to feedback type.
553         /// </summary>
554         /// <remarks>
555         /// Now this internal API works for FeedbackType.Sound only, FeedbackType.Vibration is not supported.
556         /// Counts of theme range will be 1 ~ N according to conf file.
557         /// </remarks>
558         /// <since_tizen> 10 </since_tizen>
559         /// <param name="type">The feedback type.</param>
560         /// <returns>The counf of theme can be used according to feedback type.</returns>
561         /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
562         /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
563         /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
564         /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
565         /// <example>
566         /// <code>
567         /// Feedback feedback = new Feedback();
568         /// uint coundOfTheme = feedback.GetCountOfThemeInternal(FeedbackType.Sound);
569         /// </code>
570         /// </example>
571         [EditorBrowsable(EditorBrowsableState.Never)]
572         public uint GetCountOfThemeInternal(FeedbackType type)
573         {
574             uint countOfTheme = 0;
575             Interop.Feedback.FeedbackError res;
576
577             res = (Interop.Feedback.FeedbackError)Interop.Feedback.GetCountOfThemeInternal((Interop.Feedback.FeedbackType)type, out countOfTheme);
578
579             if (res != Interop.Feedback.FeedbackError.None)
580             {
581                 Log.Warn(LogTag, string.Format("Failed to get count of theme internal. err = {0}", res));
582                 switch (res)
583                 {
584                     case Interop.Feedback.FeedbackError.NotInitialized:
585                         throw new Exception("Not initialized");
586                     case Interop.Feedback.FeedbackError.InvalidParameter:
587                         throw new ArgumentException("Invalid Arguments");
588                     case Interop.Feedback.FeedbackError.NotSupported:
589                         throw new NotSupportedException("Device is not supported");
590                     case Interop.Feedback.FeedbackError.OperationFailed:
591                     default:
592                         throw new InvalidOperationException("Failed to get count of theme internal");
593                 }
594             }
595             return countOfTheme;
596         }
597
598         /// <summary>
599         /// Gets the id of theme selected.
600         /// </summary>
601         /// <remarks>
602         /// Now this internal API works for FeedbackType.Sound only, FeedbackType.Vibration is not supported.
603         /// The theme id is positive value as defined in the conf file.
604         /// </remarks>
605         /// <since_tizen> 10 </since_tizen>
606         /// <param name="type">The feedback type.</param>
607         /// <returns>The id of theme selected as default theme according to feedback type.</returns>
608         /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
609         /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
610         /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
611         /// <example>
612         /// <code>
613         /// Feedback feedback = new Feedback();
614         /// uint idOfTheme = feedback.GetThemeIdInternal(FeedbackType.Sound);
615         /// </code>
616         /// </example>
617         [EditorBrowsable(EditorBrowsableState.Never)]
618         public uint GetThemeIdInternal(FeedbackType type)
619         {
620             uint countOfTheme = 0;
621             Interop.Feedback.FeedbackError res;
622
623             res = (Interop.Feedback.FeedbackError)Interop.Feedback.GetThemeIdInternal((Interop.Feedback.FeedbackType)type, out countOfTheme);
624
625             if (res != Interop.Feedback.FeedbackError.None)
626             {
627                 Log.Warn(LogTag, string.Format("Failed to get id of theme internal. err = {0}", res));
628                 switch (res)
629                 {
630                     case Interop.Feedback.FeedbackError.InvalidParameter:
631                         throw new ArgumentException("Invalid Arguments");
632                     case Interop.Feedback.FeedbackError.NotSupported:
633                         throw new NotSupportedException("Device is not supported");
634                     case Interop.Feedback.FeedbackError.OperationFailed:
635                     default:
636                         throw new InvalidOperationException("Failed to get id of theme internal");
637                 }
638             }
639             return countOfTheme;
640         }
641
642         /// <summary>
643         /// Sets the id of theme according to feedback type.
644         /// </summary>
645         /// <remarks>
646         /// Now this internal API works for FeedbackType.Sound only, FeedbackType.Vibration is not supported.
647         /// To set the id of theme for Sound type, the application should have http://tizen.org/privilege/systemsettings.admin privilege.
648         /// The theme id is positive value as defined in the conf file.
649         /// </remarks>
650         /// <since_tizen> 10 </since_tizen>
651         /// <param name="type">The feedback type.</param>
652         /// <param name="idOfTheme">The id of theme will be set.</param>
653         /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
654         /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
655         /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted(No privilege)</exception>
656         /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
657         /// <example>
658         /// <code>
659         /// Feedback feedback = new Feedback();
660         /// uint idOfTheme = 1;
661         /// feedback.SetThemeIdInternal(FeedbackType.Sound, idOfTheme);
662         /// </code>
663         /// </example>
664         [EditorBrowsable(EditorBrowsableState.Never)]
665         public void SetThemeIdInternal(FeedbackType type, uint idOfTheme)
666         {
667             Interop.Feedback.FeedbackError res;
668
669             res = (Interop.Feedback.FeedbackError)Interop.Feedback.SetThemeIdInternal((Interop.Feedback.FeedbackType)type, idOfTheme);
670
671             if (res != Interop.Feedback.FeedbackError.None)
672             {
673                 Log.Warn(LogTag, string.Format("Failed to set id of theme internal. err = {0}", res));
674                 switch (res)
675                 {
676                     case Interop.Feedback.FeedbackError.InvalidParameter:
677                         throw new ArgumentException("Invalid Arguments");
678                     case Interop.Feedback.FeedbackError.NotSupported:
679                         throw new NotSupportedException("Device is not supported");
680                     case Interop.Feedback.FeedbackError.PermissionDenied:
681                         throw new UnauthorizedAccessException("Access is not granted");
682                     case Interop.Feedback.FeedbackError.OperationFailed:
683                     default:
684                         throw new InvalidOperationException("Failed to set id of theme internal");
685                 }
686             }
687         }
688
689         /// <summary>
690         /// Stops the current feedback playing by feedback type
691         /// </summary>
692         /// <remarks>
693         /// To stop vibration, the application should have http://tizen.org/privilege/haptic privilege.
694         /// </remarks>
695         /// <since_tizen> 10 </since_tizen>
696         /// <param name="type">The feedback type.</param>
697         /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
698         /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument</exception>
699         /// <exception cref="NotSupportedException">Thrown when failed because the device (haptic, sound) or a specific pattern is not supported.</exception>
700         /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted (No privilege).</exception>
701         /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
702         /// <example>
703         /// <code>
704         /// Feedback Feedback = new Feedback();
705         /// feedback.StopTypeInternal(FeedbackType.Sound);
706         /// feedback.StopTypeInternal(FeedbackType.Vibration);
707         /// </code>
708         /// </example>
709         [EditorBrowsable(EditorBrowsableState.Never)]
710         public void StopTypeInternal(FeedbackType type)
711         {
712             Interop.Feedback.FeedbackError res;
713
714             res = (Interop.Feedback.FeedbackError)Interop.Feedback.StopTypeInternal((Interop.Feedback.FeedbackType)type);
715
716             if (res != Interop.Feedback.FeedbackError.None)
717             {
718                 Log.Warn(LogTag, string.Format("Failed to Stop feedback by feedback type internal. err = {0}", res));
719                 switch (res)
720                 {
721                     case Interop.Feedback.FeedbackError.NotInitialized:
722                         throw new Exception("Not initialized");
723                     case Interop.Feedback.FeedbackError.InvalidParameter:
724                         throw new ArgumentException("Invalid Arguments");
725                     case Interop.Feedback.FeedbackError.NotSupported:
726                         throw new NotSupportedException("Not supported");
727                     case Interop.Feedback.FeedbackError.PermissionDenied:
728                         throw new UnauthorizedAccessException("Access is not granted");
729                     case Interop.Feedback.FeedbackError.OperationFailed:
730                     default:
731                         throw new InvalidOperationException("Failed to stop pattern by feedback type");
732                 }
733             }
734         }
735
736         /// <summary>
737         /// Gets the id array of theme supported.
738         /// </summary>
739         /// <remarks>
740         /// Now this internal API works for FeedbackType.Sound only, FeedbackType.Vibration is not supported.
741         /// The theme id is positive value as defined in the conf file.
742         /// </remarks>
743         /// <since_tizen> 10 </since_tizen>
744         /// <param name="type">The feedback type.</param>
745         /// <returns>The array of theme id supported according to feedback type.</returns>
746         /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
747         /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
748         /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
749         /// <example>
750         /// <code>
751         /// Feedback feedback = new Feedback();
752         /// uint[] getThemeIds = feedback.GetThemeIdsInternal(FeedbackType.Sound);
753         /// </code>
754         /// </example>
755         [EditorBrowsable(EditorBrowsableState.Never)]
756         public uint[] GetThemeIdsInternal(FeedbackType type)
757         {
758             uint countOfTheme = 0;
759             IntPtr getThemeIds;
760             Interop.Feedback.FeedbackError res;
761
762             res = (Interop.Feedback.FeedbackError)Interop.Feedback.GetThemeIdsInternal((Interop.Feedback.FeedbackType)type, out countOfTheme, out getThemeIds);
763             if (res != Interop.Feedback.FeedbackError.None)
764             {
765                 Log.Warn(LogTag, string.Format("Failed to get ids of theme internal. err = {0}", res));
766                 switch (res)
767                 {
768                     case Interop.Feedback.FeedbackError.InvalidParameter:
769                         throw new ArgumentException("Invalid Arguments");
770                     case Interop.Feedback.FeedbackError.NotSupported:
771                         throw new NotSupportedException("Device is not supported");
772                     case Interop.Feedback.FeedbackError.OperationFailed:
773                     default:
774                         throw new InvalidOperationException("Failed to get ids of theme internal");
775                 }
776             }
777
778             uint[] themeIds = new uint[countOfTheme];
779             unsafe {
780                 uint index = 0;
781                 uint* themeIdsPointer = (uint*)getThemeIds;
782
783                 for (index = 0; index < countOfTheme; index++) {
784                     themeIds[index] = themeIdsPointer[index];
785                 }
786             }
787             Marshal.FreeHGlobal(getThemeIds);
788
789             return themeIds;
790         }
791     }
792 }