d335a8e1d7be2e00cb2926c17f8a35195c7176bb
[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         /// <privilege>http://tizen.org/privilege/account.read</privilege>
266         /// <privilege>http://tizen.org/privilege/account.write </privilege>
267         /// <feature>http://tizen.org/feature/account</feature>
268         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
269         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
270         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
271         /// <exception cref="OutOfMemoryException"> In case of OutOfMemory error.</exception>
272         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
273         public static int AddAccount(Account account)
274         {
275             if (account == null)
276             {
277                 throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to AddAccount");
278             }
279
280             int id = -1;
281             AccountError err = (AccountError)Interop.AccountService.AddAccount(account.SafeAccountHandle, out id);
282             if (err != AccountError.None)
283             {
284                 throw AccountErrorFactory.CreateException(err, "Failed to AddAccount");
285             }
286
287             return id;
288         }
289
290         /// <summary>
291         /// Updates the account details to the account database.
292         /// </summary>
293         /// <since_tizen> 3 </since_tizen>
294         /// <param name="account">Account instance to be updated.</param>
295         /// <privilege>http://tizen.org/privilege/account.read</privilege>
296         /// <privilege>http://tizen.org/privilege/account.write </privilege>
297         /// <feature>http://tizen.org/feature/account</feature>
298         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
299         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
300         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
301         /// <exception cref="OutOfMemoryException"> In case of OutOfMemory error.</exception>
302         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
303         public static void UpdateAccount(Account account)
304         {
305             if (account == null)
306             {
307                 throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to UpdateAccount");
308             }
309
310             AccountError err = (AccountError)Interop.AccountService.UpdateAccountToDBById(account.SafeAccountHandle, account.AccountId);
311             if (err != AccountError.None)
312             {
313                 throw AccountErrorFactory.CreateException(err, "Failed to UpdateAccount");
314             }
315         }
316
317         /// <summary>
318         /// Deletes the account information from the database.
319         /// </summary>
320         /// <since_tizen> 3 </since_tizen>
321         /// <param name="account">Account instance to be deleted from the database.</param>
322         /// <privilege>http://tizen.org/privilege/account.read</privilege>
323         /// <privilege>http://tizen.org/privilege/account.write</privilege>
324         /// <feature>http://tizen.org/feature/account</feature>
325         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
326         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
327         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
328         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
329         public static void DeleteAccount(Account account)
330         {
331             if (account == null)
332             {
333                 throw AccountErrorFactory.CreateException(AccountError.InvalidParameter, "Failed to DeleteAccount");
334             }
335
336             AccountError err = (AccountError)Interop.AccountService.DeleteAccountById(account.AccountId);
337             if (err != AccountError.None)
338             {
339                 throw AccountErrorFactory.CreateException(err, "Failed to delete the account by Id: " + account.AccountId);
340             }
341         }
342
343         /// <summary>
344         /// Deletes the account from the account database by user name.
345         /// </summary>
346         /// <since_tizen> 3 </since_tizen>
347         /// <param name="userName">The user name of the account to delete.</param>
348         /// <param name="packageName">The package name of the account to delete.</param>
349         /// <privilege>http://tizen.org/privilege/account.read</privilege>
350         /// <privilege>http://tizen.org/privilege/account.write</privilege>
351         /// <feature>http://tizen.org/feature/account</feature>
352         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
353         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
354         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
355         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
356         public static void DeleteAccount(string userName, string packageName)
357         {
358             AccountError err = (AccountError)Interop.AccountService.DeleteAccountByUser(userName, packageName);
359             if (err != AccountError.None)
360             {
361                 throw AccountErrorFactory.CreateException(err, "Failed to delete the account by userName: " + userName);
362             }
363         }
364
365         /// <summary>
366         /// Deletes the account from the account database by package name.
367         /// </summary>
368         /// <since_tizen> 3 </since_tizen>
369         /// <param name="packageName">The package name of the account to delete.</param>
370         /// <privilege>http://tizen.org/privilege/account.read</privilege>
371         /// <privilege>http://tizen.org/privilege/account.write</privilege>
372         /// <feature>http://tizen.org/feature/account</feature>
373         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
374         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
375         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
376         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
377         public static void DeleteAccount(string packageName)
378         {
379             AccountError err = (AccountError)Interop.AccountService.DeleteAccountByPackage(packageName);
380             if (err != AccountError.None)
381             {
382                 throw AccountErrorFactory.CreateException(err, "Failed to delete the account by package name: " + packageName);
383             }
384
385         }
386
387         /// <summary>
388         /// Retrieves all the accounts with the given user name.
389         /// </summary>
390         /// <since_tizen> 3 </since_tizen>
391         /// <param name="userName">The user name to search.</param>
392         /// <returns>Accounts list matched with the user name.</returns>
393         /// <privilege>http://tizen.org/privilege/account.read</privilege>
394         /// <feature>http://tizen.org/feature/account</feature>
395         /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given username.</exception>
396         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
397         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
398         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
399         public static IEnumerable<Account> GetAccountsByUserName(string userName)
400         {
401             List<Account> accounts = new List<Account>();
402             List<int> values = new List<int>();
403             Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
404             {
405                 Account account = new Account(new SafeAccountHandle(handle, true));
406                 values.Add(account.AccountId);
407                 account.Dispose();
408                 return true;
409             };
410
411             AccountError err = (AccountError)Interop.AccountService.QueryAccountByUserName(accountCallback, userName, IntPtr.Zero);
412             if (err != AccountError.None)
413             {
414                 throw AccountErrorFactory.CreateException(err, "Failed to GetAccountByUserName");
415             }
416
417             foreach (int i in values)
418             {
419                 Account account = AccountService.GetAccountById(i);
420                 accounts.Add(account);
421             }
422
423             return accounts;
424         }
425
426         /// <summary>
427         /// Retrieves all the accounts with the given package name.
428         /// </summary>
429         /// <since_tizen> 3 </since_tizen>
430         /// <param name="packageName"> The package name to search.</param>
431         /// <returns>Accounts list matched with the package name.</returns>
432         /// <privilege>http://tizen.org/privilege/account.read</privilege>
433         /// <feature>http://tizen.org/feature/account</feature>
434         /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given package name.</exception>
435         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
436         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
437         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
438         public static IEnumerable<Account> GetAccountsByPackageName(string packageName)
439         {
440             List<Account> accounts = new List<Account>();
441             List<int> values = new List<int>();
442             Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
443             {
444                 Account account = new Account(new SafeAccountHandle(handle, true));
445                 values.Add(account.AccountId);
446                 account.Dispose();
447                 return true;
448             };
449
450             AccountError err = (AccountError)Interop.AccountService.QueryAccountByPackageName(accountCallback, packageName, IntPtr.Zero);
451             if (err != AccountError.None)
452             {
453                 throw AccountErrorFactory.CreateException(err, "Failed to GetAccountByPackageName");
454             }
455
456             foreach (int i in values)
457             {
458                 Account account = AccountService.GetAccountById(i);
459                 accounts.Add(account);
460             }
461
462             return accounts;
463         }
464
465         /// <summary>
466         /// Retrieves all accounts with the given capability type.
467         /// </summary>
468         /// <since_tizen> 3 </since_tizen>
469         /// <param name="type"> Capability type.</param>
470         /// <returns>Accounts list matched with the capability type.</returns>
471         /// <privilege>http://tizen.org/privilege/account.read</privilege>
472         /// <feature>http://tizen.org/feature/account</feature>
473         /// <exception cref="InvalidOperationException">In case of any DB error or record not found for the given capability type.</exception>
474         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
475         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
476         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
477         public static IEnumerable<Account> GetAccountsByCapabilityType(string type)
478         {
479             List<Account> accounts = new List<Account>();
480             List<int> values = new List<int>();
481             Interop.Account.AccountCallback accountCallback = (IntPtr handle, IntPtr data) =>
482             {
483                 Account account = new Account(new SafeAccountHandle(handle, true));
484                 values.Add(account.AccountId);
485                 account.Dispose();
486                 return true;
487             };
488
489             AccountError err = (AccountError)Interop.AccountService.GetAccountByCapabilityType(accountCallback, type, IntPtr.Zero);
490             if (err != AccountError.None)
491             {
492                 throw AccountErrorFactory.CreateException(err, "Failed to GetAccountByCapabilityType");
493             }
494
495             foreach (int i in values)
496             {
497                 Account account = AccountService.GetAccountById(i);
498                 accounts.Add(account);
499             }
500
501             return accounts;
502         }
503
504         /// <summary>
505         /// Retrieves all the capabilities with the given account.
506         /// </summary>
507         /// <since_tizen> 3 </since_tizen>
508         /// <param name="accountId">Account instance.</param>
509         /// <returns>Capabilities list as dictionary of the capability type and state.</returns>
510         /// <privilege>http://tizen.org/privilege/account.read</privilege>
511         /// <feature>http://tizen.org/feature/account</feature>
512         /// <exception cref="InvalidOperationException">In case of any DB error or record not found for given account ID.</exception>
513         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
514         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
515         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
516         public static Dictionary<string, CapabilityState> GetCapabilitiesById(int accountId)
517         {
518             Dictionary<string, CapabilityState> capabilities = new Dictionary<string, CapabilityState>();
519             Interop.Account.AccountCapabilityCallback capabilityCallback = (string type, int capabilityState, IntPtr data) =>
520             {
521                 capabilities.Add(type, (CapabilityState)capabilityState);
522                 return true;
523             };
524
525             AccountError err = (AccountError)Interop.AccountService.QueryAccountCapabilityById(capabilityCallback, accountId, IntPtr.Zero);
526             if (err != AccountError.None)
527             {
528                 throw AccountErrorFactory.CreateException(err, "Failed to GetAllCapabilitiesById");
529             }
530
531             return capabilities;
532         }
533
534         /// <summary>
535         /// Gets the count of accounts in the account database.
536         /// </summary>
537         /// <since_tizen> 3 </since_tizen>
538         /// <returns>The number of accounts in the database.</returns>
539         /// <privilege>http://tizen.org/privilege/account.read</privilege>
540         /// <feature>http://tizen.org/feature/account</feature>
541         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
542         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
543         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
544         public static int GetAccountsCount()
545         {
546             int count = 0;
547             AccountError err = (AccountError)Interop.AccountService.GetAccountCount(out count);
548             if (err != AccountError.None)
549             {
550                 throw AccountErrorFactory.CreateException(err, "Failed to GetAccountCount");
551             }
552
553             return count;
554         }
555
556         /// <summary>
557         /// Updates the sync status of the given account.
558         /// </summary>
559         /// <since_tizen> 3 </since_tizen>
560         /// <param name="account"> Account for which the sync status needs to be updated.</param>
561         /// <param name="status">Sync State</param>
562         /// <privilege>http://tizen.org/privilege/account.read</privilege>
563         /// <privilege>http://tizen.org/privilege/account.write</privilege>
564         /// <feature>http://tizen.org/feature/account</feature>
565         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
566         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
567         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
568         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
569         public static void UpdateSyncStatusById(Account account, AccountSyncState status)
570         {
571             AccountError err = (AccountError)Interop.AccountService.UpdateAccountSyncStatusById(account.AccountId, (int)status);
572             if (err != AccountError.None)
573             {
574                 throw AccountErrorFactory.CreateException(err, "Failed to UpdateSyncStatusById");
575             }
576         }
577
578         private static readonly Interop.AccountService.SubscribeCallback s_accountUpdatedCallback = (string eventType, int accountId, IntPtr userData) =>
579         {
580             AccountSubscriberEventArgs eventArgs = new AccountSubscriberEventArgs(eventType, accountId);
581             s_accountUpdated?.Invoke(null, eventArgs);
582             return true;
583         };
584
585         private static Interop.AccountService.SafeAccountSubscriberHandle s_subscriberHandle;
586
587         private static event EventHandler<AccountSubscriberEventArgs> s_accountUpdated;
588         /// <summary>
589         /// ContentUpdated event is triggered when the media item info from DB changes.
590         /// </summary>
591         /// <since_tizen> 3 </since_tizen>
592         /// <remarks>
593         /// ContentUpdate event is triggered if the MediaInformaion updated/deleted or new information is inserted.
594         /// </remarks>
595         /// <param name="sender"></param>
596         /// <param name="e">A ContentUpdatedEventArgs object that contains information about the update operation.</param>
597         /// <privilege>http://tizen.org/privilege/account.read</privilege>
598         /// <feature>http://tizen.org/feature/account</feature>
599         /// <exception cref="InvalidOperationException">In case of any DB error.</exception>
600         /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception>
601         /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception>
602         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
603         public static event EventHandler<AccountSubscriberEventArgs> AccountUpdated
604         {
605             add
606             {
607                 if (s_accountUpdated == null)
608                 {
609                     if (s_subscriberHandle == null)
610                     {
611                         Interop.AccountService.CreateAccountSubscriber(out s_subscriberHandle);
612                     }
613
614                     AccountError ret = (AccountError)Interop.AccountService.RegisterSubscriber(s_subscriberHandle, s_accountUpdatedCallback, IntPtr.Zero);
615
616                     if (ret != AccountError.None)
617                     {
618                         throw AccountErrorFactory.CreateException(ret, "Error in callback handling");
619                     }
620                 }
621
622                 s_accountUpdated += value;
623             }
624
625             remove
626             {
627                 s_accountUpdated -= value;
628                 if (s_accountUpdated == null)
629                 {
630                     AccountError ret = (AccountError)Interop.AccountService.UnregisterSubscriber(s_subscriberHandle);
631                     if (ret != AccountError.None)
632                     {
633                         throw AccountErrorFactory.CreateException(ret, "Error in callback handling");
634                     }
635                     s_subscriberHandle = null;
636                 }
637             }
638         }
639
640     }
641 }