[Account Manager] added feature not supported exception (#756)
authorabhishekvijay <40332812+abhishekvijay@users.noreply.github.com>
Fri, 15 Mar 2019 09:21:19 +0000 (14:51 +0530)
committerWonYoung Choi <wy80.choi@samsung.com>
Fri, 15 Mar 2019 09:21:19 +0000 (18:21 +0900)
* added feature not supported exception

Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
* improved debug logs

Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
src/Tizen.Account.AccountManager/Tizen.Account.AccountManager.csproj
src/Tizen.Account.AccountManager/Tizen.Account.AccountManager.sln
src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/Account.cs
src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountErrorFactory.cs
src/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountService.cs [changed mode: 0755->0644]

index 7f4584f..5bcad70 100644 (file)
@@ -5,6 +5,7 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <ProjectReference Include="..\Tizen.System.Information\Tizen.System.Information.csproj" />
     <ProjectReference Include="..\Tizen\Tizen.csproj" />
     <ProjectReference Include="..\Tizen.Log\Tizen.Log.csproj" />
   </ItemGroup>
index 4ea5304..6d416b2 100755 (executable)
@@ -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
index 0498fb5..765d698 100644 (file)
@@ -34,6 +34,7 @@ namespace Tizen.Account.AccountManager
        /// <param name="handle"> The account handle.</param>
         public Account(SafeAccountHandle handle)
         {
+            AccountErrorFactory.CheckAccountFeature();
             _handle = handle;
         }
 
@@ -53,6 +54,8 @@ namespace Tizen.Account.AccountManager
         /// <returns>Account Instance.</returns>
         public static Account CreateAccount()
         {
+            AccountErrorFactory.CheckAccountFeature();
+
             SafeAccountHandle handle;
             AccountError err = (AccountError)Interop.Account.Create(out handle);
             if (err != AccountError.None)
index 837c4f4..1df75f7 100644 (file)
@@ -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");
+            }
+        }
     }
 }
old mode 100755 (executable)
new mode 100644 (file)
index e24bf85..fac0f29
@@ -102,6 +102,8 @@ namespace Tizen.Account.AccountManager
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         public static IEnumerable<Account> GetAccountsAsync()
         {
+            AccountErrorFactory.CheckAccountFeature();
+
             List<Account> accounts = new List<Account>();
             List<int> values = new List<int>();
             Interop.Account.AccountCallback accountCallback = (IntPtr data, IntPtr userdata) =>
@@ -141,6 +143,8 @@ namespace Tizen.Account.AccountManager
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         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
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         public static IEnumerable<AccountProvider> GetAccountProviders()
         {
+            AccountErrorFactory.CheckAccountFeature();
+
             List<string> values = new List<string>();
             List<AccountProvider> providers = new List<AccountProvider>();
             Interop.AccountProvider.AccountProviderCallback accountCallback = (IntPtr handle, IntPtr data) =>
@@ -213,6 +219,8 @@ namespace Tizen.Account.AccountManager
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         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
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         public static IEnumerable<AccountProvider> GetAccountProvidersByFeature(string feature)
         {
+            AccountErrorFactory.CheckAccountFeature();
+
             List<string> values = new List<string>();
             List<AccountProvider> providers = new List<AccountProvider>();
             Interop.AccountProvider.AccountProviderCallback providerCallback = (IntPtr handle, IntPtr data) =>
@@ -280,6 +290,8 @@ namespace Tizen.Account.AccountManager
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         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
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         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
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         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
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         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
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         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
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         public static IEnumerable<Account> GetAccountsByUserName(string userName)
         {
+            AccountErrorFactory.CheckAccountFeature();
+
             List<Account> accounts = new List<Account>();
             List<int> values = new List<int>();
             Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
@@ -445,6 +467,8 @@ namespace Tizen.Account.AccountManager
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         public static IEnumerable<Account> GetAccountsByPackageName(string packageName)
         {
+            AccountErrorFactory.CheckAccountFeature();
+
             List<Account> accounts = new List<Account>();
             List<int> values = new List<int>();
             Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
@@ -484,6 +508,8 @@ namespace Tizen.Account.AccountManager
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         public static IEnumerable<Account> GetAccountsByCapabilityType(string type)
         {
+            AccountErrorFactory.CheckAccountFeature();
+
             List<Account> accounts = new List<Account>();
             List<int> values = new List<int>();
             Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
@@ -523,6 +549,8 @@ namespace Tizen.Account.AccountManager
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         public static Dictionary<string, CapabilityState> GetCapabilitiesById(int accountId)
         {
+            AccountErrorFactory.CheckAccountFeature();
+
             Dictionary<string, CapabilityState> capabilities = new Dictionary<string, CapabilityState>();
             Interop.Account.AccountCapabilityCallback capabilityCallback = (string type, int capabilityState, IntPtr data) =>
             {
@@ -551,6 +579,8 @@ namespace Tizen.Account.AccountManager
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         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
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         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)
                 {