Add privilege check code.
[platform/framework/native/appfw.git] / src / server / app / package / FAppPkg_PackageManagerServer.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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  * @file        FAppPkg_PackageManagerServer.cpp
18  * @brief       This is the implementation for the _PackageManagerServer class.
19  */
20
21 #include <unique_ptr.h>
22
23 #include <package-manager.h>
24 #include <pkgmgr-info.h>
25 #include <package-manager-types.h>
26
27 #include <FAppPkgPackageAppInfo.h>
28 #include <FAppPkgPackageInfo.h>
29 #include <FBaseString.h>
30 #include <FBaseSysLog.h>
31 #include <FIoFile.h>
32 #include <FAppPkg_PackageManagerServer.h>
33 #include <FAppPkg_PackageAppInfoImpl.h>
34 #include <FAppPkg_PackageInfoImpl.h>
35 #include <FAppPkg_PackageParser.h>
36 #include <FBase_StringConverter.h>
37
38 using namespace Tizen::Base;
39 using namespace Tizen::Io;
40
41 namespace Tizen { namespace App { namespace Package
42 {
43
44 _PackageManagerServer::_PackageManagerServer(void)
45 {
46 }
47
48 _PackageManagerServer::~_PackageManagerServer(void)
49 {
50 }
51
52 _PackageManagerServer*
53 _PackageManagerServer::GetInstance(void)
54 {
55         static _PackageManagerServer* pPackageManagerServer = null;
56
57         if (pPackageManagerServer == null)
58         {
59                 pPackageManagerServer = new (std::nothrow) _PackageManagerServer();
60                 SysTryReturn(NID_APP, pPackageManagerServer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageManagerServer is null.");
61         }
62
63         return pPackageManagerServer;
64 }
65
66 PackageType
67 _PackageManagerServer::GetType(const PackageId& packageId) const
68 {
69         int res = PMINFO_R_OK;
70         pkgmgrinfo_pkginfo_h handle = null;
71         PackageType packageType = PACKAGE_TYPE_TPK;
72         char* pType = null;
73         String type;
74
75         std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
76         SysTryReturn(NID_APP, pPackageId, PACKAGE_TYPE_TPK, E_OUT_OF_MEMORY, "pPackageId is null.");
77
78         res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &handle);
79         SysTryReturn(NID_APP, res == PMINFO_R_OK, PACKAGE_TYPE_TPK, E_PKG_NOT_INSTALLED, "pkgmgrinfo_pkginfo_get_pkginfo() is failed. result=[%d], package=[%s]", res, pPackageId.get());
80         SysTryReturn(NID_APP, handle, PACKAGE_TYPE_TPK, E_SYSTEM, "[E_SYSTEM] handle is null.");
81
82         res = pkgmgrinfo_pkginfo_get_type(handle, &pType);
83         if (res == PMINFO_R_OK)
84         {
85                 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_type(): type = [%s]", pType);
86                 type = *pType;
87
88                 if (strcmp(pType, "tpk") == 0)
89                 {
90                         packageType = PACKAGE_TYPE_TPK;
91                 }
92                 else if (strcmp(pType, "wgt") == 0)
93                 {
94                         packageType = PACKAGE_TYPE_WGT;
95                 }
96                 else if (strcmp(pType, "rpm") == 0)
97                 {
98                         packageType = PACKAGE_TYPE_RPM;
99                 }
100         }
101         else
102         {
103                 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_type() is failed. result = [%d]", res);
104         }
105
106         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
107
108         return packageType;
109 }
110
111 } } } // Tizen::App::Package