#include <stdio.h>
#include <app2ext_interface.h>
+#include <pkgmgr_installer.h>
#include <FIoFile.h>
#include <FIoDirectory.h>
}
InstallerError
-InstallerManager::Construct(const String& path, InstallerOperation operation, InstallerOption option)
+InstallerManager::Construct(const String& path, InstallerOperation operation, InstallerOption option, void* pPkgmgrInstaller, const PackageId* pPackageId)
{
InstallerError error = INSTALLER_ERROR_NONE;
InstallerType installerType = INSTALLER_TYPE_INSTALLER;
error = __pContext->Construct();
TryReturn(error == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "__pContext->Construct() failed.");
+ __pContext->__pPkgmgrInstaller = pPkgmgrInstaller;
+
if (operation == INSTALLER_OPERATION_INSTALL)
{
FileAttributes attr;
installerType = INSTALLER_TYPE_PACKAGE;
__pContext->__packagePath = newPath;
}
+
+ if (pPackageId)
+ {
+ AppLog(" # packageId = [%ls]", pPackageId->GetPointer());
+ __pContext->__packageId = (*pPackageId);
+
+ SendEvent(__pContext, __pContext->__packageId, "start", "install");
+ }
+ else
+ {
+ AppLog("Input param(packageId) is null in case of cmd, hybrid package.");
+ }
}
else if (operation == INSTALLER_OPERATION_UNINSTALL)
{
AppLog("operation is INSTALLER_OPERATION_UNINSTALL");
__pContext->SetCurrentInstallationStep(INSTALLER_STEP_INIT_UNINSTALL);
__pContext->__packageId = newPath;
+
+ SendEvent(__pContext, __pContext->__packageId, "start", "uninstall");
}
else if (operation == INSTALLER_OPERATION_REINSTALL)
{
__pContext->SetCurrentInstallationStep(INSTALLER_STEP_RDS_INIT);
__pContext->__packageId = newPath;
+
+ SendEvent(__pContext, __pContext->__packageId, "start", "install");
}
__pContext->SetInstallerOperation(operation);
InstallerError
InstallerManager::Init(void)
{
+ SendEvent(__pContext, __pContext->__packageId, "install_percent", "0");
return __pInstaller->OnInit();
}
InstallerError
InstallerManager::Register(void)
{
+ SendEvent(__pContext, __pContext->__packageId, "install_percent", "60");
return __pInstaller->OnRegister();
}
InstallerError
InstallerManager::End(void)
{
+ SendEvent(__pContext, __pContext->__packageId, "install_percent", "100");
return __pInstaller->OnEnd();
}
{
__pContext->SetError(error);
Error();
- return error;
+ goto CATCH;
}
}
if (currentStep == INSTALLER_STEP_INIT)
{
error = Init();
- TryReturn(error == INSTALLER_ERROR_NONE, error, "error is occurred.");
+ TryCatch(error == INSTALLER_ERROR_NONE, , "error is occurred.");
}
else if (currentStep == INSTALLER_STEP_END)
{
error = Register();
- TryReturn(error == INSTALLER_ERROR_NONE, error, "error is occurred.");
+ TryCatch(error == INSTALLER_ERROR_NONE, , "error is occurred.");
error = End();
- TryReturn(error == INSTALLER_ERROR_NONE, error, "error is occurred.");
+ TryCatch(error == INSTALLER_ERROR_NONE, , "error is occurred.");
}
else if (currentStep == INSTALLER_STEP_RDS)
{
}
}
+CATCH:
+ if (error == INSTALLER_ERROR_NONE)
+ {
+ SendEvent(__pContext, __pContext->__packageId, "end", "ok");
+ }
+ else
+ {
+ char errorMsg[11] = {0};
+ snprintf(errorMsg, sizeof(errorMsg) - 1, "%d", error);
+ SendEvent(__pContext, __pContext->__packageId, "error", errorMsg);
+ SendEvent(__pContext, __pContext->__packageId, "end", "fail");
+ }
+
return error;
}
Tizen::Io::FileAttributes attr;
result r = E_SUCCESS;
char readBuf[512] = {0};
- PackageId packageId;
r = File::GetAttributes(L"/opt/apps/cmtamb4mtv/data/configuration", attr);
TryCatch(!IsFailed(r), errorType = INSTALLER_ERROR_PACKAGE_NOT_FOUND, "file not found");
if (readBuf[0] == '+')
{
- errorType = InstallerManager::Request(path, INSTALLER_OPERATION_INSTALL, INSTALLER_OPTION_NORMAL, packageId);
+ errorType = InstallerManager::Request(path, INSTALLER_OPERATION_INSTALL, INSTALLER_OPTION_NORMAL, null);
}
else if (readBuf[0] == '-')
{
- errorType = InstallerManager::Request(path, INSTALLER_OPERATION_UNINSTALL, INSTALLER_OPTION_NORMAL, packageId);
+ errorType = InstallerManager::Request(path, INSTALLER_OPERATION_UNINSTALL, INSTALLER_OPTION_NORMAL, null);
}
else if (readBuf[0] == '*')
{
}
else if (readBuf[0] == '#')
{
- errorType = InstallerManager::Request(path, INSTALLER_OPERATION_REINSTALL, INSTALLER_OPTION_NORMAL, packageId);
+ errorType = InstallerManager::Request(path, INSTALLER_OPERATION_REINSTALL, INSTALLER_OPTION_NORMAL, null);
}
}
AppLog(" # Error = %s(%d)", pError, errorType);
}
-const PackageId&
-InstallerManager::GetId(void) const
-{
- return __packageId;
-}
-
-void
-InstallerManager::SetId(const PackageId& packageId)
-{
- __packageId = packageId;
-}
-
int
InstallerManager::GetErrorType(void) const
{
return __isFileLogOn;
}
+bool
+InstallerManager::SendEvent(InstallationContext* pContext, const PackageId& packageId, const String& key, const String& val)
+{
+ TryReturn(pContext, false, "pContext is null.");
+ TryReturn(key.IsEmpty() == false, false, "key is empty.");
+ TryReturn(val.IsEmpty() == false, false, "val is empty.");
+
+ InstallerOperation operation = pContext->GetInstallerOperation();
+
+ if (pContext->__pPkgmgrInstaller == null)
+ {
+ AppLog("pContext->__pPkgmgrInstaller is null. [%ls]", packageId.GetPointer());
+ return false;
+ }
+
+ if (operation == INSTALLER_OPERATION_UNINSTALL)
+ {
+ if (key == L"install_percent")
+ {
+ AppLog("install_percent is skipped. [%ls]", packageId.GetPointer());
+ return true;
+ }
+ }
+
+ std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
+ TryReturn(pPackageId, false, "pPackageId is null.");
+
+ std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
+ TryReturn(pKey, false, "pKey is null.");
+
+ std::unique_ptr<char[]> pVal(_StringConverter::CopyToCharArrayN(val));
+ TryReturn(pVal, false, "pVal is null.");
+
+ pkgmgr_installer_send_signal((pkgmgr_installer*) pContext->__pPkgmgrInstaller, "tpk", pPackageId.get(), pKey.get(), pVal.get());
+ AppLog("pkgmgr_installer_send_signal(tpk, %s, %s, %s)", pPackageId.get(), pKey.get(), pVal.get());
+
+ return true;
+}
+
int
-InstallerManager::Request(const String& path, InstallerOperation operation, InstallerOption option, PackageId& packageId)
+InstallerManager::Request(const String& path, InstallerOperation operation, InstallerOption option, void* pPkgmgrInstaller, const PackageId* pPackageId)
{
- InstallationContext* pContext = null;
InstallerError errorType = INSTALLER_ERROR_NONE;
InstallerManager* pInstallManager = null;
pInstallManager = InstallerManager::GetInstance();
TryCatch(pInstallManager, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pInstallManager is null.");
- errorType = pInstallManager->Construct(path, operation, option);
+ errorType = pInstallManager->Construct(path, operation, option, pPkgmgrInstaller, pPackageId);
TryCatch(errorType == INSTALLER_ERROR_NONE, , "pInstallManager->Construct() failed.");
errorType = pInstallManager->Activate();
TryCatch(errorType == INSTALLER_ERROR_NONE, , "pInstallManager->Activate() failed.");
- pContext = pInstallManager->GetContext();
- TryCatch(pContext, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pInstallManager->GetContext failed.");
- packageId = pContext->__packageId;
-
CATCH:
if (pInstallManager)
{
int totalCount = 0;
int successCount = 0;
int failureCount = 0;
- PackageId packageId;
pDir = new (std::nothrow) Directory; // Allocate %Directory instance
TryCatch(pDir, res = false, "pDir is null");
AppLog("------------------------------------------");
AppLog(" # Directory = [%ls]", entryDir.GetPointer());
- errorType = Request(entryDir, INSTALLER_OPERATION_INSTALL, INSTALLER_OPTION_NORMAL, packageId);
+ errorType = Request(entryDir, INSTALLER_OPERATION_INSTALL, INSTALLER_OPTION_NORMAL, null);
if (errorType == 0)
{
successCount++;
{
int mode = 0;
char buf[BUFSIZE] = {0};
- PackageId packageId;
int errorType = 0;
bool output = false;
InstallerOption option = INSTALLER_OPTION_NORMAL;
AppLog(" # Directory = [%s]", buf);
option = (InstallerOption)(option | INSTALLER_OPTION_FILELOG_ON);
- errorType = InstallerManager::Request(buf, INSTALLER_OPERATION_INSTALL, option, packageId);
+ errorType = InstallerManager::Request(buf, INSTALLER_OPERATION_INSTALL, option, null);
if (errorType != 0)
{
// in case of command, garbage directory is not deleted.
AppLog(" # Directory = [%s]", buf);
option = (InstallerOption)(option | INSTALLER_OPTION_FILELOG_ON);
- errorType = InstallerManager::Request(buf, INSTALLER_OPERATION_UNINSTALL, option, packageId);
+ errorType = InstallerManager::Request(buf, INSTALLER_OPERATION_UNINSTALL, option, null);
}
break;
AppLog(" # Directory = [%s]", buf);
option = (InstallerOption)(option | INSTALLER_OPTION_FILELOG_ON);
- errorType = InstallerManager::Request(buf, INSTALLER_OPERATION_REINSTALL, option, packageId);
+ errorType = InstallerManager::Request(buf, INSTALLER_OPERATION_REINSTALL, option, null);
}
break;
#include <pkgmgr_installer.h>
-#include <FBase_StringConverter.h>
+#include <FIoFile.h>
+#include <FAppPkgPackageInfo.h>
+#include <FAppPkg_PackageManagerImpl.h>
#include "InstallerManager.h"
-#include "InstallerDefs.h"
-#include "InstallerUtil.h"
-using namespace Tizen::Base;
using namespace Tizen::App;
+using namespace Tizen::App::Package;
+using namespace Tizen::Base;
+using namespace Tizen::Io;
extern "C" void Osp_Initialize();
-static bool __osp_installer_report_result(const Tizen::App::PackageId& packageId, int errorType);
+static bool __osp_installer_report_result(const PackageId& packageId, int errorType);
static pkgmgr_installer *_pi = null;
main(int argc, char **argv)
{
int ret = 0;
- const char *pkg_info = NULL;
- char* pkg_path = NULL;
+ const char *pkg_info = null;
+ char* pkg_path = null;
+ const char* pOptional = null;
String path;
PackageId packageId;
int errorType = 0;
{
case PKGMGR_REQ_INSTALL:
{
- errorType = InstallerManager::Request(path, INSTALLER_OPERATION_INSTALL, INSTALLER_OPTION_NORMAL, packageId);
- if (_pi != 0)
+ pOptional = pkgmgr_installer_get_optional_data(pi);
+ if (pOptional)
{
- char resultBuf[128] = {0};
- snprintf(resultBuf, sizeof(resultBuf), "%ls", packageId.GetPointer());
- pkgmgr_installer_send_signal(_pi, "tpk", resultBuf, "start", "install");
-
- // temp
- pkgmgr_installer_send_signal(_pi, "tpk", resultBuf, "install_percent", "0");
- usleep(50000);
- pkgmgr_installer_send_signal(_pi, "tpk", resultBuf, "install_percent", "30");
- usleep(50000);
+ packageId = pOptional;
+ AppLog(" # optional = [%s]", pOptional);
}
else
{
- AppLog("_pi is null");
+ FileAttributes attr;
+ result r = File::GetAttributes(path, attr);
+ if (IsFailed(r))
+ {
+ AppLog("GetAttributes() failed. [%ls]", path.GetPointer());
+ goto CATCH;
+ }
+
+ if (attr.IsDirectory())
+ {
+ if (path.EndsWith("/") == true)
+ {
+ int length = path.GetLength();
+ path.Remove(length - 1, 1);
+ }
+
+ path.SubString(path.GetLength() - PACKAGE_ID_LENGTH, PACKAGE_ID_LENGTH, packageId);
+ }
+ else
+ {
+ std::unique_ptr< PackageInfo > pPackageInfo(_PackageManagerImpl::GetInstance()->GetPackageInfoFromFileN(path));
+ if (pPackageInfo)
+ {
+ packageId = pPackageInfo->GetId();
+ }
+ }
+
+ AppLog(" # path = [%ls] -> packageId = [%ls]", path.GetPointer(), packageId.GetPointer());
}
-// if (errorType != 0)
+ errorType = InstallerManager::Request(path, INSTALLER_OPERATION_INSTALL, INSTALLER_OPTION_NORMAL, pi, &packageId);
+
+// if (errorType != 0)
// {
// manager.RemoveGarbage(path);
// }
path.SubString(0, PACKAGE_ID_LENGTH, reqeustPackageId);
AppLog("reqeustPackageId = %ls", reqeustPackageId.GetPointer());
- ret = InstallerManager::Request(reqeustPackageId, INSTALLER_OPERATION_UNINSTALL, INSTALLER_OPTION_NORMAL, packageId);
-
- if (_pi != 0)
- {
- char resultBuf[128] = {0};
- snprintf(resultBuf, sizeof(resultBuf), "%ls", packageId.GetPointer());
- pkgmgr_installer_send_signal(_pi, "tpk", resultBuf, "start", "uninstall");
- }
- else
- {
- AppLog("_pi is null");
- }
+ ret = InstallerManager::Request(reqeustPackageId, INSTALLER_OPERATION_UNINSTALL, INSTALLER_OPTION_NORMAL, _pi);
- __osp_installer_report_result(packageId, errorType);
+ __osp_installer_report_result(reqeustPackageId, errorType);
}
break;
path.SubString(0, PACKAGE_ID_LENGTH, rdsPackageId);
AppLog("rdsPackageId = %ls", rdsPackageId.GetPointer());
- ret = InstallerManager::Request(rdsPackageId, INSTALLER_OPERATION_REINSTALL, INSTALLER_OPTION_NORMAL, packageId);
+ ret = InstallerManager::Request(rdsPackageId, INSTALLER_OPERATION_REINSTALL, INSTALLER_OPTION_NORMAL, _pi, &rdsPackageId);
- if (_pi != 0)
- {
- char resultBuf[128] = {0};
- snprintf(resultBuf, sizeof(resultBuf), "%ls", packageId.GetPointer());
- pkgmgr_installer_send_signal(_pi, "tpk", resultBuf, "start", "install");
- }
- else
- {
- AppLog("_pi is null");
- }
-
- __osp_installer_report_result(packageId, errorType);
+ __osp_installer_report_result(rdsPackageId, errorType);
}
break;
}
bool
-__osp_installer_send_error(int errorType)
-{
- char errorMsg[11] = {0};
- int error = 0;
-
- if (errorType >= INSTALLER_ERROR_USER_CANCEL)
- {
- error = INSTALLER_ERROR_FATAL_ERROR;
- }
- else
- {
- error = errorType;
- }
-
- snprintf(errorMsg, sizeof(errorMsg) - 1, "%d", error);
- pkgmgr_installer_send_signal(_pi, "tpk", "", "error", errorMsg);
-
- return true;
-}
-
-bool
__osp_installer_report_result(const PackageId& packageId, int errorType)
{
- int ret = 0;
- char resultBuf[128] = {0};
- InstallerManager manager;
- const char* pPkgType = "tpk";
- const char* pKey = "end";
- const char* pValue = null;
-
AppLog("------------------------------------------");
AppLog("osp_installer_report_result");
AppLog(" # request_type = [%d]", pkgmgr_installer_get_request_type(_pi));
AppLog(" # request_info = [%s]", pkgmgr_installer_get_request_info(_pi));
AppLog(" # session_id = [%s]", pkgmgr_installer_get_session_id(_pi));
+ if (packageId.IsEmpty() == false)
+ {
+ AppLog(" # packageId = [%ls]", packageId.GetPointer());
+ }
+ AppLog(" # errorType = [%d]", errorType);
AppLog("------------------------------------------");
if (_pi == 0)
return false;
}
- if (errorType == 0)
- {
- pValue = "ok";
- }
- else
- {
- pValue = "fail";
- __osp_installer_send_error(errorType);
- }
-
- if (packageId.IsEmpty() == false)
- {
- snprintf(resultBuf, sizeof(resultBuf), "%ls", packageId.GetPointer());
- }
-
- // temp
- pkgmgr_installer_send_signal(_pi, pPkgType, resultBuf, "install_percent", "65");
- usleep(50000);
- pkgmgr_installer_send_signal(_pi, pPkgType, resultBuf, "install_percent", "100");
- usleep(50000);
-
- ret = pkgmgr_installer_send_signal(_pi, pPkgType, resultBuf, pKey, pValue);
- AppLog("------------------------------------------");
- AppLog("pkgmgr_installer_send_signal");
- AppLog(" # type = [%s]", pPkgType);
- AppLog(" # pkg id = [%s]", resultBuf);
- AppLog(" # key = [%s]", pKey);
- AppLog(" # val = [%s]", pValue);
- AppLog(" # ret = [%s]", (ret == 0)?"success":"failure");
- AppLog("------------------------------------------");
-
pkgmgr_installer_free(_pi);
_pi = null;