From 5b4d989615d89174e5a0a6ef06d26919005dad56 Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Mon, 3 Dec 2018 14:56:26 +0900 Subject: [PATCH] [WidgetControl] Add MainAppId, PackageId properties and modify required feature (#525) * Add get main appid/package id APIS - (static)GetWidgetMainAppId - (static)GetWidgetPackageId Signed-off-by: hyunho * Fix since tizen for new APIs 5 -> 6 Signed-off-by: hyunho * Modify get widget main appid/pacakgeid to property Signed-off-by: hyunho * Add feature documentation Signed-off-by: hyunho * Add not supported exception for some memebers Signed-off-by: hyunho --- .../Interop/Interop.WidgetService.cs | 6 + .../Tizen.Applications/WidgetControl.cs | 157 ++++++++++++++++++++- 2 files changed, 159 insertions(+), 4 deletions(-) mode change 100755 => 100644 src/Tizen.Applications.WidgetControl/Tizen.Applications/WidgetControl.cs diff --git a/src/Tizen.Applications.WidgetControl/Interop/Interop.WidgetService.cs b/src/Tizen.Applications.WidgetControl/Interop/Interop.WidgetService.cs index 3be41ed..c893a23 100755 --- a/src/Tizen.Applications.WidgetControl/Interop/Interop.WidgetService.cs +++ b/src/Tizen.Applications.WidgetControl/Interop/Interop.WidgetService.cs @@ -102,5 +102,11 @@ internal static partial class Interop [DllImport(Libraries.WidgetService, EntryPoint = "widget_service_get_widget_list_by_pkgid")] internal static extern ErrorCode GetWidgetListByPkgId(string pkgId, WidgetListCallback callback, IntPtr userData); + + [DllImport(Libraries.WidgetService, EntryPoint = "widget_service_get_main_app_id")] + internal static extern string GetWidgetMainAppId(string widgetId); + + [DllImport(Libraries.WidgetService, EntryPoint = "widget_service_get_package_id")] + internal static extern string GetWidgetPackageId(string widgetId); } } diff --git a/src/Tizen.Applications.WidgetControl/Tizen.Applications/WidgetControl.cs b/src/Tizen.Applications.WidgetControl/Tizen.Applications/WidgetControl.cs old mode 100755 new mode 100644 index fe4a3d5..21606bb --- a/src/Tizen.Applications.WidgetControl/Tizen.Applications/WidgetControl.cs +++ b/src/Tizen.Applications.WidgetControl/Tizen.Applications/WidgetControl.cs @@ -52,7 +52,9 @@ namespace Tizen.Applications /// Gets the widget content. /// /// 3 + /// http://tizen.org/feature/shell.appwidget /// Thrown in case of failed conditions. + /// Thrown in case of feature not supported. public Bundle GetContent() { IntPtr h; @@ -63,9 +65,10 @@ namespace Tizen.Applications { case Interop.WidgetService.ErrorCode.InvalidParameter: throw new InvalidOperationException("Invalid parameter at unmanaged code"); - case Interop.WidgetService.ErrorCode.IoError: throw new InvalidOperationException("Failed to access DB"); + case Interop.WidgetService.ErrorCode.NotSupported: + throw new NotSupportedException("Not supported"); } return new Bundle(new SafeBundleHandle(h, true)); @@ -77,9 +80,11 @@ namespace Tizen.Applications /// 3 /// Content to be changed. /// True if you want to update your widget even if the provider is paused, otherwise false. + /// http://tizen.org/feature/shell.appwidget /// Thrown when failed because of an invalid argument. /// Thrown in case of failed conditions. /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. public void ChangeContent(Bundle content, bool force) { Interop.WidgetService.ErrorCode err = Interop.WidgetService.UpdateContent(_widgetId, Id, content.SafeBundleHandle, force ? 1 : 0); @@ -100,6 +105,9 @@ namespace Tizen.Applications case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); + + case Interop.WidgetService.ErrorCode.NotSupported: + throw new NotSupportedException("Not supported"); } } @@ -107,9 +115,11 @@ namespace Tizen.Applications /// Changes the update period for the widget instance. /// /// 3 + /// http://tizen.org/feature/shell.appwidget /// Thrown when failed because of an invalid argument. /// Thrown in case of failed conditions. /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. public void ChangePeriod(double period) { Interop.WidgetService.ErrorCode err = Interop.WidgetService.ChangePeriod(_widgetId, Id, period); @@ -127,6 +137,9 @@ namespace Tizen.Applications case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); + + case Interop.WidgetService.ErrorCode.NotSupported: + throw new NotSupportedException("Not supported"); } } } @@ -255,9 +268,11 @@ namespace Tizen.Applications /// 3 /// Package ID. /// http://tizen.org/privilege/widget.viewer + /// http://tizen.org/feature/shell.appwidget /// Thrown when failed because of an invalid argument. /// Thrown in case of failed conditions. /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. public static WidgetControl[] CreateAll(string pkgId) { List list = new List(); @@ -277,6 +292,9 @@ namespace Tizen.Applications case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); + + case Interop.WidgetService.ErrorCode.NotSupported: + throw new NotSupportedException("Not supported"); } return list.ToArray(); @@ -287,9 +305,11 @@ namespace Tizen.Applications /// /// 3 /// http://tizen.org/privilege/widget.viewer + /// http://tizen.org/feature/shell.appwidget /// Thrown when failed because of an invalid argument. /// Thrown in case of failed conditions. /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. public static string[] GetWidgetIds(string pkgId) { List list = new List(); @@ -309,12 +329,71 @@ namespace Tizen.Applications case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); + + case Interop.WidgetService.ErrorCode.NotSupported: + throw new NotSupportedException("Not supported"); } return list.ToArray(); } /// + /// Gets main appid of the widget. + /// + /// 6 + /// http://tizen.org/privilege/widget.viewer + /// http://tizen.org/feature/shell.appwidget + /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. + public string MainAppId + { + get + { + string str = Interop.WidgetService.GetWidgetMainAppId(Id); + Interop.WidgetService.ErrorCode err = + (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult(); + switch (err) + { + case Interop.WidgetService.ErrorCode.PermissionDenied: + throw new UnauthorizedAccessException(); + + case Interop.WidgetService.ErrorCode.NotSupported: + throw new NotSupportedException("Not supported"); + } + + return str; + } + } + + /// + /// Gets package ID of the widget. + /// + /// 6 + /// http://tizen.org/privilege/widget.viewer + /// http://tizen.org/feature/shell.appwidget + /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. + public string PackageId + { + get + { + string str = Interop.WidgetService.GetWidgetPackageId(Id); + Interop.WidgetService.ErrorCode err = + (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult(); + switch (err) + { + case Interop.WidgetService.ErrorCode.PermissionDenied: + throw new UnauthorizedAccessException(); + + case Interop.WidgetService.ErrorCode.NotSupported: + throw new NotSupportedException("Not supported"); + } + + return str; + } + } + + /// /// The widget ID. /// /// 3 @@ -325,11 +404,26 @@ namespace Tizen.Applications /// /// 3 /// http://tizen.org/privilege/widget.viewer + /// http://tizen.org/feature/shell.appwidget + /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. public bool IsNoDisplay { get { - if (Interop.WidgetService.GetNoDisplay(Id) != 0) + int ret = Interop.WidgetService.GetNoDisplay(Id); + Interop.WidgetService.ErrorCode err = + (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult(); + switch (err) + { + case Interop.WidgetService.ErrorCode.PermissionDenied: + throw new UnauthorizedAccessException(); + + case Interop.WidgetService.ErrorCode.NotSupported: + throw new NotSupportedException("Not supported"); + } + + if (ret != 0) return true; return false; @@ -340,8 +434,10 @@ namespace Tizen.Applications /// The event handler for a created widget instance. /// /// 3 + /// http://tizen.org/feature/shell.appwidget /// Thrown in case of failed conditions. /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. public event EventHandler Created { add @@ -360,8 +456,10 @@ namespace Tizen.Applications /// The event handler for a resumed widget instance. /// /// 3 + /// http://tizen.org/feature/shell.appwidget /// Thrown in case of failed conditions. /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. public event EventHandler Resumed { add @@ -380,8 +478,10 @@ namespace Tizen.Applications /// The event handler for a paused widget instance. /// /// 3 + /// http://tizen.org/feature/shell.appwidget /// Thrown in case of failed conditions. /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. public event EventHandler Paused { add @@ -400,8 +500,10 @@ namespace Tizen.Applications /// The event handler for a destroyed widget instance. /// /// 3 + /// http://tizen.org/feature/shell.appwidget /// Thrown in case of failed conditions. /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. public event EventHandler Destroyed { add @@ -438,6 +540,7 @@ namespace Tizen.Applications /// Gets the objects for widget instance information. /// /// 3 + /// http://tizen.org/feature/shell.appwidget /// Thrown in case of failed conditions. /// Thrown when the API is not supported in this device. /// Thrown when an application does not have the privilege to access this method. @@ -469,8 +572,10 @@ namespace Tizen.Applications /// /// 3 /// http://tizen.org/privilege/widget.viewer + /// http://tizen.org/feature/shell.appwidget /// Thrown in case of failed conditions. /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. public IEnumerable GetScales() { IntPtr wPtr; @@ -500,6 +605,9 @@ namespace Tizen.Applications case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); + + case Interop.WidgetService.ErrorCode.NotSupported: + throw new NotSupportedException(); } w = new int[cnt1]; Marshal.Copy(wPtr, w, 0, cnt1); @@ -553,13 +661,29 @@ namespace Tizen.Applications /// 3 /// Language. /// http://tizen.org/privilege/widget.viewer + /// http://tizen.org/feature/shell.appwidget /// Thrown when the argument is null. + /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. public string GetName(string lang) { if (lang == null) throw new ArgumentNullException(); - return Interop.WidgetService.GetName(Id, lang); + string str = Interop.WidgetService.GetName(Id, lang); + Interop.WidgetService.ErrorCode err = + (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult(); + + switch (err) + { + case Interop.WidgetService.ErrorCode.PermissionDenied: + throw new UnauthorizedAccessException(); + + case Interop.WidgetService.ErrorCode.NotSupported: + throw new NotSupportedException(); + } + + return str; } /// @@ -568,21 +692,40 @@ namespace Tizen.Applications /// 3 /// Language. /// http://tizen.org/privilege/widget.viewer + /// http://tizen.org/feature/shell.appwidget /// Thrown when the argument is null. + /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. public string GetIconPath(string lang) { if (lang == null) throw new ArgumentNullException(); string pkgId = Interop.WidgetService.GetPkgId(Id); + string str = Interop.WidgetService.GetIcon(pkgId, lang); + Interop.WidgetService.ErrorCode err = + (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult(); - return Interop.WidgetService.GetIcon(pkgId, lang); + switch (err) + { + case Interop.WidgetService.ErrorCode.PermissionDenied: + throw new UnauthorizedAccessException(); + + case Interop.WidgetService.ErrorCode.NotSupported: + throw new NotSupportedException(); + } + + return str; } /// /// Releases all the resources used by the WidgetControl class. /// /// 3 + /// http://tizen.org/feature/shell.appwidget + /// Thrown in case of failed conditions. + /// Thrown when an application does not have the privilege to access this method. + /// Thrown in case of feature not supported. public void Dispose() { Dispose(true); @@ -628,6 +771,9 @@ namespace Tizen.Applications case Interop.WidgetService.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException(); + + case Interop.WidgetService.ErrorCode.NotSupported: + throw new NotSupportedException(); } } @@ -661,6 +807,9 @@ namespace Tizen.Applications case Interop.WidgetService.ErrorCode.NotExist: throw new InvalidOperationException("Event handler is not exist"); + + case Interop.WidgetService.ErrorCode.NotSupported: + throw new NotSupportedException(); } _onLifecycleCallback = null; } -- 2.7.4