From 33b0087552dd078fc091fdb2f1b6ee979ad9aebb Mon Sep 17 00:00:00 2001 From: Myungki Lee Date: Fri, 15 Sep 2017 10:06:23 +0900 Subject: [PATCH] [shortcut] update exception handling Change-Id: I02b5d6ebe74a2d061fe63e064b3b3d65f876821a Signed-off-by: Myungki Lee --- .../Tizen.Applications.Shortcut/ShortcutManager.cs | 2 +- .../ShortcutEventManager.cs | 23 +++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutManager.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutManager.cs index f27507d..3b4e7c4 100755 --- a/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutManager.cs +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutManager.cs @@ -51,7 +51,7 @@ namespace Tizen.Applications.Shortcut { int type; - if (shortcut.Uri == null || shortcut.Uri == String.Empty) + if (string.IsNullOrEmpty(shortcut.Uri)) { type = 0; } diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutEventManager.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutEventManager.cs index fba8ab1..fca6ef2 100755 --- a/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutEventManager.cs +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutEventManager.cs @@ -66,8 +66,6 @@ namespace Tizen.Applications.Shortcut /// Thrown in case of any internal error. public static void RegisterEventHandler(ShortcutAdded addedEvent) { - shortcutAdded = addedEvent; - if (shortcutAddCallback == null) { shortcutAddCallback = new Interop.Shortcut.AddCallback(AddCallback); @@ -75,8 +73,15 @@ namespace Tizen.Applications.Shortcut Interop.Shortcut.ErrorCode err = Interop.Shortcut.SetShortcutAddCallback(shortcutAddCallback, IntPtr.Zero); if (err != Interop.Shortcut.ErrorCode.None) { + shortcutAddCallback = null; throw ShortcutErrorFactory.GetException(err, "unable to register callback"); } + + shortcutAdded = addedEvent; + } + else + { + throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, null); } } @@ -97,8 +102,6 @@ namespace Tizen.Applications.Shortcut /// Thrown in case of any internal error. public static void RegisterEventHandler(ShortcutDeleted deletedEvent) { - shortcutDeleted = deletedEvent; - if (shortcutDeleteCallback == null) { shortcutDeleteCallback = new Interop.Shortcut.DeleteCallback(DeleteCallback); @@ -106,8 +109,15 @@ namespace Tizen.Applications.Shortcut Interop.Shortcut.ErrorCode err = Interop.Shortcut.SetShortcutDeleteCallback(shortcutDeleteCallback, IntPtr.Zero); if (err != Interop.Shortcut.ErrorCode.None) { + shortcutDeleteCallback = null; throw ShortcutErrorFactory.GetException(err, "unable to register callback"); } + + shortcutDeleted = deletedEvent; + } + else + { + throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, null); } } @@ -123,7 +133,7 @@ namespace Tizen.Applications.Shortcut /// Thrown when Shortcut is not supported. public static void UnregisterEventHandler(ShortcutAdded addedEvent) { - if (shortcutAdded.Equals(addedEvent)) + if (shortcutAdded != null && shortcutAdded.Equals(addedEvent)) { shortcutAdded = null; @@ -157,13 +167,12 @@ namespace Tizen.Applications.Shortcut /// Thrown when Shortcut is not supported. public static void UnregisterEventHandler(ShortcutDeleted deletedEvent) { - if (shortcutDeleted.Equals(deletedEvent)) + if (shortcutDeleted != null && shortcutDeleted.Equals(deletedEvent)) { shortcutDeleted = null; if (shortcutDeleteCallback != null) { - Interop.Shortcut.UnsetShortcutDeleteCallback(); shortcutDeleteCallback = null; -- 2.7.4