Release 4.0.0-preview1-00201
[platform/core/csapi/tizenfx.git] / src / Tizen.Account.AccountManager / Tizen.Account.AccountManager / AccountService.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Collections.Generic;
19
20 namespace Tizen.Account.AccountManager
21 {
22     /// <summary>
23     /// The AccountManager APIs are separated into two major sections:
24     /// 1. Registering an account provider while an application is installed. This information will be used for the Add account screen.
25     /// 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.
26     ///
27     /// The APIs of both of the sections consist of the following functionality:
28     /// <list>
29     /// <item> Create an account or account provider.</item>
30     /// <item> Update an account or account provider (Only available for the creator).</item>
31     /// <item> Delete an account or account provider (Only available for the creator).</item>
32     /// <item> Read an account or account provider with some filter.</item>
33     /// </list>
34     /// </summary>
35     /// <since_tizen> 3 </since_tizen>
36
37     public static class AccountService
38     {
39         /// <summary>
40         /// This is the contact capability string.
41         /// </summary>
42         /// <since_tizen> 3 </since_tizen>
43         public static readonly string ContactCapability = "http://tizen.org/account/capability/contact";
44
45         /// <summary>
46         /// This is the calendar capability string.
47         /// </summary>
48         /// <since_tizen> 3 </since_tizen>
49         public static readonly string CalendarCapability = "http://tizen.org/account/capability/calendar";
50
51         /// <summary>
52         /// This is the email capability string.
53         /// </summary>
54         /// <since_tizen> 3 </since_tizen>
55         public static readonly string EmailCapability = "http://tizen.org/account/capability/email";
56
57         /// <summary>
58         /// This is the photo capability string.
59         /// </summary>
60         /// <since_tizen> 3 </since_tizen>
61         public static readonly string PhotoCapability = "http://tizen.org/account/capability/photo";
62
63         /// <summary>
64         /// This is the video capability string.
65         /// </summary>
66         /// <since_tizen> 3 </since_tizen>
67         public static readonly string VideoCapability = "http://tizen.org/account/capability/video";
68
69         /// <summary>
70         /// This is the music capability string.
71         /// </summary>
72         /// <since_tizen> 3 </since_tizen>
73         public static readonly string MusicCapability = "http://tizen.org/account/capability/music";
74
75         /// <summary>
76         /// This is the document capability string.
77         /// </summary>
78         /// <since_tizen> 3 </since_tizen>
79         public static readonly string DocumentCapability = "http://tizen.org/account/capability/document";
80
81         /// <summary>
82         /// This is the message capability string.
83         /// </summary>
84         /// <since_tizen> 3 </since_tizen>
85         public static readonly string MessageCapability = "http://tizen.org/account/capability/message";
86
87         /// <summary>
88         /// This is the game capability string.
89         /// </summary>
90         /// <since_tizen> 3 </since_tizen>
91         public static readonly string GameCapability = "http://tizen.org/account/capability/game";
92
93         /// <summary>
94         /// Retrieves all the accounts details from the account database.
95         /// </summary>
96         /// <since_tizen> 3 </since_tizen>
97         /// <returns>List of accounts.</returns>
98         /// <privilege>http://tizen.org/privilege/account.read</privilege>
99         /// <feature>http://tizen.org/feature/account</feature>
100         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
101         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
102         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
103         public static IEnumerable<Account> GetAccountsAsync()
104         {
105             List<Account> accounts = new List<Account>();
106             List<int> values = new List<int>();
107             Interop.Account.AccountCallback accountCallback = (IntPtr data, IntPtr userdata) =>
108             {
109                 Account account = new Account(new SafeAccountHandle(data, true));
110                 values.Add(account.AccountId);
111                 account.Dispose();
112                 return true;
113             };
114
115             AccountError res = (AccountError)Interop.AccountService.AccountForeachAccountFromDb(accountCallback, IntPtr.Zero);
116             if (res != AccountError.None)
117             {
118                 throw AccountErrorFactory.CreateException(res, "Failed to AccountForeachAccountFromDb");
119             }
120
121             foreach (int i in values)
122             {
123                 Account account = AccountService.GetAccountById(i);
124                 accounts.Add(account);
125             }
126
127             return accounts;
128         }
129
130         /// <summary>
131         /// Retrieves the account with the account ID.
132         /// </summary>
133         /// <since_tizen> 3 </since_tizen>
134         /// <param name="accountId"> The account ID to be searched.</param>
135         /// <returns>Account instance with reference to the given ID.</returns>
136         /// <privilege>http://tizen.org/privilege/account.read</privilege>
137         /// <feature>http://tizen.org/feature/account</feature>
138         /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given account ID.</exception>
139         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
140         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
141         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
142         public static Account GetAccountById(int accountId)
143         {
144             Account account = Account.CreateAccount();
145             SafeAccountHandle handle = account.SafeAccountHandle;
146
147             AccountError res = (AccountError)Interop.AccountService.QueryAccountById(accountId, ref handle);
148             if (res != AccountError.None)
149             {
150                 throw AccountErrorFactory.CreateException(res, "Failed to get accounts from the database for account id: " + accountId);
151             }
152             Account ref_account = new Account(handle);
153                         
154             return ref_account;
155         }
156
157         /// <summary>
158         /// Retrieves all the AccountProviders details from the account database.
159         /// </summary>
160         /// <since_tizen> 3 </since_tizen>
161         /// <returns>List of AccountProviders.</returns>
162         /// <privilege>http://tizen.org/privilege/account.read</privilege>
163         /// <feature>http://tizen.org/feature/account</feature>
164         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
165         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
166         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
167         public static IEnumerable<AccountProvider> GetAccountProviders()
168         {
169             List<string> values = new List<string>();
170             List<AccountProvider> providers = new List<AccountProvider>();
171             Interop.AccountProvider.AccountProviderCallback accountCallback = (IntPtr handle, IntPtr data) =>
172             {
173                 AccountProvider provider = new AccountProvider(handle);
174                 values.Add(provider.AppId);
175                 provider.Dispose();
176                 return true;
177             };
178
179             AccountError res = (AccountError)Interop.AccountService.GetAllAccountproviders(accountCallback, IntPtr.Zero);
180             if (res != AccountError.None)
181             {
182                 Log.Warn(AccountErrorFactory.LogTag, "Failed to get account providers from the database");
183                 throw AccountErrorFactory.CreateException(res, "Failed to get account providers from the database");
184             }
185
186             foreach (string val in values)
187             {
188                 AccountProvider provider = GetAccountProviderByAppId(val);
189                 providers.Add(provider);
190             }
191
192             return providers;
193         }
194
195         /// <summary>
196         /// Retrieves the account provider information with the application ID.
197         /// </summary>
198         /// <since_tizen> 3 </since_tizen>
199         /// <param name="appId">The application ID.</param>
200         /// <returns>The AccountProvider instance associated with the given application ID.</returns>
201         /// <privilege>http://tizen.org/privilege/account.read</privilege>
202         /// <feature>http://tizen.org/feature/account</feature>
203         /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given appId.</exception>
204         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
205         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
206         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
207         public static AccountProvider GetAccountProviderByAppId(string appId)
208         {
209             IntPtr handle;
210             Interop.AccountProvider.Create(out handle);
211             AccountError err = (AccountError)Interop.AccountService.GetAccountProviderByAppId(appId, out handle);
212             if (err != AccountError.None)
213             {
214                 throw AccountErrorFactory.CreateException(err, "Failed to GetAccountProviderByAppId");
215             }
216
217             AccountProvider provider = new AccountProvider(handle);
218             return provider;
219         }
220
221         /// <summary>
222         /// Retrieves all the account providers information with feature.
223         /// </summary>
224         /// <since_tizen> 3 </since_tizen>
225         /// <param name="feature">The capability value to search for account providers.</param>
226         /// <returns>Retrieves the AccountProviders information with the capability name.</returns>
227         /// <privilege>http://tizen.org/privilege/account.read</privilege>
228         /// <feature>http://tizen.org/feature/account</feature>
229         /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given feature.</exception>
230         /// <exception cref="ArgumentException"> In case of invalid parameter.</exception>
231         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
232         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
233         public static IEnumerable<AccountProvider> GetAccountProvidersByFeature(string feature)
234         {
235             List<string> values = new List<string>();
236             List<AccountProvider> providers = new List<AccountProvider>();
237             Interop.AccountProvider.AccountProviderCallback providerCallback = (IntPtr handle, IntPtr data) =>
238             {
239                 AccountProvider provider = new AccountProvider(handle);
240                 values.Add(provider.AppId);
241                 provider.Dispose();
242                 return true;
243             };
244
245             AccountError err = (AccountError)Interop.AccountService.GetAccountProviderByFeature(providerCallback, feature, IntPtr.Zero);
246             if (err != AccountError.None)
247             {
248                 throw AccountErrorFactory.CreateException(err, "Failed to GetAccountProviderByFeature");
249             }
250
251             foreach (string val in values)
252             {
253                 AccountProvider provider = GetAccountProviderByAppId(val);
254                 providers.Add(provider);
255             }
256
257             return providers;
258         }
259
260         /// <summary>
261         /// Inserts into the Database with the new account Information.
262         /// </summary>
263         /// <since_tizen> 3 </since_tizen>
264         /// <param name="account">New Account instance to be added.</param>
265         /// <returns>The account ID of the account instance.</returns>
266         /// <privilege>http://tizen.org/privilege/account.read</privilege>
267         /// <privilege>http://tizen.org/privilege/account.write </privilege>
268         /// <feature>http://tizen.org/feature/account</feature>
269         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
270         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
271         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
272         /// <exception cref="OutOfMemoryException"> In case of OutOfMemory error.</exception>
273         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
274         public static int AddAccount(Account account)
275         {
276             if (account == null)
277             {
278                 throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to AddAccount");
279             }
280
281             int id = -1;
282             AccountError err = (AccountError)Interop.AccountService.AddAccount(account.SafeAccountHandle, out id);
283             if (err != AccountError.None)
284             {
285                 throw AccountErrorFactory.CreateException(err, "Failed to AddAccount");
286             }
287
288             return id;
289         }
290
291         /// <summary>
292         /// Updates the account details to the account database.
293         /// </summary>
294         /// <since_tizen> 3 </since_tizen>
295         /// <param name="account">Account instance to be updated.</param>
296         /// <privilege>http://tizen.org/privilege/account.read</privilege>
297         /// <privilege>http://tizen.org/privilege/account.write </privilege>
298         /// <feature>http://tizen.org/feature/account</feature>
299         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
300         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
301         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
302         /// <exception cref="OutOfMemoryException"> In case of OutOfMemory error.</exception>
303         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
304         public static void UpdateAccount(Account account)
305         {
306             if (account == null)
307             {
308                 throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to UpdateAccount");
309             }
310
311             AccountError err = (AccountError)Interop.AccountService.UpdateAccountToDBById(account.SafeAccountHandle, account.AccountId);
312             if (err != AccountError.None)
313             {
314                 throw AccountErrorFactory.CreateException(err, "Failed to UpdateAccount");
315             }
316         }
317
318         /// <summary>
319         /// Deletes the account information from the database.
320         /// </summary>
321         /// <since_tizen> 3 </since_tizen>
322         /// <param name="account">Account instance to be deleted from the database.</param>
323         /// <privilege>http://tizen.org/privilege/account.read</privilege>
324         /// <privilege>http://tizen.org/privilege/account.write</privilege>
325         /// <feature>http://tizen.org/feature/account</feature>
326         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
327         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
328         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
329         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
330         public static void DeleteAccount(Account account)
331         {
332             if (account == null)
333             {
334                 throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to DeleteAccount");
335             }
336
337             AccountError err = (AccountError)Interop.AccountService.DeleteAccountById(account.AccountId);
338             if (err != AccountError.None)
339             {
340                 throw AccountErrorFactory.CreateException(err, "Failed to delete the account by Id: " + account.AccountId);
341             }
342         }
343
344         /// <summary>
345         /// Deletes the account from the account database by user name.
346         /// </summary>
347         /// <since_tizen> 3 </since_tizen>
348         /// <param name="userName">The user name of the account to delete.</param>
349         /// <param name="packageName">The package name of the account to delete.</param>
350         /// <privilege>http://tizen.org/privilege/account.read</privilege>
351         /// <privilege>http://tizen.org/privilege/account.write</privilege>
352         /// <feature>http://tizen.org/feature/account</feature>
353         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
354         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
355         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
356         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
357         public static void DeleteAccount(string userName, string packageName)
358         {
359             AccountError err = (AccountError)Interop.AccountService.DeleteAccountByUser(userName, packageName);
360             if (err != AccountError.None)
361             {
362                 throw AccountErrorFactory.CreateException(err, "Failed to delete the account by userName: " + userName);
363             }
364         }
365
366         /// <summary>
367         /// Deletes the account from the account database by package name.
368         /// </summary>
369         /// <since_tizen> 3 </since_tizen>
370         /// <param name="packageName">The package name of the account to delete.</param>
371         /// <privilege>http://tizen.org/privilege/account.read</privilege>
372         /// <privilege>http://tizen.org/privilege/account.write</privilege>
373         /// <feature>http://tizen.org/feature/account</feature>
374         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
375         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
376         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
377         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
378         public static void DeleteAccount(string packageName)
379         {
380             AccountError err = (AccountError)Interop.AccountService.DeleteAccountByPackage(packageName);
381             if (err != AccountError.None)
382             {
383                 throw AccountErrorFactory.CreateException(err, "Failed to delete the account by package name: " + packageName);
384             }
385
386         }
387
388         /// <summary>
389         /// Retrieves all the accounts with the given user name.
390         /// </summary>
391         /// <since_tizen> 3 </since_tizen>
392         /// <param name="userName">The user name to search.</param>
393         /// <returns>Accounts list matched with the user name.</returns>
394         /// <privilege>http://tizen.org/privilege/account.read</privilege>
395         /// <feature>http://tizen.org/feature/account</feature>
396         /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given username.</exception>
397         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
398         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
399         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
400         public static IEnumerable<Account> GetAccountsByUserName(string userName)
401         {
402             List<Account> accounts = new List<Account>();
403             List<int> values = new List<int>();
404             Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
405             {
406                 Account account = new Account(new SafeAccountHandle(handle, true));
407                 values.Add(account.AccountId);
408                 account.Dispose();
409                 return true;
410             };
411
412             AccountError err = (AccountError)Interop.AccountService.QueryAccountByUserName(accountCallback, userName, IntPtr.Zero);
413             if (err != AccountError.None)
414             {
415                 throw AccountErrorFactory.CreateException(err, "Failed to GetAccountByUserName");
416             }
417
418             foreach (int i in values)
419             {
420                 Account account = AccountService.GetAccountById(i);
421                 accounts.Add(account);
422             }
423
424             return accounts;
425         }
426
427         /// <summary>
428         /// Retrieves all the accounts with the given package name.
429         /// </summary>
430         /// <since_tizen> 3 </since_tizen>
431         /// <param name="packageName"> The package name to search.</param>
432         /// <returns>Accounts list matched with the package name.</returns>
433         /// <privilege>http://tizen.org/privilege/account.read</privilege>
434         /// <feature>http://tizen.org/feature/account</feature>
435         /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given package name.</exception>
436         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
437         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
438         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
439         public static IEnumerable<Account> GetAccountsByPackageName(string packageName)
440         {
441             List<Account> accounts = new List<Account>();
442             List<int> values = new List<int>();
443             Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
444             {
445                 Account account = new Account(new SafeAccountHandle(handle, true));
446                 values.Add(account.AccountId);
447                 account.Dispose();
448                 return true;
449             };
450
451             AccountError err = (AccountError)Interop.AccountService.QueryAccountByPackageName(accountCallback, packageName, IntPtr.Zero);
452             if (err != AccountError.None)
453             {
454                 throw AccountErrorFactory.CreateException(err, "Failed to GetAccountByPackageName");
455             }
456
457             foreach (int i in values)
458             {
459                 Account account = AccountService.GetAccountById(i);
460                 accounts.Add(account);
461             }
462
463             return accounts;
464         }
465
466         /// <summary>
467         /// Retrieves all accounts with the given capability type.
468         /// </summary>
469         /// <since_tizen> 3 </since_tizen>
470         /// <param name="type"> Capability type.</param>
471         /// <returns>Accounts list matched with the capability type.</returns>
472         /// <privilege>http://tizen.org/privilege/account.read</privilege>
473         /// <feature>http://tizen.org/feature/account</feature>
474         /// <exception cref="InvalidOperationException">In case of any DB error or record not found for the given capability type.</exception>
475         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
476         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
477         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
478         public static IEnumerable<Account> GetAccountsByCapabilityType(string type)
479         {
480             List<Account> accounts = new List<Account>();
481             List<int> values = new List<int>();
482             Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
483             {
484                 Account account = new Account(new SafeAccountHandle(handle, true));
485                 values.Add(account.AccountId);
486                 account.Dispose();
487                 return true;
488             };
489
490             AccountError err = (AccountError)Interop.AccountService.GetAccountByCapabilityType(accountCallback, type, IntPtr.Zero);
491             if (err != AccountError.None)
492             {
493                 throw AccountErrorFactory.CreateException(err, "Failed to GetAccountByCapabilityType");
494             }
495
496             foreach (int i in values)
497             {
498                 Account account = AccountService.GetAccountById(i);
499                 accounts.Add(account);
500             }
501
502             return accounts;
503         }
504
505         /// <summary>
506         /// Retrieves all the capabilities with the given account.
507         /// </summary>
508         /// <since_tizen> 3 </since_tizen>
509         /// <param name="accountId">Account instance.</param>
510         /// <returns>Capabilities list as dictionary of the capability type and state.</returns>
511         /// <privilege>http://tizen.org/privilege/account.read</privilege>
512         /// <feature>http://tizen.org/feature/account</feature>
513         /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given account ID.</exception>
514         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
515         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
516         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
517         public static Dictionary<string, CapabilityState> GetCapabilitiesById(int accountId)
518         {
519             Dictionary<string, CapabilityState> capabilities = new Dictionary<string, CapabilityState>();
520             Interop.Account.AccountCapabilityCallback capabilityCallback = (string type, int capabilityState, IntPtr data) =>
521             {
522                 capabilities.Add(type, (CapabilityState)capabilityState);
523                 return true;
524             };
525
526             AccountError err = (AccountError)Interop.AccountService.QueryAccountCapabilityById(capabilityCallback, accountId, IntPtr.Zero);
527             if (err != AccountError.None)
528             {
529                 throw AccountErrorFactory.CreateException(err, "Failed to GetAllCapabilitiesById");
530             }
531
532             return capabilities;
533         }
534
535         /// <summary>
536         /// Gets the count of accounts in the account database.
537         /// </summary>
538         /// <since_tizen> 3 </since_tizen>
539         /// <returns>The number of accounts in the database.</returns>
540         /// <privilege>http://tizen.org/privilege/account.read</privilege>
541         /// <feature>http://tizen.org/feature/account</feature>
542         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
543         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
544         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
545         public static int GetAccountsCount()
546         {
547             int count = 0;
548             AccountError err = (AccountError)Interop.AccountService.GetAccountCount(out count);
549             if (err != AccountError.None)
550             {
551                 throw AccountErrorFactory.CreateException(err, "Failed to GetAccountCount");
552             }
553
554             return count;
555         }
556
557         /// <summary>
558         /// Updates the sync status of the given account.
559         /// </summary>
560         /// <since_tizen> 3 </since_tizen>
561         /// <param name="account"> Account for which the sync status needs to be updated.</param>
562         /// <param name="status">Sync State</param>
563         /// <privilege>http://tizen.org/privilege/account.read</privilege>
564         /// <privilege>http://tizen.org/privilege/account.write</privilege>
565         /// <feature>http://tizen.org/feature/account</feature>
566         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
567         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
568         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
569         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
570         public static void UpdateSyncStatusById(Account account, AccountSyncState status)
571         {
572             AccountError err = (AccountError)Interop.AccountService.UpdateAccountSyncStatusById(account.AccountId, (int)status);
573             if (err != AccountError.None)
574             {
575                 throw AccountErrorFactory.CreateException(err, "Failed to UpdateSyncStatusById");
576             }
577         }
578
579         private static readonly Interop.AccountService.SubscribeCallback s_accountUpdatedCallback = (string eventType, int accountId, IntPtr userData) =>
580         {
581             AccountSubscriberEventArgs eventArgs = new AccountSubscriberEventArgs(eventType, accountId);
582             s_accountUpdated?.Invoke(null, eventArgs);
583             return true;
584         };
585
586         private static Interop.AccountService.SafeAccountSubscriberHandle s_subscriberHandle;
587
588         private static event EventHandler<AccountSubscriberEventArgs> s_accountUpdated;
589         /// <summary>
590         /// ContentUpdated event is triggered when the media item info from DB changes.
591         /// </summary>
592         /// <since_tizen> 3 </since_tizen>
593         /// <remarks>
594         /// ContentUpdate event is triggered if the MediaInformation updated/deleted or new information is inserted.
595         /// </remarks>
596         /// <privilege>http://tizen.org/privilege/account.read</privilege>
597         /// <feature>http://tizen.org/feature/account</feature>
598         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
599         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
600         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
601         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
602         public static event EventHandler<AccountSubscriberEventArgs> AccountUpdated
603         {
604             add
605             {
606                 if (s_accountUpdated == null)
607                 {
608                     if (s_subscriberHandle == null)
609                     {
610                         Interop.AccountService.CreateAccountSubscriber(out s_subscriberHandle);
611                     }
612
613                     AccountError ret = (AccountError)Interop.AccountService.RegisterSubscriber(s_subscriberHandle, s_accountUpdatedCallback, IntPtr.Zero);
614
615                     if (ret != AccountError.None)
616                     {
617                         throw AccountErrorFactory.CreateException(ret, "Error in callback handling");
618                     }
619                 }
620
621                 s_accountUpdated += value;
622             }
623
624             remove
625             {
626                 s_accountUpdated -= value;
627                 if (s_accountUpdated == null)
628                 {
629                     AccountError ret = (AccountError)Interop.AccountService.UnregisterSubscriber(s_subscriberHandle);
630                     if (ret != AccountError.None)
631                     {
632                         throw AccountErrorFactory.CreateException(ret, "Error in callback handling");
633                     }
634                     s_subscriberHandle = null;
635                 }
636             }
637         }
638
639     }
640 }