Merge "Fix B/S of context service" into tizen_2.1
[platform/framework/native/appfw.git] / src / app / FApp_AppControlRegistry.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file         FApp_AppControlRegistry.cpp
20  * @brief       This is the implementation for the _AppControlRegistry.cpp class.
21  */
22
23 #include <new>
24 #include <unique_ptr.h>
25 #include <app.h>
26 #include <bundle.h>
27
28 #include <FBaseErrors.h>
29 #include <FBaseSysLog.h>
30 #include <FBaseColAllElementsDeleter.h>
31 #include <FBaseColHashMap.h>
32 #include <FAppAppControl.h>
33 #include <FIoRegistry.h>
34 #include <FIoFile.h>
35
36 #include <FBase_StringConverter.h>
37 #include <FIo_RegistryImpl.h>
38
39 #include "FAppPkg_PackageManagerImpl.h"
40 #include "FApp_AppControlImpl.h"
41 #include "FApp_Aul.h"
42 #include "FApp_AppControlRegistry.h"
43 #include "FApp_AppMessageImpl.h"
44 #include "FApp_TemplateUtil.h"
45 #ifdef _SINGLETON_CLEANUP
46 #include "FApp_LongevityManager.h"
47 #endif
48
49 using namespace Tizen::App::Package;
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Collection;
52 using namespace Tizen::Io;
53
54 namespace
55 {
56
57 const wchar_t ACTL_DEFAULT_FILE[] = L"/usr/etc/app-control-info.ini";
58 const wchar_t ACTL_LEGACY_FILE[] = L"/usr/etc/app-control-alias.ini";
59 const wchar_t ACTL_ALIAS_FILE[] = L"/usr/etc/app-control-appid.ini";
60
61 const wchar_t TIZEN_ALIAS_APPID_PREFIX[] = L"tizen.";
62
63 const String ACTL_REGISTRY_OP_NUM = L"OPID_Count";
64 const String ACTL_REGISTRY_PUBLIC = L"Public";
65 const String ACTL_REGISTRY_PATH = L"Path";
66 const String ACTL_REGISTRY_TITLE = L"Title";
67 const String ACTL_REGISTRY_ALIAS_PROVIDER = L"PROVIDER_ALIAS";
68
69 const int PKG_CATEGORY_LEN = 256;
70 const int PKG_APPID_LEN = 256;
71 const int REG_VALUE_BUFFER_LEN = 256;
72
73 }
74
75
76 namespace Tizen { namespace App
77 {
78
79 _AppControlRegistry* _AppControlRegistry::__pSelf = null;
80
81 _AppControlRegistry::_AppControlRegistry(void)
82 {
83         __nativeList.Construct();
84
85         __tizenList.Construct();
86
87         __aliasList.Construct();
88
89         __aliasAppId.Construct();
90 }
91
92 _AppControlRegistry::~_AppControlRegistry(void)
93 {
94         _DeleteCollection<AppControl>(__nativeList);
95
96         _DeleteCollectionMapValue<String, _AppControlAliasEntry>(__aliasList);
97 }
98
99 _AppControlRegistry*
100 _AppControlRegistry::GetInstance(void)
101 {
102         if (__pSelf == null)
103         {
104                 SysLog(NID_APP, "Create new instance");
105                 __pSelf = new (std::nothrow) _AppControlRegistry();
106                 SysTryReturn(NID_APP, __pSelf != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
107                 SysAssertf(__pSelf != null, "AppControl registry instance creation failure");
108
109                 __pSelf->LoadRegistry();
110
111                 __pSelf->LoadTizenAppControlRegistry();
112
113                 __pSelf->LoadLegacyList();
114
115                 __pSelf->LoadAliasList();
116
117 #ifdef _SINGLETON_CLEANUP
118                 _LongevityManager::GetInstance().RegisterOwnership(*__pSelf);
119 #endif
120         }
121
122         return __pSelf;
123 }
124
125 result
126 _AppControlRegistry::LoadRegistry(void)
127 {
128         _RegistryImpl reg;
129
130         const String regPath = ACTL_DEFAULT_FILE;
131
132         result r = reg.Construct(regPath, REG_OPEN_READ_ONLY, null);
133         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
134
135         const int sec_count = reg.GetAllSectionCount();
136         SysTryReturnResult(NID_APP, !(sec_count <= 0), E_OBJ_NOT_FOUND, "Registry contains no data.");
137
138         SysLog(NID_APP, "Loading %d sections from %ls", sec_count, regPath.GetPointer());
139
140         int index = 0;
141         int size = 0;
142         int num = 0;
143         String actl_path;
144         String actl_name;
145
146
147         // actual parameter manipulation
148         for (int i = 0; i < sec_count; i++)
149         {
150                 ///////////////////////////////////////////////////////////////////////
151                 // appcontrol Id
152                 String sec_name(reg.GetSectionName(i));
153                 sec_name.Trim();
154
155                 if (sec_name.IsEmpty())
156                 {
157                         continue;
158                 }
159
160                 int public_open = 0;
161
162                 ///////////////////////////////////////////////////////////////////////
163                 // Plubic
164                 index = reg.GetEntryIndex(i, ACTL_REGISTRY_PUBLIC);
165                 if (index >= 0)
166                 {
167                         size = sizeof(size);
168                         num = 0;
169
170                         reg.GetEntryValue(i, index, REG_VALUE_TYPE_INT, &num, &size);
171                         if (num == 1)
172                         {
173                                 // public
174                                 public_open = 1;
175                         }
176                 }
177
178                 ///////////////////////////////////////////////////////////////////////
179                 // Path
180                 index = reg.GetEntryIndex(i, ACTL_REGISTRY_PATH);
181                 if (index >= 0)
182                 {
183                         size = REG_VALUE_BUFFER_LEN;
184                         reg.GetEntryValue(i, index, REG_VALUE_TYPE_STRING, &actl_path, &size);
185                 }
186
187                 ///////////////////////////////////////////////////////////////////////
188                 // Name
189                 // [FIXME] SLP localized name here
190                 index = reg.GetEntryIndex(i, ACTL_REGISTRY_TITLE);
191                 if (index >= 0)
192                 {
193                         size = REG_VALUE_BUFFER_LEN;
194                         reg.GetEntryValue(i, index, REG_VALUE_TYPE_STRING, &actl_name, &size);
195                 }
196
197                 //SysLog(NID_APP, "%dth iteration : %ls", i, sec_name.GetPointer());
198
199                 ///////////////////////////////////////////////////////////////////////
200                 // Number of operation Id
201                 index = reg.GetEntryIndex(i, ACTL_REGISTRY_OP_NUM);
202                 if (index >= 0)
203                 {
204                         size = sizeof(size);
205                         reg.GetEntryValue(i, index, REG_VALUE_TYPE_INT, &num, &size);
206
207                         String tagName;
208                         String actl_opId;
209
210                         //SysLog(NID_APP, "number of operation %d for index %d", num, index);
211
212                         for (int j = 0; j < num; j++)
213                         {
214                                 size = REG_VALUE_BUFFER_LEN;
215
216                                 ///////////////////////////////////////////////////////////////
217                                 // operation Id
218                                 tagName.Format(10, L"OPID_%d", j);
219
220                                 index = reg.GetEntryIndex(i, tagName);
221                                 if (index >= 0)
222                                 {
223                                         reg.GetEntryValue(i, index, REG_VALUE_TYPE_STRING, &actl_opId, &size);
224                                         actl_opId.Trim();
225                                 }
226                                 //SysLog(NID_APP, "Operation(%d) %ls", index, actl_opId.GetPointer());
227
228                                 ///////////////////////////////////////////////////////////////
229                                 // AppControl allocation
230
231                                 int prop = 0;
232                                 if (public_open == 1)
233                                 {
234                                         prop |= _APPCONTROL_PROPERTY_PUBLIC;
235                                 }
236
237                                 prop |= _APPCONTROL_PROPERTY_SLP;
238
239                                 //SysLog(NID_APP, "(%ls, %ls)", sec_name.GetPointer(), actl_opId.GetPointer());
240                                 AppControl* pAc = _AppControlImpl::CreateN(actl_path, sec_name, actl_opId, actl_name, prop);
241
242                                 if (pAc)
243                                 {
244                                         __nativeList.Add(pAc);
245                                 }
246                                 else
247                                 {
248                                         SysLog(NID_APP, "Failed to create AppControl instance (%ls, %ls, %d)",
249                                                                 sec_name.GetPointer(), actl_opId.GetPointer(), public_open);
250                                 }
251                         }
252                 }
253
254         }
255
256         SysLog(NID_APP, "Finished loading %d entries", __nativeList.GetCount());
257
258         return E_SUCCESS;
259 }
260
261 result
262 _AppControlRegistry::LoadTizenAppControlRegistry(void)
263 {
264         _RegistryImpl reg;
265
266         const String regPath = ACTL_DEFAULT_FILE;
267
268         result r = reg.Construct(regPath, REG_OPEN_READ_ONLY, null);
269         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
270
271         const int secCount = reg.GetAllSectionCount();
272         SysTryReturnResult(NID_APP, !(secCount <= 0), E_OBJ_NOT_FOUND, "Registry contains no data.");
273
274         SysLog(NID_APP, "Loading %d sections from %ls", secCount, regPath.GetPointer());
275
276         int index = 0;
277         int size = 0;
278         //int num = 0;
279         String path;
280
281         for (int i = 0; i < secCount; i++)
282         {
283                 ///////////////////////////////////////////////////////////////////////
284                 // appcontrol Id
285                 String sec_name(reg.GetSectionName(i));
286                 sec_name.Trim();
287
288                 if (sec_name.IsEmpty())
289                 {
290                         continue;
291                 }
292
293 #if 0
294                 int public_open = 0;
295
296                 ///////////////////////////////////////////////////////////////////////
297                 // Plubic
298                 index = reg.GetEntryIndex(i, ACTL_REGISTRY_PUBLIC);
299                 if (index >= 0)
300                 {
301                         size = sizeof(size);
302                         num = 0;
303
304                         reg.GetEntryValue(i, index, REG_VALUE_TYPE_INT, &num, &size);
305                         if (num == 1)
306                         {
307                                 // public
308                                 public_open = 1;
309                         }
310                 }
311 #endif
312
313                 ///////////////////////////////////////////////////////////////////////
314                 // Path
315                 index = reg.GetEntryIndex(i, ACTL_REGISTRY_PATH);
316                 if (index >= 0)
317                 {
318                         size = REG_VALUE_BUFFER_LEN;
319                         reg.GetEntryValue(i, index, REG_VALUE_TYPE_STRING, &path, &size);
320                 }
321
322                 __tizenList.Add(sec_name, path);
323         }
324
325         SysLog(NID_APP, "Finished loading %d tizen AppControl entries", __tizenList.GetCount());
326
327         return E_SUCCESS;
328 }
329
330 result
331 _AppControlRegistry::LoadLegacyList(void)
332 {
333         _RegistryImpl reg;
334
335         const String& regPath(ACTL_LEGACY_FILE);
336
337         result r = reg.Construct(regPath, REG_OPEN_READ_ONLY, null);
338         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
339
340         const int sec_count = reg.GetAllSectionCount();
341         SysTryReturnResult(NID_APP, !(sec_count <= 0), E_OBJ_NOT_FOUND, "Registry contains no data.");
342
343         SysLog(NID_APP, "Loading %d sections from %ls", sec_count, regPath.GetPointer());
344
345         String aliasProvider;
346         String value;
347
348
349         // actual parameter manipulation
350         for (int i = 0; i < sec_count; i++)
351         {
352                 ///////////////////////////////////////////////////////////////////////
353                 // appcontrol Id
354                 const String& secName(reg.GetSectionName(i));
355
356                 ///////////////////////////////////////////////////////////////////////
357                 // aliased appcontrol name
358                 const int index = reg.GetEntryIndex(i, ACTL_REGISTRY_ALIAS_PROVIDER);
359                 if (index >= 0)
360                 {
361                         int size = REG_VALUE_BUFFER_LEN;
362                         reg.GetEntryValue(i, index, REG_VALUE_TYPE_STRING, &aliasProvider, &size);
363                 }
364
365                 ///////////////////////////////////////////////////////////////////////
366                 // Operations
367                 IList* pList = reg.GetAllEntryNamesN(secName);
368                 if (pList == null)
369                 {
370                         continue;
371                 }
372
373                 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
374
375                 while (pEnum->MoveNext() == E_SUCCESS)
376                 {
377                         String* pStr = dynamic_cast<String*>(pEnum->GetCurrent());
378
379                         if (pStr == null || pStr->IsEmpty() || pStr->Equals(ACTL_REGISTRY_ALIAS_PROVIDER, false))
380                         {
381                                 continue;
382                         }
383
384                         r = reg.GetValue(secName, *pStr, value);
385                         if (IsFailed(r))
386                         {
387                                 SysLog(NID_APP, "[%s] Propagating.", GetErrorMessage(r));
388                                 continue;
389                         }
390
391                         // add entry to aliasList
392                         _AppControlAliasEntry* pEntry = new (std::nothrow) _AppControlAliasEntry(secName, *pStr, aliasProvider, value);
393                         SysTryReturnResult(NID_APP, pEntry != null, E_OUT_OF_MEMORY, "Insufficient memory.");
394
395                         if (pEntry)
396                         {
397                                 SysLog(NID_APP, "(%ls, %ls)", secName.GetPointer(), aliasProvider.GetPointer());
398                                 __aliasList.Add(secName, pEntry);
399                         }
400                 }
401
402                 pList->RemoveAll(true);
403                 delete pList;
404         }
405
406         SysLog(NID_APP, "Finished loading %d entries.", __aliasList.GetCount());
407
408         return E_SUCCESS;
409 }
410
411 result
412 _AppControlRegistry::LoadAliasList(void)
413 {
414         _RegistryImpl reg;
415
416         const String regPath = ACTL_ALIAS_FILE;
417
418         result r = reg.Construct(regPath, REG_OPEN_READ_ONLY, null);
419         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
420
421         HashMap* pMap = null;
422         r = reg.GetEntryListN(L"Alias", &pMap);
423         if (r != E_SUCCESS)
424         {
425                 SysLog(NID_APP, "[%s] Propagating.", GetErrorMessage(r));
426                 delete pMap;
427                 return r;
428         }
429
430         String* pKey = null;
431         String* pVal = null;
432         std::unique_ptr<IMapEnumerator> pEnum(pMap->GetMapEnumeratorN());
433         SysTryCatch(NID_APP, pEnum.get(), r = E_OUT_OF_MEMORY , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory error.");
434
435         while(pEnum->MoveNext() == E_SUCCESS)
436         {
437                 pKey = static_cast<String*>(pEnum->GetKey());
438                 pVal = static_cast<String*>(pEnum->GetValue());
439
440                 __aliasAppId.Add(*pKey, *pVal);
441                 //SysLog(NID_APP, "(%ls, %ls)", pKey->GetPointer(), pVal->GetPointer());
442         }
443
444         SysLog(NID_APP, "Loading %d alias sections", __aliasAppId.GetCount());
445
446 CATCH:
447         delete pMap;
448
449         return r;
450 }
451
452
453 AppControl*
454 _AppControlRegistry::GetTizenAppControlN(const String& aId, const String& oId) const
455 {
456         const _AppControlAliasEntry* pEntry = null;
457         int count = 0;
458
459         do
460         {
461                 const _AppControlAliasEntry* pTempEntry = GetAppControlAliasEntry(aId, oId);
462                 // number does not matter
463                 if (count >= 5 || pTempEntry == null)
464                 {
465                         break;
466                 }
467
468                 pEntry = pTempEntry;
469                 count++;
470         }
471         while (true);
472
473
474         const String* pAppId = null;
475         const String* pOperation = null;
476
477         if (count == 0)
478         {
479                 // if count is 0, then no alias is found
480                 pAppId = &aId;
481                 pOperation = &oId;
482         }
483         else if (pEntry == null)
484         {
485                 // no "TIZEN" AppControl
486                 return null;
487         }
488         else
489         {
490                 pAppId = &pEntry->provider2;
491                 pOperation = &pEntry->operation2;
492         }
493
494         SysAssert(pAppId != null);
495         SysAssert(pOperation != null);
496
497         SysLog(NID_APP, "Found matching AppControl (%ls, %ls)", pAppId->GetPointer(), pOperation->GetPointer());
498
499         const String& soName = GetTizenAppControlProvider(*pAppId, *pOperation);
500
501         if (soName.IsEmpty())
502         {
503                 SysLog(NID_APP, "No AppControl stub found for (%ls, %ls)", pAppId->GetPointer(), pOperation->GetPointer());
504                 return null;
505         }
506
507         return _AppControlImpl::CreateN(soName, *pAppId, *pOperation, L"", _APPCONTROL_PROPERTY_PUBLIC | _APPCONTROL_PROPERTY_SLP);
508 }
509
510
511 String
512 _AppControlRegistry::GetTizenAppControlProvider(const String& appId, const String& oId) const
513 {
514         String val;
515         result r = __tizenList.GetValue(appId, val);
516         if (r == E_SUCCESS)
517         {
518                 SysLog(NID_APP, "Found TIZEN AppControl stub %ls for %ls.", val.GetPointer(), appId.GetPointer());
519                 return val;
520         }
521
522         SysLog(NID_APP, "No platform AppControl and use custom AppControl instead.");
523         return L"";
524 }
525
526
527 AppControl*
528 _AppControlRegistry::GetNativeAppControlN(const String& aId, const String& oId) const
529 {
530         std::unique_ptr< IEnumeratorT<AppControl*> > pEnum(__nativeList.GetEnumeratorN());
531
532         while (pEnum->MoveNext() == E_SUCCESS)
533         {
534                 AppControl* pAc = null;
535                 pEnum->GetCurrent(pAc);
536
537                 if (pAc->GetAppControlProviderId() == aId && pAc->GetOperationId() == oId)
538                 {
539                         SysLog(NID_APP, "Found matching AppControl (%ls, %ls)", aId.GetPointer(), oId.GetPointer());
540                         return _AppControlImpl::CreateN(*pAc);
541                 }
542         }
543
544         SysLog(NID_APP, "No matching AppControl (%ls, %ls)", aId.GetPointer(), oId.GetPointer());
545
546         return null;
547 }
548
549 //
550 // data structure for _AppControlRegistry::GetAppControlListN() only
551 // 
552 struct AppSvcIterData
553 {
554 public:
555         AppSvcIterData(ArrayList* pArr, const String& op) : pArray(pArr), operation(op) {}
556
557         ArrayList* pArray;
558         const String& operation;
559 };
560
561 //
562 // callback function for _AppControlRegistry::GetAppControlListN()
563 //
564 static int
565 AppSvcIterFnCb(const char* pAppId, void* pData)
566 {
567         SysAssert(pData != null);
568
569         AppSvcIterData* pAppSvcIterData = static_cast<AppSvcIterData*>(pData);
570         ArrayList* pList = pAppSvcIterData->pArray;
571         SysAssert(pList != null);
572         const String& operation = pAppSvcIterData->operation;
573
574         if (pAppId == NULL)
575         {
576                 SysLog(NID_APP, "Empty appId received.");
577                 return -1;
578         }
579
580         String appId = pAppId;
581         AppControl* pAc = _AppControlImpl::CreateN(appId, operation, false);
582         if (pAc == null)
583         {
584                 SysLog(NID_APP, "AppControl allocation failure for %ls.", appId.GetPointer());
585                 return -1;
586         }
587
588         pList->Add(pAc);
589
590         return 0;
591 }
592
593 Tizen::Base::Collection::ArrayList*
594 _AppControlRegistry::FindAppControlListN(const String* pOid, const String* pUri, const String* pMimeType, const String* pCategory) const
595 {
596         String operation = (pOid) ? *pOid : TIZEN_OPERATION_MAIN;
597
598         std::unique_ptr<bundle, BundleDeleter> pBundle(bundle_create());
599         SysTryReturn(NID_APP, pBundle.get(), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Bundle creation failure.");
600
601         _AppMessageImpl::SetOperation(pBundle.get(), operation);
602
603         if (pUri)
604         {
605                 _AppMessageImpl::SetUri(pBundle.get(), *pUri);
606         }
607
608         if (pMimeType)
609         {
610                 _AppMessageImpl::SetMime(pBundle.get(), *pMimeType);
611         }
612
613         if (pCategory)
614         {
615                 _AppMessageImpl::SetCategory(pBundle.get(), *pCategory);
616         }
617
618         ArrayList* pList = new (std::nothrow) ArrayList;
619         SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] ArrayList creation failure.");
620         pList->Construct();
621
622         AppSvcIterData data(pList, operation);
623
624         appsvc_get_list(pBundle.get(), AppSvcIterFnCb, reinterpret_cast<void*>(&data));
625
626         if (pList->GetCount() == 0)
627         {
628                 SysLog(NID_APP, "Found no AppControl entry for operation %ls.", operation.GetPointer());
629
630                 delete pList;
631                 pList = null;
632         }
633
634         return pList;
635 }
636
637 const _AppControlRegistry::_AppControlAliasEntry*
638 _AppControlRegistry::GetAppControlAliasEntry(const String& aId, const String& oId) const
639 {
640         std::unique_ptr< IEnumeratorT<_AppControlAliasEntry*> > pEnum(__aliasList.GetValuesN(aId));
641         if (pEnum.get() == null)
642         {
643                 SysLog(NID_APP, "[E_OBJ_NOT_FOUND] No alias entry for %ls.", aId.GetPointer());
644                 return null;
645         }
646
647         while (pEnum->MoveNext() == E_SUCCESS)
648         {
649                 _AppControlAliasEntry* pEntry = null;
650                 pEnum->GetCurrent(pEntry);
651                 if (pEntry->provider == aId && pEntry->operation == oId)
652                 {
653                         SysLog(NID_APP, "Found matching AppControl (%ls, %ls)->(%ls, %ls)", aId.GetPointer(), oId.GetPointer(), pEntry->provider2.GetPointer(), pEntry->operation2.GetPointer());
654
655                         return pEntry;
656                 }
657         }
658
659         return null;
660 }
661
662 const _AppControlRegistry::_AppControlAliasEntry*
663 _AppControlRegistry::GetReverseAppControlAliasEntry(const String& aId, const String& oId) const
664 {
665         std::unique_ptr< IMapEnumeratorT<String, _AppControlAliasEntry*> > pEnum(__aliasList.GetMapEnumeratorN());
666
667         while (pEnum->MoveNext() == E_SUCCESS)
668         {
669                 _AppControlAliasEntry* pEntry = null;
670                 pEnum->GetValue(pEntry);
671                 if (pEntry->provider2 == aId && pEntry->operation2 == oId)
672                 {
673                         SysLog(NID_APP, "Found matching AppControl (%ls, %ls)<-(%ls, %ls)", aId.GetPointer(), oId.GetPointer(), pEntry->provider.GetPointer(), pEntry->operation.GetPointer());
674
675                         return pEntry;
676                 }
677         }
678
679         return null;
680 }
681
682 AppControl*
683 _AppControlRegistry::GetAliasAppControlN(const String& aId, const String& oId) const
684 {
685         const _AppControlAliasEntry* pEntry = GetAppControlAliasEntry(aId, oId);
686
687         if (pEntry)
688         {
689                 AppControl* pAc = GetNativeAppControlN(pEntry->provider2, pEntry->operation2);
690                 if (pAc)
691                 {
692                         _AppControlImpl* pImpl = _AppControlImpl::GetInstance(*pAc);
693                         pImpl->SetProperty(_APPCONTROL_PROPERTY_ALIAS);
694                 }
695                 else
696                 {
697                         pAc = GetAppControlN(pEntry->provider2, pEntry->operation2);
698                         if (pAc)
699                         {
700                                 _AppControlImpl* pImpl = _AppControlImpl::GetInstance(*pAc);
701                                 pImpl->SetProperty(_APPCONTROL_PROPERTY_ALIAS);
702                         }
703                         else
704                         {
705                                 SysLog(NID_APP, "No matching AppControl found.");
706                         }
707                 }
708
709                 return pAc;
710         }
711
712         SysLog(NID_APP, "No matching AppControl found.");
713         return null;
714 }
715
716 AppControl*
717 _AppControlRegistry::GetAppControlN(const String& appId, const String& operationId) const
718 {
719         bool changeAppId = false;
720
721         String actualAppId = appId;
722         if (appId.StartsWith(TIZEN_ALIAS_APPID_PREFIX, 0))
723         {
724                 const String& tmp = GetAliasAppId(appId);
725
726                 if (!tmp.IsEmpty())
727                 {
728                         actualAppId = tmp;
729                         SysLog(NID_APP, "Found alias appId (%ls -> %ls).", appId.GetPointer(), tmp.GetPointer());
730
731                         changeAppId = true;
732                 }
733         }
734
735         bool b = _Aul::IsInstalled(actualAppId);
736         SysTryReturn(NID_APP, b == true, null, E_APP_NOT_INSTALLED, "[E_APP_NOT_INSTALLED] %ls not installed.", actualAppId.GetPointer());
737
738         return _AppControlImpl::CreateN(actualAppId, operationId, changeAppId);
739 }
740
741
742 AppId
743 _AppControlRegistry::GetAliasAppId(const AppId& appId) const
744 {
745         String tmp;
746         result r = __aliasAppId.GetValue(appId, tmp);
747         if (r != E_SUCCESS)
748         {
749                 tmp.Clear();
750         }
751
752         return tmp;
753 }
754
755
756 AppId
757 _AppControlRegistry::GetReverseAliasAppId(const AppId& appId) const
758 {
759         std::unique_ptr< IMapEnumeratorT<String, String> > pEnum(__aliasAppId.GetMapEnumeratorN());
760
761         String key;
762         String value;
763         while (pEnum->MoveNext() == E_SUCCESS)
764         {
765                 pEnum->GetKey(key);
766                 pEnum->GetValue(value);
767                 if (value == appId)
768                 {
769                         return key;
770                 }
771         }
772
773         SysLog(NID_APP, "No entry found for %ls", appId.GetPointer());
774         return L"";
775 }
776
777 } } // Tizen::App