22 #ifndef APPLICATIONINSTALLER_H_
23 #define APPLICATIONINSTALLER_H_
32 #include <cjson/json.h>
33 #include <cjson/json_util.h>
35 #include <lunaservice.h>
37 #include "MutexLocker.h"
41 #include <sys/statfs.h>
42 #include <sys/statvfs.h>
51 #define IPKG_PROCESS_PRIORITY 1
81 InstallParams(
const std::string& target,
const std::string&
id,
const unsigned long ticket, LSHandle * lshandle,
const LSMessage * msg,
const unsigned int uncompressedSizeInKB,
bool verify =
true,
bool systemMode =
false)
85 const std::string
_id;
97 RemoveParams(
const std::string& packageName,
const unsigned long ticket,LSHandle * lshandle,
const LSMessage * msg,
int cause)
118 static bool cbInstall(LSHandle* lshandle, LSMessage *msg,
void *user_data);
119 static bool cbInstallNoVerify(LSHandle* lshandle, LSMessage *msg,
void *user_data);
120 static bool cbRemove(LSHandle* lshandle, LSMessage *msg,
void *user_data);
122 static bool cbIsInstalled(LSHandle* lshandle, LSMessage *msg,
void *user_data);
123 static bool cbNotifyOnChange(LSHandle* lshandle, LSMessage *msg,
void *user_data);
124 static bool cbGetSizes(LSHandle* lshandle,LSMessage *msg,
void *user_data);
127 static bool cbRevoke(LSHandle* lshandle,LSMessage *msg,
void *user_data);
128 static bool cbPubSubRegister(LSHandle* handle, LSMessage* message,
void* ctxt);
129 static bool cbPubSubStatus(LSHandle* handle, LSMessage* msg,
void* ctxt);
132 static bool cbDbgCopyDir(LSHandle* lshandle,LSMessage *msg,
void *user_data);
133 static bool cbDbgFakeFsSize(LSHandle* lshandle,LSMessage *msg,
void *user_data);
135 static bool cbGetFsSize(LSHandle* lshandle,LSMessage *msg,
void *user_data);
136 static bool cbDbgFillSize(LSHandle* lshandle,LSMessage *msg,
void *user_data);
140 bool install(
const std::string& targetPackageName,
unsigned int uncompressedAppSizeInKB,
const unsigned long ticket);
143 bool downloadAndInstall (LSHandle* handle,
const std::string& targetPackageFile,
struct json_object* authToken,
struct json_object* deviceId,
144 unsigned long ticket,
bool subscribe);
156 static int _getSizeCbFn(
const char *fpath,
const struct stat *sb,
int typeflag,
struct FTW *ftwbuf);
157 static int _getSizeOfAppCbFn(
const char *fpath,
const struct stat *sb,
int typeflag,
struct FTW *ftwbuf);
160 static uint64_t
getSizeOfAppOnFs(
const std::string& destFsPath,
const std::string& dirName,uint32_t * r_pBsize=NULL);
169 #define APPREMOVED_CAUSE_UNKNOWN -1
170 #define APPREMOVED_CAUSE_USERDELETED 0
171 #define APPREMOVED_CAUSE_APPREVOKED 1
182 void slotMediaPartitionAvailable(
bool val);
191 std::list<std::string> m_appInstallBaseDirs;
197 void enterBrickMode();
198 void exitBrickMode();
200 bool lunasvcInstallProgressQuery(LSHandle* lshandle, LSMessage *msg,
void *user_data);
202 bool lunasvcIsInstalled(LSHandle* lshandle, LSMessage *msg,
void *user_data);
203 bool lunasvcNotifyOnChange(
const std::string& packageName,LSHandle * lshandle,LSMessage *msg);
204 bool lunasvcGetInstalledSizes(LSHandle * lshandle,LSMessage *msg);
205 int lunasvcQueryInstallCapacity(
const std::string& packageId,uint64_t packageSizeInKB,uint64_t uncompressedPackageSizeInKB,uint64_t& r_spaceNeeded);
210 bool processNextCommand();
212 void closeApp(
const std::string& appId);
214 static bool packageNameFromControl(
const std::string& controlTarGzPathAndFile,
const std::string& tempDir,std::string& return_PackageName);
215 static int getAllUserInstalledAppNames(std::vector<std::string>& appList,std::string basePkgDirName);
216 static bool findUserInstalledAppName(
const std::string& packageName,
const std::string& basePkgDirName);
217 static int getAllUserInstalledAppSizes(std::vector<std::pair<std::string,uint64_t> >& appList,std::string basePkgDirName);
219 static bool arePathsOnSameFilesystem(
const std::string& path1,
const std::string& path2);
221 static int doSignatureVerifyOnFile(
const std::string& file,
const std::string& signatureFile,
const std::string& pubkeyFile);
222 static int doSignatureVerifyOnFiles(std::vector<std::string>& files,
const std::string& signatureFile,
const std::string& pubkeyFile);
223 static int extractPublicKeyFromCert(
const std::string& certFile,
const std::string& pubkeyFile);
224 static int runOpenSSL(std::vector<std::string>& params,
const std::string& command);
225 static int runIpkgRemove(
const std::string& ipkgRoot,
const std::string& packageName);
227 static std::list<CommandParams*> s_commandParams;
230 struct CommandState {
246 CommandState m_cmdState;
252 static int dbg_restoreFakeFsEntriesAtStartup();
253 static int dbg_statfs(
const char *,
struct statfs *);
254 static int dbg_statvfs(
const char *,
struct statvfs *);
255 static int dbg_fill(std::string& path,uint32_t& bsize,uint32_t& nblocks);
256 static int dbg_getAppSizeOnFs(
const std::string& fspath,
const std::string& appbasepath,uint64_t& r_size);
257 static std::map<uint32_t,std::pair<uint32_t,uint32_t> > dbg_statfs_map;
258 static std::map<uint32_t,std::pair<uint32_t,uint32_t> > dbg_statvfs_map;
259 static json_object * dbg_statxfs_persistent;