From ca0d6f018cc255927a3cba769c918cbe5504ef29 Mon Sep 17 00:00:00 2001 From: Jaemin Ryu Date: Wed, 16 Aug 2017 13:19:20 +0900 Subject: [PATCH] Change device policy manager interface Signed-off-by: Jaemin Ryu --- CMakeLists.txt | 68 +----- administration.cpp | 80 ------- application.cpp | 144 ------------ bluetooth.cpp | 234 ------------------- krate.cpp | 101 -------- libs/CMakeLists.txt | 70 ++++++ {dpm => libs}/administration.cpp | 20 +- {dpm => libs}/application.cpp | 68 +++--- {dpm => libs}/array.h | 0 {dpm => libs}/bluetooth.cpp | 62 ++--- {dpm => libs}/client-handle.cpp | 22 +- {dpm => libs}/debug.h | 0 dpm.pc.in => libs/dpm.pc.in | 0 {dpm => libs/dpm}/administration.h | 0 {dpm => libs/dpm}/application.h | 0 {dpm => libs/dpm}/bluetooth.h | 0 {dpm => libs/dpm}/device-policy-manager.h | 0 {dpm => libs/dpm}/password.h | 0 {dpm => libs/dpm}/password_internal.h | 0 {dpm => libs/dpm}/restriction.h | 0 {dpm => libs/dpm}/security.h | 0 {dpm => libs/dpm}/storage.h | 0 {dpm => libs/dpm}/wifi.h | 0 {dpm => libs/dpm}/zone.h | 0 {dpm => libs}/password.cpp | 267 ++++++++++----------- libs/policy-client.cpp | 103 ++++++++ policy-client.h => libs/policy-client.h | 30 +-- {dpm => libs}/restriction.cpp | 233 +++++++++++-------- {dpm => libs}/security.cpp | 49 ++-- status.h => libs/status.h | 0 {dpm => libs}/storage.cpp | 13 +- {dpm => libs}/wifi.cpp | 48 ++-- {dpm => libs}/zone.cpp | 39 ++-- location.cpp | 79 ------- password.cpp | 375 ------------------------------ policy-client.cpp | 135 ----------- policy-context.hxx | 26 --- policy/administration.hxx | 44 ---- policy/application.hxx | 66 ------ policy/bluetooth.hxx | 67 ------ policy/krate.hxx | 53 ----- policy/location.hxx | 45 ---- policy/password.hxx | 98 -------- policy/restriction.hxx | 69 ------ policy/security.hxx | 53 ----- policy/smack.hxx | 70 ------ policy/storage.hxx | 49 ---- policy/wifi.hxx | 60 ----- restriction.cpp | 257 -------------------- security.cpp | 112 --------- storage.cpp | 68 ------ wifi.cpp | 168 ------------- 52 files changed, 616 insertions(+), 2929 deletions(-) delete mode 100644 administration.cpp delete mode 100644 application.cpp delete mode 100644 bluetooth.cpp delete mode 100644 krate.cpp create mode 100755 libs/CMakeLists.txt rename {dpm => libs}/administration.cpp (73%) rename {dpm => libs}/application.cpp (62%) rename {dpm => libs}/array.h (100%) rename {dpm => libs}/bluetooth.cpp (61%) rename {dpm => libs}/client-handle.cpp (79%) rename {dpm => libs}/debug.h (100%) rename dpm.pc.in => libs/dpm.pc.in (100%) rename {dpm => libs/dpm}/administration.h (100%) rename {dpm => libs/dpm}/application.h (100%) rename {dpm => libs/dpm}/bluetooth.h (100%) rename {dpm => libs/dpm}/device-policy-manager.h (100%) rename {dpm => libs/dpm}/password.h (100%) rename {dpm => libs/dpm}/password_internal.h (100%) rename {dpm => libs/dpm}/restriction.h (100%) rename {dpm => libs/dpm}/security.h (100%) rename {dpm => libs/dpm}/storage.h (100%) rename {dpm => libs/dpm}/wifi.h (100%) rename {dpm => libs/dpm}/zone.h (100%) rename {dpm => libs}/password.cpp (59%) create mode 100644 libs/policy-client.cpp rename policy-client.h => libs/policy-client.h (63%) rename {dpm => libs}/restriction.cpp (57%) rename {dpm => libs}/security.cpp (64%) rename status.h => libs/status.h (100%) rename {dpm => libs}/storage.cpp (73%) rename {dpm => libs}/wifi.cpp (64%) rename {dpm => libs}/zone.cpp (71%) delete mode 100644 location.cpp delete mode 100644 password.cpp delete mode 100644 policy-client.cpp delete mode 100644 policy-context.hxx delete mode 100644 policy/administration.hxx delete mode 100644 policy/application.hxx delete mode 100644 policy/bluetooth.hxx delete mode 100644 policy/krate.hxx delete mode 100644 policy/location.hxx delete mode 100644 policy/password.hxx delete mode 100644 policy/restriction.hxx delete mode 100644 policy/security.hxx delete mode 100644 policy/smack.hxx delete mode 100644 policy/storage.hxx delete mode 100644 policy/wifi.hxx delete mode 100644 restriction.cpp delete mode 100644 security.cpp delete mode 100644 storage.cpp delete mode 100644 wifi.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 630b15e..eeb4c25 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,9 +15,7 @@ # CMAKE_MINIMUM_REQUIRED(VERSION 2.8) -PROJECT(dpm) -SET(LIB_VERSION "${VERSION}") -SET(LIB_SOVERSION "0") +PROJECT(device-policy-client) INCLUDE(FindPkgConfig) @@ -25,8 +23,7 @@ IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "DEBUG") ENDIF(NOT CMAKE_BUILD_TYPE) -SET(DPM_POLICY ${PROJECT_SOURCE_DIR}/policy) -SET(DPM_LIBS ${PROJECT_SOURCE_DIR}/) +SET(DPM_LIBS ${PROJECT_SOURCE_DIR}/libs) IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7) SET(CXX_STD "c++0x") @@ -58,64 +55,5 @@ ENDIF(NOT DEFINED TEST_DATA_INSTALL_DIR) ADD_DEFINITIONS(-DUG_WAYLAND) -SET(PC_FILE "${PROJECT_NAME}.pc") +ADD_SUBDIRECTORY(${DPM_LIBS}) -SET(FOUNDATION policy-client.cpp - dpm/client-handle.cpp -) - -SET(POLICY administration.cpp - application.cpp - bluetooth.cpp - location.cpp - restriction.cpp - security.cpp - storage.cpp - wifi.cpp - password.cpp - krate.cpp - dpm/administration.cpp - dpm/application.cpp - dpm/bluetooth.cpp - dpm/restriction.cpp - dpm/security.cpp - dpm/wifi.cpp - dpm/password.cpp - dpm/zone.cpp -) - -SET(CAPI dpm/device-policy-manager.h - dpm/administration.h - dpm/application.h - dpm/bluetooth.h - dpm/restriction.h - dpm/security.h - dpm/wifi.h - dpm/password.h - dpm/password_internal.h - dpm/zone.h -) - -SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack") - -ADD_LIBRARY(${PROJECT_NAME} SHARED ${FOUNDATION} ${POLICY}) - -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-fvisibility=hidden") -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${LIB_SOVERSION}) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${LIB_VERSION}) - -PKG_CHECK_MODULES(LIBS_DEPS REQUIRED - klay - glib-2.0 - capi-base-common - capi-system-info -) - -INCLUDE_DIRECTORIES(SYSTEM ${LIBS_DEPS_INCLUDE_DIRS} ${DPM_POLICY} ${DPM_LIBS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIBS_DEPS_LIBRARIES} pthread) - -CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_BINARY_DIR}/${PC_FILE} @ONLY) - -INSTALL(FILES ${CMAKE_BINARY_DIR}/${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) -INSTALL(FILES ${CAPI} DESTINATION ${INCLUDE_INSTALL_DIR}/dpm) diff --git a/administration.cpp b/administration.cpp deleted file mode 100644 index 507076f..0000000 --- a/administration.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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 "status.h" -#include "administration.hxx" - -namespace DevicePolicyManager { - -struct AdministrationPolicy::Private { - Private(PolicyControlContext& ctx) : context(ctx) {} - PolicyControlContext& context; -}; - -AdministrationPolicy::AdministrationPolicy(AdministrationPolicy&& rhs) = default; -AdministrationPolicy& AdministrationPolicy::operator=(AdministrationPolicy&& rhs) = default; - -AdministrationPolicy::AdministrationPolicy(const AdministrationPolicy& rhs) : - pimpl(nullptr) -{ - if (rhs.pimpl) { - pimpl.reset(new Private(*rhs.pimpl)); - } -} - -AdministrationPolicy& AdministrationPolicy::operator=(const AdministrationPolicy& rhs) -{ - if (!rhs.pimpl) { - pimpl.reset(); - } else { - pimpl.reset(new Private(*rhs.pimpl)); - } - - return *this; -} - -AdministrationPolicy::AdministrationPolicy(PolicyControlContext& ctx) : - pimpl(new Private(ctx)) -{ -} - -AdministrationPolicy::~AdministrationPolicy() -{ -} - -int AdministrationPolicy::registerPolicyClient(const std::string& name, uid_t uid) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("AdministrationPolicy::registerPolicyClient", name, uid); - - return status.get(); -} - -int AdministrationPolicy::deregisterPolicyClient(const std::string& name, uid_t uid) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("AdministrationPolicy::deregisterPolicyClient", name, uid); - - return status.get(); -} - -} // namespace DevicePolicyManager diff --git a/application.cpp b/application.cpp deleted file mode 100644 index 429e6bd..0000000 --- a/application.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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 "status.h" -#include "application.hxx" - -namespace DevicePolicyManager { - -struct ApplicationPolicy::Private { - Private(PolicyControlContext& ctxt) : context(ctxt) {} - PolicyControlContext& context; -}; - -ApplicationPolicy::ApplicationPolicy(ApplicationPolicy&& rhs) = default; -ApplicationPolicy& ApplicationPolicy::operator=(ApplicationPolicy&& rhs) = default; - -ApplicationPolicy::ApplicationPolicy(const ApplicationPolicy& rhs) -{ - if (rhs.pimpl) { - pimpl.reset(new Private(*rhs.pimpl)); - } -} - -ApplicationPolicy& ApplicationPolicy::operator=(const ApplicationPolicy& rhs) -{ - if (!rhs.pimpl) { - pimpl.reset(); - } else { - pimpl.reset(new Private(*rhs.pimpl)); - } - - return *this; -} - -ApplicationPolicy::ApplicationPolicy(PolicyControlContext& ctxt) : - pimpl(new Private(ctxt)) -{ -} - -ApplicationPolicy::~ApplicationPolicy() -{ -} - -int ApplicationPolicy::installPackage(const std::string& pkgpath) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("ApplicationPolicy::installPackage", pkgpath); - - return status.get(); -} - -int ApplicationPolicy::uninstallPackage(const std::string& pkgid) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("ApplicationPolicy::uninstallPackage", pkgid); - - return status.get(); -} - -int ApplicationPolicy::setModeRestriction(int mode) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("ApplicationPolicy::setModeRestriction", mode); - - return status.get(); -} - -int ApplicationPolicy::unsetModeRestriction(int mode) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("ApplicationPolicy::unsetModeRestriction", mode); - - return status.get(); -} - -int ApplicationPolicy::getModeRestriction() -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("ApplicationPolicy::getModeRestriction"); - - return status.get(); -} - -int ApplicationPolicy::addPrivilegeToBlacklist(int type, const std::string& privilege) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("ApplicationPolicy::addPrivilegeToBlacklist", type, privilege); - - return status.get(); -} - -int ApplicationPolicy::removePrivilegeFromBlacklist(int type, const std::string& privilege) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("ApplicationPolicy::removePrivilegeFromBlacklist", type, privilege); - - return status.get(); -} - -int ApplicationPolicy::checkPrivilegeIsBlacklisted(int type, const std::string& privilege) -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("ApplicationPolicy::checkPrivilegeIsBlacklisted", type, privilege); - - return status.get(); -} -} // namespace DevicePolicyManager diff --git a/bluetooth.cpp b/bluetooth.cpp deleted file mode 100644 index ade8f32..0000000 --- a/bluetooth.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright (c) 2016 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 "status.h" -#include "bluetooth.hxx" - -namespace DevicePolicyManager { - -struct BluetoothPolicy::Private { - Private(PolicyControlContext& ctx) : context(ctx) {} - PolicyControlContext& context; -}; - -BluetoothPolicy::BluetoothPolicy(BluetoothPolicy&& rhs) = default; -BluetoothPolicy& BluetoothPolicy::operator=(BluetoothPolicy&& rhs) = default; - -BluetoothPolicy::BluetoothPolicy(const BluetoothPolicy& rhs) -{ - if (rhs.pimpl) { - pimpl.reset(new Private(*rhs.pimpl)); - } -} - -BluetoothPolicy& BluetoothPolicy::operator=(const BluetoothPolicy& rhs) -{ - if (!rhs.pimpl) { - pimpl.reset(); - } else { - pimpl.reset(new Private(*rhs.pimpl)); - } - - return *this; -} - -BluetoothPolicy::BluetoothPolicy(PolicyControlContext& ctxt) : - pimpl(new Private(ctxt)) -{ -} - -BluetoothPolicy::~BluetoothPolicy() -{ -} - -// for restriction CPIs -int BluetoothPolicy::setModeChangeState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("BluetoothPolicy::setModeChangeState", enable); - - return status.get(); -} - -bool BluetoothPolicy::getModeChangeState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("BluetoothPolicy::getModeChangeState"); - - return status.get(); -} - -int BluetoothPolicy::setDesktopConnectivityState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("BluetoothPolicy::setDesktopConnectivityState", enable); - - return status.get(); -} - -bool BluetoothPolicy::getDesktopConnectivityState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("BluetoothPolicy::getDesktopConnectivityState"); - - return status.get(); -} - -int BluetoothPolicy::setTetheringState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("BluetoothPolicy::setTetheringState", enable); - - return status.get(); -} - -bool BluetoothPolicy::getTetheringState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("BluetoothPolicy::getTetheringState"); - - return status.get(); -} - -int BluetoothPolicy::setPairingState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("BluetoothPolicy::setPairingState", enable); - - return status.get(); -} - -bool BluetoothPolicy::getPairingState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("BluetoothPolicy::getPairingState"); - - return status.get(); -} - -int BluetoothPolicy::addDeviceToBlacklist(const std::string& mac) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("BluetoothPolicy::addDeviceToBlacklist", mac); - - return status.get(); -} - -int BluetoothPolicy::removeDeviceFromBlacklist(const std::string& mac) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("BluetoothPolicy::removeDeviceFromBlacklist", mac); - - return status.get(); -} - -int BluetoothPolicy::setDeviceRestriction(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("BluetoothPolicy::setDeviceRestriction", enable); - - return status.get(); -} - -bool BluetoothPolicy::isDeviceRestricted() -{ - PolicyControlContext& context = pimpl->context; - - Status status { false }; - - status = context.methodCall("BluetoothPolicy::isDeviceRestricted"); - - return status.get(); -} - -int BluetoothPolicy::addUuidToBlacklist(const std::string& uuid) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("BluetoothPolicy::addUuidToBlacklist", uuid); - - return status.get(); -} - -int BluetoothPolicy::removeUuidFromBlacklist(const std::string& uuid) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("BluetoothPolicy::removeUuidFromBlacklist", uuid); - - return status.get(); -} - -int BluetoothPolicy::setUuidRestriction(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("BluetoothPolicy::setUuidRestriction", enable); - - return status.get(); -} - -bool BluetoothPolicy::isUuidRestricted() -{ - PolicyControlContext& context = pimpl->context; - - Status status { false }; - - status = context.methodCall("BluetoothPolicy::isUuidRestricted"); - - return status.get(); -} - -} // namespace DevicePolicyManager diff --git a/krate.cpp b/krate.cpp deleted file mode 100644 index b49ac3f..0000000 --- a/krate.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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 "status.h" -#include "krate.hxx" - -namespace DevicePolicyManager { - -struct KratePolicy::Private { - Private(PolicyControlContext& ctxt) : context(ctxt) {} - PolicyControlContext& context; -}; - -KratePolicy::KratePolicy(KratePolicy&& rhs) = default; -KratePolicy& KratePolicy::operator=(KratePolicy&& rhs) = default; - -KratePolicy::KratePolicy(const KratePolicy& rhs) -{ - if (rhs.pimpl) { - pimpl.reset(new Private(*rhs.pimpl)); - } -} - -KratePolicy& KratePolicy::operator=(const KratePolicy& rhs) -{ - if (!rhs.pimpl) { - pimpl.reset(); - } else { - pimpl.reset(new Private(*rhs.pimpl)); - } - - return *this; -} - -KratePolicy::KratePolicy(PolicyControlContext& ctx) : - pimpl(new Private(ctx)) -{ -} - -KratePolicy::~KratePolicy() -{ -} - -int KratePolicy::createKrate(const std::string& name, const std::string& setupWizAppid) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("KratePolicy::createKrate", name, setupWizAppid); - - return status.get(); -} - -int KratePolicy::removeKrate(const std::string& name) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("KratePolicy::removeKrate", name); - - return status.get(); -} - -int KratePolicy::getKrateState(const std::string& name) -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("KratePolicy::getKrateState", name); - - return status.get(); -} - -std::vector KratePolicy::getKrateList(int state) -{ - PolicyControlContext& context = pimpl->context; - - Status> status { std::vector() }; - - status = context.methodCall>("KratePolicy::getKrateList", state); - - return status.get(); -} - -} // namespace DevicePolicyManager diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt new file mode 100755 index 0000000..3d5f6bd --- /dev/null +++ b/libs/CMakeLists.txt @@ -0,0 +1,70 @@ +# +# 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. +# +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) + +SET(TARGET "dpm") +SET(LIB_VERSION "${VERSION}") +SET(LIB_SOVERSION "0") + +SET(PC_FILE "${TARGET}.pc") + +SET(POLICY policy-client.cpp + client-handle.cpp + administration.cpp + application.cpp + bluetooth.cpp + restriction.cpp + security.cpp + wifi.cpp + password.cpp + zone.cpp +) + +SET(CAPI dpm/device-policy-manager.h + dpm/administration.h + dpm/application.h + dpm/bluetooth.h + dpm/restriction.h + dpm/security.h + dpm/wifi.h + dpm/password.h + dpm/password_internal.h + dpm/zone.h +) + +SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack") + +ADD_LIBRARY(${TARGET} SHARED ${FOUNDATION} ${POLICY}) + +SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=hidden") +SET_TARGET_PROPERTIES(${TARGET} PROPERTIES SOVERSION ${LIB_SOVERSION}) +SET_TARGET_PROPERTIES(${TARGET} PROPERTIES VERSION ${LIB_VERSION}) + +PKG_CHECK_MODULES(LIBS_DEPS REQUIRED + klay + glib-2.0 + capi-base-common + capi-system-info +) + +INCLUDE_DIRECTORIES(SYSTEM ${LIBS_DEPS_INCLUDE_DIRS} ${DPM_LIBS}) +TARGET_LINK_LIBRARIES(${TARGET} ${LIBS_DEPS_LIBRARIES} pthread) + +CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_BINARY_DIR}/${PC_FILE} @ONLY) + +INSTALL(FILES ${CMAKE_BINARY_DIR}/${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL(TARGETS ${TARGET} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(FILES ${CAPI} DESTINATION ${INCLUDE_INSTALL_DIR}/dpm) diff --git a/dpm/administration.cpp b/libs/administration.cpp similarity index 73% rename from dpm/administration.cpp rename to libs/administration.cpp index 6a19eaf..5e8b500 100644 --- a/dpm/administration.cpp +++ b/libs/administration.cpp @@ -17,25 +17,24 @@ #include #include -#include "administration.h" -#include "administration.hxx" +#include "dpm/administration.h" #include "debug.h" +#include "status.h" #include "policy-client.h" -using namespace DevicePolicyManager; - EXPORT_API int dpm_admin_register_client(device_policy_manager_h handle, const char* name, uid_t uid) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(name, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(uid, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - AdministrationPolicy admin = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return admin.registerPolicyClient(name, uid); + Status status { -1 }; + status = client.methodCall("DevicePolicyManager::enroll", name, uid); + return status.get(); } catch (...) { return -1; } @@ -47,11 +46,12 @@ EXPORT_API int dpm_admin_deregister_client(device_policy_manager_h handle, const RET_ON_FAILURE(name, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(uid, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - AdministrationPolicy admin = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return admin.deregisterPolicyClient(name, uid); + Status status { -1 }; + status = client.methodCall("DevicePolicyManager::disenroll", name, uid); + return status.get(); } catch (...) { return -1; } diff --git a/dpm/application.cpp b/libs/application.cpp similarity index 62% rename from dpm/application.cpp rename to libs/application.cpp index 0983819..4b3ae3b 100644 --- a/dpm/application.cpp +++ b/libs/application.cpp @@ -14,24 +14,23 @@ * limitations under the License */ -#include "application.h" -#include "application.hxx" +#include "dpm/application.h" #include "debug.h" +#include "status.h" #include "policy-client.h" -using namespace DevicePolicyManager; - EXPORT_API int dpm_application_set_mode_restriction(device_policy_manager_h handle, int mode) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(mode, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext& client = GetDevicePolicyContext(handle); - ApplicationPolicy application = client.createPolicyInterface(); + DevicePolicyClient& client = GetDevicePolicyClient(handle); try { - return application.setModeRestriction(mode); + Status status { -1 }; + status = client.methodCall("Application::setModeRestriction", mode); + return status.get(); } catch (...) { return -1; } @@ -42,11 +41,12 @@ EXPORT_API int dpm_application_unset_mode_restriction(device_policy_manager_h ha RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(mode, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext& client = GetDevicePolicyContext(handle); - ApplicationPolicy application = client.createPolicyInterface(); + DevicePolicyClient& client = GetDevicePolicyClient(handle); try { - return application.unsetModeRestriction(mode); + Status status { -1 }; + status = client.methodCall("Application::unsetModeRestriction", mode); + return status.get(); } catch (...) { return -1; } @@ -57,15 +57,15 @@ EXPORT_API int dpm_application_get_mode_restriction(device_policy_manager_h hand RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(mode, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext& client = GetDevicePolicyContext(handle); - ApplicationPolicy application = client.createPolicyInterface(); + DevicePolicyClient& client = GetDevicePolicyClient(handle); try { - int ret = application.getModeRestriction(); - if (ret < 0) { + Status status { 0 }; + status = client.methodCall("Application::getModeRestriction"); + if (status.get() < 0) { return -1; } - *mode = ret; + *mode = status.get(); } catch (...) { return -1; } @@ -78,11 +78,12 @@ EXPORT_API int dpm_application_add_privilege_to_blacklist(device_policy_manager_ RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(privilege, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext& client = GetDevicePolicyContext(handle); - ApplicationPolicy application = client.createPolicyInterface(); + DevicePolicyClient& client = GetDevicePolicyClient(handle); try { - return application.addPrivilegeToBlacklist(type, privilege); + Status status { -1 }; + status = client.methodCall("Application::addPrivilegeToBlacklist", type, privilege); + return status.get(); } catch (...) { return -1; } @@ -93,11 +94,12 @@ EXPORT_API int dpm_application_remove_privilege_from_blacklist(device_policy_man RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(privilege, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext& client = GetDevicePolicyContext(handle); - ApplicationPolicy application = client.createPolicyInterface(); + DevicePolicyClient& client = GetDevicePolicyClient(handle); try { - return application.removePrivilegeFromBlacklist(type, privilege); + Status status { -1 }; + status = client.methodCall("Application::removePrivilegeFromBlacklist", type, privilege); + return status.get(); } catch (...) { return -1; } @@ -109,16 +111,16 @@ EXPORT_API int dpm_application_check_privilege_is_blacklisted(device_policy_mana RET_ON_FAILURE(privilege, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_blacklisted, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext& client = GetDevicePolicyContext(handle); - ApplicationPolicy application = client.createPolicyInterface(); + DevicePolicyClient& client = GetDevicePolicyClient(handle); try { - int ret = application.checkPrivilegeIsBlacklisted(type, privilege); - if (ret < 0) { + Status status { 0 }; + status = client.methodCall("Application::checkPrivilegeIsBlacklisted", type, privilege); + if (status.get() < 0) { return -1; } - *is_blacklisted = ret; + *is_blacklisted = status.get(); } catch (...) { return -1; } @@ -131,11 +133,12 @@ EXPORT_API int dpm_application_install_package(device_policy_manager_h handle, c RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(pkgpath, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext& client = GetDevicePolicyContext(handle); - ApplicationPolicy application = client.createPolicyInterface(); + DevicePolicyClient& client = GetDevicePolicyClient(handle); try { - return application.installPackage(pkgpath); + Status status { -1 }; + status = client.methodCall("Application::installPackage", pkgpath); + return status.get(); } catch (...) { return -1; } @@ -146,11 +149,12 @@ EXPORT_API int dpm_application_uninstall_package(device_policy_manager_h handle, RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(pkgid, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext& client = GetDevicePolicyContext(handle); - ApplicationPolicy application = client.createPolicyInterface(); + DevicePolicyClient& client = GetDevicePolicyClient(handle); try { - return application.uninstallPackage(pkgid); + Status status { -1 }; + status = client.methodCall("Application::uninstallPackage", pkgid); + return status.get(); } catch (...) { return -1; } diff --git a/dpm/array.h b/libs/array.h similarity index 100% rename from dpm/array.h rename to libs/array.h diff --git a/dpm/bluetooth.cpp b/libs/bluetooth.cpp similarity index 61% rename from dpm/bluetooth.cpp rename to libs/bluetooth.cpp index cb8c409..a5d8470 100644 --- a/dpm/bluetooth.cpp +++ b/libs/bluetooth.cpp @@ -14,24 +14,23 @@ * limitations under the License */ -#include "bluetooth.h" -#include "bluetooth.hxx" +#include "dpm/bluetooth.h" #include "debug.h" +#include "status.h" #include "policy-client.h" -using namespace DevicePolicyManager; - EXPORT_API int dpm_bluetooth_add_device_to_blacklist(device_policy_manager_h handle, const char* mac) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(mac, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return bluetooth.addDeviceToBlacklist(mac); + Status status { -1 }; + status = client.methodCall("Bluetooth::addDeviceToBlacklist", mac); + return status.get(); } catch (...) { return -1; } @@ -42,11 +41,12 @@ EXPORT_API int dpm_bluetooth_remove_device_from_blacklist(device_policy_manager_ RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(mac, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return bluetooth.removeDeviceFromBlacklist(mac); + Status status { -1 }; + status = client.methodCall("Bluetooth::removeDeviceFromBlacklist", mac); + return status.get(); } catch (...) { return -1; } @@ -56,11 +56,12 @@ EXPORT_API int dpm_bluetooth_set_device_restriction(device_policy_manager_h hand { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return bluetooth.setDeviceRestriction(enable); + Status status { -1 }; + status = client.methodCall("Bluetooth::setDeviceRestriction", enable); + return status.get(); } catch (...) { return -1; } @@ -70,11 +71,12 @@ EXPORT_API int dpm_bluetooth_is_device_restricted(device_policy_manager_h handle { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *state = bluetooth.isDeviceRestricted(); + Status status { false }; + status = client.methodCall("Bluetooth::isDeviceRestricted"); + *state = status.get(); } catch (...) { return -1; } @@ -87,11 +89,12 @@ EXPORT_API int dpm_bluetooth_add_uuid_to_blacklist(device_policy_manager_h handl RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(uuid, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return bluetooth.addUuidToBlacklist(uuid); + Status status { -1 }; + status = client.methodCall("Bluetooth::addUuidToBlacklist", uuid); + return status.get(); } catch (...) { return -1; } @@ -102,11 +105,12 @@ EXPORT_API int dpm_bluetooth_remove_uuid_from_blacklist(device_policy_manager_h RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(uuid, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return bluetooth.removeUuidFromBlacklist(uuid); + Status status { -1 }; + status = client.methodCall("Bluetooth::removeUuidFromBlacklist", uuid); + return status.get(); } catch (...) { return -1; } @@ -116,11 +120,12 @@ EXPORT_API int dpm_bluetooth_set_uuid_restriction(device_policy_manager_h handle { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return bluetooth.setUuidRestriction(enable); + Status status { -1 }; + status = client.methodCall("Bluetooth::setUuidRestriction", enable); + return status.get(); } catch (...) { return -1; } @@ -130,11 +135,12 @@ EXPORT_API int dpm_bluetooth_is_uuid_restricted(device_policy_manager_h handle, { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *state = bluetooth.isUuidRestricted(); + Status status { false }; + status = client.methodCall("Bluetooth::isUuidRestricted"); + *state = status.get(); } catch (...) { return -1; } diff --git a/dpm/client-handle.cpp b/libs/client-handle.cpp similarity index 79% rename from dpm/client-handle.cpp rename to libs/client-handle.cpp index 1c5eb7d..d2ea116 100644 --- a/dpm/client-handle.cpp +++ b/libs/client-handle.cpp @@ -17,20 +17,20 @@ #include #include -#include "device-policy-manager.h" +#include "dpm/device-policy-manager.h" #include "policy-client.h" #include "debug.h" -DevicePolicyContext& GetDevicePolicyContext(void* handle) +DevicePolicyClient& GetDevicePolicyClient(void* handle) { assert(handle); - return *reinterpret_cast(handle); + return *reinterpret_cast(handle); } EXPORT_API device_policy_manager_h dpm_manager_create(void) { - DevicePolicyContext* client = new(std::nothrow) DevicePolicyContext(); + DevicePolicyClient* client = new(std::nothrow) DevicePolicyClient(); if (client == nullptr) { return NULL; } @@ -47,7 +47,7 @@ EXPORT_API int dpm_manager_destroy(device_policy_manager_h handle) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - delete &GetDevicePolicyContext(handle); + delete &GetDevicePolicyClient(handle); return 0; } @@ -63,8 +63,8 @@ EXPORT_API int dpm_add_policy_changed_cb(device_policy_manager_h handle, RET_ON_FAILURE(callback, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(id, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext& client = GetDevicePolicyContext(handle); - int ret = client.subscribePolicyChange(name, callback, user_data); + DevicePolicyClient& client = GetDevicePolicyClient(handle); + int ret = client.subscribeSignal(name, callback, user_data); if (ret < 0) { return -1; } @@ -78,8 +78,8 @@ EXPORT_API int dpm_remove_policy_changed_cb(device_policy_manager_h handle, int RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(id >= 0, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext& client = GetDevicePolicyContext(handle); - return client.unsubscribePolicyChange(id); + DevicePolicyClient& client = GetDevicePolicyClient(handle); + return client.unsubscribeSignal(id); } EXPORT_API int dpm_add_signal_cb(device_policy_manager_h handle, const char* signal, @@ -90,7 +90,7 @@ EXPORT_API int dpm_add_signal_cb(device_policy_manager_h handle, const char* sig RET_ON_FAILURE(callback, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(id, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext& context = GetDevicePolicyContext(handle); + DevicePolicyClient& context = GetDevicePolicyClient(handle); int ret = context.subscribeSignal(signal, callback, user_data); if (ret < 0) { return -1; @@ -105,6 +105,6 @@ EXPORT_API int dpm_remove_signal_cb(device_policy_manager_h handle, int id) RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(id >= 0, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext& context = GetDevicePolicyContext(handle); + DevicePolicyClient& context = GetDevicePolicyClient(handle); return context.unsubscribeSignal(id); } diff --git a/dpm/debug.h b/libs/debug.h similarity index 100% rename from dpm/debug.h rename to libs/debug.h diff --git a/dpm.pc.in b/libs/dpm.pc.in similarity index 100% rename from dpm.pc.in rename to libs/dpm.pc.in diff --git a/dpm/administration.h b/libs/dpm/administration.h similarity index 100% rename from dpm/administration.h rename to libs/dpm/administration.h diff --git a/dpm/application.h b/libs/dpm/application.h similarity index 100% rename from dpm/application.h rename to libs/dpm/application.h diff --git a/dpm/bluetooth.h b/libs/dpm/bluetooth.h similarity index 100% rename from dpm/bluetooth.h rename to libs/dpm/bluetooth.h diff --git a/dpm/device-policy-manager.h b/libs/dpm/device-policy-manager.h similarity index 100% rename from dpm/device-policy-manager.h rename to libs/dpm/device-policy-manager.h diff --git a/dpm/password.h b/libs/dpm/password.h similarity index 100% rename from dpm/password.h rename to libs/dpm/password.h diff --git a/dpm/password_internal.h b/libs/dpm/password_internal.h similarity index 100% rename from dpm/password_internal.h rename to libs/dpm/password_internal.h diff --git a/dpm/restriction.h b/libs/dpm/restriction.h similarity index 100% rename from dpm/restriction.h rename to libs/dpm/restriction.h diff --git a/dpm/security.h b/libs/dpm/security.h similarity index 100% rename from dpm/security.h rename to libs/dpm/security.h diff --git a/dpm/storage.h b/libs/dpm/storage.h similarity index 100% rename from dpm/storage.h rename to libs/dpm/storage.h diff --git a/dpm/wifi.h b/libs/dpm/wifi.h similarity index 100% rename from dpm/wifi.h rename to libs/dpm/wifi.h diff --git a/dpm/zone.h b/libs/dpm/zone.h similarity index 100% rename from dpm/zone.h rename to libs/dpm/zone.h diff --git a/dpm/password.cpp b/libs/password.cpp similarity index 59% rename from dpm/password.cpp rename to libs/password.cpp index 377788a..131113e 100644 --- a/dpm/password.cpp +++ b/libs/password.cpp @@ -17,26 +17,25 @@ #include #include -#include "password.h" -#include "password_internal.h" -#include "password.hxx" +#include "dpm/password.h" +#include "dpm/password_internal.h" #include "array.h" #include "debug.h" +#include "status.h" #include "policy-client.h" -using namespace DevicePolicyManager; - EXPORT_API int dpm_password_set_quality(device_policy_manager_h handle, int quality) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(quality >= 0, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.setQuality(quality); + Status status { -1 }; + status = client.methodCall("Password::setQuality", quality); + return status.get(); } catch (...) { return -1; } @@ -47,16 +46,15 @@ EXPORT_API int dpm_password_get_quality(device_policy_manager_h handle, int *qua RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(quality, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - int ret = password.getQuality(); - if (ret < 0) { + Status status { 0 }; + status = client.methodCall("Password::getQuality"); + if (status.get() < 0) return -1; - } - *quality = (dpm_password_quality_e)ret; + *quality = (dpm_password_quality_e)status.get(); } catch (...) { return -1; } @@ -69,11 +67,12 @@ EXPORT_API int dpm_password_set_minimum_length(device_policy_manager_h handle, i RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.setMinimumLength(value); + Status status { 0 }; + status = client.methodCall("Password::setMinimumLength", value); + return status.get(); } catch (...) { return -1; } @@ -84,16 +83,15 @@ EXPORT_API int dpm_password_get_minimum_length(device_policy_manager_h handle, i RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - int ret = password.getMinimumLength(); - if (ret < 0) { + Status status { 0 }; + status = client.methodCall("Password::getMinimumLength"); + if (status.get() < 0) return -1; - } - *value = ret; + *value = status.get(); } catch (...) { return -1; } @@ -106,11 +104,12 @@ EXPORT_API int dpm_password_set_min_complex_chars(device_policy_manager_h handle RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.setMinComplexChars(value); + Status status { -1 }; + status = client.methodCall("Password::setMinComplexChars", value); + return status.get(); } catch (...) { return -1; } @@ -121,16 +120,15 @@ EXPORT_API int dpm_password_get_min_complex_chars(device_policy_manager_h handle RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - int ret = password.getMinComplexChars(); - if (ret < 0) { + Status status { 0 }; + status = client.methodCall("Password::getMinComplexChars"); + if (status.get() < 0) return -1; - } - *value = ret; + *value = status.get(); } catch (...) { return -1; } @@ -143,11 +141,12 @@ EXPORT_API int dpm_password_set_maximum_failed_attempts_for_wipe(device_policy_m RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.setMaximumFailedForWipe(value); + Status status { -1 }; + status = client.methodCall("Password::setMaximumFailedForWipe", value); + return status.get(); } catch (...) { return -1; } @@ -158,16 +157,15 @@ EXPORT_API int dpm_password_get_maximum_failed_attempts_for_wipe(device_policy_m RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - int ret = password.getMaximumFailedForWipe(); - if (ret < 0) { + Status status { 0 }; + status = client.methodCall("Password::getMaximumFailedForWipe"); + if (status.get() < 0) return -1; - } - *value = ret; + *value = status.get(); } catch (...) { return -1; } @@ -180,11 +178,12 @@ EXPORT_API int dpm_password_set_expires(device_policy_manager_h handle, int valu RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.setExpires(value); + Status status { -1 }; + status = client.methodCall("Password::setExpires", value); + return status.get(); } catch (...) { return -1; } @@ -195,16 +194,15 @@ EXPORT_API int dpm_password_get_expires(device_policy_manager_h handle, int *val RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - int ret = password.getExpires(); - if (ret < 0) { + Status status { 0 }; + status = client.methodCall("Password::getExpires"); + if (status.get() < 0) return -1; - } - *value = ret; + *value = status.get(); } catch (...) { return -1; } @@ -217,11 +215,12 @@ EXPORT_API int dpm_password_set_history(device_policy_manager_h handle, int valu RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.setHistory(value); + Status status { -1 }; + status = client.methodCall("Password::setHistory", value); + return status.get(); } catch (...) { return -1; } @@ -232,16 +231,15 @@ EXPORT_API int dpm_password_get_history(device_policy_manager_h handle, int *val RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - int ret = password.getHistory(); - if (ret < 0) { + Status status { 0 }; + status = client.methodCall("Password::getHistory"); + if (status.get() < 0) return -1; - } - *value = ret; + *value = status.get(); } catch (...) { return -1; } @@ -254,11 +252,12 @@ EXPORT_API int dpm_password_set_pattern(device_policy_manager_h handle, const ch RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(pattern, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.setPattern(pattern); + Status status { -1 }; + status = client.methodCall("Password::setPattern", pattern); + return status.get(); } catch (...) { return -1; } @@ -269,11 +268,12 @@ EXPORT_API int dpm_password_reset(device_policy_manager_h handle, const char *pa RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(passwd, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.reset(passwd); + Status status { -1 }; + status = client.methodCall("Password::reset", passwd); + return status.get(); } catch (...) { return -1; } @@ -283,11 +283,12 @@ EXPORT_API int dpm_password_enforce_change(device_policy_manager_h handle) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.enforceChange(); + Status status { -1 }; + status = client.methodCall("Password::enforceChange"); + return status.get(); } catch (...) { return -1; } @@ -298,11 +299,12 @@ EXPORT_API int dpm_password_set_max_inactivity_time_device_lock(device_policy_ma RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.setMaxInactivityTimeDeviceLock(value); + Status status { -1 }; + status = client.methodCall("Password::setMaxInactivityTimeDeviceLock", value); + return status.get(); } catch (...) { return -1; } @@ -313,16 +315,15 @@ EXPORT_API int dpm_password_get_max_inactivity_time_device_lock(device_policy_ma RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - int ret = password.getMaxInactivityTimeDeviceLock(); - if (ret < 0) { + Status status { 0 }; + status = client.methodCall("Password::getMaxInactivityTimeDeviceLock");; + if (status.get() < 0) return -1; - } - *value = ret; + *value = status.get(); } catch (...) { return -1; } @@ -330,38 +331,38 @@ EXPORT_API int dpm_password_get_max_inactivity_time_device_lock(device_policy_ma return DPM_ERROR_NONE; } -EXPORT_API int dpm_password_set_status(device_policy_manager_h handle, dpm_password_status_e status) +EXPORT_API int dpm_password_set_status(device_policy_manager_h handle, dpm_password_status_e stat) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - RET_ON_FAILURE(status >= DPM_PASSWORD_STATUS_NORMAL && - status <= DPM_PASSWORD_STATUS_PATTERN_CHANGED, + RET_ON_FAILURE(stat >= DPM_PASSWORD_STATUS_NORMAL && + stat <= DPM_PASSWORD_STATUS_PATTERN_CHANGED, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.setStatus(status); + Status status { -1 }; + status = client.methodCall("Password::setStatus", (int)stat); + return status.get(); } catch (...) { return -1; } } -EXPORT_API int dpm_password_get_status(device_policy_manager_h handle, dpm_password_status_e *status) +EXPORT_API int dpm_password_get_status(device_policy_manager_h handle, dpm_password_status_e *stat) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - RET_ON_FAILURE(status, DPM_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(stat, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - int ret = password.getStatus(); - if (ret < 0) { + Status status { 0 }; + status = client.methodCall("Password::getStatus"); + if (status.get() < 0) return -1; - } - *status = (dpm_password_status_e)ret; + *stat = (dpm_password_status_e)status.get(); } catch (...) { return -1; } @@ -373,11 +374,12 @@ EXPORT_API int dpm_password_delete_pattern(device_policy_manager_h handle) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.deletePattern(); + Status status { -1 }; + status = client.methodCall("Password::deletePattern"); + return status.get(); } catch (...) { return -1; } @@ -388,11 +390,12 @@ EXPORT_API int dpm_password_get_pattern(device_policy_manager_h handle, char **p RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(pattern, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *pattern = ::strdup(password.getPattern().c_str()); + Status status { std::string() }; + status = client.methodCall("Password::getPattern"); + *pattern = ::strdup(status.get().c_str()); } catch (...) { return -1; } @@ -405,11 +408,12 @@ EXPORT_API int dpm_password_set_maximum_character_occurrences(device_policy_mana RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.setMaximumCharacterOccurrences(value); + Status status { -1 }; + status = client.methodCall("Password::setMaximumCharacterOccurrences", value); + return status.get(); } catch (...) { return -1; } @@ -420,16 +424,15 @@ EXPORT_API int dpm_password_get_maximum_character_occurrences(device_policy_mana RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - int ret = password.getMaximumCharacterOccurrences(); - if (ret < 0) { + Status status { 0 }; + status = client.methodCall("Password::getMaximumCharacterOccurrences"); + if (status.get() < 0) return -1; - } - *value = ret; + *value = status.get(); } catch (...) { return -1; } @@ -442,11 +445,12 @@ EXPORT_API int dpm_password_set_maximum_numeric_sequence_length(device_policy_ma RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.setMaximumNumericSequenceLength(value); + Status status { -1 }; + status = client.methodCall("Password::setMaximumNumericSequenceLength", value); + return status.get(); } catch (...) { return -1; } @@ -457,16 +461,15 @@ EXPORT_API int dpm_password_get_maximum_numeric_sequence_length(device_policy_ma RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - int ret = password.getMaximumNumericSequenceLength(); - if (ret < 0) { + Status status { 0 }; + status = client.methodCall("Password::getMaximumNumericSequenceLength"); + if (status.get() < 0) return -1; - } - *value = ret; + *value = status.get(); } catch (...) { return -1; } @@ -480,10 +483,13 @@ EXPORT_API dpm_password_iterator_h dpm_password_create_iterator(device_policy_ma { RET_ON_FAILURE(handle, NULL); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); + + Status> status { std::vector() }; + status = client.methodCall>("Password::getForbiddenStrings"); - return reinterpret_cast(new dpm_password_iterator(password.getForbiddenStrings())); + dpm_password_iterator *iter = new dpm_password_iterator(status.get()); + return reinterpret_cast(iter); } EXPORT_API int dpm_password_iterator_next(dpm_password_iterator_h iter, const char **result) @@ -522,14 +528,15 @@ EXPORT_API int dpm_password_set_forbidden_strings(device_policy_manager_h handle RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(strings, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); for (iter = 0; iter < length; iter++) forbiddenStrings.push_back(strings[iter]); try { - return password.setForbiddenStrings(forbiddenStrings); + Status status { -1 }; + status = client.methodCall("Password::setForbiddenStrings", forbiddenStrings); + return status.get(); } catch (...) { return -1; } @@ -539,11 +546,12 @@ EXPORT_API int dpm_password_set_recovery(device_policy_manager_h handle, int ena { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return password.setRecovery(enable); + Status status { -1 }; + status = client.methodCall("Password::setRecovery", enable); + return status.get(); } catch (...) { return -1; } @@ -554,16 +562,15 @@ EXPORT_API int dpm_password_get_recovery(device_policy_manager_h handle, int *en RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - PasswordPolicy password = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - int ret = password.getRecovery(); - if (ret < 0) { + Status status { false }; + status = client.methodCall("Password::getRecovery"); + if (status.get() < 0) return -1; - } - *enable = ret; + *enable = status.get(); } catch (...) { return -1; } diff --git a/libs/policy-client.cpp b/libs/policy-client.cpp new file mode 100644 index 0000000..8c819c3 --- /dev/null +++ b/libs/policy-client.cpp @@ -0,0 +1,103 @@ +/* + * 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 "policy-client.h" + +namespace { + +const std::string SIGNAL_INTERFACE = "DevicePolicyManager::subscribeSignal"; + +const std::string POLICY_MANAGER_ADDRESS = "/tmp/.device-policy-manager.sock"; + +int GetPolicyEnforceMode() +{ + runtime::File policyManagerSocket(POLICY_MANAGER_ADDRESS); + + if (policyManagerSocket.exists()) { + return 1; + } + + return 0; +} + +} // namespace + + +DevicePolicyClient::DevicePolicyClient() noexcept : + maintenanceMode(GetPolicyEnforceMode()) +{ +} + +DevicePolicyClient::~DevicePolicyClient() noexcept +{ + disconnect(); +} + +int DevicePolicyClient::connect(const std::string& address) noexcept +{ + try { + client.reset(new rmi::Client(address)); + if (maintenanceMode) { + client->connect(); + } + } catch (runtime::Exception& e) { + return -1; + } + + return 0; +} + +int DevicePolicyClient::connect() noexcept +{ + return connect(POLICY_MANAGER_ADDRESS); +} + +void DevicePolicyClient::disconnect() noexcept +{ + client.reset(); +} + +int DevicePolicyClient::subscribeSignal(const std::string& name, + const SignalHandler& handler, + void* data) +{ + auto dispatch = [handler, data](const std::string &name, const std::string &object) { + handler(name.c_str(), object.c_str(), data); + }; + + if (!maintenanceMode) { + return 0; + } + + try { + return client->subscribe(SIGNAL_INTERFACE, name, dispatch); + } catch (runtime::Exception& e) { + std::cout << e.what() << std::endl; + return -1; + } +} + +int DevicePolicyClient::unsubscribeSignal(int id) +{ + if (!maintenanceMode) { + return 0; + } + + return client->unsubscribe("", id); +} diff --git a/policy-client.h b/libs/policy-client.h similarity index 63% rename from policy-client.h rename to libs/policy-client.h index 4d5145d..3fa15a3 100644 --- a/policy-client.h +++ b/libs/policy-client.h @@ -24,32 +24,20 @@ #include -typedef std::function PolicyChangeListener; -typedef std::function SignalListener; +typedef std::function SignalHandler; -class DevicePolicyContext { +class DevicePolicyClient { public: - typedef DevicePolicyContext PolicyControlContext; - - DevicePolicyContext() noexcept; - ~DevicePolicyContext() noexcept; + DevicePolicyClient() noexcept; + ~DevicePolicyClient() noexcept; int connect() noexcept; int connect(const std::string& address) noexcept; void disconnect() noexcept; - int subscribePolicyChange(const std::string& name, const PolicyChangeListener& listener, void* data); - int unsubscribePolicyChange(int subscriberId); - - int subscribeSignal(const std::string& name, const SignalListener& listener, void* data); + int subscribeSignal(const std::string& name, const SignalHandler& handler, void* data); int unsubscribeSignal(int subscriberId); - template - Policy createPolicyInterface(Args&&... args) noexcept - { - return Policy(getPolicyControlContext(), std::forward(args)...); - } - template Type methodCall(const std::string& method, Args&&... args) { @@ -62,16 +50,10 @@ public: } private: - PolicyControlContext& getPolicyControlContext() - { - return *this; - } - -private: int maintenanceMode; std::unique_ptr client; }; -DevicePolicyContext& GetDevicePolicyContext(void* handle); +DevicePolicyClient& GetDevicePolicyClient(void* handle); #endif //__POLICY_CLIENT_H__ diff --git a/dpm/restriction.cpp b/libs/restriction.cpp similarity index 57% rename from dpm/restriction.cpp rename to libs/restriction.cpp index 97021a4..662ddff 100644 --- a/dpm/restriction.cpp +++ b/libs/restriction.cpp @@ -14,26 +14,22 @@ * limitations under the License */ -#include "restriction.h" -#include "restriction.hxx" -#include "location.hxx" -#include "bluetooth.hxx" -#include "wifi.hxx" +#include "dpm/restriction.h" #include "debug.h" +#include "status.h" #include "policy-client.h" -using namespace DevicePolicyManager; - EXPORT_API int dpm_restriction_set_camera_state(device_policy_manager_h handle, int allow) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return restriction.setCameraState(allow); + Status status { -1 }; + status = client.methodCall("Media::setCameraState", allow); + return status.get(); } catch (...) { return -1; } @@ -44,11 +40,12 @@ EXPORT_API int dpm_restriction_get_camera_state(device_policy_manager_h handle, RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = restriction.getCameraState(); + Status status { true }; + status = client.methodCall("Media::getCameraState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -60,11 +57,12 @@ EXPORT_API int dpm_restriction_set_microphone_state(device_policy_manager_h hand { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return restriction.setMicrophoneState(allow); + Status status { -1 }; + status = client.methodCall("Media::setMicrophoneState", allow); + return status.get(); } catch (...) { return -1; } @@ -75,11 +73,12 @@ EXPORT_API int dpm_restriction_get_microphone_state(device_policy_manager_h hand RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = restriction.getMicrophoneState(); + Status status { true }; + status = client.methodCall("Media::getMicrophoneState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -91,11 +90,12 @@ EXPORT_API int dpm_restriction_set_location_state(device_policy_manager_h handle { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - LocationPolicy location = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return location.setLocationState(allow); + Status status { -1 }; + status = client.methodCall("Location::setState", allow); + return status.get(); } catch (...) { return -1; } @@ -106,11 +106,12 @@ EXPORT_API int dpm_restriction_get_location_state(device_policy_manager_h handle RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - LocationPolicy location = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = location.getLocationState(); + Status status { true }; + status = client.methodCall("Location::getState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -122,11 +123,12 @@ EXPORT_API int dpm_restriction_set_usb_debugging_state(device_policy_manager_h h { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return restriction.setUsbDebuggingState(allow); + Status status { -1 }; + status = client.methodCall("Usb::setDebuggingState", allow); + return status.get(); } catch (...) { return -1; } @@ -137,11 +139,12 @@ EXPORT_API int dpm_restriction_get_usb_debugging_state(device_policy_manager_h h RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = restriction.getUsbDebuggingState(); + Status status { true }; + status = client.methodCall("Usb::getDebuggingState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -153,11 +156,12 @@ EXPORT_API int dpm_restriction_set_usb_tethering_state(device_policy_manager_h h { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return restriction.setUsbTetheringState(allow); + Status status { -1 }; + status = client.methodCall("Usb::setTetheringState", allow); + return status.get(); } catch (...) { return -1; } @@ -168,11 +172,12 @@ EXPORT_API int dpm_restriction_get_usb_tethering_state(device_policy_manager_h h RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = restriction.getUsbTetheringState(); + Status status { true }; + status = client.methodCall("Usb::getTetheringState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -184,11 +189,12 @@ EXPORT_API int dpm_restriction_set_external_storage_state(device_policy_manager_ { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return restriction.setExternalStorageState(allow); + Status status { -1 }; + status = client.methodCall("Storage::setExternalStorageState", allow); + return status.get(); } catch (...) { return -1; } @@ -199,11 +205,12 @@ EXPORT_API int dpm_restriction_get_external_storage_state(device_policy_manager_ RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = restriction.getExternalStorageState(); + Status status { true }; + status = client.methodCall("Storage::getExternalStorageState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -215,11 +222,12 @@ EXPORT_API int dpm_restriction_set_clipboard_state(device_policy_manager_h handl { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return restriction.setClipboardState(allow); + Status status { -1 }; + status = client.methodCall("Media::setClipboardState", allow); + return status.get(); } catch (...) { return -1; } @@ -230,11 +238,12 @@ EXPORT_API int dpm_restriction_get_clipboard_state(device_policy_manager_h handl RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = restriction.getClipboardState(); + Status status { true }; + status = client.methodCall("Media::getClipboardState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -246,11 +255,12 @@ EXPORT_API int dpm_restriction_set_wifi_state(device_policy_manager_h handle, in { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - WifiPolicy wifi = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return wifi.setState(allow); + Status status { -1 }; + status = client.methodCall("Wifi::setState", allow); + return status.get(); } catch (...) { return -1; } @@ -261,11 +271,12 @@ EXPORT_API int dpm_restriction_get_wifi_state(device_policy_manager_h handle, in RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - WifiPolicy wifi = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = wifi.getState(); + Status status { true }; + status = client.methodCall("Wifi::getState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -277,11 +288,12 @@ EXPORT_API int dpm_restriction_set_wifi_hotspot_state(device_policy_manager_h ha { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - WifiPolicy wifi = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return wifi.setHotspotState(allow); + Status status { -1 }; + status = client.methodCall("Wifi::setHotspotState", allow); + return status.get(); } catch (...) { return -1; } @@ -292,11 +304,12 @@ EXPORT_API int dpm_restriction_get_wifi_hotspot_state(device_policy_manager_h ha RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - WifiPolicy wifi = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = wifi.getHotspotState(); + Status status { true }; + status = client.methodCall("Wifi::getHotspotState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -308,11 +321,12 @@ EXPORT_API int dpm_restriction_set_bluetooth_tethering_state(device_policy_manag { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return bluetooth.setTetheringState(allow); + Status status { -1 }; + status = client.methodCall("Bluetooth::setTetheringState", allow); + return status.get(); } catch (...) { return -1; } @@ -323,11 +337,12 @@ EXPORT_API int dpm_restriction_get_bluetooth_tethering_state(device_policy_manag RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = bluetooth.getTetheringState(); + Status status { true }; + status = client.methodCall("Bluetooth::getTetheringState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -339,11 +354,12 @@ EXPORT_API int dpm_restriction_set_bluetooth_mode_change_state(device_policy_man { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return bluetooth.setModeChangeState(allow); + Status status { -1 }; + status = client.methodCall("Bluetooth::setModeChangeState", allow); + return status.get(); } catch (...) { return -1; } @@ -354,11 +370,12 @@ EXPORT_API int dpm_restriction_get_bluetooth_mode_change_state(device_policy_man RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = bluetooth.getModeChangeState(); + Status status { true }; + status = client.methodCall("Bluetooth::getModeChangeState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -370,11 +387,12 @@ EXPORT_API int dpm_restriction_set_bluetooth_desktop_connectivity_state(device_p { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return bluetooth.setDesktopConnectivityState(allow); + Status status { -1 }; + status = client.methodCall("Bluetooth::setDesktopConnectivityState", allow); + return status.get(); } catch (...) { return -1; } @@ -385,11 +403,12 @@ EXPORT_API int dpm_restriction_get_bluetooth_desktop_connectivity_state(device_p RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = bluetooth.getDesktopConnectivityState(); + Status status { true }; + status = client.methodCall("Bluetooth::getDesktopConnectivityState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -401,11 +420,12 @@ EXPORT_API int dpm_restriction_set_bluetooth_pairing_state(device_policy_manager { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return bluetooth.setPairingState(allow); + Status status { -1 }; + status = client.methodCall("Bluetooth::setPairingState", allow); + return status.get(); } catch (...) { return -1; } @@ -416,11 +436,12 @@ EXPORT_API int dpm_restriction_get_bluetooth_pairing_state(device_policy_manager RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - BluetoothPolicy bluetooth = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = bluetooth.getPairingState(); + Status status { true }; + status = client.methodCall("Bluetooth::getPairingState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -432,11 +453,12 @@ EXPORT_API int dpm_restriction_set_popimap_email_state(device_policy_manager_h h { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return restriction.setPopImapEmailState(allow); + Status status { -1 }; + status = client.methodCall("EMail::setPopImapState", allow); + return status.get(); } catch (...) { return -1; } @@ -447,11 +469,12 @@ EXPORT_API int dpm_restriction_get_popimap_email_state(device_policy_manager_h h RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = restriction.getPopImapEmailState(); + Status status { true }; + status = client.methodCall("EMail::getPopImapState"); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -463,11 +486,12 @@ EXPORT_API int dpm_restriction_set_messaging_state(device_policy_manager_h handl { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return restriction.setMessagingState(sim_id, allow); + Status status { -1 }; + status = client.methodCall("Telephony::setMessagingState", sim_id, allow); + return status.get(); } catch (...) { return -1; } @@ -478,11 +502,12 @@ EXPORT_API int dpm_restriction_get_messaging_state(device_policy_manager_h handl RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = restriction.getMessagingState(sim_id); + Status status { true }; + status = client.methodCall("Telephony::getMessagingState", sim_id); + *is_allowed = status.get(); } catch (...) { return -1; } @@ -494,11 +519,12 @@ EXPORT_API int dpm_restriction_set_browser_state(device_policy_manager_h handle, { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return restriction.setBrowserState(allow); + Status status { -1 }; + status = client.methodCall("Browser::setState", allow); + return status.get(); } catch (...) { return -1; } @@ -509,11 +535,12 @@ EXPORT_API int dpm_restriction_get_browser_state(device_policy_manager_h handle, RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - RestrictionPolicy restriction = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_allowed = restriction.getBrowserState(); + Status status { true }; + status = client.methodCall("Browser::getState"); + *is_allowed = status.get(); } catch (...) { return -1; } diff --git a/dpm/security.cpp b/libs/security.cpp similarity index 64% rename from dpm/security.cpp rename to libs/security.cpp index 328c4c7..78b77f3 100644 --- a/dpm/security.cpp +++ b/libs/security.cpp @@ -14,23 +14,21 @@ * limitations under the License */ -#include "security.h" -#include "security.hxx" -#include "storage.hxx" +#include "dpm/security.h" #include "debug.h" +#include "status.h" #include "policy-client.h" -using namespace DevicePolicyManager; - EXPORT_API int dpm_security_lockout_screen(device_policy_manager_h handle) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &context = GetDevicePolicyContext(handle); - SecurityPolicy security = context.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return security.lockoutScreen(); + Status status { -1 }; + status = client.methodCall("Security::lockoutScreen"); + return status.get(); } catch (...) { return -1; } @@ -40,10 +38,11 @@ EXPORT_API int dpm_security_set_internal_storage_encryption(device_policy_manage { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &context = GetDevicePolicyContext(handle); - SecurityPolicy security = context.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return security.setInternalStorageEncryption(encrypt); + Status status { -1 }; + status = client.methodCall("Security::setInternalStorageEncryption", encrypt); + return status.get(); } catch (...) { return -1; } @@ -54,10 +53,11 @@ EXPORT_API int dpm_security_is_internal_storage_encrypted(device_policy_manager_ RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_encrypted, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &context = GetDevicePolicyContext(handle); - SecurityPolicy security = context.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_encrypted = security.isInternalStorageEncrypted(); + Status status { false }; + status = client.methodCall("Security::isInternalStorageEncrypted"); + *is_encrypted = status.get(); } catch (...) { return -1; } @@ -69,10 +69,11 @@ EXPORT_API int dpm_security_set_external_storage_encryption(device_policy_manage { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &context = GetDevicePolicyContext(handle); - SecurityPolicy security = context.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return security.setExternalStorageEncryption(encrypt); + Status status { -1 }; + status = client.methodCall("Security::setExternalStorageEncryption", encrypt); + return status.get(); } catch (...) { return -1; } @@ -83,10 +84,11 @@ EXPORT_API int dpm_security_is_external_storage_encrypted(device_policy_manager_ RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_encrypted, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &context = GetDevicePolicyContext(handle); - SecurityPolicy security = context.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *is_encrypted = security.isExternalStorageEncrypted(); + Status status { false }; + status = client.methodCall("Security::isExternalStorageEncrypted"); + *is_encrypted = status.get(); } catch (...) { return -1; } @@ -101,10 +103,11 @@ EXPORT_API int dpm_security_wipe_data(device_policy_manager_h handle, dpm_securi RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(mask, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - StoragePolicy storage = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return storage.wipeData(type); + Status status { -1 }; + status = client.methodCall("Security::wipeData", (int)type); + return status.get(); } catch (...) { return -1; } diff --git a/status.h b/libs/status.h similarity index 100% rename from status.h rename to libs/status.h diff --git a/dpm/storage.cpp b/libs/storage.cpp similarity index 73% rename from dpm/storage.cpp rename to libs/storage.cpp index ca828af..60398bc 100644 --- a/dpm/storage.cpp +++ b/libs/storage.cpp @@ -14,20 +14,18 @@ * limitations under the License */ -#include "storage.h" -#include "storage.hxx" +#include "dpm/storage.h" #include "debug.h" +#include "status.h" #include "policy-client.h" -using namespace DevicePolicyManager; - -dpm_storage_policy_h dpm_context_acquire_storage_policy(dpm_context_h handle) +dpm_storage_policy_h dpm_client_acquire_storage_policy(dpm_client_h handle) { return handle; } -int dpm_context_release_storage_policy(dpm_storage_policy_h handle) +int dpm_client_release_storage_policy(dpm_storage_policy_h handle) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); return DPM_ERROR_NONE; @@ -37,8 +35,7 @@ int dpm_storage_wipe_data(dpm_storage_policy_h handle, const dpm_wipe_type_e typ { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - StoragePolicy storage = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { return storage.wipeData(type); } catch (...) { diff --git a/dpm/wifi.cpp b/libs/wifi.cpp similarity index 64% rename from dpm/wifi.cpp rename to libs/wifi.cpp index bdcf094..ae056c8 100644 --- a/dpm/wifi.cpp +++ b/libs/wifi.cpp @@ -14,23 +14,22 @@ * limitations under the License */ -#include "wifi.h" -#include "wifi.hxx" +#include "dpm/wifi.h" #include "debug.h" +#include "status.h" #include "policy-client.h" -using namespace DevicePolicyManager; - EXPORT_API int dpm_wifi_set_profile_change_restriction(device_policy_manager_h handle, int enable) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - WifiPolicy wifi = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return wifi.setProfileChangeRestriction(enable); + Status status { -1 }; + status = client.methodCall("Wifi::setProfileChangeRestriction", enable); + return status.get(); } catch (...) { return -1; } @@ -41,11 +40,12 @@ EXPORT_API int dpm_wifi_is_profile_change_restricted(device_policy_manager_h han RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - WifiPolicy wifi = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *enable = wifi.isProfileChangeRestricted(); + Status status { false }; + status = client.methodCall("Wifi::isProfileChangeRestricted"); + *enable = status.get(); } catch (...) { return -1; } @@ -57,11 +57,12 @@ EXPORT_API int dpm_wifi_set_network_access_restriction(device_policy_manager_h h { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - WifiPolicy wifi = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return wifi.setNetworkAccessRestriction(enable); + Status status { -1 }; + status = client.methodCall("Wifi::setNetworkAccessRestriction", enable); + return status.get(); } catch (...) { return -1; } @@ -72,11 +73,12 @@ EXPORT_API int dpm_wifi_is_network_access_restricted(device_policy_manager_h han RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - WifiPolicy wifi = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - *enable = wifi.isNetworkAccessRestricted(); + Status status { false }; + status = client.methodCall("Wifi::isNetworkAccessRestricted"); + *enable = status.get(); } catch (...) { return -1; } @@ -89,11 +91,12 @@ EXPORT_API int dpm_wifi_add_ssid_to_blocklist(device_policy_manager_h handle, co RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(ssid, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - WifiPolicy wifi = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return wifi.addSsidToBlocklist(ssid); + Status status { -1 }; + status = client.methodCall("Wifi::addSsidToBlocklist", ssid); + return status.get(); } catch (...) { return -1; } @@ -104,11 +107,12 @@ EXPORT_API int dpm_wifi_remove_ssid_from_blocklist(device_policy_manager_h handl RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(ssid, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - WifiPolicy wifi = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return wifi.removeSsidFromBlocklist(ssid); + Status status { -1 }; + status = client.methodCall("Wifi::removeSsidFromBlocklist", ssid); + return status.get(); } catch (...) { return -1; } diff --git a/dpm/zone.cpp b/libs/zone.cpp similarity index 71% rename from dpm/zone.cpp rename to libs/zone.cpp index 9e51c67..ac99b4d 100755 --- a/dpm/zone.cpp +++ b/libs/zone.cpp @@ -14,26 +14,25 @@ * limitations under the License */ -#include "zone.h" -#include "krate.hxx" +#include "dpm/zone.h" #include "array.h" #include "debug.h" +#include "status.h" #include "policy-client.h" -using namespace DevicePolicyManager; - EXPORT_API int dpm_zone_create(device_policy_manager_h handle, const char* name, const char* pkgname) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(name, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(pkgname, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - KratePolicy krate = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return krate.createKrate(name, pkgname); + Status status { -1 }; + status = client.methodCall("Zone::create", name, pkgname); + return status.get(); } catch (...) { return -1; } @@ -44,11 +43,12 @@ EXPORT_API int dpm_zone_destroy(device_policy_manager_h handle, const char* name RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(name, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - KratePolicy krate = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - return krate.removeKrate(name); + Status status { -1 }; + status = client.methodCall("Zone::remove", name); + return status.get(); } catch (...) { return -1; } @@ -60,16 +60,15 @@ EXPORT_API int dpm_zone_get_state(device_policy_manager_h handle, const char* na RET_ON_FAILURE(name, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - KratePolicy krate = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - int result = krate.getKrateState(name); - if (result == 0) { + Status status { 0 }; + status = client.methodCall("Zone::getState", name); + if (status.get() == 0) return DPM_ERROR_NO_DATA; - } - *state = (dpm_zone_state_e)result; + *state = (dpm_zone_state_e)status.get(); } catch (...) { return -1; } @@ -86,12 +85,12 @@ EXPORT_API int dpm_zone_foreach_name(device_policy_manager_h handle, dpm_zone_st RET_ON_FAILURE(callback, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(mask, DPM_ERROR_INVALID_PARAMETER); - DevicePolicyContext &client = GetDevicePolicyContext(handle); - KratePolicy krate = client.createPolicyInterface(); + DevicePolicyClient &client = GetDevicePolicyClient(handle); try { - std::vector list = krate.getKrateList(state); - for (const std::string& name : list) { + Status> status { std::vector() }; + status = client.methodCall>("Zone::enumerate", (int)state); + for (const std::string& name : status.get()) { if (!callback(name.c_str(), user_data)) break; } diff --git a/location.cpp b/location.cpp deleted file mode 100644 index 5a5bcb6..0000000 --- a/location.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2016 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 "status.h" -#include "location.hxx" - -namespace DevicePolicyManager { - -struct LocationPolicy::Private { - Private(PolicyControlContext& ctxt) : context(ctxt) {} - PolicyControlContext& context; -}; - -LocationPolicy::LocationPolicy(LocationPolicy&& rhs) = default; -LocationPolicy& LocationPolicy::operator=(LocationPolicy&& rhs) = default; - -LocationPolicy::LocationPolicy(const LocationPolicy& rhs) -{ - if (rhs.pimpl) { - pimpl.reset(new Private(*rhs.pimpl)); - } -} - -LocationPolicy& LocationPolicy::operator=(const LocationPolicy& rhs) -{ - if (!rhs.pimpl) { - pimpl.reset(); - } else { - pimpl.reset(new Private(*rhs.pimpl)); - } - - return *this; -} - -LocationPolicy::LocationPolicy(PolicyControlContext& ctxt) : - pimpl(new Private(ctxt)) -{ -} - -LocationPolicy::~LocationPolicy() -{ -} - -int LocationPolicy::setLocationState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("LocationPolicy::setLocationState", enable); - - return status.get(); -} - -bool LocationPolicy::getLocationState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("LocationPolicy::getLocationState"); - - return status.get(); -} - -} //namespace DevicePolicyManager diff --git a/password.cpp b/password.cpp deleted file mode 100644 index 8724c47..0000000 --- a/password.cpp +++ /dev/null @@ -1,375 +0,0 @@ -/* - * 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 "status.h" -#include "password.hxx" - -namespace DevicePolicyManager { - -struct PasswordPolicy::Private { - Private(PolicyControlContext& ctxt) : context(ctxt) {} - PolicyControlContext& context; -}; - -PasswordPolicy::PasswordPolicy(PasswordPolicy&& rhs) = default; -PasswordPolicy& PasswordPolicy::operator=(PasswordPolicy&& rhs) = default; - -PasswordPolicy::PasswordPolicy(const PasswordPolicy& rhs) -{ - if (rhs.pimpl) { - pimpl.reset(new Private(*rhs.pimpl)); - } -} - -PasswordPolicy& PasswordPolicy::operator=(const PasswordPolicy& rhs) -{ - if (!rhs.pimpl) { - pimpl.reset(); - } else { - pimpl.reset(new Private(*rhs.pimpl)); - } - - return *this; -} - -PasswordPolicy::PasswordPolicy(PolicyControlContext &ctxt) : - pimpl(new Private(ctxt)) -{ -} - -PasswordPolicy::~PasswordPolicy() -{ -} - -int PasswordPolicy::setQuality(const int quality) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::setQuality", quality); - - return status.get(); -} - -int PasswordPolicy::getQuality() -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("PasswordPolicy::getQuality"); - - return status.get(); -} - -int PasswordPolicy::setMinimumLength(int value) -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("PasswordPolicy::setMinimumLength", value); - - return status.get(); -} - -int PasswordPolicy::getMinimumLength() -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("PasswordPolicy::getMinimumLength"); - - return status.get(); -} - -int PasswordPolicy::setMinComplexChars(int value) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::setMinComplexChars", value); - - return status.get(); -} - -int PasswordPolicy::getMinComplexChars() -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("PasswordPolicy::getMinComplexChars"); - - return status.get(); -} - -int PasswordPolicy::setMaximumFailedForWipe(int value) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::setMaximumFailedForWipe", value); - - return status.get(); -} - -int PasswordPolicy::getMaximumFailedForWipe() -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("PasswordPolicy::getMaximumFailedForWipe"); - - return status.get(); -} - -int PasswordPolicy::setExpires(int value) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::setExpires", value); - - return status.get(); -} - -int PasswordPolicy::getExpires() -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("PasswordPolicy::getExpires"); - - return status.get(); -} - -int PasswordPolicy::setHistory(int value) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::setHistory", value); - - return status.get(); -} - -int PasswordPolicy::getHistory() -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("PasswordPolicy::getHistory"); - - return status.get(); -} - -int PasswordPolicy::setPattern(const std::string &pattern) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::setPattern", pattern); - - return status.get(); -} - -int PasswordPolicy::reset(const std::string &passwd) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::reset", passwd); - - return status.get(); -} - -int PasswordPolicy::enforceChange() -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::enforceChange"); - - return status.get(); -} - -int PasswordPolicy::setMaxInactivityTimeDeviceLock(int value) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::setMaxInactivityTimeDeviceLock", value); - - return status.get(); -} - -int PasswordPolicy::getMaxInactivityTimeDeviceLock() -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("PasswordPolicy::getMaxInactivityTimeDeviceLock");; - - return status.get(); -} - -int PasswordPolicy::setStatus(int status) -{ - PolicyControlContext& context = pimpl->context; - - Status rstatus { -1 }; - - rstatus = context.methodCall("PasswordPolicy::setStatus", status); - - return rstatus.get(); -} - -int PasswordPolicy::getStatus() -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("PasswordPolicy::getStatus"); - - return status.get(); -} - -int PasswordPolicy::deletePattern() -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::deletePattern"); - - return status.get(); -} - -std::string PasswordPolicy::getPattern() -{ - PolicyControlContext& context = pimpl->context; - - Status status { std::string() }; - - status = context.methodCall("PasswordPolicy::getPattern"); - - return status.get(); -} - -int PasswordPolicy::setMaximumCharacterOccurrences(int value) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::setMaximumCharacterOccurrences", value); - - return status.get(); -} - -int PasswordPolicy::getMaximumCharacterOccurrences() -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("PasswordPolicy::getMaximumCharacterOccurrences"); - - return status.get(); -} - -int PasswordPolicy::setMaximumNumericSequenceLength(int value) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::setMaximumNumericSequenceLength", value); - - return status.get(); -} - -int PasswordPolicy::getMaximumNumericSequenceLength() -{ - PolicyControlContext& context = pimpl->context; - - Status status { 0 }; - - status = context.methodCall("PasswordPolicy::getMaximumNumericSequenceLength"); - - return status.get(); -} - -int PasswordPolicy::setForbiddenStrings(const std::vector &forbiddenStrings) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::setForbiddenStrings", forbiddenStrings); - - return status.get(); -} - -std::vector PasswordPolicy::getForbiddenStrings() -{ - PolicyControlContext& context = pimpl->context; - - Status> status { std::vector() }; - - status = context.methodCall>("PasswordPolicy::getForbiddenStrings"); - - return status.get(); -} - -int PasswordPolicy::setRecovery(int enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("PasswordPolicy::setRecovery", enable); - - return status.get(); -} - -int PasswordPolicy::getRecovery() -{ - PolicyControlContext& context = pimpl->context; - - Status status { false }; - - status = context.methodCall("PasswordPolicy::getRecovery"); - - return status.get(); -} -} /* namespace DevicePolicyManager */ diff --git a/policy-client.cpp b/policy-client.cpp deleted file mode 100644 index ebcc32a..0000000 --- a/policy-client.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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 "policy-client.h" - -namespace { - -const std::string SUBSCRIBER_REGISTER = "Server::registerNotificationSubscriber"; -const std::string SUBSCRIBER_UNREGISTER = "Server::unregisterNotificationSubscriber"; - -const std::string POLICY_MANAGER_ADDRESS = "/tmp/.device-policy-manager.sock"; - -int GetPolicyEnforceMode() -{ - runtime::File policyManagerSocket(POLICY_MANAGER_ADDRESS); - - if (policyManagerSocket.exists()) { - return 1; - } - - return 0; -} - -} // namespace - - -DevicePolicyContext::DevicePolicyContext() noexcept : - maintenanceMode(GetPolicyEnforceMode()) -{ -} - -DevicePolicyContext::~DevicePolicyContext() noexcept -{ - disconnect(); -} - -int DevicePolicyContext::connect(const std::string& address) noexcept -{ - try { - client.reset(new rmi::Client(address)); - if (maintenanceMode) { - client->connect(); - } - } catch (runtime::Exception& e) { - return -1; - } - - return 0; -} - -int DevicePolicyContext::connect() noexcept -{ - return connect(POLICY_MANAGER_ADDRESS); -} - -void DevicePolicyContext::disconnect() noexcept -{ - client.reset(); -} - -int DevicePolicyContext::subscribePolicyChange(const std::string& name, - const PolicyChangeListener& listener, - void* data) -{ - auto listenerDispatcher = [listener, data](const std::string& policy, std::string &state) { - listener(policy.c_str(), state.c_str(), data); - }; - - if (!maintenanceMode) { - return 0; - } - - try { - return client->subscribe(SUBSCRIBER_REGISTER, - name, listenerDispatcher); - } catch (runtime::Exception& e) { - std::cout << e.what() << std::endl; - return -1; - } -} - -int DevicePolicyContext::unsubscribePolicyChange(int subscriberId) -{ - if (!maintenanceMode) { - return 0; - } - - return client->unsubscribe(SUBSCRIBER_UNREGISTER, subscriberId); -} - -int DevicePolicyContext::subscribeSignal(const std::string& name, - const SignalListener& listener, - void* data) -{ - auto listenerDispatcher = [listener, data](std::string &name, std::string &from, std::string &object) { - listener(from.c_str(), object.c_str(), data); - }; - - if (!maintenanceMode) { - return 0; - } - - try { - return client->subscribe(SUBSCRIBER_REGISTER, - name, listenerDispatcher); - } catch (runtime::Exception& e) { - std::cout << e.what() << std::endl; - return -1; - } -} - -int DevicePolicyContext::unsubscribeSignal(int subscriberId) -{ - if (!maintenanceMode) { - return 0; - } - - return client->unsubscribe(SUBSCRIBER_UNREGISTER, subscriberId); -} diff --git a/policy-context.hxx b/policy-context.hxx deleted file mode 100644 index f5d872f..0000000 --- a/policy-context.hxx +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 __DEVICE_POLICY_CONTEXT__ -#define __DEVICE_POLICY_CONTEXT__ - -#include - -#include "policy-client.h" - -using PolicyControlContext = ::DevicePolicyContext::PolicyControlContext; - -#endif //!__DEVICE_POLICY_CONTEXT__ diff --git a/policy/administration.hxx b/policy/administration.hxx deleted file mode 100644 index 9cc1fbb..0000000 --- a/policy/administration.hxx +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 __ADMINISTRATION_POLICY__ -#define __ADMINISTRATION_POLICY__ - -#include "policy-context.hxx" - -namespace DevicePolicyManager { - -class AdministrationPolicy { -public: - AdministrationPolicy(PolicyControlContext& ctxt); - ~AdministrationPolicy(); - - AdministrationPolicy(const AdministrationPolicy& rhs); - AdministrationPolicy(AdministrationPolicy&& rhs); - - AdministrationPolicy& operator=(const AdministrationPolicy& rhs); - AdministrationPolicy& operator=(AdministrationPolicy&& rhs); - - int registerPolicyClient(const std::string& name, uid_t uid); - int deregisterPolicyClient(const std::string& name, uid_t uid); - -private: - struct Private; - std::unique_ptr pimpl; -}; - -} // namespace DevicePolicyManager -#endif // __ADMINISTRATION_POLICY__ diff --git a/policy/application.hxx b/policy/application.hxx deleted file mode 100644 index c141441..0000000 --- a/policy/application.hxx +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 "policy-context.hxx" - -namespace DevicePolicyManager { - -class ApplicationPolicy { -public: - enum PrivilegeType { - PRIVILEGE_TYPE_WRT = 0, - PRIVILEGE_TYPE_CORE = 1 - }; - - enum RestrictionMode { - RESTRICTION_MODE_ALL = 0x0F, - RESTRICTION_MODE_INSTALL = 0x01, - RESTRICTION_MODE_UNINSTALL = 0x02, - RESTRICTION_MODE_REINSTALL = 0x04, - RESTRICTION_MODE_MVOE = 0x08 - }; - - ApplicationPolicy(PolicyControlContext& ctxt); - ~ApplicationPolicy(); - - ApplicationPolicy(const ApplicationPolicy& rhs); - ApplicationPolicy(ApplicationPolicy&& rhs); - - ApplicationPolicy& operator=(const ApplicationPolicy& rhs); - ApplicationPolicy& operator=(ApplicationPolicy&& rhs); - - - int installPackage(const std::string& pkgpath); - int uninstallPackage(const std::string& pkgid); - - int setModeRestriction(int mode); - int unsetModeRestriction(int mode); - int getModeRestriction(); - - int addPrivilegeToBlacklist(int type, const std::string& privilege); - int removePrivilegeFromBlacklist(int type, const std::string& privilege); - int checkPrivilegeIsBlacklisted(int type, const std::string& privilege); - -private: - struct Private; - std::unique_ptr pimpl; -}; - -} // namespace DevicePolicyManager -#endif // __APPLICATION_POLICY__ diff --git a/policy/bluetooth.hxx b/policy/bluetooth.hxx deleted file mode 100644 index fd2e3bb..0000000 --- a/policy/bluetooth.hxx +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2016 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 __BLUETOOTH_POLICY__ -#define __BLUETOOTH_POLICY__ - -#include "policy-context.hxx" - -namespace DevicePolicyManager { - -/** - * This class provides APIs to control bluetooth functionalities - * such as bluetooth device or uuid restriction - */ - -class BluetoothPolicy { -public: - BluetoothPolicy(PolicyControlContext& ctxt); - ~BluetoothPolicy(); - - BluetoothPolicy(const BluetoothPolicy& rhs); - BluetoothPolicy(BluetoothPolicy&& rhs); - - BluetoothPolicy& operator=(const BluetoothPolicy& rhs); - BluetoothPolicy& operator=(BluetoothPolicy&& rhs); - - // for restriction CPIs - int setModeChangeState(bool enable); - bool getModeChangeState(); - int setDesktopConnectivityState(bool enable); - bool getDesktopConnectivityState(); - int setTetheringState(bool enable); - bool getTetheringState(); - int setPairingState(bool enable); - bool getPairingState(); - - // for bluetooth CAPIs - int addDeviceToBlacklist(const std::string& mac); - int removeDeviceFromBlacklist(const std::string& mac); - int setDeviceRestriction(bool enable); - bool isDeviceRestricted(); - - int addUuidToBlacklist(const std::string& uuid); - int removeUuidFromBlacklist(const std::string& uuid); - int setUuidRestriction(bool enable); - bool isUuidRestricted(); - -private: - struct Private; - std::unique_ptr pimpl; -}; - -} // namespace DevicePolicyManager -#endif // __BLUETOOTH_POLICY__ diff --git a/policy/krate.hxx b/policy/krate.hxx deleted file mode 100644 index a638c54..0000000 --- a/policy/krate.hxx +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 __KRATE_POLICY__ -#define __KRATE_POLICY__ - -#include "policy-context.hxx" - -namespace DevicePolicyManager { - -class KratePolicy { -public: - enum State { - Locked = 0x01, - Running = 0x02, - }; - - KratePolicy(PolicyControlContext& ctxt); - ~KratePolicy(); - - KratePolicy(const KratePolicy& rhs); - KratePolicy(KratePolicy&& rhs); - - KratePolicy& operator=(const KratePolicy& rhs); - KratePolicy& operator=(KratePolicy&& rhs); - - int createKrate(const std::string& name, const std::string& setupWizardAppid); - int removeKrate(const std::string& name); - - int getKrateState(const std::string& name); - - std::vector getKrateList(int state); - -private: - struct Private; - std::unique_ptr pimpl; -}; - -} // namespace DevicePolicyManager -#endif // __KRATE_POLICY__ diff --git a/policy/location.hxx b/policy/location.hxx deleted file mode 100644 index 4f071c3..0000000 --- a/policy/location.hxx +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2016 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 __LOCATION_POLICY__ -#define __LOCATION_POLICY__ - -#include "policy-context.hxx" - -namespace DevicePolicyManager { - -class LocationPolicy { -public: - LocationPolicy(PolicyControlContext& ctxt); - ~LocationPolicy(); - - LocationPolicy(const LocationPolicy& rhs); - LocationPolicy(LocationPolicy&& rhs); - - LocationPolicy& operator=(const LocationPolicy& rhs); - LocationPolicy& operator=(LocationPolicy&& rhs); - - int setLocationState(bool enable); - bool getLocationState(); - -private: - struct Private; - std::unique_ptr pimpl; -}; - -} // namespace DevicePolicyManager - -#endif /* __LOCATION_POLICY__ */ diff --git a/policy/password.hxx b/policy/password.hxx deleted file mode 100644 index f35d323..0000000 --- a/policy/password.hxx +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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 __PASSWORD_POLICY__ -#define __PASSWORD_POLICY__ - -#include "policy-context.hxx" - -namespace DevicePolicyManager { - -class PasswordPolicy { -public: - typedef enum { - DPM_PASSWORD_QUALITY_UNSPECIFIED = 0x00, /**< No requirements for password. */ - DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD = 0x01, /**< Eas requirement for simple password */ - DPM_PASSWORD_QUALITY_SOMETHING = 0x10, /**< Some kind password is required, but doesn't care what it is */ - DPM_PASSWORD_QUALITY_NUMERIC = 0x20, /**< Containing at least numeric characters */ - DPM_PASSWORD_QUALITY_ALPHABETIC = 0x40, /**< Containing at least alphabetic (or other symbol) characters */ - DPM_PASSWORD_QUALITY_ALPHANUMERIC = 0x80, /**< Containing at least numeric and alphabetic characters */ - } PasswordPolicyQuality; - - typedef enum { - DPM_PASSWORD_STATUS_NORMAL, /**< Password normal status */ - DPM_PASSWORD_STATUS_CHANGED, /**< Password successfully changed */ - DPM_PASSWORD_STATUS_NOT_CHANGED, /**< Password not changed */ - DPM_PASSWORD_STATUS_CHANGE_REQUIRED , /**< Password change required */ - DPM_PASSWORD_STATUS_MAX_ATTEMPTS_EXCEEDED, /**< Password Max Attempts Exceeded*/ - - DPM_PASSWORD_STATUS_EXPIRED, /**< Password expired */ - DPM_PASSWORD_STATUS_RECOVERY_PASSWORD_FAILED, /**< Device unlock failed by Password Recovery */ - DPM_PASSWORD_STATUS_RECOVERY_PASSWORD_SUCCEEDED,/**< Device unlock succeeded by Password Recovery */ - - DPM_PASSWORD_STATUS_QUALITY_CHANGED, /**< Password quality successfully changed */ - DPM_PASSWORD_STATUS_MIN_LENGTH_CHANGED, /**< Password min_length successfully changed */ - DPM_PASSWORD_STATUS_COMPLEX_CHAR_CHANGED, /**< Password complex_char successfully changed */ - DPM_PASSWORD_STATUS_PATTERN_CHANGED, /**< Password pattern successfully changed */ - DPM_PASSWORD_STATUS_MAX - } PasswordPolicyStatus; - - PasswordPolicy(PolicyControlContext &ctxt); - ~PasswordPolicy(); - - PasswordPolicy(const PasswordPolicy& rhs); - PasswordPolicy(PasswordPolicy&& rhs); - - PasswordPolicy& operator=(const PasswordPolicy& rhs); - PasswordPolicy& operator=(PasswordPolicy&& rhs); - - int setQuality(int quality); - int getQuality(); - int setMinimumLength(int value); - int getMinimumLength(); - int setMinComplexChars(int value); - int getMinComplexChars(); - int setMaximumFailedForWipe(int value); - int getMaximumFailedForWipe(); - int setExpires(int value); - int getExpires(); - int setHistory(int value); - int getHistory(); - int setPattern(const std::string &pattern); - int reset(const std::string &passwd); - int enforceChange(); - int setMaxInactivityTimeDeviceLock(int value); - int getMaxInactivityTimeDeviceLock(); - int setStatus(int status); - int getStatus(); - int deletePattern(); - std::string getPattern(); - int setMaximumCharacterOccurrences(int value); - int getMaximumCharacterOccurrences(); - int setMaximumNumericSequenceLength(int value); - int getMaximumNumericSequenceLength(); - int setForbiddenStrings(const std::vector &forbiddenStrings); - std::vector getForbiddenStrings(); - int setRecovery(int enable); - int getRecovery(); - -private: - struct Private; - std::unique_ptr pimpl; -}; - -} /* namespace DevicePolicyManager */ -#endif /* __PASSWORD_POLICY__ */ diff --git a/policy/restriction.hxx b/policy/restriction.hxx deleted file mode 100644 index 8a5245a..0000000 --- a/policy/restriction.hxx +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2016 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 __RESTRICTION_POLICY__ -#define __RESTRICTION_POLICY__ - -#include "policy-context.hxx" - -namespace DevicePolicyManager { - -class RestrictionPolicy { -public: - RestrictionPolicy(PolicyControlContext& ctxt); - ~RestrictionPolicy(); - - RestrictionPolicy(const RestrictionPolicy& rhs); - RestrictionPolicy(RestrictionPolicy&& rhs); - - RestrictionPolicy& operator=(const RestrictionPolicy& rhs); - RestrictionPolicy& operator=(RestrictionPolicy&& rhs); - - int setCameraState(bool enable); - bool getCameraState(); - - int setMicrophoneState(bool enable); - bool getMicrophoneState(); - - int setClipboardState(bool enable); - bool getClipboardState(); - - int setUsbDebuggingState(bool enable); - bool getUsbDebuggingState(); - - int setUsbTetheringState(bool enable); - bool getUsbTetheringState(); - - int setExternalStorageState(bool enable); - bool getExternalStorageState(); - - int setPopImapEmailState(bool enable); - bool getPopImapEmailState(); - - int setMessagingState(const std::string& sim_id, bool enable); - bool getMessagingState(const std::string& sim_id); - - int setBrowserState(bool enable); - bool getBrowserState(); - -private: - struct Private; - std::unique_ptr pimpl; -}; - -} // namespace DevicePolicyManager - -#endif /* __RESTRICTION_POLICY__ */ diff --git a/policy/security.hxx b/policy/security.hxx deleted file mode 100644 index 9fa0801..0000000 --- a/policy/security.hxx +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 __SECURITY_POLICY__ -#define __SECURITY_POLICY__ - -#include "policy-context.hxx" - -namespace DevicePolicyManager { - -/** - * This class provides APIs to control security functionalities - * such as certificate installation, encryption and wipe - */ - -class SecurityPolicy { -public: - SecurityPolicy(PolicyControlContext& ctxt); - ~SecurityPolicy(); - - SecurityPolicy(const SecurityPolicy& rhs); - SecurityPolicy(SecurityPolicy&& rhs); - - SecurityPolicy& operator=(const SecurityPolicy& rhs); - SecurityPolicy& operator=(SecurityPolicy&& rhs); - - int lockoutScreen(); - int wipeData(int id); - int setInternalStorageEncryption(bool encrypt); - bool isInternalStorageEncrypted(); - int setExternalStorageEncryption(bool encrypt); - bool isExternalStorageEncrypted(); - -private: - struct Private; - std::unique_ptr pimpl; -}; - -} // namespace DevicePolicyManager -#endif // __SECURITY_POLICY__ diff --git a/policy/smack.hxx b/policy/smack.hxx deleted file mode 100644 index 8b3f13d..0000000 --- a/policy/smack.hxx +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2017 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 - */ - -/** - * @file smack.hxx - * @brief SMACK agent internal interface. - * @author Dmytro Logachev (d.logachev@samsung.com) - * @date Created Oct 13, 2016 - * @par In Samsung Ukraine R&D Center (SRK) under a contract between - * @par LLC "Samsung Electronics Ukraine Company" (Kyiv, Ukraine) - * @par and "Samsung Electronics Co", Ltd (Seoul, Republic of Korea) - * @par Copyright: (c) Samsung Electronics Co, Ltd 2016. All rights reserved. -**/ - -#ifndef __SMACK_SECURITY_MONITOR__ -#define __SMACK_SECURITY_MONITOR__ - -#include "policy-context.hxx" - -namespace DevicePolicyManager { - -/** - * This class provides APIs to control smack security monitor functionalities - */ - -class SmackSecurityMonitor { -public: - SmackSecurityMonitor(PolicyControlContext &ctxt); - ~SmackSecurityMonitor(); - - SmackSecurityMonitor(const SmackSecurityMonitor &rhs); - SmackSecurityMonitor(SmackSecurityMonitor &&rhs); - - SmackSecurityMonitor &operator=(const SmackSecurityMonitor &rhs); - SmackSecurityMonitor &operator=(SmackSecurityMonitor &&rhs); - - /** - * @brief Returns SMACK report. - * @details This API can be used for requesting current SMACK report - * @return String contains SMACK report - */ - std::string getReport(); - - /** - * @brief Returns number of SMACK issues. - * @details This API can be used for requesting current number of of SMACK issues - * @return Number of threats - */ - int getIssueCount(); - -private: - struct Private; - std::unique_ptr pimpl; -}; - -} // namespace DevicePolicyManager -#endif // __SMACK_SECURITY_MONITOR__ diff --git a/policy/storage.hxx b/policy/storage.hxx deleted file mode 100644 index 31ca994..0000000 --- a/policy/storage.hxx +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2016 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 __STORAGE_POLICY__ -#define __STORAGE_POLICY__ - -#include "policy-context.hxx" - -namespace DevicePolicyManager { - -class StoragePolicy { -public: - enum { - WIPE_INTERNAL_STORAGE = (1 << 0), - WIPE_EXTERNAL_STORAGE = (1 << 1) - }; - - StoragePolicy(PolicyControlContext& ctxt); - ~StoragePolicy(); - - StoragePolicy(const StoragePolicy& rhs); - StoragePolicy(StoragePolicy&& rhs); - - StoragePolicy& operator=(const StoragePolicy& rhs); - StoragePolicy& operator=(StoragePolicy&& rhs); - - int wipeData(int id); - -private: - struct Private; - std::unique_ptr pimpl; -}; - -} // namespace DeivcePolicyManager - -#endif //!__STORAGE_POLICY__ diff --git a/policy/wifi.hxx b/policy/wifi.hxx deleted file mode 100644 index e77c050..0000000 --- a/policy/wifi.hxx +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 __WIFI_POLICY__ -#define __WIFI_POLICY__ - -#include "policy-context.hxx" - -namespace DevicePolicyManager { - -/** - * This class provides APIs to configure Wi-Fi related settings and manage Wi-Fi profiles. - */ - -class WifiPolicy { -public: - WifiPolicy(PolicyControlContext& ctxt); - ~WifiPolicy(); - - WifiPolicy(const WifiPolicy& rhs); - WifiPolicy(WifiPolicy&& rhs); - - WifiPolicy& operator=(const WifiPolicy& rhs); - WifiPolicy& operator=(WifiPolicy&& rhs); - - int setState(bool enable); - bool getState(); - - int setHotspotState(bool enable); - bool getHotspotState(); - - int setProfileChangeRestriction(bool restrict); - bool isProfileChangeRestricted(); - - int setNetworkAccessRestriction(bool restrict); - bool isNetworkAccessRestricted(); - - int addSsidToBlocklist(const std::string& ssid); - int removeSsidFromBlocklist(const std::string& ssid); - -private: - struct Private; - std::unique_ptr pimpl; -}; - -} // namespace DevicePolicyManager -#endif // __WIFI_POLICY__ diff --git a/restriction.cpp b/restriction.cpp deleted file mode 100644 index 9decd7f..0000000 --- a/restriction.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2016 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 "status.h" -#include "restriction.hxx" - -namespace DevicePolicyManager { - -struct RestrictionPolicy::Private { - Private(PolicyControlContext& ctxt) : context(ctxt) {} - PolicyControlContext& context; -}; - -RestrictionPolicy::RestrictionPolicy(RestrictionPolicy&& rhs) = default; -RestrictionPolicy& RestrictionPolicy::operator=(RestrictionPolicy&& rhs) = default; - -RestrictionPolicy::RestrictionPolicy(const RestrictionPolicy& rhs) -{ - std::cout << "Copy Constructor" << std::endl; - if (rhs.pimpl) { - pimpl.reset(new Private(*rhs.pimpl)); - } -} - -RestrictionPolicy& RestrictionPolicy::operator=(const RestrictionPolicy& rhs) -{ - std::cout << "Copy Operator" << std::endl; - if (!rhs.pimpl) { - pimpl.reset(); - } else { - pimpl.reset(new Private(*rhs.pimpl)); - } - - return *this; -} - -RestrictionPolicy::RestrictionPolicy(PolicyControlContext& ctxt) : - pimpl(new Private(ctxt)) -{ -} - -RestrictionPolicy::~RestrictionPolicy() -{ -} - -int RestrictionPolicy::setMicrophoneState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("RestrictionPolicy::setMicrophoneState", enable); - - return status.get(); -} - -bool RestrictionPolicy::getMicrophoneState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("RestrictionPolicy::getMicrophoneState"); - - return status.get(); -} - -int RestrictionPolicy::setCameraState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("RestrictionPolicy::setCameraState", enable); - - return status.get(); -} - -bool RestrictionPolicy::getCameraState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("RestrictionPolicy::getCameraState"); - - return status.get(); -} - -int RestrictionPolicy::setClipboardState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("RestrictionPolicy::setClipboardState", enable); - - return status.get(); -} - -bool RestrictionPolicy::getClipboardState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("RestrictionPolicy::getClipboardState"); - - return status.get(); -} - -int RestrictionPolicy::setUsbDebuggingState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("RestrictionPolicy::setUsbDebuggingState", enable); - - return status.get(); -} - -bool RestrictionPolicy::getUsbDebuggingState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("RestrictionPolicy::getUsbDebuggingState"); - - return status.get(); -} - -int RestrictionPolicy::setUsbTetheringState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("RestrictionPolicy::setUsbTetheringState", enable); - - return status.get(); -} - -bool RestrictionPolicy::getUsbTetheringState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("RestrictionPolicy::getUsbTetheringState"); - - return status.get(); -} - -int RestrictionPolicy::setExternalStorageState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("RestrictionPolicy::setExternalStorageState", enable); - - return status.get(); -} - -bool RestrictionPolicy::getExternalStorageState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("RestrictionPolicy::getExternalStorageState"); - - return status.get(); -} - -int RestrictionPolicy::setPopImapEmailState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("RestrictionPolicy::setPopImapEmailState", enable); - - return status.get(); -} - -bool RestrictionPolicy::getPopImapEmailState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("RestrictionPolicy::getPopImapEmailState"); - - return status.get(); -} - -int RestrictionPolicy::setMessagingState(const std::string &sim_id, bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("RestrictionPolicy::setMessagingState", sim_id, enable); - - return status.get(); -} - -bool RestrictionPolicy::getMessagingState(const std::string &sim_id) -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("RestrictionPolicy::getMessagingState", sim_id); - - return status.get(); -} - -int RestrictionPolicy::setBrowserState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("RestrictionPolicy::setBrowserState", enable); - - return status.get(); -} - -bool RestrictionPolicy::getBrowserState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("RestrictionPolicy::getBrowserState"); - - return status.get(); -} - -} //namespace DevicePolicyManager diff --git a/security.cpp b/security.cpp deleted file mode 100644 index cb2513d..0000000 --- a/security.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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 "status.h" -#include "security.hxx" - -namespace DevicePolicyManager { - -struct SecurityPolicy::Private { - Private(PolicyControlContext& ctxt) : context(ctxt) {} - PolicyControlContext& context; -}; - -SecurityPolicy::SecurityPolicy(SecurityPolicy&& rhs) = default; -SecurityPolicy& SecurityPolicy::operator=(SecurityPolicy&& rhs) = default; - -SecurityPolicy::SecurityPolicy(const SecurityPolicy& rhs) -{ - if (rhs.pimpl) { - pimpl.reset(new Private(*rhs.pimpl)); - } -} - -SecurityPolicy& SecurityPolicy::operator=(const SecurityPolicy& rhs) -{ - if (!rhs.pimpl) { - pimpl.reset(); - } else { - pimpl.reset(new Private(*rhs.pimpl)); - } - - return *this; -} - -SecurityPolicy::SecurityPolicy(PolicyControlContext& ctxt) : - pimpl(new Private(ctxt)) -{ -} - -SecurityPolicy::~SecurityPolicy() -{ -} - -int SecurityPolicy::lockoutScreen() -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("SecurityPolicy::lockoutScreen"); - - return status.get(); -} - -int SecurityPolicy::setInternalStorageEncryption(bool encrypt) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("SecurityPolicy::setInternalStorageEncryption", encrypt); - - return status.get(); -} - -bool SecurityPolicy::isInternalStorageEncrypted() -{ - PolicyControlContext& context = pimpl->context; - - Status status { false }; - - status = context.methodCall("SecurityPolicy::isInternalStorageEncrypted"); - - return status.get(); -} - -int SecurityPolicy::setExternalStorageEncryption(bool encrypt) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("SecurityPolicy::setExternalStorageEncryption", encrypt); - - return status.get(); -} - -bool SecurityPolicy::isExternalStorageEncrypted() -{ - PolicyControlContext& context = pimpl->context; - - Status status { false }; - - status = context.methodCall("SecurityPolicy::isExternalStorageEncrypted"); - - return status.get(); -} - -} // namespace DevicePolicyManager diff --git a/storage.cpp b/storage.cpp deleted file mode 100644 index 2d98adc..0000000 --- a/storage.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 "status.h" -#include "storage.hxx" - -namespace DevicePolicyManager { - -struct StoragePolicy::Private { - Private(PolicyControlContext& ctxt) : context(ctxt) {} - PolicyControlContext& context; -}; - -StoragePolicy::StoragePolicy(StoragePolicy&& rhs) = default; -StoragePolicy& StoragePolicy::operator=(StoragePolicy&& rhs) = default; - -StoragePolicy::StoragePolicy(const StoragePolicy& rhs) -{ - if (rhs.pimpl) { - pimpl.reset(new Private(*rhs.pimpl)); - } -} - -StoragePolicy& StoragePolicy::operator=(const StoragePolicy& rhs) -{ - if (!rhs.pimpl) { - pimpl.reset(); - } else { - pimpl.reset(new Private(*rhs.pimpl)); - } - - return *this; -} - -StoragePolicy::StoragePolicy(PolicyControlContext& ctx) : - pimpl(new Private(ctx)) -{ -} - -StoragePolicy::~StoragePolicy() -{ -} - -int StoragePolicy::wipeData(int type) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("StoragePolicy::wipeData", type); - - return status.get(); -} - -} //namespace DevicePolicyManager diff --git a/wifi.cpp b/wifi.cpp deleted file mode 100644 index 69d338e..0000000 --- a/wifi.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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 "status.h" -#include "wifi.hxx" - -namespace DevicePolicyManager { - -struct WifiPolicy::Private { - Private(PolicyControlContext& ctxt) : context(ctxt) {} - PolicyControlContext& context; -}; - -WifiPolicy::WifiPolicy(WifiPolicy&& rhs) = default; -WifiPolicy& WifiPolicy::operator=(WifiPolicy&& rhs) = default; - -WifiPolicy::WifiPolicy(const WifiPolicy& rhs) -{ - if (rhs.pimpl) { - pimpl.reset(new Private(*rhs.pimpl)); - } -} - - -WifiPolicy& WifiPolicy::operator=(const WifiPolicy& rhs) -{ - if (!rhs.pimpl) { - pimpl.reset(); - } else { - pimpl.reset(new Private(*rhs.pimpl)); - } - - return *this; -} - -WifiPolicy::WifiPolicy(PolicyControlContext& ctxt) : - pimpl(new Private(ctxt)) -{ -} - -WifiPolicy::~WifiPolicy() -{ -} - -int WifiPolicy::setState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("WifiPolicy::setState", enable); - - return status.get(); -} - -bool WifiPolicy::getState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("WifiPolicy::getState"); - - return status.get(); -} - -int WifiPolicy::setHotspotState(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("WifiPolicy::setHotspotState", enable); - - return status.get(); -} - -bool WifiPolicy::getHotspotState() -{ - PolicyControlContext& context = pimpl->context; - - Status status { true }; - - status = context.methodCall("WifiPolicy::getHotspotState"); - - return status.get(); -} - -int WifiPolicy::setProfileChangeRestriction(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("WifiPolicy::setProfileChangeRestriction", enable); - - return status.get(); -} - -bool WifiPolicy::isProfileChangeRestricted() -{ - PolicyControlContext& context = pimpl->context; - - Status status { false }; - - status = context.methodCall("WifiPolicy::isProfileChangeRestricted"); - - return status.get(); -} - -int WifiPolicy::setNetworkAccessRestriction(bool enable) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("WifiPolicy::setNetworkAccessRestriction", enable); - - return status.get(); -} - -bool WifiPolicy::isNetworkAccessRestricted() -{ - PolicyControlContext& context = pimpl->context; - - Status status { false }; - - status = context.methodCall("WifiPolicy::isNetworkAccessRestricted"); - - return status.get(); -} - -int WifiPolicy::addSsidToBlocklist(const std::string& ssid) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("WifiPolicy::addSsidToBlocklist", ssid); - - return status.get(); -} - -int WifiPolicy::removeSsidFromBlocklist(const std::string& ssid) -{ - PolicyControlContext& context = pimpl->context; - - Status status { -1 }; - - status = context.methodCall("WifiPolicy::removeSsidFromBlocklist", ssid); - - return status.get(); -} - -} // namespace DevicePolicyManager -- 2.7.4