From cad24c54e333534a30d63e645ef1cbf4322b39af Mon Sep 17 00:00:00 2001 From: Jaemin Ryu Date: Wed, 30 Mar 2016 10:21:10 +0900 Subject: [PATCH] Add application policy Change-Id: I96f02ed5e711e12466993ac0ef3fcdbd91959f65 Signed-off-by: Jaemin Ryu --- libs/CMakeLists.txt | 3 + libs/application.cpp | 203 ++++++++++++++++++++++++++++++++++ libs/dpm/application.cpp | 78 +++++++++++++ libs/dpm/application.h | 192 ++++++++++++++++++++++++++++++++ policy/application.hxx | 64 +++++++++++ server/CMakeLists.txt | 1 + server/application.cpp | 225 ++++++++++++++++++++++++++++++++++++++ tests/integration/CMakeLists.txt | 2 + tests/integration/application.cpp | 108 ++++++++++++++++++ 9 files changed, 876 insertions(+) create mode 100644 libs/application.cpp create mode 100644 libs/dpm/application.cpp create mode 100644 libs/dpm/application.h create mode 100644 policy/application.hxx create mode 100644 server/application.cpp create mode 100644 tests/integration/application.cpp diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 6536da0..777def6 100755 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -22,6 +22,7 @@ SET(PC_FILE "${PROJECT_NAME}.pc") SET(SOURCES policy-client.cpp administration.cpp + application.cpp security.cpp password.cpp zone.cpp @@ -29,10 +30,12 @@ SET(SOURCES policy-client.cpp dpm/security.cpp dpm/password.cpp dpm/zone.cpp + dpm/application.cpp ) SET(CAPI_INCLUDE_FILES dpm/dpm.h dpm/device-policy-client.h + dpm/application.h dpm/security.h dpm/password.h dpm/zone.h diff --git a/libs/application.cpp b/libs/application.cpp new file mode 100644 index 0000000..a4aec35 --- /dev/null +++ b/libs/application.cpp @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include "policy-client.h" + +#include "application.hxx" + +namespace DevicePolicyManager { + +Application::Application(PolicyControlContext& ctxt) : + context(ctxt) +{ +} + +Application::~Application() +{ +} + + +int Application::setApplicationInstallationMode(const bool mode) +{ + try { + return context->methodCall("Application::setApplicationInstallatioMode", mode); + } catch (runtime::Exception& e) { + return -1; + } +} + +bool Application::getApplicationInstallationMode() +{ + try { + return context->methodCall("Application::getApplicationInstallationMode"); + } catch (runtime::Exception& e) { + return -1; + } +} + +int Application::setApplicationUninstallationMode(const bool mode) +{ + try { + return context->methodCall("Application::setApplicationUninstallationMode", mode); + } catch (runtime::Exception& e) { + return -1; + } +} + +bool Application::getApplicationUninstallationMode() +{ + try { + return context->methodCall("Application::getApplicationUninstallationMode"); + } catch (runtime::Exception& e) { + return -1; + } +} + +int Application::setApplicationState(const std::string& appid, const int state) +{ + try { + return context->methodCall("Application::setApplicationState", appid, state); + } catch (runtime::Exception& e) { + return -1; + } +} + +int Application::getApplicationState(const std::string& appid) +{ + try { + return context->methodCall("Application::getApplicationState", appid); + } catch (runtime::Exception& e) { + return -1; + } +} + +std::vector Application::getInstalledPackageList() +{ + try { + return context->methodCall>("Application::getInstalledPackageList"); + } catch (runtime::Exception& e) { + return std::vector(); + } +} + +bool Application::isApplicationInstallationEnabled(const std::string& appid) +{ + try { + return context->methodCall("Application::isApplicationInstallationEnabled", appid); + } catch (runtime::Exception& e) { + return false; + } +} + +bool Application::isApplicationUninstallationEnabled(const std::string& appid) +{ + try { + return context->methodCall("Application::isApplicationInstallationEnabled", appid); + } catch (runtime::Exception& e) { + return false; + } +} + +bool Application::isApplicationRunning(const std::string& appid) +{ + try { + return context->methodCall("Application::isApplicationRunning", appid); + } catch (runtime::Exception& e) { + return false; + } +} + +bool Application::isApplicationInstalled(const std::string& appid) +{ + try { + return context->methodCall("Application::isApplicationInstalled", appid); + } catch (runtime::Exception& e) { + return false; + } +} + +bool Application::isPackageInstalled(const std::string& pkgid) +{ + try { + return context->methodCall("Application::isPackageInstalled", pkgid); + } catch (runtime::Exception& e) { + return false; + } +} + +int Application::installPackage(const std::string& pkgpath) +{ + try { + return context->methodCall("Application::installPackage", pkgpath); + } catch (runtime::Exception& e) { + return -1; + } +} + +int Application::uninstallPackage(const std::string& pkgid) +{ + try { + return context->methodCall("Application::uninstallPackage", pkgid); + } catch (runtime::Exception& e) { + return -1; + } +} + +int Application::disableApplication(const std::string& appid) +{ + try { + return context->methodCall("Application::disableApplication", appid); + } catch (runtime::Exception& e) { + return -1; + } +} + +int Application::enableApplication(const std::string& appid) +{ + try { + return context->methodCall("Application::enableApplication", appid); + } catch (runtime::Exception& e) { + return -1; + } +} + +int Application::startApplication(const std::string& appid) +{ + try { + return context->methodCall("Application::startApplication", appid); + } catch (runtime::Exception& e) { + return -1; + } +} + +int Application::stopApplication(const std::string& appid) +{ + try { + return context->methodCall("Application::stopApplication", appid); + } catch (runtime::Exception& e) { + return -1; + } +} + +int Application::wipeApplicationData(const std::string& appid) +{ + try { + return context->methodCall("Application::wipeApplicationData", appid); + } catch (runtime::Exception& e) { + return -1; + } +} +} // namespace DevicePolicyManager diff --git a/libs/dpm/application.cpp b/libs/dpm/application.cpp new file mode 100644 index 0000000..4e399b2 --- /dev/null +++ b/libs/dpm/application.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include + +#include "application.hxx" + +#include "application.h" +#include "policy-client.h" + +using namespace DevicePolicyManager; + +int dpm_set_package_installation_mode(dpm_client_h handle, int mode) +{ + assert(handle); + + DevicePolicyClient& client = GetDevicePolicyClient(handle); + Application application = client.createPolicyInterface(); + return application.setApplicationInstallationMode(mode); +} + +int dpm_set_package_uninstallation_mode(dpm_client_h handle, int mode) +{ + assert(handle); + + DevicePolicyClient& client = GetDevicePolicyClient(handle); + Application application = client.createPolicyInterface(); + return application.setApplicationUninstallationMode(mode); +} + +int dpm_get_package_installation_mode(dpm_client_h handle) +{ + assert(handle); + + DevicePolicyClient &client = GetDevicePolicyClient(handle); + Application application = client.createPolicyInterface(); + return application.getApplicationInstallationMode(); +} + +int dpm_get_package_uninstallation_mode(dpm_client_h handle) +{ + assert(handle); + + DevicePolicyClient &client = GetDevicePolicyClient(handle); + Application application = client.createPolicyInterface(); + return application.getApplicationUninstallationMode(); +} + +int dpm_set_application_state(dpm_client_h handle, const char* pkgid, dpm_application_state_e state) +{ + assert(handle); + + DevicePolicyClient &client = GetDevicePolicyClient(handle); + Application application = client.createPolicyInterface(); + return application.setApplicationState(pkgid, state); +} + +int dpm_get_application_state(dpm_client_h handle, const char* pkgid) +{ + assert(handle); + + DevicePolicyClient &client = GetDevicePolicyClient(handle); + Application application = client.createPolicyInterface(); + return application.getApplicationState(pkgid); +} diff --git a/libs/dpm/application.h b/libs/dpm/application.h new file mode 100644 index 0000000..6eaabf8 --- /dev/null +++ b/libs/dpm/application.h @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __CAPI_APPLICATION_POLICY_H__ +#define __CAPI_APPLICATION_POLICY_H__ + +#include + +/** + * @file application.h + * @brief This file provides APIs to control application functionality + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup CAPI_DPM_APPLICATION_POLICY_MODULE + * @{ + */ + + /** + * @brief Enumeration for application state + * @since_tizen 3.0 + */ + typedef enum { + APPLICATION_STATE_DISABLE = 0, /**< Application disable */ + APPLICATION_STATE_ENABLE = 1 /**< Application enable */ + } dpm_application_state_e; + + /** + * @brief Enumeration for installation mode + * @since_tizen 3.0 + */ + typedef enum { + PACKAGE_INSTALLATION_MODE_DISALLOW = 0, /**< Package installation disable */ + PACKAGE_INSTALLATION_MODE_ALLOW = 1 /**< Pasckage installation enable */ + } dpm_application_installation_mode_e; + + /** + * @brief Enumeration for uninstallation mode + * @since_tizen 3.0 + */ + typedef enum { + PACKAGE_UNINSTALLATION_MODE_DISALLOW = 0, /**< Package uninstallation disable */ + package_UNINSTALLATION_MODE_ALLOW = 1 /**< Package uninstallation enable */ + } dpm_application_uninstallation_mode_e; + + /** + * @brief Sets the default mode for application installation. + * @details If the mode is set to APPLICATION_INSTALLATION_MODE_DISALLOW, + * no application can be installed on the device. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/dpm.application + * @param[in] handle Device Policy Client handle + * @param[in] mode Installation mode to be set, one of APPLICATION_INSTALLATION_MODE_ALLOW or + APPLICATION_INSTALLATION_MODE_DISALLOW + * @return #DPM_ERROR_NONE on success, otherwise a negative value + * @retval #DPM_ERROR_NONE Successful + * @retval #DPM_ERROR_TIMEOUT Timeout + * @retval #DPM_ERROR_ACCESS_DENIED The application does not have + * the privilege to call this API + * @pre handle must be created by dpm_create_client() + * @post + * @see dpm_create_client() + * @see dpm_destroy_client() + * @see dpm_get_package_installation_mode() + */ + DPM_API int dpm_set_package_installation_mode(dpm_client_h handle, int mode); + + /** + * @brief Sets the default mode for application uninstallation. + * @details If the mode is set to APPLICATION_UNINSTALLATION_MODE_DISALLOW, + * no application can be uninstalled from the device. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/dpm.application + * @param[in] handle Device Policy Client handle + * @param[in] mode Unstallation mode to be set, one of APPLICATION_UNINSTALLATION_MODE_ALLOW of + APPLICATION_UNINSTALLATION_MODE_DISALLOW + * @return #DPM_ERROR_NONE on success, otherwise a negative value + * @retval #DPM_ERROR_NONE Successful + * @retval #DPM_ERROR_TIMEOUT TImeout + * @retval #DPM_ERROR_ACCESS_DENIED The application does not have + * the privilege to call this API + * @pre handle must be created by dpm_create_client() + * @post + * @see dpm_create_client() + * @see dpm_destroy_client() + * @see dpm_get_package_uninstallation_mode() + */ + DPM_API int dpm_set_package_uninstallation_mode(dpm_client_h handle, int mode); + + /** + * @brief Gets the current installation mode for all packages. + * @details The default mode is to allow any package to be installed. + * @since_tizen 3.0 + * @param[in] handle Device Policy Client handle + * @return Current mode of operation, which is one of the following: + * DPM_APPLICATION_INSTALLATION_MODE_ALLOWED or + * DPM_APPLICATION_INSTALLATION_MODE_DISALLOWED + * @retval #DPM_APPLICATION_INSTALLATION_MODE_ALLOWED Application installation is allowed + * @retval #DPM_APPLICATION_INSTALLATION_MODE_DISALLOWED Application installation is not allowed + * @pre handle must be created by dpm_create_client() + * @post + * @see dpm_create_client() + * @see dpm_destroy_client() + * @see dpm_set_package_installation_mode() + */ + DPM_API int dpm_get_package_installation_mode(dpm_client_h handle); + + /** + * @brief Gets the current uninstallation mode for all packages. + * @details The default mode is to allow any package to be uninstalled. + * @since_tizen 3.0 + * @param[in] handle Device Policy Client handle + * @return Current mode of operation, which is one of the following: + * DPM_APPLICATION_UNINSTALLATION_MODE_ALLOWED or + * DPM_APPLICATION_UNINSTALLATION_MODE_DISALLOWED + * @retval #DPM_APPLICATION_UNINSTALLATION_MODE_ALLOWED Application uninstallation is allowed + * @retval #DPM_APPLICATION_UNINSTALLATION_MODE_DISALLOWED Application uninstallation is not allowed + * @pre handle must be created by dpm_create_client() + * @post + * @see dpm_create_client() + * @see dpm_destroy_client() + * @see dpm_get_package_uninstallation_mode() + */ + DPM_API int dpm_get_package_uninstallation_mode(dpm_client_h handle); + +/** + * @brief Enables/disables an package without installation/uninstallation. + * @details Administrator can silently enable/disable any package without + * user interaction. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/dpm.application + * @param[in] handle Device Policy Client handle + * @param[in] pkgid The package name + * @return #DPM_ERROR_NONE on success, otherwise a negative value + * @retval #DPM_ERROR_NONE Successful + * @retval #DPM_ERROR_TIMEOUT Timeout + * @retval #DPM_ERROR_ACCESS_DENIED The application does not have + * the privilege to call this API + * @pre handle must be created by dpm_create_client() + * @post + * @see dpm_create_client() + * @see dpm_destroy_client() + * @see dpm_get_application_state() + */ +DPM_API int dpm_set_application_state(dpm_client_h handle, const char* pkgid, dpm_application_state_e state); + +/** + * @brief Checks whether a geiven application package is enabled or disabled + * @details Administrator can use this API to silently disable installation of an application + * without user interaction. The user can not install applications for which + * the administrator has disabled installation. + * @since_tizen 3.0 + * @param[in] handle Device Policy Client handle + * @param[in] pkgid The package name of the application whose installation is to be disabled + * @return Current state of the application package + * @pre handle must be created by dpm_create_client() + * @post + * @see dpm_create_client() + * @see dpm_destroy_client() + * @see dpm_set_application_state() + */ +DPM_API int dpm_get_application_state(dpm_client_h handle, const char* pkgid); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif //! __CAPI_APPLICATION_POLICY_H__ diff --git a/policy/application.hxx b/policy/application.hxx new file mode 100644 index 0000000..9f6f49b --- /dev/null +++ b/policy/application.hxx @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __APPLICATION_POLICY__ +#define __APPLICATION_POLICY__ + +#include "data-type.h" +#include "policy-context.hxx" + +namespace DevicePolicyManager { + +class Application { +public: + Application(PolicyControlContext& ctxt); + ~Application(); + + int setApplicationInstallationMode(const bool mode); + bool getApplicationInstallationMode(); + + int setApplicationUninstallationMode(const bool mode); + bool getApplicationUninstallationMode(); + + int setApplicationState(const std::string& appid, const int state); + int getApplicationState(const std::string& appid); + + int disableApplication(const std::string& appid); + int enableApplication(const std::string& appid); + + std::vector getInstalledPackageList(); + + int installPackage(const std::string& pkgpath); + int uninstallPackage(const std::string& pkgid); + + bool isApplicationInstallationEnabled(const std::string& appid); + bool isApplicationUninstallationEnabled(const std::string& appid); + + bool isApplicationInstalled(const std::string& appid); + bool isApplicationRunning(const std::string& appid); + bool isPackageInstalled(const std::string& pkgid); + + int startApplication(const std::string& appid); + int stopApplication(const std::string& appid); + + int wipeApplicationData(const std::string& appid); + +private: + PolicyControlContext& context; +}; + +} // namespace DevicePolicyManager +#endif // __APPLICATION_POLICY__ diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 8862edc..529055d 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -22,6 +22,7 @@ SET(SOURCES main.cpp policy-storage.cpp client-manager.cpp administration.cpp + application.cpp security.cpp password.cpp zone.cpp diff --git a/server/application.cpp b/server/application.cpp new file mode 100644 index 0000000..a026f13 --- /dev/null +++ b/server/application.cpp @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include +#include +#include +#include + +#include "application.hxx" + +#include "packman.h" +#include "launchpad.h" +#include "audit/logger.h" + +namespace DevicePolicyManager { + +Application::Application(PolicyControlContext& ctxt) : + context(ctxt) +{ + context.registerNonparametricMethod(this, (bool)(Application::getApplicationInstallationMode)()); + context.registerNonparametricMethod(this, (bool)(Application::getApplicationUninstallationMode)()); + context.registerNonparametricMethod(this, (std::vector)(Application::getInstalledPackageList)()); + + context.registerParametricMethod(this, (int)(Application::setApplicationInstallationMode)(bool)); + context.registerParametricMethod(this, (int)(Application::setApplicationUninstallationMode)(bool)); + context.registerParametricMethod(this, (bool)(Application::isPackageInstalled)(std::string)); + context.registerParametricMethod(this, (bool)(Application::isApplicationInstalled)(std::string)); + context.registerParametricMethod(this, (bool)(Application::isApplicationRunning)(std::string)); + context.registerParametricMethod(this, (int)(Application::installPackage)(std::string)); + context.registerParametricMethod(this, (int)(Application::uninstallPackage)(std::string)); + context.registerParametricMethod(this, (int)(Application::disableApplication)(std::string)); + context.registerParametricMethod(this, (int)(Application::enableApplication)(std::string)); + context.registerParametricMethod(this, (int)(Application::getApplicationState)(std::string)); + context.registerParametricMethod(this, (int)(Application::setApplicationState)(std::string, int)); + context.registerParametricMethod(this, (bool)(Application::isApplicationInstallationEnabled)(std::string)); + context.registerParametricMethod(this, (bool)(Application::isApplicationUninstallationEnabled)(std::string)); + context.registerParametricMethod(this, (int)(Application::startApplication)(std::string)); + context.registerParametricMethod(this, (int)(Application::stopApplication)(std::string)); + context.registerParametricMethod(this, (int)(Application::wipeApplicationData)(std::string)); +} + +Application::~Application() +{ +} + +int Application::setApplicationInstallationMode(const bool mode) +{ + return 0; +} + +bool Application::getApplicationInstallationMode() +{ + return true; +} + +int Application::setApplicationUninstallationMode(const bool mode) +{ + return 0; +} + +bool Application::getApplicationUninstallationMode() +{ + return true; +} + +std::vector Application::getInstalledPackageList() +{ + try { + return PackageManager::getInstalledPackageList(context.getPeerUid()); + } catch (runtime::Exception& e) { + ERROR("Failed to retrieve package info installed in the devioce"); + return std::vector(); + } +} + +bool Application::isApplicationInstallationEnabled(const std::string& appid) +{ + return true; +} + +bool Application::isApplicationUninstallationEnabled(const std::string& appid) +{ + return true; +} + +bool Application::isApplicationInstalled(const std::string& appid) +{ + try { + AppInfo appInfo(appid, context.getPeerUid()); + + return true; + } catch (runtime::Exception& e) { + return false; + } +} + +bool Application::isApplicationRunning(const std::string& appid) +{ + Launchpad launchpad(context.getPeerUid()); + return launchpad.instantiated(appid); +} + +bool Application::isPackageInstalled(const std::string& pkgid) +{ + try { + PackageInfo pkgInfo(pkgid); + + return true; + } catch (runtime::Exception& e) { + return false; + } +} + + +int Application::installPackage(const std::string& pkgpath) +{ + try { + PackageManager::installPackage(pkgpath, context.getPeerUid()); + } catch (runtime::Exception& e) { + ERROR("Exception in Package Id"); + return -1; + } + + return 0; +} + +int Application::uninstallPackage(const std::string& pkgid) +{ + try { + PackageManager::uninstallPackage(pkgid, context.getPeerUid()); + } catch (runtime::Exception& e) { + ERROR("Exception in Package Id"); + return -1; + } + + return 0; +} + +int Application::disableApplication(const std::string& appid) +{ + try { + Launchpad launchpad(context.getPeerUid()); + if (launchpad.instantiated(appid)) { + launchpad.terminate(appid); + // Notify user that the app hass terminated due to the policy + } + + PackageManager::deactivatePackage(appid, context.getPeerUid()); + } catch (runtime::Exception& e) { + return -1; + } + + return 0; +} + +int Application::enableApplication(const std::string& appid) +{ + try { + PackageManager::activatePackage(appid, context.getPeerUid()); + } catch (runtime::Exception& e) { + return -1; + } + + return 0; +} + +int Application::getApplicationState(const std::string& appid) +{ + return true; +} + +int Application::setApplicationState(const std::string& appid, const int state) +{ + return true; +} + +int Application::startApplication(const std::string& appid) +{ + Launchpad launchpad(context.getPeerUid()); + if (launchpad.launch(appid) < 0) { + ERROR("Failed to start device encryption"); + return -1; + } + + return 0; +} + +int Application::stopApplication(const std::string& appid) +{ + Launchpad launchpad(context.getPeerUid()); + if (launchpad.instantiated(appid)) { + launchpad.terminate(appid); + } + + return 0; +} + +int Application::wipeApplicationData(const std::string& appid) +{ + try { + PackageManager::wipePackageData(appid, context.getPeerUid()); + } catch (runtime::Exception& e) { + ERROR("Exception in Package Id"); + return -1; + } + + return 0; +} + +Application applicationPolicy(Server::instance()); + +} // namespace DevicePolicyManager diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index 1d5c0a1..a0a6a64 100755 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -17,9 +17,11 @@ SET(INTEGRATION_TEST_TARGET "dpm-integration-tests") SET(INTEGRATION_TEST_SOURCES main.cpp administration.cpp + application.cpp security.cpp zone.cpp ${DPM_LIBS}/policy-client.cpp + ${DPM_LIBS}/application.cpp ${DPM_LIBS}/administration.cpp ${DPM_LIBS}/security.cpp ${DPM_LIBS}/zone.cpp diff --git a/tests/integration/application.cpp b/tests/integration/application.cpp new file mode 100644 index 0000000..5b7a726 --- /dev/null +++ b/tests/integration/application.cpp @@ -0,0 +1,108 @@ +// Copyright (c) 2015 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include "policy-client.h" +#include "application.hxx" + +#include "audit/logger.h" +#include "testbench/testbench.h" + +namespace { + +const std::string TestAppId = "org.tizen.music-player"; + +}; //namespace + +TESTCASE(AppInfoTest) +{ + DevicePolicyClient client; + std::cout << "Begin connection" << std::endl; + TEST_EXPECT(0, client.connect()); + + std::cout << "End connection" << std::endl; + DevicePolicyManager::Application app = client.createPolicyInterface(); + + bool ret = app.isApplicationInstalled(TestAppId); + TEST_EXPECT(true, ret); + + ret = app.isApplicationInstalled("unknown-application"); + TEST_EXPECT(false, ret); +} + +TESTCASE(PkgInfoTest) +{ + DevicePolicyClient client; + + TEST_EXPECT(0, client.connect()); + + DevicePolicyManager::Application app = client.createPolicyInterface(); + + bool ret = app.isPackageInstalled(TestAppId); + TEST_EXPECT(true, ret); + + ret = app.isPackageInstalled("unknown-package"); + TEST_EXPECT(false, ret); + + std::cout << "Iterate installed packages" << std::endl; + std::vector packages = app.getInstalledPackageList(); + for (std::string& pkg : packages) { + std::cout << pkg << std::endl; + } +} + +TESTCASE(AppRunStateTest) +{ + DevicePolicyClient client; + + TEST_EXPECT(0, client.connect()); + + DevicePolicyManager::Application app = client.createPolicyInterface(); + + int ret = app.startApplication(TestAppId); + TEST_EXPECT(0, ret); + + ret = app.isApplicationRunning(TestAppId); + TEST_EXPECT(true, ret); + + ret = app.isApplicationRunning("unknown-application"); + TEST_EXPECT(false, ret); +} + +TESTCASE(AppActivationTest) +{ + DevicePolicyClient client; + + TEST_EXPECT(0, client.connect()); + + DevicePolicyManager::Application app = client.createPolicyInterface(); + + int ret = app.disableApplication(TestAppId); + TEST_EXPECT(0, ret); +} + +TESTCASE(AppStartTest) +{ + DevicePolicyClient client; + + TEST_EXPECT(0, client.connect()); + + DevicePolicyManager::Application app = client.createPolicyInterface(); + + int ret = app.startApplication(TestAppId); + TEST_EXPECT(0, ret); + sleep(3); + ret = app.stopApplication(TestAppId); + TEST_EXPECT(0, ret); +} -- 2.7.4