From e13eab5631366b6d77dd8f541023300f76d50108 Mon Sep 17 00:00:00 2001 From: Jooseok Song Date: Mon, 28 Aug 2017 17:36:11 +0900 Subject: [PATCH] [TCSACR-81][Add] Added new property to get account handle Change-Id: Ia4e308943c99b851b46e3b4561e40abdf620e8fb --- .../Interop/Interop.Account.cs | 69 +++++++++++----------- .../Interop/Interop.AccountService.cs | 7 ++- .../Tizen.Account.AccountManager.csproj | 2 +- .../Tizen.Account.AccountManager/Account.cs | 32 +++++----- .../AccountProvider.cs | 14 +++++ .../Tizen.Account.AccountManager/AccountService.cs | 57 ++++++++++++++---- .../SafeAccountHandle.cs | 63 ++++++++++++++++++++ packaging/csapi-account-manager.spec | 2 +- 8 files changed, 182 insertions(+), 64 deletions(-) create mode 100644 Tizen.Account.AccountManager/Tizen.Account.AccountManager/SafeAccountHandle.cs diff --git a/Tizen.Account.AccountManager/Interop/Interop.Account.cs b/Tizen.Account.AccountManager/Interop/Interop.Account.cs index 25b03e2..90489bc 100644 --- a/Tizen.Account.AccountManager/Interop/Interop.Account.cs +++ b/Tizen.Account.AccountManager/Interop/Interop.Account.cs @@ -30,115 +30,116 @@ internal static partial class Interop internal static partial class Account { [DllImport(Libraries.AccountSvc, EntryPoint = "account_create", CallingConvention = CallingConvention.Cdecl)] - internal static extern int Create(out IntPtr handle); + internal static extern int Create(out SafeAccountHandle handle); + [DllImport(Libraries.AccountSvc, EntryPoint = "account_destroy", CallingConvention = CallingConvention.Cdecl)] internal static extern int Destroy(IntPtr handle); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_account_id", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountId(IntPtr data, out int accountId); + internal static extern int GetAccountId(SafeAccountHandle data, out int accountId); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_user_name", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountUserName(IntPtr data, out string userName); + internal static extern int GetAccountUserName(SafeAccountHandle data, out string userName); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_user_name", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountUserName(IntPtr handle, string userName); + internal static extern int SetAccountUserName(SafeAccountHandle handle, string userName); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_display_name", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountDisplayName(IntPtr handle, out string displayName); + internal static extern int GetAccountDisplayName(SafeAccountHandle handle, out string displayName); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_display_name", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountDisplayName(IntPtr handle, string displayName); + internal static extern int SetAccountDisplayName(SafeAccountHandle handle, string displayName); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_capability", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountCapability(IntPtr handle, string capabilityType, out int capabilityValue); + internal static extern int GetAccountCapability(SafeAccountHandle handle, string capabilityType, out int capabilityValue); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_capability", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountCapability(IntPtr handle, string capabilityType, int capabilityValue); + internal static extern int SetAccountCapability(SafeAccountHandle handle, string capabilityType, int capabilityValue); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_icon_path", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountIconPath(IntPtr handle, out string iconPath); + internal static extern int GetAccountIconPath(SafeAccountHandle handle, out string iconPath); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_icon_path", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountIconPath(IntPtr handle, string iconPath); + internal static extern int SetAccountIconPath(SafeAccountHandle handle, string iconPath); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_domain_name", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountDomainName(IntPtr handle, out string domainName); + internal static extern int GetAccountDomainName(SafeAccountHandle handle, out string domainName); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_domain_name", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountDomainName(IntPtr handle, string domainName); + internal static extern int SetAccountDomainName(SafeAccountHandle handle, string domainName); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_email_address", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountEmail(IntPtr handle, out string email); + internal static extern int GetAccountEmail(SafeAccountHandle handle, out string email); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_email_address", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountEmail(IntPtr handle, string email); + internal static extern int SetAccountEmail(SafeAccountHandle handle, string email); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_package_name", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountPackageName(IntPtr handle, out string name); + internal static extern int GetAccountPackageName(SafeAccountHandle handle, out string name); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_package_name", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountPackageName(IntPtr handle, string name); + internal static extern int SetAccountPackageName(SafeAccountHandle handle, string name); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_access_token", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountAccessToken(IntPtr handle, out string accessToken); + internal static extern int GetAccountAccessToken(SafeAccountHandle handle, out string accessToken); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_access_token", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountAccessToken(IntPtr handle, string accessToken); + internal static extern int SetAccountAccessToken(SafeAccountHandle handle, string accessToken); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_user_text", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountUserText(IntPtr handle, int index, out string userText); + internal static extern int GetAccountUserText(SafeAccountHandle handle, int index, out string userText); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_user_text", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountUserText(IntPtr handle, int index, string userText); + internal static extern int SetAccountUserText(SafeAccountHandle handle, int index, string userText); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_user_int", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountUserInt(IntPtr handle, int index, out int value); + internal static extern int GetAccountUserInt(SafeAccountHandle handle, int index, out int value); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_user_int", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountUserInt(IntPtr handle, int index, int value); + internal static extern int SetAccountUserInt(SafeAccountHandle handle, int index, int value); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_auth_type", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountAuthType(IntPtr handle, out int authType); + internal static extern int GetAccountAuthType(SafeAccountHandle handle, out int authType); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_auth_type", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountAuthType(IntPtr handle, int authType); + internal static extern int SetAccountAuthType(SafeAccountHandle handle, int authType); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_secret", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountSercet(IntPtr handle, out int secretType); + internal static extern int GetAccountSercet(SafeAccountHandle handle, out int secretType); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_secret", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountSecret(IntPtr handle, int secretType); + internal static extern int SetAccountSecret(SafeAccountHandle handle, int secretType); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_sync_support", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountSyncSupport(IntPtr handle, out int syncType); + internal static extern int GetAccountSyncSupport(SafeAccountHandle handle, out int syncType); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_sync_support", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountSyncSupport(IntPtr handle, int syncType); + internal static extern int SetAccountSyncSupport(SafeAccountHandle handle, int syncType); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_source", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountSource(IntPtr handle, out string source); + internal static extern int GetAccountSource(SafeAccountHandle handle, out string source); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_source", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountSource(IntPtr handle, string source); + internal static extern int SetAccountSource(SafeAccountHandle handle, string source); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_custom", CallingConvention = CallingConvention.Cdecl)] - internal static extern int GetAccountCustomValue(IntPtr handle, string key, out string value); + internal static extern int GetAccountCustomValue(SafeAccountHandle handle, string key, out string value); [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_custom", CallingConvention = CallingConvention.Cdecl)] - internal static extern int SetAccountCustomValue(IntPtr handle, string key, string value); + internal static extern int SetAccountCustomValue(SafeAccountHandle handle, string key, string value); [DllImport(Libraries.AccountSvc, EntryPoint = "account_update_sync_status_by_id", CallingConvention = CallingConvention.Cdecl)] internal static extern int UpdateAccountSyncStatusById(int accountId, int status); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_capability_all")] - internal static extern int GetAllAccountCapabilities(IntPtr handle, AccountCapabilityCallback callback, IntPtr userData); + internal static extern int GetAllAccountCapabilities(SafeAccountHandle handle, AccountCapabilityCallback callback, IntPtr userData); [DllImport(Libraries.AccountSvc, EntryPoint = "account_query_capability_by_account_id")] internal static extern int QueryAccountCapabilityById(AccountCapabilityCallback callback, int accountId, IntPtr userData); [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_custom_all")] - internal static extern int GetAllAccountCustomValues(IntPtr handle, AccountCustomCallback callback, IntPtr userData); + internal static extern int GetAllAccountCustomValues(SafeAccountHandle handle, AccountCustomCallback callback, IntPtr userData); //Callbacks [UnmanagedFunctionPointer(CallingConvention.Cdecl)] diff --git a/Tizen.Account.AccountManager/Interop/Interop.AccountService.cs b/Tizen.Account.AccountManager/Interop/Interop.AccountService.cs index 581a00d..1995ce0 100644 --- a/Tizen.Account.AccountManager/Interop/Interop.AccountService.cs +++ b/Tizen.Account.AccountManager/Interop/Interop.AccountService.cs @@ -16,6 +16,7 @@ using System; using System.Runtime.InteropServices; +using Tizen.Account.AccountManager; /// /// Interop for Account class APIs. @@ -30,13 +31,13 @@ internal static partial class Interop internal static partial class AccountService { [DllImport(Libraries.AccountSvc, EntryPoint = "account_update_to_db_by_id", CallingConvention = CallingConvention.Cdecl)] - internal static extern int UpdateAccountToDBById(IntPtr handle, int id); + internal static extern int UpdateAccountToDBById(SafeAccountHandle handle, int id); [DllImport(Libraries.AccountSvc, EntryPoint = "account_update_to_db_by_user_name", CallingConvention = CallingConvention.Cdecl)] internal static extern int UpdateAccountToDBByUserName(IntPtr handle, string userName, string packageName); [DllImport(Libraries.AccountSvc, EntryPoint = "account_query_account_by_account_id", CallingConvention = CallingConvention.Cdecl)] - internal static extern int QueryAccountById(int accountId, out IntPtr handle); + internal static extern int QueryAccountById(int accountId, ref SafeAccountHandle handle); [DllImport(Libraries.AccountSvc, EntryPoint = "account_query_account_by_user_name", CallingConvention = CallingConvention.Cdecl)] internal static extern int QueryAccountByUserName(Interop.Account.AccountCallback callback, string userName, IntPtr userData); @@ -51,7 +52,7 @@ internal static partial class Interop internal static extern int UpdateAccountSyncStatusById(int accoutId, int status); [DllImport(Libraries.AccountSvc, EntryPoint = "account_insert_to_db", CallingConvention = CallingConvention.Cdecl)] - internal static extern int AddAccount(IntPtr handle, out int accountId); + internal static extern int AddAccount(SafeAccountHandle handle, out int accountId); [DllImport(Libraries.AccountSvc, EntryPoint = "account_delete_from_db_by_id", CallingConvention = CallingConvention.Cdecl)] internal static extern int DeleteAccountById(int accountId); diff --git a/Tizen.Account.AccountManager/Tizen.Account.AccountManager.csproj b/Tizen.Account.AccountManager/Tizen.Account.AccountManager.csproj index d1b0495..44a636e 100644 --- a/Tizen.Account.AccountManager/Tizen.Account.AccountManager.csproj +++ b/Tizen.Account.AccountManager/Tizen.Account.AccountManager.csproj @@ -1,7 +1,7 @@  - 1.0.7 + 1.0.8 Samsung Electronics © Samsung Electronics Co., Ltd All Rights Reserved Account Service APIs for Tizen.Account.AccountManager diff --git a/Tizen.Account.AccountManager/Tizen.Account.AccountManager/Account.cs b/Tizen.Account.AccountManager/Tizen.Account.AccountManager/Account.cs index d51bd33..498bb84 100644 --- a/Tizen.Account.AccountManager/Tizen.Account.AccountManager/Account.cs +++ b/Tizen.Account.AccountManager/Tizen.Account.AccountManager/Account.cs @@ -25,16 +25,18 @@ namespace Tizen.Account.AccountManager /// 3 public class Account : IDisposable { - private IntPtr _handle = IntPtr.Zero; - internal Account(IntPtr handle) + private readonly SafeAccountHandle _handle; + + public Account(SafeAccountHandle handle) { - Handle = handle; + _handle = handle; } ~Account() { Dispose(false); } + /// /// Creates a new account instance. /// @@ -42,7 +44,7 @@ namespace Tizen.Account.AccountManager /// Account Instance. public static Account CreateAccount() { - IntPtr handle; + SafeAccountHandle handle; AccountError err = (AccountError)Interop.Account.Create(out handle); if (err != AccountError.None) { @@ -391,17 +393,17 @@ namespace Tizen.Account.AccountManager } } - internal IntPtr Handle + /// + /// Handle of the account. + /// + /// 4 + /// Account handle. + public SafeAccountHandle SafeAccountHandle { get { return _handle; } - - set - { - _handle = value; - } } /// /// Sets the account capability. @@ -609,10 +611,12 @@ namespace Tizen.Account.AccountManager { if (!disposing) { - if (_handle != IntPtr.Zero) - { - _handle = IntPtr.Zero; - } + //if (_handle != IntPtr.Zero) + //{ + // _handle = IntPtr.Zero; + //} + //_handle.Dispose(); + GC.SuppressFinalize(this); } } } diff --git a/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountProvider.cs b/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountProvider.cs index 6ad4401..ce34491 100644 --- a/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountProvider.cs +++ b/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountProvider.cs @@ -149,11 +149,13 @@ namespace Tizen.Account.AccountManager /// /// 3 /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// /// The list of capability information. /// /// In case of any DB error. /// In case of privilege not defined. + /// The required feature is not supported. public IEnumerable GetAllCapabilities() { List capabilities = new List(); @@ -183,8 +185,10 @@ namespace Tizen.Account.AccountManager /// /// The label text given for the locale. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error or record not found for given locale. /// In case of privilege not defined. + /// The required feature is not supported. public string GetLabel(string locale) { string label; @@ -206,9 +210,11 @@ namespace Tizen.Account.AccountManager /// /// All the labels information for the given application ID. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error or record not found for given the application ID. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static Dictionary GetLabelsByAppId(string appId) { @@ -234,8 +240,10 @@ namespace Tizen.Account.AccountManager /// 3 /// All the labels information for the given account provider. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error. /// In case of privilege not defined. + /// The required feature is not supported. public Dictionary GetLabels() { @@ -262,9 +270,11 @@ namespace Tizen.Account.AccountManager /// The application ID to check. /// returns true If App is supported /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error or record not found for the given application ID. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public bool IsAppSupported(string appId) { bool isSupported = false; @@ -293,9 +303,11 @@ namespace Tizen.Account.AccountManager /// otherwise FALSE if the application does not support the given capability /// /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static bool IsFeatureSupportedByApp(string appId, string capability) { bool supported = Interop.AccountProvider.IsFeatureSupported(appId, capability); @@ -319,9 +331,11 @@ namespace Tizen.Account.AccountManager /// The application ID. /// Capability information list for the given appId. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error or record not found for the given application ID. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static IEnumerable GetFeaturesByAppId(string appId) { diff --git a/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountService.cs b/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountService.cs index 2626ed7..d335a8e 100644 --- a/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountService.cs +++ b/Tizen.Account.AccountManager/Tizen.Account.AccountManager/AccountService.cs @@ -96,15 +96,17 @@ namespace Tizen.Account.AccountManager /// 3 /// List of accounts. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error. /// In case of privilege not defined. + /// The required feature is not supported. public static IEnumerable GetAccountsAsync() { List accounts = new List(); List values = new List(); Interop.Account.AccountCallback accountCallback = (IntPtr data, IntPtr userdata) => { - Account account = new Account(data); + Account account = new Account(new SafeAccountHandle(data, true)); values.Add(account.AccountId); account.Dispose(); return true; @@ -132,21 +134,24 @@ namespace Tizen.Account.AccountManager /// The account ID to be searched. /// Account instance with reference to the given ID. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error or record not found for given account ID. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static Account GetAccountById(int accountId) { Account account = Account.CreateAccount(); - IntPtr handle = account.Handle; - AccountError res = (AccountError)Interop.AccountService.QueryAccountById(accountId, out handle); + SafeAccountHandle handle = account.SafeAccountHandle; + + AccountError res = (AccountError)Interop.AccountService.QueryAccountById(accountId, ref handle); if (res != AccountError.None) { throw AccountErrorFactory.CreateException(res, "Failed to get accounts from the database for account id: " + accountId); } - - account.Handle = handle; - return account; + Account ref_account = new Account(handle); + + return ref_account; } /// @@ -155,8 +160,10 @@ namespace Tizen.Account.AccountManager /// 3 /// List of AccountProviders. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error. /// In case of privilege not defined. + /// The required feature is not supported. public static IEnumerable GetAccountProviders() { List values = new List(); @@ -192,9 +199,11 @@ namespace Tizen.Account.AccountManager /// The application ID. /// The AccountProvider instance associated with the given application ID. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error or record not found for given appid. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static AccountProvider GetAccountProviderByAppId(string appId) { IntPtr handle; @@ -216,9 +225,11 @@ namespace Tizen.Account.AccountManager /// The capability value to search for account providers. /// Retrieves the AccountProviders information with the capability name. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error or record not found for given feature. /// In case of invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static IEnumerable GetAccountProvidersByFeature(string feature) { List values = new List(); @@ -253,10 +264,12 @@ namespace Tizen.Account.AccountManager /// New Account instance to be added. /// http://tizen.org/privilege/account.read /// http://tizen.org/privilege/account.write + /// http://tizen.org/feature/account /// In case of any DB error. /// In case of an invalid parameter. /// In case of privilege not defined. /// In case of OutOfMemory error. + /// The required feature is not supported. public static int AddAccount(Account account) { if (account == null) @@ -265,7 +278,7 @@ namespace Tizen.Account.AccountManager } int id = -1; - AccountError err = (AccountError)Interop.AccountService.AddAccount(account.Handle, out id); + AccountError err = (AccountError)Interop.AccountService.AddAccount(account.SafeAccountHandle, out id); if (err != AccountError.None) { throw AccountErrorFactory.CreateException(err, "Failed to AddAccount"); @@ -281,10 +294,12 @@ namespace Tizen.Account.AccountManager /// Account instance to be updated. /// http://tizen.org/privilege/account.read /// http://tizen.org/privilege/account.write + /// http://tizen.org/feature/account /// In case of any DB error. /// In case of an invalid parameter. /// In case of privilege not defined. /// In case of OutOfMemory error. + /// The required feature is not supported. public static void UpdateAccount(Account account) { if (account == null) @@ -292,7 +307,7 @@ namespace Tizen.Account.AccountManager throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to UpdateAccount"); } - AccountError err = (AccountError)Interop.AccountService.UpdateAccountToDBById(account.Handle, account.AccountId); + AccountError err = (AccountError)Interop.AccountService.UpdateAccountToDBById(account.SafeAccountHandle, account.AccountId); if (err != AccountError.None) { throw AccountErrorFactory.CreateException(err, "Failed to UpdateAccount"); @@ -306,9 +321,11 @@ namespace Tizen.Account.AccountManager /// Account instance to be deleted from the database. /// http://tizen.org/privilege/account.read /// http://tizen.org/privilege/account.write + /// http://tizen.org/feature/account /// In case of any DB error. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static void DeleteAccount(Account account) { if (account == null) @@ -331,9 +348,11 @@ namespace Tizen.Account.AccountManager /// The package name of the account to delete. /// http://tizen.org/privilege/account.read /// http://tizen.org/privilege/account.write + /// http://tizen.org/feature/account /// In case of any DB error. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static void DeleteAccount(string userName, string packageName) { AccountError err = (AccountError)Interop.AccountService.DeleteAccountByUser(userName, packageName); @@ -350,9 +369,11 @@ namespace Tizen.Account.AccountManager /// The package name of the account to delete. /// http://tizen.org/privilege/account.read /// http://tizen.org/privilege/account.write + /// http://tizen.org/feature/account /// In case of any DB error. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static void DeleteAccount(string packageName) { AccountError err = (AccountError)Interop.AccountService.DeleteAccountByPackage(packageName); @@ -370,16 +391,18 @@ namespace Tizen.Account.AccountManager /// The user name to search. /// Accounts list matched with the user name. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error or record not found for given username. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static IEnumerable GetAccountsByUserName(string userName) { List accounts = new List(); List values = new List(); Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) => { - Account account = new Account(handle); + Account account = new Account(new SafeAccountHandle(handle, true)); values.Add(account.AccountId); account.Dispose(); return true; @@ -407,16 +430,18 @@ namespace Tizen.Account.AccountManager /// The package name to search. /// Accounts list matched with the package name. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error or record not found for given package name. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static IEnumerable GetAccountsByPackageName(string packageName) { List accounts = new List(); List values = new List(); Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) => { - Account account = new Account(handle); + Account account = new Account(new SafeAccountHandle(handle, true)); values.Add(account.AccountId); account.Dispose(); return true; @@ -444,16 +469,18 @@ namespace Tizen.Account.AccountManager /// Capability type. /// Accounts list matched with the capability type. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error or record not found for the given capability type. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static IEnumerable GetAccountsByCapabilityType(string type) { List accounts = new List(); List values = new List(); Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) => { - Account account = new Account(handle); + Account account = new Account(new SafeAccountHandle(handle, true)); values.Add(account.AccountId); account.Dispose(); return true; @@ -481,9 +508,11 @@ namespace Tizen.Account.AccountManager /// Account instance. /// Capabilities list as dictionary of the capability type and state. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error or record not found for given account ID. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static Dictionary GetCapabilitiesById(int accountId) { Dictionary capabilities = new Dictionary(); @@ -508,8 +537,10 @@ namespace Tizen.Account.AccountManager /// 3 /// The number of accounts in the database. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error. /// In case of privilege not defined. + /// The required feature is not supported. public static int GetAccountsCount() { int count = 0; @@ -530,9 +561,11 @@ namespace Tizen.Account.AccountManager /// Sync State /// http://tizen.org/privilege/account.read /// http://tizen.org/privilege/account.write + /// http://tizen.org/feature/account /// In case of any DB error. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static void UpdateSyncStatusById(Account account, AccountSyncState status) { AccountError err = (AccountError)Interop.AccountService.UpdateAccountSyncStatusById(account.AccountId, (int)status); @@ -562,9 +595,11 @@ namespace Tizen.Account.AccountManager /// /// A ContentUpdatedEventArgs object that contains information about the update operation. /// http://tizen.org/privilege/account.read + /// http://tizen.org/feature/account /// In case of any DB error. /// In case of an invalid parameter. /// In case of privilege not defined. + /// The required feature is not supported. public static event EventHandler AccountUpdated { add diff --git a/Tizen.Account.AccountManager/Tizen.Account.AccountManager/SafeAccountHandle.cs b/Tizen.Account.AccountManager/Tizen.Account.AccountManager/SafeAccountHandle.cs new file mode 100644 index 0000000..a27d0ce --- /dev/null +++ b/Tizen.Account.AccountManager/Tizen.Account.AccountManager/SafeAccountHandle.cs @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; + +namespace Tizen.Account.AccountManager +{ + /// + /// Represents a wrapper class for a unmanaged Account handle. + /// + public sealed class SafeAccountHandle : SafeHandle + { + /// + /// Initializes a new instance of the SafeAppControlHandle class. + /// + public SafeAccountHandle() : base(IntPtr.Zero, true) + { + } + + /// + /// Initializes a new instance of the SafeAccountHandle class. + /// + /// An IntPtr object that represents the pre-existing handle to use. + /// true to reliably release the handle during the finalization phase; false to prevent reliable release. + public SafeAccountHandle(IntPtr existingHandle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) + { + SetHandle(existingHandle); + } + + /// + /// Gets a value that indicates whether the handle is invalid. + /// + public override bool IsInvalid + { + get { return this.handle == IntPtr.Zero; } + } + + /// + /// When overridden in a derived class, executes the code required to free the handle. + /// + /// true if the handle is released successfully + protected override bool ReleaseHandle() + { + this.SetHandle(IntPtr.Zero); + return true; + } + } +} diff --git a/packaging/csapi-account-manager.spec b/packaging/csapi-account-manager.spec index 3363fe2..c744d67 100644 --- a/packaging/csapi-account-manager.spec +++ b/packaging/csapi-account-manager.spec @@ -1,6 +1,6 @@ Name: csapi-account-manager Summary: Tizen account manager API for C# -Version: 1.0.7 +Version: 1.0.8 Release: 1 Group: Development/Libraries License: Apache-2.0 -- 2.7.4