#include <sys/stat.h>
#include <dirent.h>
+#include <dlfcn.h>
#include <errno.h>
#include <unistd.h>
#include <unique_ptr.h>
+#include <vconf.h>
#include <FBaseErrorDefine.h>
#include <FIoFile.h>
}
bool
-InstallerUtil::CreateSymlink(const String& oldPath, const String& newPath)
+InstallerUtil::CreateSymlink(const String& oldPath, const String& newPath, bool SmackLabelToRealPath)
{
int err = -1;
bool res = false;
SmackManager smackManager;
String label("_");
- smackManager.AddLabelDir(label, newPath);
+
+ if (SmackLabelToRealPath == true)
+ {
+ smackManager.AddLabelDir(label, newPath);
+ }
+ else
+ {
+ smackManager.AddLabelSymlink(label, newPath);
+ }
AppLog("CreateSymlink(): [%ls] -> [%ls]", newPath.GetPointer(), oldPath.GetPointer());
}
bool
-InstallerUtil::ChangeDirectoryPermission(const String& filePath, int mode, bool appOwner)
+InstallerUtil::ChangeDirectoryPermission(const String& file, int mode, bool appOwner)
{
result r = E_SUCCESS;
bool res = false;
- res = File::IsFileExist(filePath);
+ res = File::IsFileExist(file);
if (res == false)
{
- AppLog("path=[%ls]: skip", filePath.GetPointer());
+ AppLog("path=[%ls]: skip", file.GetPointer());
return true;
}
std::unique_ptr<Directory> pDir(new (std::nothrow) Directory);
TryReturn(pDir, false, "pDir is null.");
- r = pDir->Construct(filePath);
- TryReturn(!IsFailed(r), false, "pDir->Construct() failed, filePath=[%ls]", filePath.GetPointer());
+ r = pDir->Construct(file);
+ TryReturn(!IsFailed(r), false, "pDir->Construct() failed, file=[%ls]", file.GetPointer());
std::unique_ptr<DirEnumerator> pDirEnum(pDir->ReadN());
TryReturn(pDirEnum, false, "pDirEnum is null.");
continue;
}
- String entryDir = filePath;
+ String entryDir = file;
entryDir += L"/";
entryDir += entryName;
}
AppLog("path=[%ls], mode=[%04o], appOwner=[%s]",
- filePath.GetPointer(), mode, appOwner?"true":"false");
+ file.GetPointer(), mode, appOwner?"true":"false");
return true;
}
bool
InstallerUtil::IsDrmFile(const String& path)
{
- return false;
+ int ret = 0;
+ void* pHandle = null;
+ char* pErrorMsg = null;
+ int (*drm_oem_sapps_is_drm_file)(const char* pDcfPath, int dcfPathLen);
+
+ std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(path));
+ TryReturn(pFilePath, false, "pFilePath is null.");
+
+ pHandle = dlopen("/usr/lib/libdrm-service-core-sapps.so.0", RTLD_LAZY | RTLD_GLOBAL);
+ if (!pHandle)
+ {
+ AppLog("dlopen() failed. [%ls][%s]", path.GetPointer(), dlerror());
+ return false;
+ }
+
+ drm_oem_sapps_is_drm_file = reinterpret_cast <int (*)(const char*, int)>(dlsym(pHandle, "drm_oem_sapps_is_drm_file"));
+ pErrorMsg = dlerror();
+ if ((pErrorMsg != null) || (drm_oem_sapps_is_drm_file == null))
+ {
+ AppLog("dlsym() failed. [%ls][%s]", path.GetPointer(), pErrorMsg);
+ dlclose(pHandle);
+ return false;
+ }
+
+ AppLog("[drm] drm_oem_sapps_is_drm_file(%s, %d)", pFilePath.get(), strlen(pFilePath.get()));
+ ret = drm_oem_sapps_is_drm_file(pFilePath.get(), strlen(pFilePath.get()));
+ AppLog("[drm] drm_oem_sapps_is_drm_file(), result = [%d]", ret);
+
+ dlclose(pHandle);
+
+ if (ret == 1)
+ {
+ AppLog("file[%ls] is DRM file.", path.GetPointer());
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
bool
-InstallerUtil::DecryptPackage(const String& packagePath)
+InstallerUtil::DecryptPackage(const String& path, const String& decryptedPath)
{
- return true;
+ int ret = 0;
+ void* pHandle = null;
+ char* pErrorMsg = null;
+ int (*drm_oem_sapps_decrypt_package)(const char* pDcfPath, int dcfPathLen, const char* pDecryptedFile, int decryptedFileLen);
+
+ std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(path));
+ TryReturn(pFilePath, false, "pFilePath is null.");
+
+ std::unique_ptr<char[]> pDecryptedPath(_StringConverter::CopyToCharArrayN(decryptedPath));
+ TryReturn(pDecryptedPath, false, "pDecryptedPath is null.");
+
+ pHandle = dlopen("/usr/lib/libdrm-service-core-sapps.so.0", RTLD_LAZY | RTLD_GLOBAL);
+ if (!pHandle)
+ {
+ AppLog("dlopen() failed. [%ls][%s]", path.GetPointer(), dlerror());
+ return false;
+ }
+
+ drm_oem_sapps_decrypt_package = reinterpret_cast <int (*)(const char*, int, const char*, int)>(dlsym(pHandle, "drm_oem_sapps_decrypt_package"));
+ pErrorMsg = dlerror();
+ if ((pErrorMsg != null) || (drm_oem_sapps_decrypt_package == null))
+ {
+ AppLog("dlsym() failed. [%ls][%s]", path.GetPointer(), pErrorMsg);
+ dlclose(pHandle);
+ return false;
+ }
+
+ AppLog("[drm] drm_oem_sapps_decrypt_package(%s, %d, %s, %d)", pFilePath.get(), strlen(pFilePath.get()), pDecryptedPath.get(), strlen(pDecryptedPath.get()));
+ ret = drm_oem_sapps_decrypt_package(pFilePath.get(), strlen(pFilePath.get()), pDecryptedPath.get(), strlen(pDecryptedPath.get()));
+ AppLog("[drm] drm_oem_sapps_decrypt_package(), result = [%d]", ret);
+
+ dlclose(pHandle);
+
+ if (ret == 1)
+ {
+ AppLog("[%ls] -> [%ls] is decrypted.", path.GetPointer(), decryptedPath.GetPointer());
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
String
InstallerUtil::TerminateApps(const PackageId& packageId)
{
std::unique_ptr< PackageInfo > pPackageInfo(_PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId));
+ TryReturn(pPackageInfo, false, "GetPackageInfoN() failed.");
_PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
TryReturn(pPackageInfoImpl, false, "GetInstance() failed.");
return true;
}
+
+bool
+InstallerUtil::IsUninstallable(const PackageId& packageId)
+{
+ bool res = false;
+
+ std::unique_ptr< PackageInfo > pPackageInfo(_PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId));
+ TryReturn(pPackageInfo, false, "GetPackageInfoN() failed.");
+
+ _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
+ TryReturn(pPackageInfoImpl, false, "GetInstance() failed.");
+
+ res = pPackageInfoImpl->IsUninstallable();
+
+ AppLog("packageId[%ls]: Uninstallable = [%s]", packageId.GetPointer(), res?"true":"false");
+
+ return res;
+}
+
+bool
+InstallerUtil::IsCscPackage(const PackageId& packageId, String& cscInfo)
+{
+ bool res = false;
+ int result = 0;
+ char* pPath = null;
+ pkgmgrinfo_pkginfo_h handle = null;
+
+ std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
+ TryReturn(pPackageId, false, "pPackageId is null.");
+
+ result = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &handle);
+ TryReturn(result == PMINFO_R_OK, false, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", result, pPackageId.get());
+
+ result = pkgmgrinfo_pkginfo_get_csc_path(handle, &pPath);
+ TryReturn(result == PMINFO_R_OK, false, "pkgmgrinfo_pkginfo_get_csc_path() failed. result=[%d], package=[%s]", result, pPackageId.get());
+
+ AppLog("csc_path = [%s]", pPath);
+
+ cscInfo = pPath;
+
+ if (cscInfo.IsEmpty() == false)
+ {
+ res = true;
+ AppLog("packageId[%ls]: cscInfo = [%ls]", packageId.GetPointer(), cscInfo.GetPointer());
+ }
+
+ if (handle)
+ {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ }
+
+ return res;
+}
+
+bool
+InstallerUtil::IsDefaultExternalStorage()
+{
+ int res = 0;
+ int storage = 0;
+ int mmcStatus = VCONFKEY_SYSMAN_MMC_REMOVED;
+
+ res = vconf_get_int("db/setting/default_memory/download", &storage);
+ TryReturn(res == 0, false, "vconf_get_int(db/setting/default_memory/download) failed.");
+
+ AppLog("Storage = [%d]", storage);
+
+ if (storage == 1)
+ {
+ res = vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmcStatus);
+ TryReturn(res == 0, false, "vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS) failed.");
+
+ if ((mmcStatus == VCONFKEY_SYSMAN_MMC_REMOVED) || (mmcStatus == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED))
+ {
+ AppLog("mmcStatus is MMC_REMOVED or NOT_MOUNTED.");
+ }
+ else
+ {
+ AppLog("mmcStatus is MMC_MOUNTED.");
+ return true;
+ }
+ }
+
+ return false;
+}