2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
19 using System.ComponentModel;
22 namespace Tizen.System
25 /// The Feedback API provides functions to control haptic and sound.
26 /// The Feedback API provides the way to play and stop feedback, and get the information whether a specific pattern is supported.
27 /// Below is the supported pattern string:
44 /// HardwareKeyPressed
60 /// VibrationModeAbled
61 /// SilentModeDisabled
62 /// BluetoothDeviceConnected
63 /// BluetoothDeviceDisconnected
69 /// For controlling the haptic device:
70 /// http://tizen.org/privilege/haptic
71 /// For controlling the sound, privilege is not needed.
75 /// Feedback feedback = new Feedback();
76 /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
79 /// <since_tizen> 3 </since_tizen>
82 private const string LogTag = "Tizen.System.Feedback";
84 private readonly Dictionary<string, int> Pattern = new Dictionary<string, int>
87 {"SoftInputPanel", 1},
107 {"HardwareKeyPressed", 21},
108 {"HardwareKeyHold", 22},
110 {"MessageOnCall", 24},
114 {"WakeUpOnCall", 28},
116 {"ScheduleOnCall", 30},
120 {"GeneralOnCall", 34},
124 {"ChargerConnected", 38},
125 {"ChargerconnOnCall", 39},
126 {"ChargingError", 40},
127 {"ChargingErrorOnCall", 41},
128 {"FullyCharged", 42},
129 {"FullchargedOnCall", 43},
131 {"LowBattOnCall", 45},
134 {"GeometricLock", 50},
136 {"Discallconnect", 52},
137 {"OutgoingCall", 53},
138 {"Minuteminder", 54},
139 {"VibrationModeAbled", 55},
140 {"SilentModeDisabled", 56},
141 {"BluetoothDeviceConnected", 57},
142 {"BluetoothDeviceDisconnected", 58},
145 {"ScreenCapture", 61},
148 {"VolumeKeyPressed", 64},
149 {"UvProcessing", 95},
150 {"ShealthStart", 96},
151 {"ShealthPause", 97},
153 {"3rdApplication", 99},
155 {"TransitionCircular", 101},
156 {"TransitionPop", 102},
160 {"ClockSecondHand", 106},
161 {"SystemShort", 107},
162 {"SystemError", 108},
169 {"InactiveTension", 115},
170 {"InactiveFine", 116},
172 {"ShealthNotice", 118},
173 {"ShealthGentleAlert", 119},
174 {"EndEffectFine", 120},
176 {"ClickFineTrain1", 122},
178 {"ClickSlider", 124},
179 {"ClickMedium", 125},
180 {"ClickStrong", 126},
186 {"Communication", 132},
187 {"MessageStrongBuzz", 133},
188 {"EmailStrongBuzz", 134},
189 {"GeneralStrongBuzz", 135},
190 {"CommunicationStrongBuzz", 136},
191 {"ScheduleStrongBuzz", 137},
192 {"WakeupStrongBuzz", 138},
193 {"TimerStrongBuzz", 139},
194 {"RingerStrongBuzz", 140},
196 {"HeartbeatFast", 142},
202 {"Notification1", 148},
203 {"Notification1StrongBuzz", 149},
204 {"Notification2", 150},
205 {"Notification2StrongBuzz", 151},
206 {"Notification3", 152},
207 {"Notification3StrongBuzz", 153},
208 {"Notification4", 154},
209 {"Notification4StrongBuzz", 155},
210 {"Notification5", 156},
211 {"Notification5StrongBuzz", 157},
212 {"Notification6", 158},
213 {"Notification6StrongBuzz", 159},
214 {"Notification7", 160},
215 {"Notification7StrongBuzz", 161},
216 {"Notification8", 162},
217 {"Notification8StrongBuzz", 163},
218 {"Notification9", 164},
219 {"Notification9StrongBuzz", 165},
220 {"Notification10", 166},
221 {"Notification10StrongBuzz", 167},
223 {"Ring1StrongBuzz", 169},
225 {"Ring2StrongBuzz", 171},
227 {"Ring3StrongBuzz", 173},
229 {"Ring4StrongBuzz", 175},
231 {"Ring5StrongBuzz", 177},
233 {"Ring6StrongBuzz", 179},
235 {"Ring7StrongBuzz", 181},
237 {"Ring8StrongBuzz", 183},
239 {"Ring9StrongBuzz", 185},
241 {"Ring10StrongBuzz", 187},
243 {"Alarm1StrongBuzz", 189},
245 {"Alarm2StrongBuzz", 191},
247 {"Alarm3StrongBuzz", 193},
249 {"Alarm4StrongBuzz", 195},
251 {"Alarm5StrongBuzz", 197},
253 {"Alarm6StrongBuzz", 199},
255 {"Alarm7StrongBuzz", 201},
257 {"Alarm8StrongBuzz", 203},
259 {"Alarm9StrongBuzz", 205},
261 {"Alarm10StrongBuzz", 207},
263 {"PickerFinish", 209},
264 {"OnOffSwitch", 210},
268 {"HourlyAlert", 10001},
269 {"SafetyAlert", 10002},
270 {"AccidentDetect", 10003},
271 {"SendSosMessage", 10004},
272 {"EndSosMessage", 10005},
273 {"EmergencyBuzzer", 10006},
274 {"SafetyLowPower", 10007},
277 {"Notification", 10010},
281 {"Emergency", 10014},
282 {"InternalWakeup", 10015},
283 {"InternalTimer", 10016},
284 {"TemperatureWarning", 10017},
285 {"CooldownWarning1", 10018},
286 {"CooldownWarning2", 10019},
289 {"KeepThisPace", 10022},
290 {"GoalAchieved", 10023},
291 {"ExerciseCount", 10024},
293 {"HealthPace", 10026},
294 {"InactiveTime", 10027},
296 {"NfcSuccess", 10029},
297 {"MeasuringSuccess", 10030},
298 {"MeasuringFailure", 10031},
299 {"Meditation", 10032},
300 {"MeditationInternal", 10033},
301 {"FallDetection1", 10034},
302 {"FallDetection2", 10035},
303 {"SmartGesture", 10036},
304 {"BreathingExhale", 12000},
310 {"ToggleOff", 40003},
311 {"LongPressOn", 40004},
312 {"LongPressOff", 40005},
316 {"PreheatEnding", 40009},
317 {"TaskEnding", 40010},
324 {"DefaultLevel1", 40017},
335 {"TimerEnding", 40028},
336 {"BurnerDetected", 40029},
337 {"BurnerMoved", 40030},
338 {"Connected", 40031},
339 {"Disconnected", 40032},
341 {"AutoDoorOpen", 40034},
345 /// Constructor of Feedback class
347 /// <since_tizen> 3 </since_tizen>
349 /// http://tizen.org/feature/feedback.vibration for FeedbackType.Vibration
351 /// <exception cref="NotSupportedException">Thrown when failed because the devices (vibration and sound) are not supported.</exception>
352 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
353 /// <privilege>http://tizen.org/privilege/haptic</privilege>
356 /// Feedback feedback = new Feedback();
361 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Initialize();
362 if (res != Interop.Feedback.FeedbackError.None)
364 Log.Warn(LogTag, string.Format("Failed to initialize feedback. err = {0}", res));
367 case Interop.Feedback.FeedbackError.NotSupported:
368 throw new NotSupportedException("Device is not supported");
370 throw new InvalidOperationException("Failed to initialize");
376 /// Finalizes an instance of the Feedback class.
380 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Deinitialize();
381 if (res != Interop.Feedback.FeedbackError.None)
383 Log.Warn(LogTag, string.Format("Failed to deinitialize feedback. err = {0}", res));
388 /// Gets the supported information about a specific type and pattern.
391 /// Now, IsSupportedPattern is not working for FeedbackType.All.
392 /// This API is working for FeedbackType.Sound and FeedbackType.Vibration only.
393 /// If you use FeedbackType.All for type parameter, this API will throw ArgumentException.
394 /// To get the supported information for Vibration type, the application should have http://tizen.org/privilege/haptic privilege.
396 /// <since_tizen> 3 </since_tizen>
397 /// <param name="type">The feedback type.</param>
398 /// <param name="pattern">The feedback pattern string.</param>
400 /// http://tizen.org/feature/feedback.vibration for FeedbackType.Vibration
402 /// <returns>Information whether a pattern is supported.</returns>
403 /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
404 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
405 /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
406 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted (No privilege).</exception>
407 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
408 /// <privilege>http://tizen.org/privilege/haptic</privilege>
411 /// Feedback feedback = new Feedback();
412 /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
415 public bool IsSupportedPattern(FeedbackType type, String pattern)
417 bool supported = false;
419 Interop.Feedback.FeedbackError res;
421 if (!Pattern.TryGetValue(pattern, out number))
422 throw new ArgumentException($"Not supported pattern string : {pattern}", nameof(pattern));
424 res = (Interop.Feedback.FeedbackError)Interop.Feedback.IsSupportedPattern((Interop.Feedback.FeedbackType)type, number, out supported);
426 if (res != Interop.Feedback.FeedbackError.None)
428 Log.Warn(LogTag, string.Format("Failed to get supported information. err = {0}", res));
431 case Interop.Feedback.FeedbackError.NotInitialized:
432 throw new Exception("Not initialized");
433 case Interop.Feedback.FeedbackError.InvalidParameter:
434 throw new ArgumentException("Invalid Arguments");
435 case Interop.Feedback.FeedbackError.NotSupported:
436 throw new NotSupportedException("Device is not supported");
437 case Interop.Feedback.FeedbackError.PermissionDenied:
438 throw new UnauthorizedAccessException("Access is not granted");
439 case Interop.Feedback.FeedbackError.OperationFailed:
441 throw new InvalidOperationException("Failed to get supported information");
448 /// Plays a specific feedback pattern.
451 /// To play Vibration type, app should have http://tizen.org/privilege/haptic privilege.
453 /// <since_tizen> 3 </since_tizen>
454 /// <param name="type">The feedback type.</param>
455 /// <param name="pattern">The feedback pattern string.</param>
457 /// http://tizen.org/feature/feedback.vibration for FeedbackType.Vibration
459 /// <exception cref="Exception">Thrown when failed because feedback is not initialized.</exception>
460 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
461 /// <exception cref="NotSupportedException">Thrown when failed because the device (haptic, sound) or a specific pattern is not supported.</exception>
462 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted(No privilege)</exception>
463 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
464 /// <privilege>http://tizen.org/privilege/haptic</privilege>
467 /// Feedback feedback = new Feedback();
468 /// feedback.Play(FeedbackType.All, "Tap");
471 public void Play(FeedbackType type, String pattern)
474 Interop.Feedback.FeedbackError res;
476 if (!Pattern.TryGetValue(pattern, out number))
477 throw new ArgumentException($"Not supported pattern string : {pattern}", nameof(pattern));
479 if (type == FeedbackType.All)
480 res = (Interop.Feedback.FeedbackError)Interop.Feedback.Play(number);
482 res = (Interop.Feedback.FeedbackError)Interop.Feedback.PlayType((Interop.Feedback.FeedbackType)type, number);
484 if (res != Interop.Feedback.FeedbackError.None)
486 Log.Warn(LogTag, string.Format("Failed to play feedback. err = {0}", res));
489 case Interop.Feedback.FeedbackError.NotInitialized:
490 throw new Exception("Not initialized");
491 case Interop.Feedback.FeedbackError.InvalidParameter:
492 throw new ArgumentException("Invalid Arguments");
493 case Interop.Feedback.FeedbackError.NotSupported:
494 throw new NotSupportedException("Not supported");
495 case Interop.Feedback.FeedbackError.PermissionDenied:
496 throw new UnauthorizedAccessException("Access is not granted");
497 case Interop.Feedback.FeedbackError.OperationFailed:
499 throw new InvalidOperationException("Failed to play pattern");
505 /// Stops to play the feedback.
508 /// To stop vibration, the application should have http://tizen.org/privilege/haptic privilege.
510 /// <since_tizen> 3 </since_tizen>
512 /// http://tizen.org/feature/feedback.vibration
514 /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
515 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament</exception>
516 /// <exception cref="NotSupportedException">Thrown when failed because the device (haptic, sound) or a specific pattern is not supported.</exception>
517 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted (No privilege).</exception>
518 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
519 /// <privilege>http://tizen.org/privilege/haptic</privilege>
522 /// Feedback Feedback1 = new Feedback();
523 /// Feedback1.Stop();
528 Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Stop();
530 if (res != Interop.Feedback.FeedbackError.None)
532 Log.Warn(LogTag, string.Format("Failed to stop feedback. err = {0}", res));
535 case Interop.Feedback.FeedbackError.NotInitialized:
536 throw new Exception("Not initialized");
537 case Interop.Feedback.FeedbackError.InvalidParameter:
538 throw new ArgumentException("Invalid Arguments");
539 case Interop.Feedback.FeedbackError.NotSupported:
540 throw new NotSupportedException("Not supported");
541 case Interop.Feedback.FeedbackError.PermissionDenied:
542 throw new UnauthorizedAccessException("Access is not granted");
543 case Interop.Feedback.FeedbackError.OperationFailed:
545 throw new InvalidOperationException("Failed to stop pattern");
551 /// Gets the count of theme can be used according to feedback type.
554 /// Now this internal API works for FeedbackType.Sound only, FeedbackType.Vibration is not supported.
555 /// Counts of theme range will be 1 ~ N according to conf file.
557 /// <since_tizen> 10 </since_tizen>
558 /// <param name="type">The feedback type.</param>
559 /// <returns>The counf of theme can be used according to feedback type.</returns>
560 /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
561 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
562 /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
563 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
566 /// Feedback feedback = new Feedback();
567 /// uint coundOfTheme = feedback.GetCountOfThemeInternal(FeedbackType.Sound);
570 [EditorBrowsable(EditorBrowsableState.Never)]
571 public uint GetCountOfThemeInternal(FeedbackType type)
573 uint countOfTheme = 0;
574 Interop.Feedback.FeedbackError res;
576 res = (Interop.Feedback.FeedbackError)Interop.Feedback.GetCountOfThemeInternal((Interop.Feedback.FeedbackType)type, out countOfTheme);
578 if (res != Interop.Feedback.FeedbackError.None)
580 Log.Warn(LogTag, string.Format("Failed to get count of theme internal. err = {0}", res));
583 case Interop.Feedback.FeedbackError.NotInitialized:
584 throw new Exception("Not initialized");
585 case Interop.Feedback.FeedbackError.InvalidParameter:
586 throw new ArgumentException("Invalid Arguments");
587 case Interop.Feedback.FeedbackError.NotSupported:
588 throw new NotSupportedException("Device is not supported");
589 case Interop.Feedback.FeedbackError.OperationFailed:
591 throw new InvalidOperationException("Failed to get count of theme internal");
598 /// Gets the id of theme selected.
601 /// Now this internal API works for FeedbackType.Sound only, FeedbackType.Vibration is not supported.
602 /// The theme id is positive value as defined in the conf file.
604 /// <since_tizen> 10 </since_tizen>
605 /// <param name="type">The feedback type.</param>
606 /// <returns>The id of theme selected as default theme according to feedback type.</returns>
607 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
608 /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
609 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
612 /// Feedback feedback = new Feedback();
613 /// uint idOfTheme = feedback.GetThemeIdInternal(FeedbackType.Sound);
616 [EditorBrowsable(EditorBrowsableState.Never)]
617 public uint GetThemeIdInternal(FeedbackType type)
619 uint countOfTheme = 0;
620 Interop.Feedback.FeedbackError res;
622 res = (Interop.Feedback.FeedbackError)Interop.Feedback.GetThemeIdInternal((Interop.Feedback.FeedbackType)type, out countOfTheme);
624 if (res != Interop.Feedback.FeedbackError.None)
626 Log.Warn(LogTag, string.Format("Failed to get id of theme internal. err = {0}", res));
629 case Interop.Feedback.FeedbackError.InvalidParameter:
630 throw new ArgumentException("Invalid Arguments");
631 case Interop.Feedback.FeedbackError.NotSupported:
632 throw new NotSupportedException("Device is not supported");
633 case Interop.Feedback.FeedbackError.OperationFailed:
635 throw new InvalidOperationException("Failed to get id of theme internal");
642 /// Sets the id of theme according to feedback type.
645 /// Now this internal API works for FeedbackType.Sound only, FeedbackType.Vibration is not supported.
646 /// To set the id of theme for Sound type, the application should have http://tizen.org/privilege/systemsettings.admin privilege.
647 /// The theme id is positive value as defined in the conf file.
649 /// <since_tizen> 10 </since_tizen>
650 /// <param name="type">The feedback type.</param>
651 /// <param name="idOfTheme">The id of theme will be set.</param>
652 /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
653 /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
654 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted(No privilege)</exception>
655 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
658 /// Feedback feedback = new Feedback();
659 /// uint idOfTheme = 1;
660 /// feedback.SetThemeIdInternal(FeedbackType.Sound, idOfTheme);
663 [EditorBrowsable(EditorBrowsableState.Never)]
664 public void SetThemeIdInternal(FeedbackType type, uint idOfTheme)
666 Interop.Feedback.FeedbackError res;
668 res = (Interop.Feedback.FeedbackError)Interop.Feedback.SetThemeIdInternal((Interop.Feedback.FeedbackType)type, idOfTheme);
670 if (res != Interop.Feedback.FeedbackError.None)
672 Log.Warn(LogTag, string.Format("Failed to set id of theme internal. err = {0}", res));
675 case Interop.Feedback.FeedbackError.InvalidParameter:
676 throw new ArgumentException("Invalid Arguments");
677 case Interop.Feedback.FeedbackError.NotSupported:
678 throw new NotSupportedException("Device is not supported");
679 case Interop.Feedback.FeedbackError.PermissionDenied:
680 throw new UnauthorizedAccessException("Access is not granted");
681 case Interop.Feedback.FeedbackError.OperationFailed:
683 throw new InvalidOperationException("Failed to set id of theme internal");
689 /// Stops the current feedback playing by feedback type
692 /// To stop vibration, the application should have http://tizen.org/privilege/haptic privilege.
694 /// <since_tizen> 10 </since_tizen>
695 /// <param name="type">The feedback type.</param>
696 /// <exception cref="Exception">Thrown when failed because the feedback is not initialized.</exception>
697 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument</exception>
698 /// <exception cref="NotSupportedException">Thrown when failed because the device (haptic, sound) or a specific pattern is not supported.</exception>
699 /// <exception cref="UnauthorizedAccessException">Thrown when failed because the access is not granted (No privilege).</exception>
700 /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
703 /// Feedback Feedback = new Feedback();
704 /// feedback.StopTypeInternal(FeedbackType.Sound);
705 /// feedback.StopTypeInternal(FeedbackType.Vibration);
708 [EditorBrowsable(EditorBrowsableState.Never)]
709 public void StopTypeInternal(FeedbackType type)
711 Interop.Feedback.FeedbackError res;
713 res = (Interop.Feedback.FeedbackError)Interop.Feedback.StopTypeInternal((Interop.Feedback.FeedbackType)type);
715 if (res != Interop.Feedback.FeedbackError.None)
717 Log.Warn(LogTag, string.Format("Failed to Stop feedback by feedback type internal. err = {0}", res));
720 case Interop.Feedback.FeedbackError.NotInitialized:
721 throw new Exception("Not initialized");
722 case Interop.Feedback.FeedbackError.InvalidParameter:
723 throw new ArgumentException("Invalid Arguments");
724 case Interop.Feedback.FeedbackError.NotSupported:
725 throw new NotSupportedException("Not supported");
726 case Interop.Feedback.FeedbackError.PermissionDenied:
727 throw new UnauthorizedAccessException("Access is not granted");
728 case Interop.Feedback.FeedbackError.OperationFailed:
730 throw new InvalidOperationException("Failed to stop pattern by feedback type");