From: abhishekvijay <40332812+abhishekvijay@users.noreply.github.com> Date: Fri, 15 Mar 2019 09:21:19 +0000 (+0530) Subject: [Account Manager] added feature not supported exception (#756) X-Git-Tag: submit/tizen/20190316.005813~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fa602a039624ab5ceec99825f41a5849618d7163;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Account Manager] added feature not supported exception (#756) * added feature not supported exception Signed-off-by: Abhishek Vijay * improved debug logs Signed-off-by: Abhishek Vijay --- diff --git a/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager.csproj b/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager.csproj index 7f4584ffe..5bcad7037 100644 --- a/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager.csproj +++ b/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager.csproj @@ -5,6 +5,7 @@ + diff --git a/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager.sln b/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager.sln index 4ea530483..6d416b285 100755 --- a/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager.sln +++ b/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager.sln @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen", "..\Tizen\Tizen.csp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Log", "..\Tizen.Log\Tizen.Log.csproj", "{7B75CA54-AA68-425B-86E2-B550D8F9BA4C}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.System.Information", "..\Tizen.System.Information\Tizen.System.Information.csproj", "{EBEAD3D4-4335-4BC4-9101-24FAF565E43E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,8 +29,15 @@ Global {7B75CA54-AA68-425B-86E2-B550D8F9BA4C}.Debug|Any CPU.Build.0 = Debug|Any CPU {7B75CA54-AA68-425B-86E2-B550D8F9BA4C}.Release|Any CPU.ActiveCfg = Release|Any CPU {7B75CA54-AA68-425B-86E2-B550D8F9BA4C}.Release|Any CPU.Build.0 = Release|Any CPU + {EBEAD3D4-4335-4BC4-9101-24FAF565E43E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EBEAD3D4-4335-4BC4-9101-24FAF565E43E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EBEAD3D4-4335-4BC4-9101-24FAF565E43E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EBEAD3D4-4335-4BC4-9101-24FAF565E43E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {45E17114-C180-41F6-B625-800EFB07838F} + EndGlobalSection EndGlobal diff --git a/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/Account.cs b/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/Account.cs index 0498fb5f8..765d69886 100644 --- a/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/Account.cs +++ b/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/Account.cs @@ -34,6 +34,7 @@ namespace Tizen.Account.AccountManager /// The account handle. public Account(SafeAccountHandle handle) { + AccountErrorFactory.CheckAccountFeature(); _handle = handle; } @@ -53,6 +54,8 @@ namespace Tizen.Account.AccountManager /// Account Instance. public static Account CreateAccount() { + AccountErrorFactory.CheckAccountFeature(); + SafeAccountHandle handle; AccountError err = (AccountError)Interop.Account.Create(out handle); if (err != AccountError.None) diff --git a/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountErrorFactory.cs b/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountErrorFactory.cs index 837c4f476..1df75f77b 100644 --- a/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountErrorFactory.cs +++ b/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountErrorFactory.cs @@ -15,7 +15,8 @@ */ using System; -using Tizen; +using System.IO; +using Tizen.System; namespace Tizen.Account.AccountManager { @@ -135,59 +136,59 @@ namespace Tizen.Account.AccountManager { case AccountError.InvalidParameter: { - exp = new ArgumentException(msg + " Invalid Parameters Provided"); + exp = new ArgumentException($"{msg} Invalid Parameters Provided"); break; } case AccountError.OutOfMemory: { - exp = new OutOfMemoryException(msg + " Out Of Memory"); + exp = new OutOfMemoryException($"{msg} Out Of Memory"); break; } case AccountError.InvalidOperation: { - exp = new InvalidOperationException(msg + " Inavlid operation"); + exp = new InvalidOperationException($"{msg} Inavlid operation"); break; } case AccountError.NoData: { - exp = new InvalidOperationException(msg + " Empty Data"); + exp = new InvalidOperationException($"{msg} Empty Data"); break; } case AccountError.PermissionDenied: { - exp = new UnauthorizedAccessException(msg + " Permission Denied"); + exp = new UnauthorizedAccessException($"{msg} Permission Denied"); break; } case AccountError.DBFailed: { - exp = new InvalidOperationException(msg + " DataBase Failed"); + exp = new InvalidOperationException($"{msg} DataBase Failed"); break; } case AccountError.DBBusy: { - exp = new InvalidOperationException(msg + " DataBase Busy"); + exp = new InvalidOperationException($"{msg} DataBase Busy"); break; } case AccountError.QuerySyntaxError: { - exp = new InvalidOperationException(msg + " Network Error"); + exp = new InvalidOperationException($"{msg} Network Error"); break; } case AccountError.XMLFileNotFound: { - exp = new System.IO.FileNotFoundException(msg + " XML File not found"); + exp = new FileNotFoundException($"{msg} XML File not found"); break; } case AccountError.XMLParseFailed: { - exp = new System.IO.InvalidDataException(msg + " XML parse error"); + exp = new InvalidDataException($"{msg} XML parse error"); break; } @@ -200,5 +201,19 @@ namespace Tizen.Account.AccountManager return exp; } + + internal static bool IsAccountFeatureSupported() + { + return ((Information.TryGetValue("http://tizen.org/feature/account", out bool IsAccountSupported)) && IsAccountSupported); + } + + internal static void CheckAccountFeature() + { + if (IsAccountFeatureSupported() == false) + { + Log.Warn(AccountErrorFactory.LogTag, "platform account feature is disabled"); + throw new NotSupportedException("platform account feature is disabled"); + } + } } } diff --git a/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountService.cs b/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountService.cs old mode 100755 new mode 100644 index e24bf854d..fac0f29b4 --- a/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountService.cs +++ b/src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountService.cs @@ -102,6 +102,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static IEnumerable GetAccountsAsync() { + AccountErrorFactory.CheckAccountFeature(); + List accounts = new List(); List values = new List(); Interop.Account.AccountCallback accountCallback = (IntPtr data, IntPtr userdata) => @@ -141,6 +143,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static Account GetAccountById(int accountId) { + AccountErrorFactory.CheckAccountFeature(); + AccountError err = (AccountError)Interop.Account.CreateUnmanagedHandle(out IntPtr handle); if (err != AccountError.None) { @@ -173,6 +177,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static IEnumerable GetAccountProviders() { + AccountErrorFactory.CheckAccountFeature(); + List values = new List(); List providers = new List(); Interop.AccountProvider.AccountProviderCallback accountCallback = (IntPtr handle, IntPtr data) => @@ -213,6 +219,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static AccountProvider GetAccountProviderByAppId(string appId) { + AccountErrorFactory.CheckAccountFeature(); + IntPtr handle; Interop.AccountProvider.Create(out handle); AccountError err = (AccountError)Interop.AccountService.GetAccountProviderByAppId(appId, out handle); @@ -239,6 +247,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static IEnumerable GetAccountProvidersByFeature(string feature) { + AccountErrorFactory.CheckAccountFeature(); + List values = new List(); List providers = new List(); Interop.AccountProvider.AccountProviderCallback providerCallback = (IntPtr handle, IntPtr data) => @@ -280,6 +290,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static int AddAccount(Account account) { + AccountErrorFactory.CheckAccountFeature(); + if (account == null) { throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to AddAccount"); @@ -310,6 +322,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static void UpdateAccount(Account account) { + AccountErrorFactory.CheckAccountFeature(); + if (account == null) { throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to UpdateAccount"); @@ -336,6 +350,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static void DeleteAccount(Account account) { + AccountErrorFactory.CheckAccountFeature(); + if (account == null) { throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to DeleteAccount"); @@ -363,6 +379,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static void DeleteAccount(string userName, string packageName) { + AccountErrorFactory.CheckAccountFeature(); + AccountError err = (AccountError)Interop.AccountService.DeleteAccountByUser(userName, packageName); if (err != AccountError.None) { @@ -384,6 +402,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static void DeleteAccount(string packageName) { + AccountErrorFactory.CheckAccountFeature(); + AccountError err = (AccountError)Interop.AccountService.DeleteAccountByPackage(packageName); if (err != AccountError.None) { @@ -406,6 +426,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static IEnumerable GetAccountsByUserName(string userName) { + AccountErrorFactory.CheckAccountFeature(); + List accounts = new List(); List values = new List(); Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) => @@ -445,6 +467,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static IEnumerable GetAccountsByPackageName(string packageName) { + AccountErrorFactory.CheckAccountFeature(); + List accounts = new List(); List values = new List(); Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) => @@ -484,6 +508,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static IEnumerable GetAccountsByCapabilityType(string type) { + AccountErrorFactory.CheckAccountFeature(); + List accounts = new List(); List values = new List(); Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) => @@ -523,6 +549,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static Dictionary GetCapabilitiesById(int accountId) { + AccountErrorFactory.CheckAccountFeature(); + Dictionary capabilities = new Dictionary(); Interop.Account.AccountCapabilityCallback capabilityCallback = (string type, int capabilityState, IntPtr data) => { @@ -551,6 +579,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static int GetAccountsCount() { + AccountErrorFactory.CheckAccountFeature(); + int count = 0; AccountError err = (AccountError)Interop.AccountService.GetAccountCount(out count); if (err != AccountError.None) @@ -576,6 +606,8 @@ namespace Tizen.Account.AccountManager /// The required feature is not supported. public static void UpdateSyncStatusById(Account account, AccountSyncState status) { + AccountErrorFactory.CheckAccountFeature(); + AccountError err = (AccountError)Interop.AccountService.UpdateAccountSyncStatusById(account.AccountId, (int)status); if (err != AccountError.None) { @@ -585,6 +617,8 @@ namespace Tizen.Account.AccountManager private static readonly Interop.AccountService.SubscribeCallback s_accountUpdatedCallback = (string eventType, int accountId, IntPtr userData) => { + AccountErrorFactory.CheckAccountFeature(); + AccountSubscriberEventArgs eventArgs = new AccountSubscriberEventArgs(eventType, accountId); s_accountUpdated?.Invoke(null, eventArgs); return true; @@ -610,6 +644,8 @@ namespace Tizen.Account.AccountManager { add { + AccountErrorFactory.CheckAccountFeature(); + if (s_accountUpdated == null) { if (s_subscriberHandle == null) @@ -630,6 +666,8 @@ namespace Tizen.Account.AccountManager remove { + AccountErrorFactory.CheckAccountFeature(); + s_accountUpdated -= value; if (s_accountUpdated == null) {