Merge "Revert "add workaround code for LifeDuration"" into tizen_2.1
[platform/framework/native/appfw.git] / src / app / inc / FAppPkg_PackageManagerImpl.h
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        FAppPkg_PackageManagerImpl.h
20  * @brief       This is the header file for the _PackageManagerImpl class.
21  */
22
23 #ifndef _FAPP_PKG_INTERNAL_PACKAGE_MANAGER_IMPL_H_
24 #define _FAPP_PKG_INTERNAL_PACKAGE_MANAGER_IMPL_H_
25
26 #include <package-manager.h>
27 #include <pkgmgr-info.h>
28
29 #include <FBaseObject.h>
30 #include <FBaseString.h>
31 #include <FAppPkgPackageManager.h>
32 #include <FBaseColHashMapT.h>
33 #include <FBaseColLinkedListT.h>
34 #include <FBaseRt_Event.h>
35
36 #include <FApp_Types.h>
37 #include <FAppPkg_PackageAppInfoImpl.h>
38
39 namespace Tizen { namespace Base { namespace Runtime
40 {
41 class IEventArg;
42 }}}
43
44 namespace Tizen { namespace Io
45 {
46 class Database;
47 class DbStatement;
48 class DbEnumerator;
49 }}
50
51 namespace Tizen { namespace App { namespace Package
52 {
53
54 class _PackageInfoImpl;
55 class IPackageInstallationEventListener;
56 class IPackageInstallationResponseListener;
57 class IPackageUninstallationResponseListener;
58
59 static const int MAX_DATABASE_RETRY_COUNT = 30;
60 static const wchar_t PACKAGE_DATABASE_FILE_NAME[] = L"/opt/usr/dbspace/.app-package.db";
61
62 // PackageFilter
63 static const wchar_t PACKAGE_FILTER_UNINSTALLABLE[] = L"http://tizen.org/package/uninstallable";
64 static const wchar_t PACKAGE_FILTER_DOWNLOADED[] = L"http://tizen.org/package/downloaded";
65 static const wchar_t PACKAGE_FILTER_EXTERNAL_STORAGE[] = L"http://tizen.org/package/externalstorage";
66 static const wchar_t PACKAGE_FILTER_APP_SETTING[] = L"http://tizen.org/package/appsetting";
67
68 // PackageFilter(internal)
69 static const wchar_t PACKAGE_FILTER_TPK[] = L"http://tizen.org/package/tpk";
70
71 // PackageAppFilter
72 static const wchar_t PACKAGE_APP_FILTER_MENUICON_VISIBLE[] = L"http://tizen.org/package/app/menuiconvisible";
73 static const wchar_t PACKAGE_APP_FILTER_CATEGORY_HOMEAPP[] = L"http://tizen.org/category/homeapp";
74 static const wchar_t PACKAGE_APP_FILTER_CATEGORY_LOCKAPP[] = L"http://tizen.org/category/lockapp";
75 static const wchar_t PACKAGE_APP_FILTER_CATEGORY_MENUAPP[] = L"http://tizen.org/category/menuapp";
76
77 enum PackageStorageType
78 {
79         PACKAGE_STORAGE_TYPE_INTERNAL,
80         PACKAGE_STORAGE_TYPE_EXTERNAL,
81 };
82
83 class _PackageManagerEventArg
84         : public Tizen::Base::Runtime::IEventArg
85 {
86 public:
87         _PackageManagerEventArg()
88                 : __install(true)
89         {
90         }
91
92         PackageId __packageId;
93         Tizen::Base::String __eventKey;
94         Tizen::Base::String __eventValue;
95         bool __install;
96 };
97
98 class _PackageManagerEvent
99         : public Tizen::Base::Runtime::_Event
100 {
101 public:
102         _PackageManagerEvent()
103                 : __pListener(null)
104         {
105         }
106
107         IPackageInstallationEventListener* __pListener;
108
109 public:
110         result Construct(void)
111         {
112                 return _Event::Initialize();
113         }
114
115 protected:
116         virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
117 };
118
119 class _OSP_EXPORT_ _PackageManagerImpl
120         : public Tizen::Base::Object
121 {
122 public:
123         static PackageId GetPackageIdByAppId(const AppId& appId);
124
125         result AddEventListener(IPackageInstallationEventListener* pListener, int priority = 2);
126         result RemoveEventListener(IPackageInstallationEventListener* pListener);
127
128         PackageInfo* GetPackageInfoN(const PackageId& packageId) const;
129         PackageAppInfo* GetPackageAppInfoN(const AppId& appId) const;
130         Tizen::Base::Collection::IList* GetPackageInfoListN(void) const;
131
132         bool IsPackageInstalled(const PackageId& packageId) const;
133
134         result InstallPackage(const PackageId& packageId, const Tizen::Base::String& packagePath, IPackageInstallationResponseListener* pListener);
135         result UninstallPackage(const PackageId& packageId, IPackageUninstallationResponseListener* pListener);
136
137         result MoveToExternalStorage(const PackageId& packageId);
138         result MoveToInternalStorage(const PackageId& packageId);
139         
140         static _PackageManagerImpl* GetInstance(void);
141
142         PackageInfo* GetPackageInfoFromFileN(const Tizen::Base::String& filePath) const;
143         Tizen::Base::Collection::IList* GetPackageInfoListN(const Tizen::Base::Collection::IMap& packageFilterMap) const;
144         Tizen::Base::Collection::IList* GetPackageAppInfoListN(const Tizen::Base::Collection::IMap& packageAppFilterMap) const;
145         Tizen::Base::Collection::IList* GetPackageAppInfoListN(const Tizen::Base::Collection::IMap& packageFilterMap, const Tizen::Base::Collection::IMap& packageAppFilterMap) const;
146
147         static int PackageInfoHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData);
148         static int PackageAppInfoHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData);
149         static int PackageAppInfoMetadataHandler(const pkgmgrinfo_appinfo_h handle, void* pUserdata);
150
151         void SendPackageEvent(PackageType type, const PackageId& packageId, const char* eventKey, const char* eventValue);
152
153         Tizen::Base::String* GetAppIdOfDataControlN(const Tizen::Base::String& providerId);
154
155         PackageInfo* GetPackageInfoN(const Tizen::Base::String& providerId, const Tizen::Base::String& operationId) const;
156         PackageInfo* GetPackageInfoN(PackageType packageType, const Tizen::Base::String& packageName) const;
157
158         static int PackageInfoEventHandler(const pkgmgrinfo_pkginfo_h handle, void* pUser_data);
159
160         Tizen::Base::Collection::IList* GetFilteredAppIdListN(const Tizen::Base::String& feature, const Tizen::Base::String& value) const;
161         Tizen::Base::Collection::IList* GetDataControlInfoN(const Tizen::Base::String& providerId, const Tizen::Base::String& type) const;
162         Tizen::Base::Collection::IMap* GetUiThemeListN(const PackageId& packageId) const;
163
164         Tizen::Base::Collection::ArrayList* GetPackageAppInfoImplListN(const PackageId& packageId) const;
165         Tizen::Base::Collection::ArrayList* GetPackageAppFeatureListN(const PackageId& packageId, const Tizen::Base::String& executableName) const;
166         Tizen::Base::Collection::HashMapT<Tizen::Base::String, _AppFeatureInfoImpl*>* GetPackageAppFeatureMapN(const PackageId& packageId, const Tizen::Base::String& executableName) const;
167         Tizen::Base::Collection::ArrayList* GetAppLaunchConditionListN(const Tizen::Base::String& packageName) const;
168
169         result GetPackageName(const PackageId& packageId, const Tizen::Base::String* pName, char* pPackageName, int bufferSize);
170         Tizen::Base::String GetDefaultAppExecutableName(const PackageId& packageId);
171
172         static bool IsAppInstalled(const AppId& appId);
173
174         static Tizen::Io::DbStatement* CreateStatementN(Tizen::Io::Database& db, const Tizen::Base::String& query);
175         static Tizen::Io::DbEnumerator* ExecuteStatementN(Tizen::Io::Database& db, const Tizen::Io::DbStatement* pStmt);
176
177 private:
178         result Construct(void);
179
180         _PackageManagerImpl(void);
181         virtual ~_PackageManagerImpl(void);
182
183         static int PackageEventHandler(int req_id, const char* pkg_type, const char* pkg_name, const char* key, const char* val, const void* pmsg, void* data);
184         static int InstallationEventHandler(int reqId, const char* pType, const char* pPackageId, const char* pKey, const char* pVal, const void* pMsg, void* pData);
185         static int UninstallationEventHandler(int reqId, const char* pType, const char* pPackageId, const char* pKey, const char* pVal, const void* pMsg, void* pData);
186
187 protected:
188         friend class PackageManager;
189
190 private:
191         void* __pRequestClient;
192         void* __pListeningClient;
193         static Tizen::Base::Collection::HashMap __installationList;
194         Tizen::Base::Collection::LinkedListT <_PackageManagerEvent*> __packageEventListenerList;
195
196 }; // _PackageManagerImpl
197
198 } } } // Tizen::App::Package
199
200 #endif // _FAPP_PKG_INTERNAL_PACKAGE_MANAGER_IMPL_H_