--- /dev/null
+/*
+ * 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.Runtime.InteropServices;
+using Tizen.Account.AccountManager;
+/// <summary>
+/// Interop for Account class APIs
+/// </summary>
+/// <since_tizen> 3 </since_tizen>
+internal static partial class Interop
+{
+ /// <summary>
+ /// Interop for Account class APIs
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ internal static partial class Account
+ {
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_create", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int Create(out IntPtr 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);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_user_name", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAccountUserName(IntPtr data, out string userName);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_user_name", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountUserName(IntPtr handle, string userName);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_display_name", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAccountDisplayName(IntPtr handle, out string displayName);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_display_name", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountDisplayName(IntPtr 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);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_capability", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountCapability(IntPtr 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);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_icon_path", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountIconPath(IntPtr handle, string iconPath);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_domain_name", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAccountDomainName(IntPtr handle, out string domainName);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_domain_name", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountDomainName(IntPtr handle, string domainName);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_email_address", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAccountEmail(IntPtr handle, out string email);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_email_address", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountEmail(IntPtr handle, string email);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_package_name", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAccountPackageName(IntPtr handle, out string name);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_package_name", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountPackageName(IntPtr handle, string name);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_access_token", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAccountAccessToken(IntPtr handle, out string accessToken);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_access_token", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountAccessToken(IntPtr 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);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_user_text", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountUserText(IntPtr 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);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_user_int", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountUserInt(IntPtr 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);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_auth_type", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountAuthType(IntPtr handle, int authType);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_secret", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAccountSercet(IntPtr handle, out int secretType);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_secret", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountSecret(IntPtr handle, int secretType);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_sync_support", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAccountSyncSupport(IntPtr handle, out int syncType);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_sync_support", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountSyncSupport(IntPtr handle, int syncType);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_source", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAccountSource(IntPtr handle, out string source);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_source", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountSource(IntPtr 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);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_set_custom", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int SetAccountCustomValue(IntPtr 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);
+
+ [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);
+
+ //Callbacks
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool AccountCapabilityCallback(string capabilityType, int capabilityState, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool AccountCustomCallback(string key, string value, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool AccountCallback(IntPtr data, IntPtr userData);
+ }
+}
--- /dev/null
+/*
+ * 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.Runtime.InteropServices;
+using Tizen.Account.AccountManager;
+
+/// <summary>
+/// Interop for AccountProvider class APIs
+/// </summary>
+/// <since_tizen> 3 </since_tizen>
+internal static partial class Interop
+{
+ /// <summary>
+ /// Interop for AccountProvider class APIs
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ internal static partial class AccountProvider
+ {
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_create", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int Create(out IntPtr handle);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_destroy", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int Destroy(IntPtr handle);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_get_app_id", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAppId(IntPtr handle, out string appId);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_query_supported_feature", CallingConvention = CallingConvention.Cdecl)]
+ [return: MarshalAs(UnmanagedType.I1)]
+ internal static extern bool IsFeatureSupported(string appId, string capability);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_get_service_provider_id", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetServiceProviderId(IntPtr handle, out string providerId);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_get_icon_path", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAccountProviderIconPath(IntPtr handle, out string iconPath);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_get_small_icon_path", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAccountProviderSmallIconPath(IntPtr handle, out string iconPath);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_get_multiple_account_support", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetMultipleAccountSupport(IntPtr handle, out int suppport);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_get_label_by_locale", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetlabelbyLocale(IntPtr handle, string locale, out string label);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_query_app_id_exist", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAppIdExists(string appId);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_foreach_account_type_from_db", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAllAccountProviders(AccountProviderCallback callback, IntPtr data);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_query_provider_feature_by_app_id")]
+ internal static extern int GetAccountProviderFeaturesByAppId(AccountProviderFeatureCallback callback, string appId, IntPtr userData);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_get_provider_feature_all")]
+ internal static extern int GetAccountProviderFeatures(IntPtr handle, AccountProviderFeatureCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_get_label")]
+ internal static extern int GetAccountProviderLabels(IntPtr handle, LabelCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_query_label_by_app_id")]
+ internal static extern int GetLablesByAppId(LabelCallback callback, string appId, IntPtr userData);
+
+
+ //Callbacks
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool AccountProviderFeatureCallback(string appId, string key, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool AccountProviderCallback(IntPtr handle, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool LabelCallback(string appId, string label, string locale, IntPtr user_data);
+
+ }
+}
--- /dev/null
+/*
+ * 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.Runtime.InteropServices;
+
+/// <summary>
+/// Interop for Account class APIs
+/// </summary>
+/// <since_tizen> 3 </since_tizen>
+internal static partial class Interop
+{
+ /// <summary>
+ /// Interop for Account class APIs
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ 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);
+
+ [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);
+
+ [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);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_query_account_by_package_name", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int QueryAccountByPackageName(Interop.Account.AccountCallback callback, string packageName, IntPtr userData);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_query_capability_by_account_id", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int QueryAccountCapabilityById(Interop.Account.AccountCapabilityCallback callback, int accoutId, IntPtr data);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_update_sync_status_by_id", CallingConvention = CallingConvention.Cdecl)]
+ 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);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_delete_from_db_by_id", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int DeleteAccountById(int accountId);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_delete_from_db_by_user_name", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int DeleteAccountByUser(string userName, string packageName);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_delete_from_db_by_package_name", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int DeleteAccountByPackage(string packageName);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_total_count_from_db", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAccountCount(out int count);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_foreach_account_from_db")]
+ internal static extern int AccountForeachAccountFromDb(Interop.Account.AccountCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_query_account_by_capability")]
+ internal static extern int GetAccountByCapability(Interop.Account.AccountCallback callback, string capabilityType, int value, IntPtr userData);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_query_account_by_capability_type")]
+ internal static extern int GetAccountByCapabilityType(Interop.Account.AccountCallback callback, string capabilityType, IntPtr userData);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_foreach_account_type_from_db")]
+ internal static extern int GetAllAccountproviders(Interop.AccountProvider.AccountProviderCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_query_by_provider_feature")]
+ internal static extern int GetAccountProviderByFeature(Interop.AccountProvider.AccountProviderCallback callback, string key, IntPtr userData);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_query_by_app_id")]
+ internal static extern int GetAccountProviderByAppId(string appId, out IntPtr handle);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_subscribe_create")]
+ internal static extern int CreateAccountSubscriber(out Interop.AccountService.SafeAccountSubscriberHandle handle);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_subscribe_notification")]
+ internal static extern int RegisterSubscriber(Interop.AccountService.SafeAccountSubscriberHandle handle, Interop.AccountService.SubscribeCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.AccountSvc, EntryPoint = "account_unsubscribe_notification")]
+ internal static extern int UnregisterSubscriber(Interop.AccountService.SafeAccountSubscriberHandle handle);
+
+ //Callbacks
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool SubscribeCallback(string eventType, int accountId, IntPtr userData);
+
+ internal sealed class SafeAccountSubscriberHandle : SafeHandle
+ {
+ public SafeAccountSubscriberHandle()
+ : base(IntPtr.Zero, true)
+ {
+ }
+
+ public override bool IsInvalid
+ {
+ get { return this.handle == IntPtr.Zero; }
+ }
+
+ protected override bool ReleaseHandle()
+ {
+ this.SetHandle(IntPtr.Zero);
+ return true;
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+/// <summary>
+/// Interop for Library reference
+/// </summary>
+/// <since_tizen> 3 </since_tizen>
+internal static partial class Interop
+{
+ /// <summary>
+ /// Interop for Library reference
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ internal static partial class Libraries
+ {
+ public const string AccountSvc = "libaccounts-svc.so.0";
+ public const string Glib = "libglib-2.0.so.0";
+ public const string Libc = "libc.so.6";
+ }
+}
--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <Version>1.0.7</Version>
+ <Authors>Samsung Electronics</Authors>
+ <Copyright>© Samsung Electronics Co., Ltd All Rights Reserved</Copyright>
+ <Description>Account Service APIs for Tizen.Account.AccountManager</Description>
+ <PackageProjectUrl>https://www.tizen.org/</PackageProjectUrl>
+ <PackageLicenseUrl>https://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
+ <PackageIconUrl>https://developer.tizen.org/sites/default/files/images/tizen-pinwheel-on-light-rgb_64_64.png</PackageIconUrl>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <TargetFramework>netstandard1.6</TargetFramework>
+ <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
+ <SignAssembly>True</SignAssembly>
+ <AssemblyOriginatorKeyFile>Tizen.Account.AccountManager.snk</AssemblyOriginatorKeyFile>
+ <PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Tizen" Version="1.0.5" />
+ </ItemGroup>
+
+</Project>
--- /dev/null
+/*
+ * 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;
+
+namespace Tizen.Account.AccountManager
+{
+ /// <summary>
+ /// Represents the Account Information.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public class Account : IDisposable
+ {
+ private IntPtr _handle = IntPtr.Zero;
+ internal Account(IntPtr handle)
+ {
+ Handle = handle;
+ }
+
+ ~Account()
+ {
+ Dispose(false);
+ }
+ /// <summary>
+ /// Creates a new Account instance.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <returns>Account Instance.</returns>
+ public static Account CreateAccount()
+ {
+ IntPtr handle;
+ AccountError err = (AccountError)Interop.Account.Create(out handle);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to create new error.");
+ }
+
+ return new Account(handle);
+ }
+
+ /// <summary>
+ /// Id of the Account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <remarks>Account Id shall be created only when account is added to the database.</remarks>
+ public int AccountId
+ {
+ get
+ {
+ int id = 0;
+ AccountError res = (AccountError)Interop.Account.GetAccountId(_handle, out id);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get Id for the Account");
+ }
+
+ return id;
+ }
+ }
+
+ /// <summary>
+ /// UserName of the Account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>User Name of the Account.</value>
+ public string UserName
+ {
+ get
+ {
+ string name = "";
+ AccountError res = (AccountError)Interop.Account.GetAccountUserName(_handle, out name);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get UserName for the Account");
+ }
+
+ return name;
+ }
+
+ set
+ {
+ AccountError res = (AccountError)Interop.Account.SetAccountUserName(_handle, value);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to Set UserName for Account");
+ }
+ }
+ }
+
+ /// <summary>
+ /// Display Name of the Account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>DisplayName of the Account.</value>
+ public string DisplayName
+ {
+ get
+ {
+ string name = "";
+ AccountError res = (AccountError)Interop.Account.GetAccountDisplayName(_handle, out name);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get DisplayName for the Account");
+ }
+
+ return name;
+ }
+
+ set
+ {
+ AccountError res = (AccountError)Interop.Account.SetAccountDisplayName(_handle, value);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to Set DisplayName for Account");
+ }
+ }
+ }
+
+ /// <summary>
+ /// Icon path of the Account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>Icon path of the Account.</value>
+ public string IconPath
+ {
+ get
+ {
+ string path = "";
+ AccountError res = (AccountError)Interop.Account.GetAccountIconPath(_handle, out path);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get IconPath for the Account");
+ }
+
+ return path;
+ }
+
+ set
+ {
+ AccountError res = (AccountError)Interop.Account.SetAccountIconPath(_handle, value);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to Set IconPath for Account");
+ }
+ }
+ }
+
+ /// <summary>
+ /// Domain name of the Account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>Domain name of the Account.</value>
+ public string DomainName
+ {
+ get
+ {
+ string name = "";
+ AccountError res = (AccountError)Interop.Account.GetAccountDomainName(_handle, out name);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get DomainName for the Account");
+ }
+
+ return name;
+ }
+
+ set
+ {
+ AccountError res = (AccountError)Interop.Account.SetAccountDomainName(_handle, value);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to Set DomainName for Account");
+ }
+ }
+ }
+
+ /// <summary>
+ /// Email Id of the Account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>Email Id of the Account.</value>
+ public string EmailId
+ {
+ get
+ {
+ string email = "";
+ AccountError res = (AccountError)Interop.Account.GetAccountEmail(_handle, out email);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get email for the Account");
+ }
+
+ return email;
+ }
+
+ set
+ {
+ AccountError res = (AccountError)Interop.Account.SetAccountEmail(_handle, value);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to Set email for Account");
+ }
+ }
+ }
+
+ /// <summary>
+ /// Package Name of the Account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>Package Name.</value>
+ public string PackageName
+ {
+ get
+ {
+ string name = "";
+ AccountError res = (AccountError)Interop.Account.GetAccountPackageName(_handle, out name);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get PacakageName for the Account");
+ }
+
+ return name;
+ }
+
+ set
+ {
+ AccountError res = (AccountError)Interop.Account.SetAccountPackageName(_handle, value);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to Set PacakageName for Account");
+ }
+ }
+ }
+
+ /// <summary>
+ /// Access Token of the Account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>Access Token.</value>
+ public string AccessToken
+ {
+ get
+ {
+ string token = "";
+ AccountError res = (AccountError)Interop.Account.GetAccountAccessToken(_handle, out token);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get token for the Account");
+ }
+
+ return token;
+ }
+
+ set
+ {
+ AccountError res = (AccountError)Interop.Account.SetAccountAccessToken(_handle, value);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to Set token for Account");
+ }
+ }
+ }
+
+ /// <summary>
+ /// Authentication type of the Account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>Authentication type.</value>
+ public AccountAuthType AuthType
+ {
+ get
+ {
+ int user;
+ AccountError res = (AccountError)Interop.Account.GetAccountAuthType(_handle, out user);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get AuthType for the Account");
+ }
+
+ return (AccountAuthType)user;
+ }
+
+ set
+ {
+ AccountError res = (AccountError)Interop.Account.SetAccountAuthType(_handle, (int)value);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to Set AuthType for Account");
+ }
+ }
+ }
+
+ /// <summary>
+ /// Secrecy State of the Account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>Secrecy State.</value>
+ public AccountSecrecyState SecrecyState
+ {
+ get
+ {
+ int state;
+ AccountError res = (AccountError)Interop.Account.GetAccountSercet(_handle, out state);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get User Secret for the Account");
+ }
+
+ return (AccountSecrecyState)state;
+ }
+
+ set
+ {
+ AccountError res = (AccountError)Interop.Account.SetAccountSecret(_handle, (int)value);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to Set User Secret for Account");
+ }
+ }
+ }
+
+ /// <summary>
+ /// Sync State of the Account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>Sync State.</value>
+ public AccountSyncState SyncState
+ {
+ get
+ {
+ int supported;
+ AccountError res = (AccountError)Interop.Account.GetAccountSyncSupport(_handle, out supported);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get AuthType for the Account");
+ }
+
+ return (AccountSyncState)supported;
+ }
+
+ set
+ {
+ AccountError res = (AccountError)Interop.Account.SetAccountSyncSupport(_handle, (int)value);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to Set AuthType for Account");
+ }
+ }
+ }
+
+ /// <summary>
+ /// Source of the Account .
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>Account Source.</value>
+ public string Source
+ {
+ get
+ {
+ string text = "";
+ AccountError res = (AccountError)Interop.Account.GetAccountSource(_handle, out text);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get User Secret for the Account");
+ }
+
+ return text;
+ }
+
+ set
+ {
+ AccountError res = (AccountError)Interop.Account.SetAccountSource(_handle, value);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to Set User Secret for Account");
+ }
+ }
+ }
+
+ internal IntPtr Handle
+ {
+ get
+ {
+ return _handle;
+ }
+
+ set
+ {
+ _handle = value;
+ }
+ }
+ /// <summary>
+ /// Sets the account capability.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="capabilityType"> The Account capability type</param>
+ /// <param name="state">The Account capability state</param>
+ /// <exception cref="ArgumentException">In case of invalid parameters</exception>
+ public void SetCapability(string capabilityType, CapabilityState state)
+ {
+ AccountError ret = (AccountError)Interop.Account.SetAccountCapability(_handle, capabilityType, (int)state);
+ if (ret != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(ret, "failed to set account capability");
+ }
+ }
+ /// <summary>
+ /// Gets all the capabilities of an account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="capabilityType"> The capability type to get the capability value.</param>
+ /// <returns>The capability value (on/off) of the specified CapabilityState .</returns>
+ /// <exception cref="ArgumentException">In case of invalid parameters</exception>
+ public CapabilityState GetCapability(string capabilityType)
+ {
+ int type;
+ AccountError res = (AccountError)Interop.Account.GetAccountCapability(_handle, capabilityType, out type);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to GetCapability for Account");
+ }
+
+ return (CapabilityState)type;
+ }
+
+ /// <summary>
+ /// Gets all the capabilities of an account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <returns>List of Cpabailities as Dictionary</returns>
+ public Dictionary<string, CapabilityState> GetAllCapabilities()
+ {
+
+ AccountError res = AccountError.None;
+ Dictionary<string, CapabilityState> list = new Dictionary<string, CapabilityState>();
+ Interop.Account.AccountCapabilityCallback capabilityCallback = (string type, int state, IntPtr data) =>
+ {
+ list.Add(type, (CapabilityState)state);
+ return true;
+ };
+
+ res = (AccountError)Interop.Account.GetAllAccountCapabilities(_handle, capabilityCallback, IntPtr.Zero);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to get account capabilities");
+ }
+
+ return list;
+ }
+
+ /// <summary>
+ /// Sets the Custom Value to the Account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="key">key to be added to the Account.</param>
+ /// <param name="value">value to be updated for respective key for the Account.</param>
+ /// <exception cref="ArgumentException">In case of invalid parameters</exception>
+ public void SetCustomValue(string key, string value)
+ {
+ AccountError err = (AccountError)Interop.Account.SetAccountCustomValue(_handle, key, value);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to set the value for : " + key);
+ }
+ }
+
+ /// <summary>
+ /// Gets the user specific custom text of an account key.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="key">The key to retrieve custom text .</param>
+ /// <returns>The text of the given key</returns>
+ /// <exception cref="ArgumentException">In case of invalid parameters</exception>
+ /// <exception cref="InvalidOperationException">If there is no given capability type in the account </exception>
+ public string GetCustomValue(string key)
+ {
+ string result = "";
+ AccountError err = (AccountError)Interop.Account.GetAccountCustomValue(_handle, key, out result);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to get the value for : " + key);
+ }
+
+ return result;
+ }
+
+ /// <summary>
+ /// Gets All the custome values.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <returns>List of custom key, value pairs as Dictionary.</returns>
+ public Dictionary<string, string> GetAllCustomValues()
+ {
+ AccountError res = AccountError.None;
+ Dictionary<string, string> list = new Dictionary<string, string>();
+
+ Interop.Account.AccountCustomCallback customCallback = (string key, string value, IntPtr data) =>
+ {
+ list.Add(key, value);
+ return true;
+ };
+
+ res = (AccountError)Interop.Account.GetAllAccountCustomValues(_handle, customCallback, IntPtr.Zero);
+
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to get account capabilities");
+ }
+
+ return list;
+ }
+
+ /// <summary>
+ /// Sets the user text.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="index">The index of the user text (must be in range from 0 to 4) </param>
+ /// <param name="text">The text string to set as the user text</param>
+ /// <exception cref="ArgumentException">In case of invalid parameters</exception>
+ public void SetUserText(int index, string text)
+ {
+ AccountError err = (AccountError)Interop.Account.SetAccountUserText(_handle, index, text);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to get the value for : " + index);
+ }
+ }
+
+ /// <summary>
+ /// Gets the user text.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="index">The index of the user text (range: 0 ~ 4)</param>
+ /// <returns>The user text of the given key</returns>
+ /// <exception cref="ArgumentException">In case of invalid parameters</exception>
+ /// <exception cref="OutOfMemoryException">In case of out of memory</exception>
+ public string GetUserText(int index)
+ {
+ string result = "";
+ AccountError err = (AccountError)Interop.Account.GetAccountUserText(_handle, index, out result);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to get the value for : " + index);
+ }
+
+ return result;
+ }
+
+ /// <summary>
+ /// Gets the user int value.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="index">The index of the user int (range: 0 ~ 4)</param>
+ /// <returns>The user int of the given key</returns>
+ /// <exception cref="ArgumentException">In case of invalid parameters</exception>
+ public int GetUserInt(int index)
+ {
+ int result = -1;
+ AccountError err = (AccountError)Interop.Account.GetAccountUserInt(_handle, index, out result);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to get the value for : " + index);
+ }
+
+ return result;
+ }
+
+ /// <summary>
+ /// Sets the user integer value.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="index">The index of the user integer (must be in range from 0 to 4) </param>
+ /// <param name="value">The integer to set as the user integer</param>
+ /// <exception cref="ArgumentException">In case of invalid parameters</exception>
+ public void SetUserInt(int index, int value)
+ {
+ AccountError err = (AccountError)Interop.Account.SetAccountUserInt(_handle, index, value);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to get the value for : " + index);
+ }
+ }
+
+ /// <summary>
+ /// Overloaded Dispose API for destroying the Account Handle.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ private void Dispose(bool disposing)
+ {
+ if (!disposing)
+ {
+ if (_handle != IntPtr.Zero)
+ {
+ _handle = IntPtr.Zero;
+ }
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+namespace Tizen.Account.AccountManager
+{
+ /// <summary>
+ /// Enumeration for the state of capability
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public enum CapabilityState
+ {
+ /// <summary>
+ /// Account capability is invalid
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ InvalidState,
+
+ /// <summary>
+ /// Account capability is disabled
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Disabled,
+
+ /// <summary>
+ /// Account capability is enabled
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Enabled
+ }
+
+ /// <summary>
+ /// Enumeration for the state of account secrecy.
+ /// </summary>
+ public enum AccountSecrecyState
+ {
+ /// <summary>
+ /// Account secrecy is invalid
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ InvalidState,
+
+ /// <summary>
+ /// Account is not visible
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Invisible,
+
+ /// <summary>
+ /// Account is visible
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Visible
+ }
+
+ /// <summary>
+ /// Enumeration for the account sync status.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public enum AccountSyncState
+ {
+ /// <summary>
+ /// Account sync is invalid
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ InvalidState,
+
+ /// <summary>
+ /// Account sync not supported
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ NotSupported,
+
+ /// <summary>
+ /// Account sync supported but all synchronization functionalities are off
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Off,
+
+ /// <summary>
+ /// Account sync support and sync status is idle
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Idle,
+
+ /// <summary>
+ /// Account sync support and sync status is running
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Running
+ }
+
+ /// <summary>
+ /// Enumeration for the account auth type.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public enum AccountAuthType
+ {
+ /// <summary>
+ /// Auth type is invalid
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Invalid,
+
+ /// <summary>
+ /// XAuth type
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ XAuth,
+
+ /// <summary>
+ /// OAuth type
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ OAuth,
+
+ /// <summary>
+ /// Client-Login type
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ ClientLogin
+ }
+
+ /// <summary>
+ /// Account information change notification type
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <remarks>
+ /// When the account database is changed, You can distinguish one event type from the other which are set for subscribing notification.
+ /// </remarks>
+ public enum AccountNotificationType
+ {
+ /// <summary>
+ /// The insert notification type.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Insert,
+ /// <summary>
+ /// The delete notification type.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Delete,
+ /// <summary>
+ /// The update notification type.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Update,
+ /// <summary>
+ /// The sync update notification type.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ syncUpdate
+ }
+}
--- /dev/null
+/*
+ * 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 Tizen;
+
+namespace Tizen.Account.AccountManager
+{
+ /// <summary>
+ /// Enum to give the type of error occured, if any.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public enum AccountError
+ {
+ //TIZEN_ERROR_ACCOUNT = -0x01000000
+ /// <summary>
+ /// Successful.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ None = Tizen.Internals.Errors.ErrorCode.None,
+ /// <summary>
+ /// Invalid parameter.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
+ /// <summary>
+ /// Out of memory.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
+ /// <summary>
+ /// Same user name exists in your application
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Duplcated = -0x01000000 | 0x01,
+ /// <summary>
+ /// Empty Data
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ NoData = Tizen.Internals.Errors.ErrorCode.NoData,
+ /// <summary>
+ /// elated record does not exist
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ RecordNotFound = -0x01000000 | 0x03,
+ /// <summary>
+ /// Invalid Operation.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ InvalidOperation = Tizen.Internals.Errors.ErrorCode.InvalidOperation,
+ /// <summary>
+ /// DB operation failed.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ DBFailed = -0x01000000 | 0x04,
+ /// <summary>
+ /// DB is not connected.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ DBNotOpened = -0x01000000 | 0x05,
+ /// <summary>
+ /// DB query syntax error
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ QuerySyntaxError = -0x01000000 | 0x06,
+ /// <summary>
+ /// Iterator has reached the end
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ IteratorEnd = -0x01000000 | 0x07,
+ /// <summary>
+ /// Notification failed
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ NotificationFailed = -0x01000000 | 0x08,
+ /// <summary>
+ /// Permission denied.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
+ /// <summary>
+ /// XML parse failed
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ XMLParseFailed = -0x01000000 | 0x0a,
+ /// <summary>
+ /// XML File not found
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ XMLFileNotFound = -0x01000000 | 0x0b,
+ /// <summary>
+ /// Subscription failed
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ EventSubscriptionFailed = -0x01000000 | 0x0c,
+ /// <summary>
+ /// Account provider is not registered
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ ProviderNotRegistered = -0x01000000 | 0x0d,
+ /// <summary>
+ /// Multiple accounts are not supported.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ MultipleNotAllowed = -0x01000000 | 0x0e,
+ /// <summary>
+ /// SQLite busy handler expired
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ DBBusy = -0x01000000 | 0x10
+ };
+
+ internal class AccountErrorFactory
+ {
+ internal const string LogTag = "Tizen.Account.AccountManager";
+
+ internal static Exception CreateException(AccountError err, string msg)
+ {
+ Log.Info(LogTag, "Got Error " + err + " throwing Exception with msg " + msg);
+ Exception exp;
+ switch (err)
+ {
+ case AccountError.InvalidParameter:
+ {
+ exp = new ArgumentException(msg + " Invalid Parameters Provided");
+ break;
+ }
+
+ case AccountError.OutOfMemory:
+ {
+ exp = new OutOfMemoryException(msg + " Out Of Memory");
+ break;
+ }
+
+ case AccountError.InvalidOperation:
+ {
+ exp = new InvalidOperationException(msg + " Inavlid operation");
+ break;
+ }
+
+ case AccountError.NoData:
+ {
+ exp = new InvalidOperationException(msg + " Empty Data");
+ break;
+ }
+
+ case AccountError.PermissionDenied:
+ {
+ exp = new UnauthorizedAccessException(msg + " Permission Denied");
+ break;
+ }
+
+ case AccountError.DBFailed:
+ {
+ exp = new InvalidOperationException(msg + " DataBase Failed");
+ break;
+ }
+
+ case AccountError.DBBusy:
+ {
+ exp = new InvalidOperationException(msg + " DataBase Busy");
+ break;
+ }
+
+ case AccountError.QuerySyntaxError:
+ {
+ exp = new InvalidOperationException(msg + " Network Error");
+ break;
+ }
+ case AccountError.XMLFileNotFound:
+ {
+ exp = new System.IO.FileNotFoundException(msg + " XML File not found");
+ break;
+ }
+ case AccountError.XMLParseFailed:
+ {
+ exp = new System.IO.InvalidDataException(msg + " XML parse error");
+ break;
+ }
+
+ default:
+ {
+ exp = new InvalidOperationException(err + " " + msg);
+ break;
+ }
+ }
+
+ return exp;
+ }
+ }
+}
--- /dev/null
+/*
+ * 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 Tizen.Internals.Errors;
+
+namespace Tizen.Account.AccountManager
+{
+ /// <summary>
+ /// Account Id.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public class AccountProvider : IDisposable
+ {
+ internal IntPtr _handle;
+ internal AccountProvider(IntPtr handle)
+ {
+ Handle = handle;
+ }
+
+ ~AccountProvider()
+ {
+ Dispose(false);
+ }
+
+ internal IntPtr Handle
+ {
+ get
+ {
+ return _handle;
+ }
+
+ set
+ {
+ _handle = value;
+ }
+ }
+ /// <summary>
+ /// Account Id.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public string AppId
+ {
+ get
+ {
+ string id = "";
+ AccountError res = (AccountError)Interop.AccountProvider.GetAppId(Handle, out id);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get AppId for the AccountProvider");
+ }
+
+ return id;
+ }
+ }
+
+ /// <summary>
+ /// Serviceprovider Id of the account provider.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public string ServiceProviderId
+ {
+ get
+ {
+ string id = "";
+ AccountError res = (AccountError)Interop.AccountProvider.GetServiceProviderId(Handle, out id);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get ServiceProviderId for the AccountProvider");
+ }
+
+ return id;
+ }
+ }
+
+ /// <summary>
+ /// Icon path of an account provider.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public string IconPath
+ {
+ get
+ {
+ string path = "";
+ AccountError res = (AccountError)Interop.AccountProvider.GetAccountProviderIconPath(Handle, out path);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get IconPath for the AccountProvider");
+ }
+
+ return path;
+ }
+ }
+
+ /// <summary>
+ /// Small icon path of an account provider.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public string SmallIconPath
+ {
+ get
+ {
+ string path = "";
+ AccountError res = (AccountError)Interop.AccountProvider.GetAccountProviderSmallIconPath(Handle, out path);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get SmallIconPath for the AccountProvider");
+ }
+
+ return path;
+ }
+ }
+
+ /// <summary>
+ /// Flag for account provider If supports multiple accounts.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public bool MultipleAccountSupport
+ {
+ get
+ {
+ int multiple = 0;
+ AccountError res = (AccountError)Interop.AccountProvider.GetMultipleAccountSupport(Handle, out multiple);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get SmallIconPath for the AccountProvider");
+ }
+
+ return (multiple == 0) ? false : true;
+ }
+ }
+
+ /// <summary>
+ /// Retrieves all the capability information of the account provider.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <returns>
+ /// list of capability information.
+ /// </returns>
+ /// <exception cref="InvalidOperationException">In case of any DB error</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public IEnumerable<string> GetAllCapabilities()
+ {
+ List<string> capabilities = new List<string>();
+ AccountError res;
+ Interop.AccountProvider.AccountProviderFeatureCallback callback = (string appId, string key, IntPtr data) =>
+ {
+ capabilities.Add(key);
+ return true;
+ };
+
+ res = (AccountError)Interop.AccountProvider.GetAccountProviderFeatures(Handle, callback, IntPtr.Zero);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to GetAllCapabilities for AccountProvider");
+ }
+
+ return capabilities;
+ }
+
+ /// <summary>
+ /// Gets the specific label information detail of an account provider.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="locale">
+ /// The locale is specified as an ISO 3166 alpha-2 two letter country-code followed by ISO 639-1 for the two-letter language code.
+ /// For example, "ko_KR" or "ko-kr" for Korean, "en_US" or "en-us" for American English.
+ /// </param>
+ /// <returns>The label text given for the locale</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given locale</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public string GetLabel(string locale)
+ {
+ string label;
+ AccountError res = (AccountError)Interop.AccountProvider.GetlabelbyLocale(Handle, locale, out label);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to GetLabel for AccountProvider");
+ }
+
+ return label;
+ }
+
+ /// <summary>
+ /// Gets the specific label information detail of an account provider.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="appId">
+ /// The application ID to search
+ /// </param>
+ /// <returns> All the labels information for the given application Id.</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given appid</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static Dictionary<string, string> GetLabelsByAppId(string appId)
+ {
+
+ Dictionary<string, string> labels = new Dictionary<string, string>();
+ Interop.AccountProvider.LabelCallback callback = (string applicationId, string label, string locale, IntPtr userData) =>
+ {
+ labels.Add(locale, label);
+ return true;
+ };
+
+ AccountError err = (AccountError)Interop.AccountProvider.GetLablesByAppId(callback, appId, IntPtr.Zero);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to GetLablesByAppId");
+ }
+
+ return labels;
+ }
+
+ /// <summary>
+ /// Gets the label information detail of an account provider.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <returns> All the labels information for the given account provider.</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public Dictionary<string, string> GetLabels()
+ {
+
+ Dictionary<string, string> labels = new Dictionary<string, string>();
+ Interop.AccountProvider.LabelCallback callback = (string applicationId, string label, string locale, IntPtr userData) =>
+ {
+ labels.Add(locale, label);
+ return true;
+ };
+
+ AccountError err = (AccountError)Interop.AccountProvider.GetAccountProviderLabels(Handle, callback, IntPtr.Zero);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to GetAccountProviderLabels");
+ }
+
+ return labels;
+ }
+
+ /// <summary>
+ /// Checks whether the given appId exists in the account provider DB.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="appId">The application ID to check.</param>
+ /// <returns>returns true If App is supported </returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given appid</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public bool IsAppSupported(string appId)
+ {
+ bool isSupported = false;
+ AccountError res = (AccountError)Interop.AccountProvider.GetAppIdExists(appId);
+
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to GetLabel for AccountProvider");
+ }
+ else
+ {
+ isSupported = true;
+ }
+
+ return isSupported;
+ }
+
+ /// <summary>
+ /// Checks whether the given application ID supports the capability.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="appId">The application Id</param>
+ /// <param name="capability">The capability information</param>
+ /// <returns>
+ /// TRUE if the application supports the given capability,
+ /// otherwise FALSE if the application does not support the given capability
+ /// </returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static bool IsFeatureSupportedByApp(string appId, string capability)
+ {
+ bool supported = Interop.AccountProvider.IsFeatureSupported(appId, capability);
+ if (!supported)
+ {
+ //Get last result and validate error code.
+ AccountError err = (AccountError)ErrorFacts.GetLastResult();
+ if ((err != AccountError.None) && (err != AccountError.RecordNotFound))
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to get IsFeatureSupported");
+ }
+ }
+
+ return supported;
+ }
+
+ /// <summary>
+ /// Retrieves capability information with application ID.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="appId">application Id</param>
+ /// <returns> Capability information list for the given appId.</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given appid</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static IEnumerable<string> GetFeaturesByAppId(string appId)
+ {
+
+ List<string> features = new List<string>();
+ Interop.AccountProvider.AccountProviderFeatureCallback callback = (string applicationId, string key, IntPtr userData) =>
+ {
+ features.Add(key);
+ return true;
+ };
+
+ AccountError err = (AccountError)Interop.AccountProvider.GetAccountProviderFeaturesByAppId(callback, appId, IntPtr.Zero);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to GetAccountProviderFeaturesByAppId");
+ }
+
+ return (IEnumerable<string>)features;
+ }
+
+ /// <summary>
+ /// Overloaded Dispose API for destroying the AccountProvider Handle.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ private void Dispose(bool disposing)
+ {
+ if (!disposing)
+ {
+ if (_handle != IntPtr.Zero)
+ {
+ Interop.AccountProvider.Destroy(_handle);
+ _handle = IntPtr.Zero;
+ }
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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;
+
+namespace Tizen.Account.AccountManager
+{
+ /// <summary>
+ /// The AccountManager APIs is separated into two major sections:
+ /// 1. Registering an account provider while an application is installed. This information will be used for the Add account screen.
+ /// 2. Adding an account information when an application signs in successfully to share the account information to the Tizen system. This information will be shown in the Tizen settings account menu.
+ ///
+ /// The APIs of both of the sections consist of the following functionality:
+ /// <list>
+ /// <item> Create an account or account provider </item>
+ /// <item> Update an account or account provider(Only available for the creator) </item>
+ /// <item> Delete an account or account provider(Only available for the creator) </item>
+ /// <item> Read an account or account provider with some filter </item>
+ /// </list>
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+
+ public static class AccountService
+ {
+ /// <summary>
+ /// This is contact capability string.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public static readonly string ContactCapability = "http://tizen.org/account/capability/contact";
+
+ /// <summary>
+ /// This is calendar capability string.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public static readonly string CalendarCapability = "http://tizen.org/account/capability/calendar";
+
+ /// <summary>
+ /// This is email capability string.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public static readonly string EmailCapability = "http://tizen.org/account/capability/email";
+
+ /// <summary>
+ /// This is photo capability string.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public static readonly string PhotoCapability = "http://tizen.org/account/capability/photo";
+
+ /// <summary>
+ /// This is video capability string.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public static readonly string VideoCapability = "http://tizen.org/account/capability/video";
+
+ /// <summary>
+ /// This is music capability string.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public static readonly string MusicCapability = "http://tizen.org/account/capability/music";
+
+ /// <summary>
+ /// This is document capability string.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public static readonly string DocumentCapability = "http://tizen.org/account/capability/document";
+
+ /// <summary>
+ /// This is message capability string.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public static readonly string MessageCapability = "http://tizen.org/account/capability/message";
+
+ /// <summary>
+ /// This is game capability string.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public static readonly string GameCapability = "http://tizen.org/account/capability/game";
+
+ /// <summary>
+ /// Retrieves all accounts details from the account database.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <returns>List of Accounts</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error. </exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static IEnumerable<Account> GetAccountsAsync()
+ {
+ List<Account> accounts = new List<Account>();
+ List<int> values = new List<int>();
+ Interop.Account.AccountCallback accountCallback = (IntPtr data, IntPtr userdata) =>
+ {
+ Account account = new Account(data);
+ values.Add(account.AccountId);
+ account.Dispose();
+ return true;
+ };
+
+ AccountError res = (AccountError)Interop.AccountService.AccountForeachAccountFromDb(accountCallback, IntPtr.Zero);
+ if (res != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(res, "Failed to AccountForeachAccountFromDb");
+ }
+
+ foreach (int i in values)
+ {
+ Account account = AccountService.GetAccountById(i);
+ accounts.Add(account);
+ }
+
+ return accounts;
+ }
+
+ /// <summary>
+ /// Retrieve an account with the account ID.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="accountId"> The account Id to be searched.</param>
+ /// <returns>Account instance with reference to the given id.</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given account id</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static Account GetAccountById(int accountId)
+ {
+ Account account = Account.CreateAccount();
+ IntPtr handle = account.Handle;
+ AccountError res = (AccountError)Interop.AccountService.QueryAccountById(accountId, out 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;
+ }
+
+ /// <summary>
+ /// Retrieves all AccountProviders details from the account database.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <returns>List of AccountProviders</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static IEnumerable<AccountProvider> GetAccountProviders()
+ {
+ List<string> values = new List<string>();
+ List<AccountProvider> providers = new List<AccountProvider>();
+ Interop.AccountProvider.AccountProviderCallback accountCallback = (IntPtr handle, IntPtr data) =>
+ {
+ AccountProvider provider = new AccountProvider(handle);
+ values.Add(provider.AppId);
+ provider.Dispose();
+ return true;
+ };
+
+ AccountError res = (AccountError)Interop.AccountService.GetAllAccountproviders(accountCallback, IntPtr.Zero);
+ if (res != AccountError.None)
+ {
+ Log.Warn(AccountErrorFactory.LogTag, "Failed to get account providers from the database");
+ throw AccountErrorFactory.CreateException(res, "Failed to get account providers from the database");
+ }
+
+ foreach (string val in values)
+ {
+ AccountProvider provider = GetAccountProviderByAppId(val);
+ providers.Add(provider);
+ }
+
+ return providers;
+ }
+
+ /// <summary>
+ /// Retrieves the account provider information with application Id.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="appId">Application Id.</param>
+ /// <returns>The AccountProvider instance associated with the given application Id.</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given appid</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static AccountProvider GetAccountProviderByAppId(string appId)
+ {
+ IntPtr handle;
+ Interop.AccountProvider.Create(out handle);
+ AccountError err = (AccountError)Interop.AccountService.GetAccountProviderByAppId(appId, out handle);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to GetAccountProviderByAppId");
+ }
+
+ AccountProvider provider = new AccountProvider(handle);
+ return provider;
+ }
+
+ /// <summary>
+ /// Retrieves all the account providers information with feature.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="feature">The capability value to search for account providers.</param>
+ /// <returns>Retrieves AccountProviders information with the capability name.</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given feature</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static IEnumerable<AccountProvider> GetAccountProvidersByFeature(string feature)
+ {
+ List<string> values = new List<string>();
+ List<AccountProvider> providers = new List<AccountProvider>();
+ Interop.AccountProvider.AccountProviderCallback providerCallback = (IntPtr handle, IntPtr data) =>
+ {
+ AccountProvider provider = new AccountProvider(handle);
+ values.Add(provider.AppId);
+ provider.Dispose();
+ return true;
+ };
+
+ AccountError err = (AccountError)Interop.AccountService.GetAccountProviderByFeature(providerCallback, feature, IntPtr.Zero);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to GetAccountProviderByFeature");
+ }
+
+ foreach (string val in values)
+ {
+ AccountProvider provider = GetAccountProviderByAppId(val);
+ providers.Add(provider);
+ }
+
+ return providers;
+ }
+
+ /// <summary>
+ /// Inserts into the Database with the new account Infomration.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="account">New Account instance to be added.</param>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <privilege>http://tizen.org/privilege/account.write </privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ /// <exception cref="OutOfMemoryException"> In case of OutOfMemory error.</exception>
+ public static int AddAccount(Account account)
+ {
+ if (account == null)
+ {
+ throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to AddAccount");
+ }
+
+ int id = -1;
+ AccountError err = (AccountError)Interop.AccountService.AddAccount(account.Handle, out id);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to AddAccount");
+ }
+
+ return id;
+ }
+
+ /// <summary>
+ /// Updates the account details to the account database.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="account">account instance to be updated.</param>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <privilege>http://tizen.org/privilege/account.write </privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error </exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ /// <exception cref="OutOfMemoryException"> In case of OutOfMemory error.</exception>
+ public static void UpdateAccount(Account account)
+ {
+ if (account == null)
+ {
+ throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to UpdateAccount");
+ }
+
+ AccountError err = (AccountError)Interop.AccountService.UpdateAccountToDBById(account.Handle, account.AccountId);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to UpdateAccount");
+ }
+ }
+
+ /// <summary>
+ /// Deletes the account information from the Database.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="account">Account instance to be deleted from the database.</param>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <privilege>http://tizen.org/privilege/account.write </privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error </exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static void DeleteAccount(Account account)
+ {
+ if (account == null)
+ {
+ throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to DeleteAccount");
+ }
+
+ AccountError err = (AccountError)Interop.AccountService.DeleteAccountById(account.AccountId);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to delete the account by Id: " + account.AccountId);
+ }
+ }
+
+ /// <summary>
+ /// Deletes an account from the account database by user name.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="userName">The user name of the account to delete.</param>
+ /// <param name="packageName">The package name of the account to delete.</param>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <privilege>http://tizen.org/privilege/account.write </privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static void DeleteAccount(string userName, string packageName)
+ {
+ AccountError err = (AccountError)Interop.AccountService.DeleteAccountByUser(userName, packageName);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to delete the account by userName: " + userName);
+ }
+ }
+
+ /// <summary>
+ /// Deletes an account from the account database by package name.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="packageName">The package name of the account to delete.</param>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <privilege>http://tizen.org/privilege/account.write </privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static void DeleteAccount(string packageName)
+ {
+ AccountError err = (AccountError)Interop.AccountService.DeleteAccountByPackage(packageName);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to delete the account by package name: " + packageName);
+ }
+
+ }
+
+ /// <summary>
+ /// Retrieves all accounts with the given user name.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="userName">The user name to search .</param>
+ /// <returns>Accounts list matched with the user name</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given username</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static IEnumerable<Account> GetAccountsByUserName(string userName)
+ {
+ List<Account> accounts = new List<Account>();
+ List<int> values = new List<int>();
+ Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
+ {
+ Account account = new Account(handle);
+ values.Add(account.AccountId);
+ account.Dispose();
+ return true;
+ };
+
+ AccountError err = (AccountError)Interop.AccountService.QueryAccountByUserName(accountCallback, userName, IntPtr.Zero);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to GetAccountByUserName");
+ }
+
+ foreach (int i in values)
+ {
+ Account account = AccountService.GetAccountById(i);
+ accounts.Add(account);
+ }
+
+ return accounts;
+ }
+
+ /// <summary>
+ /// Retrieves all accounts with the given package name.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="packageName"> The package name to Search</param>
+ /// <returns>Accounts list matched with the package name</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given package name</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static IEnumerable<Account> GetAccountsByPackageName(string packageName)
+ {
+ List<Account> accounts = new List<Account>();
+ List<int> values = new List<int>();
+ Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
+ {
+ Account account = new Account(handle);
+ values.Add(account.AccountId);
+ account.Dispose();
+ return true;
+ };
+
+ AccountError err = (AccountError)Interop.AccountService.QueryAccountByPackageName(accountCallback, packageName, IntPtr.Zero);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to GetAccountByPackageName");
+ }
+
+ foreach (int i in values)
+ {
+ Account account = AccountService.GetAccountById(i);
+ accounts.Add(account);
+ }
+
+ return accounts;
+ }
+
+ /// <summary>
+ /// Retrieves all accounts with the given cpability type.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="type"> Capability type</param>
+ /// <returns>Accounts list matched with the capability type</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given capability type</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static IEnumerable<Account> GetAccountsByCapabilityType(string type)
+ {
+ List<Account> accounts = new List<Account>();
+ List<int> values = new List<int>();
+ Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
+ {
+ Account account = new Account(handle);
+ values.Add(account.AccountId);
+ account.Dispose();
+ return true;
+ };
+
+ AccountError err = (AccountError)Interop.AccountService.GetAccountByCapabilityType(accountCallback, type, IntPtr.Zero);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to GetAccountByCapabilityType");
+ }
+
+ foreach (int i in values)
+ {
+ Account account = AccountService.GetAccountById(i);
+ accounts.Add(account);
+ }
+
+ return accounts;
+ }
+
+ /// <summary>
+ /// Retrieves all capabilities with the given account
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="accountId">account instance</param>
+ /// <returns>Capabilities list as Dictionary of Capability type and State.</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given account id</exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static Dictionary<string, CapabilityState> GetCapabilitiesById(int accountId)
+ {
+ Dictionary<string, CapabilityState> capabilities = new Dictionary<string, CapabilityState>();
+ Interop.Account.AccountCapabilityCallback capabilityCallback = (string type, int capabilityState, IntPtr data) =>
+ {
+ capabilities.Add(type, (CapabilityState)capabilityState);
+ return true;
+ };
+
+ AccountError err = (AccountError)Interop.AccountService.QueryAccountCapabilityById(capabilityCallback, accountId, IntPtr.Zero);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to GetAllCapabilitiesById");
+ }
+
+ return capabilities;
+ }
+
+ /// <summary>
+ /// Gets the count of accounts in the account database.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <returns>The number of accounts in the database</returns>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error </exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static int GetAccountsCount()
+ {
+ int count = 0;
+ AccountError err = (AccountError)Interop.AccountService.GetAccountCount(out count);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to GetAccountCount");
+ }
+
+ return count;
+ }
+
+ /// <summary>
+ /// Updates the sync status of the given account.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="account"> Account for which sync status needs to be updated</param>
+ /// <param name="status">Sync State</param>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <privilege>http://tizen.org/privilege/account.write</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error </exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static void UpdateSyncStatusById(Account account, AccountSyncState status)
+ {
+ AccountError err = (AccountError)Interop.AccountService.UpdateAccountSyncStatusById(account.AccountId, (int)status);
+ if (err != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(err, "Failed to UpdateSyncStatusById");
+ }
+ }
+
+ private static readonly Interop.AccountService.SubscribeCallback s_accountUpdatedCallback = (string eventType, int accountId, IntPtr userData) =>
+ {
+ AccountSubscriberEventArgs eventArgs = new AccountSubscriberEventArgs(eventType, accountId);
+ s_accountUpdated?.Invoke(null, eventArgs);
+ return true;
+ };
+
+ private static Interop.AccountService.SafeAccountSubscriberHandle s_subscriberHandle;
+
+ private static event EventHandler<AccountSubscriberEventArgs> s_accountUpdated;
+ /// <summary>
+ /// ContentUpdated event is triggered when the media item info from DB changes.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <remarks>
+ /// ContentUpdate event is triggered if the MediaInformaion updated/deleted or new Inforamtion is Inserted.
+ /// </remarks>
+ /// <param name="sender"></param>
+ /// <param name="e">A ContentUpdatedEventArgs object that contains information about the update operation.</param>
+ /// <privilege>http://tizen.org/privilege/account.read</privilege>
+ /// <exception cref="InvalidOperationException">In case of any DB error </exception>
+ /// <exception cref="ArgumentException"> In case of invalid parameter</exception>
+ /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
+ public static event EventHandler<AccountSubscriberEventArgs> AccountUpdated
+ {
+ add
+ {
+ if (s_accountUpdated == null)
+ {
+ if (s_subscriberHandle == null)
+ {
+ Interop.AccountService.CreateAccountSubscriber(out s_subscriberHandle);
+ }
+
+ AccountError ret = (AccountError)Interop.AccountService.RegisterSubscriber(s_subscriberHandle, s_accountUpdatedCallback, IntPtr.Zero);
+
+ if (ret != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(ret, "Error in callback handling");
+ }
+ }
+
+ s_accountUpdated += value;
+ }
+
+ remove
+ {
+ s_accountUpdated -= value;
+ if (s_accountUpdated == null)
+ {
+ AccountError ret = (AccountError)Interop.AccountService.UnregisterSubscriber(s_subscriberHandle);
+ if (ret != AccountError.None)
+ {
+ throw AccountErrorFactory.CreateException(ret, "Error in callback handling");
+ }
+ s_subscriberHandle = null;
+ }
+ }
+ }
+
+ }
+}
--- /dev/null
+/*
+ * 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;
+
+namespace Tizen.Account.AccountManager
+{
+ /// <summary>
+ /// Event arguments passed when Event is triggered to notify that account is updated/removed from the account database.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public class AccountSubscriberEventArgs : EventArgs
+ {
+ private const string NotiInsert = "insert";
+ private const string NotiDelete = "delete";
+ private const string NotiUpdate = "update";
+ private const string NotiSyncUpdate = "sync_update";
+ internal AccountSubscriberEventArgs(string eventType, int accountId)
+ {
+ if (eventType.CompareTo(NotiInsert) == 0)
+ {
+ EventType = AccountNotificationType.Insert;
+ }
+ else if (eventType.CompareTo(NotiDelete) == 0)
+ {
+ EventType = AccountNotificationType.Delete;
+ }
+ else if (eventType.CompareTo(NotiUpdate) == 0)
+ {
+ EventType = AccountNotificationType.Update;
+ }
+ else if (eventType.CompareTo(NotiSyncUpdate) == 0)
+ {
+ EventType = AccountNotificationType.syncUpdate;
+ }
+
+ AccountId = accountId;
+ }
+
+ /// <summary>
+ /// The account event type
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public AccountNotificationType EventType
+ {
+ get;
+ internal set;
+ }
+
+ /// <summary>
+ /// The account ID to update
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public int AccountId
+ {
+ get;
+ internal set;
+ }
+ }
+}