Ignore callback for null AppId case and optimize the loop body.
[platform/framework/native/appfw.git] / src / app / FApp_AppManagerImpl.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 3bde180..f696327
@@ -1062,6 +1062,14 @@ _AppManagerImpl::FireActiveAppEvent(unsigned int xid, int pid, char* pAppName)
        if (oldPid != pid)
        {
                oldPid = pid;
+               char pkgname[255] = {0, };
+               if ((AUL_R_OK != aul_app_get_pkgname_bypid(pid, pkgname, 255)) || pkgname[0] == 0)
+               {
+                       SysSecureLog(NID_APP, "Failed to get the package name from pid=%x pAppName=%s", pid, pAppName ? pAppName : "null");
+                       return;
+               }
+               AppId appId(_Aul::GetRealAppId(String(pkgname)));
+
                std::unique_ptr<IEnumeratorT<Tizen::App::IActiveAppEventListener* > > pEnum(__activeAppEventListenerList.GetEnumeratorN());
                if (pEnum.get())
                {
@@ -1071,10 +1079,7 @@ _AppManagerImpl::FireActiveAppEvent(unsigned int xid, int pid, char* pAppName)
                                pEnum->GetCurrent(pListener);
                                if (pListener)
                                {
-                                       char pkgname[255] = {0, };
-                                       aul_app_get_pkgname_bypid(pid, pkgname, 255);
-                                       // TODO: Translate it to package name --> AppId
-                                       pListener->OnActiveAppChanged(AppId(pkgname));
+                                       pListener->OnActiveAppChanged(appId);
                                }
                        }
                }
@@ -1236,13 +1241,33 @@ _AppManagerImpl::RemoveActiveAppEventListener(IActiveAppEventListener& listener)
 result
 _AppManagerImpl::GetActiveApp(AppId& appId)
 {
-       unsigned int windowId = GetActiveWindow();
-       int processId = GetProcessId(windowId);
+       const unsigned int windowId = GetActiveWindow();
+       const int processId = GetProcessId(windowId);
        char pkgname[255] = {0, };
        aul_app_get_pkgname_bypid(processId, pkgname, 255);
-       // TODO: Translate it to package name --> AppId
-       appId = pkgname;
+       
+       appId = _Aul::GetRealAppId(String(pkgname));
+
+       SysLog(NID_APP, "ActiveApp is %ls.", appId.GetPointer());
        return E_SUCCESS;
 }
 
+bool 
+_AppManagerImpl::IsUserPreferredAppForAppControlResolution(const AppId& appId) const
+{
+       _IAppManager* pMgr = _AppManagerProxy::GetService();
+       SysTryReturn(NID_APP, pMgr, false, E_SYSTEM, "Failed to _AppManagerProxy::GetService().");
+
+       return pMgr->IsUserPreferredAppForAppControlResolution(appId);
+}
+
+result 
+_AppManagerImpl::ClearUserPreferenceForAppControlResolution(const AppId& appId)
+{
+       _IAppManager* pMgr = _AppManagerProxy::GetService();
+       SysTryReturnResult(NID_APP, pMgr, E_SYSTEM, "Failed to _AppManagerProxy::GetService().");
+
+       return pMgr->ClearUserPreferenceForAppControlResolution(appId);
+}
+
 }} // Tizen::App