string(REPLACE " " "_" ProjectId ${ProjectId})
project(${ProjectId})
+include_directories (
+ ${NETWORK_MANAGER_LIB}/dpm/inc
+)
+
add_executable (${PROJECT_NAME} main.cpp)
-#target_link_libraries (${PROJECT_NAME} dpm)
+add_dependencies (${PROJECT_NAME} ${NETWORK_MANAGER_LIB_PROJECT_NAME})
+target_link_libraries (${PROJECT_NAME} ${NETWORK_MANAGER_LIB_PROJECT_NAME})
install(TARGETS ${PROJECT_NAME} DESTINATION ${TESTS_DIR})
+install(FILES agent.manifest DESTINATION ${MANIFESTDIR})
message(STATUS "Configuring: " ${ProjectId})
message(STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS})
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
+#include "dpm.h"
char s[1024];
+DPM *dpm;
+
void print_menu(const char *state_s, const char *menu_s)
{
printf("\n=================\n");
//----------------------------------------------
void dev_bl(const char *mac, bool add)
{
- printf("MAC %s %s\n", mac, add ? "added" : "removed");
+ dpm_error err;
+ if (add)
+ err = dpm->bluetooth_add_device_to_blacklist(mac);
+ else
+ err = dpm->bluetooth_remove_device_from_blacklist(mac);
+
+ if (err == DPM_OK)
+ printf("MAC %s %s\n", mac, add ? "added" : "removed");
+ else
+ printf("Error: %s\n", dpm->get_error_string(err));
}
void uuid_bl(const char *uuid, bool add)
void get_rst_state(char *str)
{
char *p = str;
+ bool allow = false;
+ dpm_error err;
+ int i = 0;
- for(int i = 0; i < 16; i++)
- p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], rst[i] ? "disallowed" : "allowed");
+ err = dpm->get_camera_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_microphone_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_location_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_external_storage_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_clipboard_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_usb_debugging_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_wifi_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_wifi_hotspot_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_bluetooth_tethering_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_usb_tethering_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_bluetooth_mode_change_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_bluetooth_desktop_connectivity_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_bluetooth_pairing_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_messaging_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_popimap_email_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+ err = dpm->get_browser_state(allow);
+ if (err == DPM_OK)
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], allow ? "allowed" : "disallowed");
+ else
+ p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], dpm->get_error_string(err));
+ rst[i++] = allow;
+
+// for(int i = 0; i < 16; i++)
+// p += sprintf(p, " %i) %s: %s\n", i + 1, item[i], rst[i] ? "disallowed" : "allowed");
}
void menu_restrict()
static char st[1024];
static char items[1024];
char *p = items;
+ dpm_error err = DPM_OK;
+ bool allow;
get_rst_state(st);
BEGIN(st, items)
else if (atoi(s) > 0 && atoi(s) <= 16)
{
- int n = atoi(s) - 1;
- rst[n] = !rst[n];
+ int n = atoi(s);
+ rst[n - 1] = !rst[n - 1];
+
+ if (n == 1) err = dpm->set_camera_state(rst[n - 1]);
+ else if (n == 2) err = dpm->set_microphone_state(rst[n - 1]);
+ else if (n == 3) err = dpm->set_location_state(rst[n - 1]);
+ else if (n == 4) err = dpm->set_external_storage_state(rst[n - 1]);
+ else if (n == 5) err = dpm->set_clipboard_state(rst[n - 1]);
+ else if (n == 6) err = dpm->set_usb_debugging_state(rst[n - 1]);
+ else if (n == 7) err = dpm->set_wifi_state(rst[n - 1]);
+ else if (n == 8) err = dpm->set_wifi_hotspot_state(rst[n - 1]);
+ else if (n == 9) err = dpm->set_bluetooth_tethering_state(rst[n - 1]);
+ else if (n == 10) err = dpm->set_usb_tethering_state(rst[n - 1]);
+ else if (n == 11) err = dpm->set_bluetooth_mode_change_state(rst[n - 1]);
+ else if (n == 12) err = dpm->set_bluetooth_desktop_connectivity_state(rst[n - 1]);
+ else if (n == 13) err = dpm->set_bluetooth_pairing_state(rst[n - 1]);
+ else if (n == 14) err = dpm->set_messaging_state(rst[n - 1]);
+ else if (n == 15) err = dpm->set_popimap_email_state(rst[n - 1]);
+ else if (n == 16) err = dpm->set_browser_state(rst[n - 1]);
+
+ if (err == DPM_OK)
+ printf(" %s: %s\n", item[n-1], rst[n-1] ? "allowed" : "disallowed");
+ else
+ printf(" %s error: %s\n", item[n-1], dpm->get_error_string(err));
+
get_rst_state(st);
printf("State:\n%s", st);
}
void menu_sequrity()
{
+ dpm_error err;
+
BEGIN("",
" 1 - lock the device screen immediately\n"
" 2 - encrypt internal storage\n"
else if (!strcmp(s, "1"))
{
- printf("device screen locked\n");
+ err = dpm->lockout_screen();
+ if (err == DPM_OK)
+ printf("device screen locked\n");
+ else
+ printf("%s\n", dpm->get_error_string(err));
}
else if (!strcmp(s, "2"))
{
- printf("internal storage encrypted\n");
+ err = dpm->set_internal_storage_encryption(true);
+ if (err == DPM_OK)
+ printf("internal storage encrypted\n");
+ else
+ printf("%s\n", dpm->get_error_string(err));
}
else if (!strcmp(s, "3"))
{
- printf("internal storage decrypted\n");
+ err = dpm->set_internal_storage_encryption(false);
+ if (err == DPM_OK)
+ printf("internal storage decrypted\n");
+ else
+ printf("%s\n", dpm->get_error_string(err));
}
else if (!strcmp(s, "4"))
{
- printf("external storage encrypted\n");
+ err = dpm->set_external_storage_encryption(true);
+ if (err == DPM_OK)
+ printf("external storage encrypted\n");
+ else
+ printf("%s\n", dpm->get_error_string(err));
}
else if (!strcmp(s, "5"))
{
- printf("external storage decrypted\n");
+ err = dpm->set_external_storage_encryption(false);
+ if (err == DPM_OK)
+ printf("external storage decrypted\n");
+ else
+ printf("%s\n", dpm->get_error_string(err));
}
else if (!strcmp(s, "6"))
{
- printf("internal memory wiped\n");
+ err = dpm->wipe_internal_data();
+ if (err == DPM_OK)
+ printf("internal memory wiped\n");
+ else
+ printf("%s\n", dpm->get_error_string(err));
}
else if (!strcmp(s, "7"))
{
- printf("external memory wiped\n");
+ err = dpm->wipe_external_data();
+ if (err == DPM_OK)
+ printf("external memory wiped\n");
+ else
+ printf("%s\n", dpm->get_error_string(err));
}
END;
}
void menu_wifi()
{
- char st[256];
+ static char st[256];
+ dpm_error err;
+
+ err = dpm->wifi_is_profile_change_restricted(wifi_prof_change);
+ if (err != DPM_OK)
+ printf("Profile change error: %s\n", dpm->get_error_string(err));
+ err = dpm->wifi_is_network_access_restricted(wifi_network_access);
+ if (err != DPM_OK)
+ printf("Network access error: %s\n", dpm->get_error_string(err));
sprintf(st, "WiFi restrictions:\n %s: %s\n %s: %s\n",
"Profile change", wifi_prof_change ? "restricted" : "allowed",
else if (!strcmp(s, "1"))
{
wifi_prof_change = true;
- printf("Profile change restriction on\n");
+ err = dpm->wifi_set_profile_change_restriction(wifi_prof_change);
+ if (err != DPM_OK)
+ printf("Profile change error: %s\n", dpm->get_error_string(err));
+ else
+ printf("Profile change restriction on\n");
}
else if (!strcmp(s, "2"))
{
wifi_prof_change = false;
- printf("Profile change restriction off\n");
+ err = dpm->wifi_set_profile_change_restriction(wifi_prof_change);
+ if (err != DPM_OK)
+ printf("Profile change error: %s\n", dpm->get_error_string(err));
+ else
+ printf("Profile change restriction off\n");
}
else if (!strcmp(s, "3"))
{
wifi_network_access = true;
- printf("Network access restriction on\n");
+ err = dpm->wifi_set_network_access_restriction(wifi_network_access);
+ if (err != DPM_OK)
+ printf("Network access error: %s\n", dpm->get_error_string(err));
+ else
+ printf("Network access restriction on\n");
}
else if (!strcmp(s, "4"))
{
wifi_network_access = false;
- printf("Network access restriction off\n");
+ err = dpm->wifi_set_network_access_restriction(wifi_network_access);
+ if (err != DPM_OK)
+ printf("Network access error: %s\n", dpm->get_error_string(err));
+ else
+ printf("Network access restriction off\n");
}
else if (!strcmp(s, "5"))
{
printf("Enter SSID: ");
res = scanf("%s", s);
- printf("SSID %s added\n", s);
+ err = dpm->wifi_add_ssid_to_blocklist(s);
+ if (err != DPM_OK)
+ printf("Blacklist error: %s\n", dpm->get_error_string(err));
+ else
+ printf("SSID [%s] added\n", s);
}
else if (!strcmp(s, "6"))
{
printf("Enter SSID: ");
res = scanf("%s", s);
- printf("SSID %s removed\n", s);
+ err = dpm->wifi_remove_ssid_from_blocklist(s);
+ if (err != DPM_OK)
+ printf("Blacklist error: %s\n", dpm->get_error_string(err));
+ else
+ printf("SSID [%s] removed\n", s);
}
END;
}
printf("#### Reference Agent App ####\n");
printf("#############################\n");
- while (1)
+ dpm = new DPM;
+
+ try
{
- printf("\n==============\n");
- printf("Select module:\n");
- printf(" 1 - Application\n");
- printf(" 2 - Bluetooth\n");
- printf(" 3 - Restriction\n");
- printf(" 4 - Sequrity\n");
- printf(" 5 - WiFi\n");
- printf(" q - Exit\n");
-
- while(1)
+ while (1)
{
- res = scanf("%s", s);
- if (!strcmp(s, "q")) return 0;
- else if (!strcmp(s, "1")) menu_app();
- else if (!strcmp(s, "2")) menu_bt();
- else if (!strcmp(s, "3")) menu_restrict();
- else if (!strcmp(s, "4")) menu_sequrity();
- else if (!strcmp(s, "5")) menu_wifi();
- else
+ printf("\n==============\n");
+ printf("Select module:\n");
+ printf(" 1 - Application\n");
+ printf(" 2 - Bluetooth\n");
+ printf(" 3 - Restriction\n");
+ printf(" 4 - Sequrity\n");
+ printf(" 5 - WiFi\n");
+ printf(" q - Exit\n");
+
+ while(1)
{
- printf("Wrong input\n");
- continue;
+ res = scanf("%s", s);
+ if (!strcmp(s, "q")) throw 0;
+ else if (!strcmp(s, "1")) menu_app();
+ else if (!strcmp(s, "2")) menu_bt();
+ else if (!strcmp(s, "3")) menu_restrict();
+ else if (!strcmp(s, "4")) menu_sequrity();
+ else if (!strcmp(s, "5")) menu_wifi();
+ else
+ {
+ printf("Wrong input\n");
+ continue;
+ }
+
+ break;
}
-
- break;
}
}
+ catch(...)
+ {
+
+ }
+
+ delete dpm;
return 0;
}
INCLUDE(FindPkgConfig)
pkg_check_modules(NMLIB_REQ_PKGS REQUIRED libcurl)
+pkg_check_modules(NMLIB_REQ_PKGS REQUIRED dpm)
+pkg_check_modules(NMLIB_REQ_PKGS REQUIRED dlog)
include_directories(REST/inc dpm/inc)
SET(LIB_SOURCES REST/src/rest_helper.cpp dpm/src/dpm.cpp)
add_library(${PROJECT_NAME} SHARED ${LIB_SOURCES})
target_link_libraries(${PROJECT_NAME} ${NMLIB_REQ_PKGS_LIBRARIES})
+target_link_libraries (${PROJECT_NAME} dpm)
#target_link_libraries(${PROJECT_NAME} curl)
#ifndef DPMLIB_H_
#define DPMLIB_H_
+enum dpm_error
+{
+ DPM_OK, /**< The operation was successful */
+ DPM_INVALID_PARAMETER, /**< Invalid parameter */
+ DPM_CONNECTION_REFUSED, /**< Connection refused */
+ DPM_TIMED_OUT, /**< Time out */
+ DPM_PERMISSION_DENIED, /**< Access privilege is not sufficient */
+ DPM_NOT_PERMITTED, /**< Operation not permitted */
+ DPM_FILE_EXISTS, /**< File exists */
+ DPM_OUT_OF_MEMORY, /**< Out of memory */
+ DPM_NO_DATA, /**< No Data */
+ DPM_NOT_INITIALIZED, /**< Library not initialized */
+ DPM_UNKNOWN, /**< Unknown error */
+};
+
+class DPM
+{
+ void *handle;
+
+public:
+ DPM();
+ ~DPM();
+
+ const char* get_error_string(dpm_error err);
+
+ dpm_error set_camera_state(bool allow);
+ dpm_error get_camera_state(bool &allow);
+ dpm_error set_microphone_state(bool allow);
+ dpm_error get_microphone_state(bool &allow);
+ dpm_error set_location_state(bool allow);
+ dpm_error get_location_state(bool &allow);
+ dpm_error set_external_storage_state(bool allow);
+ dpm_error get_external_storage_state(bool &allow);
+ dpm_error set_clipboard_state(bool allow);
+ dpm_error get_clipboard_state(bool &allow);
+ dpm_error set_usb_debugging_state(bool allow);
+ dpm_error get_usb_debugging_state(bool &allow);
+ dpm_error set_wifi_state(bool allow);
+ dpm_error get_wifi_state(bool &allow);
+ dpm_error set_wifi_hotspot_state(bool allow);
+ dpm_error get_wifi_hotspot_state(bool &allow);
+ dpm_error set_bluetooth_tethering_state(bool allow);
+ dpm_error get_bluetooth_tethering_state(bool &allow);
+ dpm_error set_usb_tethering_state(bool allow);
+ dpm_error get_usb_tethering_state(bool &allow);
+ dpm_error set_bluetooth_mode_change_state(bool allow);
+ dpm_error get_bluetooth_mode_change_state(bool &allow);
+ dpm_error set_bluetooth_desktop_connectivity_state(bool allow);
+ dpm_error get_bluetooth_desktop_connectivity_state(bool &allow);
+ dpm_error set_bluetooth_pairing_state(bool allow);
+ dpm_error get_bluetooth_pairing_state(bool &allow);
+ dpm_error set_messaging_state(bool allow);
+ dpm_error get_messaging_state(bool &allow);
+ dpm_error set_popimap_email_state(bool allow);
+ dpm_error get_popimap_email_state(bool &allow);
+ dpm_error set_browser_state(bool allow);
+ dpm_error get_browser_state(bool &allow);
+
+ enum package_mode
+ {
+ PACKAGE_INSTALL , /**< Package install restriction */
+ PACKAGE_UNINSTALL , /**< Package uninstall restriction */
+ PACKAGE_REINSTALL , /**< Package reinstall restriction */
+ PACKAGE_MOVE /**< Package move restriction */
+ };
+
+ dpm_error set_package_restriction(package_mode mode, bool allow);
+ dpm_error get_package_restriction(package_mode mode, bool &allow);
+ dpm_error add_privilege_to_blacklist(const char* privilege);
+ dpm_error remove_privilege_from_blacklist(const char* privilege);
+ dpm_error check_privilege_is_blacklisted(const char* privilege, bool &blacklisted);
+
+ dpm_error bluetooth_add_device_to_blacklist(const char* address);
+ dpm_error bluetooth_remove_device_from_blacklist(const char* address);
+ dpm_error bluetooth_set_device_restriction(bool enable);
+ dpm_error bluetooth_is_device_restricted(bool &is_enabled);
+ dpm_error bluetooth_add_uuid_to_blacklist(const char* uuid);
+ dpm_error bluetooth_remove_uuid_from_blacklist(const char* uuid);
+ dpm_error bluetooth_set_uuid_restriction(bool enable);
+ dpm_error bluetooth_is_uuid_restricted(bool &is_enabled);
+
+ dpm_error lockout_screen();
+ dpm_error set_internal_storage_encryption(bool encrypt);
+ dpm_error is_internal_storage_encrypted(bool &is_encrypted);
+ dpm_error set_external_storage_encryption(bool encrypt);
+ dpm_error is_external_storage_encrypted(bool &is_encrypted);
+ dpm_error wipe_external_data();
+ dpm_error wipe_internal_data();
+
+ dpm_error wifi_set_profile_change_restriction(bool enable);
+ dpm_error wifi_is_profile_change_restricted(bool &is_enabled);
+ dpm_error wifi_set_network_access_restriction(bool enable);
+ dpm_error wifi_is_network_access_restricted(bool &is_enabled);
+ dpm_error wifi_add_ssid_to_blocklist(const char* ssid);
+ dpm_error wifi_remove_ssid_from_blocklist(const char* ssid);
+
+private:
+ dpm_error convert_err(int err);
+ dpm_error get_state(int (*f)(void*, int*), bool &allow);
+ dpm_error set_state(int (*f)(void*, int), bool allow);
+};
#define DPMLIB_CPP_
#include "../inc/dpm.h"
+#include <dpm/device-policy-manager.h>
+#include <dpm/bluetooth.h>
+#include <dpm/wifi.h>
+#include <dpm/restriction.h>
+#include <dpm/application.h>
+#include <dpm/security.h>
+typedef device_policy_manager_h dpmh;
+DPM::DPM() : handle(nullptr)
+{
+ handle = (dpmh)dpm_manager_create();
+}
+
+DPM::~DPM()
+{
+ if (handle) dpm_manager_destroy((dpmh)handle);
+}
+
+dpm_error DPM::convert_err(int err)
+{
+ switch (err)
+ {
+ case DPM_ERROR_NONE: return DPM_OK;
+ case DPM_ERROR_INVALID_PARAMETER: return DPM_INVALID_PARAMETER;
+ case DPM_ERROR_CONNECTION_REFUSED: return DPM_CONNECTION_REFUSED;
+ case DPM_ERROR_TIMED_OUT: return DPM_TIMED_OUT;
+ case DPM_ERROR_PERMISSION_DENIED: return DPM_PERMISSION_DENIED;
+ case DPM_ERROR_NOT_PERMITTED: return DPM_NOT_PERMITTED;
+ case DPM_ERROR_FILE_EXISTS: return DPM_FILE_EXISTS;
+ case DPM_ERROR_OUT_OF_MEMORY: return DPM_OUT_OF_MEMORY;
+ case DPM_ERROR_NO_DATA: return DPM_NO_DATA;
+ default:
+ return DPM_UNKNOWN;
+ }
+ return DPM_UNKNOWN;
+}
+
+const char* DPM::get_error_string(dpm_error err)
+{
+ struct errs
+ {
+ dpm_error code;
+ const char *name;
+ };
+
+ static const errs errs_arr[] =
+ {
+ {DPM_OK, "The operation was successful"},
+ {DPM_INVALID_PARAMETER, "Invalid parameter"},
+ {DPM_CONNECTION_REFUSED, "Connection refused"},
+ {DPM_TIMED_OUT, "Time out"},
+ {DPM_PERMISSION_DENIED, "Access privilege is not sufficient"},
+ {DPM_NOT_PERMITTED, "Operation not permitted"},
+ {DPM_FILE_EXISTS, "File exists"},
+ {DPM_OUT_OF_MEMORY, "Out of memory"},
+ {DPM_NO_DATA, "No Data"},
+ {DPM_NOT_INITIALIZED, "Library not initialized"},
+ {DPM_UNKNOWN, "Unknown error"},
+ };
+
+ for(unsigned int i = 0; i < sizeof(errs_arr) / sizeof(errs_arr[0]); i++)
+ {
+ if (errs_arr[i].code == err) return errs_arr[i].name;
+ }
+
+ return "Unknown";
+}
+
+dpm_error DPM::get_state(int (*f)(void*, int*), bool &allow)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int is_allow = 0;
+ int res = f(handle, &is_allow);
+ allow = (is_allow != 0);
+ return convert_err(res);
+}
+
+dpm_error DPM::set_state(int (*f)(void*, int), bool allow)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = f(handle, allow ? 1 : 0);
+ return convert_err(res);
+}
+
+dpm_error DPM::set_camera_state(bool allow)
+{
+ return set_state(dpm_restriction_set_camera_state, allow);
+}
+
+dpm_error DPM::get_camera_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_camera_state, allow);
+}
+
+dpm_error DPM::set_microphone_state(bool allow)
+{
+ return set_state(dpm_restriction_set_microphone_state, allow);
+}
+
+dpm_error DPM::get_microphone_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_microphone_state, allow);
+}
+
+dpm_error DPM::set_location_state(bool allow)
+{
+ return set_state(dpm_restriction_set_location_state, allow);
+}
+
+dpm_error DPM::get_location_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_location_state, allow);
+}
+
+dpm_error DPM::set_external_storage_state(bool allow)
+{
+ return set_state(dpm_restriction_set_external_storage_state, allow);
+}
+
+dpm_error DPM::get_external_storage_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_external_storage_state, allow);
+}
+
+dpm_error DPM::set_clipboard_state(bool allow)
+{
+ return set_state(dpm_restriction_set_clipboard_state, allow);
+}
+
+dpm_error DPM::get_clipboard_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_clipboard_state, allow);
+}
+
+dpm_error DPM::set_usb_debugging_state(bool allow)
+{
+ return set_state(dpm_restriction_set_usb_debugging_state, allow);
+}
+
+dpm_error DPM::get_usb_debugging_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_usb_debugging_state, allow);
+}
+
+dpm_error DPM::set_wifi_state(bool allow)
+{
+ return set_state(dpm_restriction_set_wifi_state, allow);
+}
+
+dpm_error DPM::get_wifi_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_wifi_state, allow);
+}
+
+dpm_error DPM::set_wifi_hotspot_state(bool allow)
+{
+ return set_state(dpm_restriction_set_wifi_hotspot_state, allow);
+}
+
+dpm_error DPM::get_wifi_hotspot_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_wifi_hotspot_state, allow);
+}
+
+dpm_error DPM::set_bluetooth_tethering_state(bool allow)
+{
+ return set_state(dpm_restriction_set_bluetooth_tethering_state, allow);
+}
+
+dpm_error DPM::get_bluetooth_tethering_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_bluetooth_tethering_state, allow);
+}
+
+dpm_error DPM::set_usb_tethering_state(bool allow)
+{
+ return set_state(dpm_restriction_set_usb_tethering_state, allow);
+}
+
+dpm_error DPM::get_usb_tethering_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_usb_tethering_state, allow);
+}
+
+dpm_error DPM::set_bluetooth_mode_change_state(bool allow)
+{
+ return set_state(dpm_restriction_set_bluetooth_mode_change_state, allow);
+}
+
+dpm_error DPM::get_bluetooth_mode_change_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_bluetooth_mode_change_state, allow);
+}
+
+dpm_error DPM::set_bluetooth_desktop_connectivity_state(bool allow)
+{
+ return set_state(dpm_restriction_set_bluetooth_desktop_connectivity_state, allow);
+}
+
+dpm_error DPM::get_bluetooth_desktop_connectivity_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_bluetooth_desktop_connectivity_state, allow);
+}
+
+dpm_error DPM::set_bluetooth_pairing_state(bool allow)
+{
+ return set_state(dpm_restriction_set_bluetooth_pairing_state, allow);
+}
+
+dpm_error DPM::get_bluetooth_pairing_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_bluetooth_pairing_state, allow);
+}
+
+dpm_error DPM::set_messaging_state(bool allow)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_restriction_set_messaging_state((dpmh)handle, "sim_id", allow ? 1 : 0);
+ return convert_err(res);
+}
+
+dpm_error DPM::get_messaging_state(bool &allow)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int is_allow = 0;
+ int res = dpm_restriction_get_messaging_state((dpmh)handle, "sim_id", &is_allow);
+ allow = (is_allow != 0);
+ return convert_err(res);
+}
+
+dpm_error DPM::set_popimap_email_state(bool allow)
+{
+ return set_state(dpm_restriction_set_popimap_email_state, allow);
+}
+
+dpm_error DPM::get_popimap_email_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_popimap_email_state, allow);
+}
+
+dpm_error DPM::set_browser_state(bool allow)
+{
+ return set_state(dpm_restriction_set_browser_state, allow);
+}
+
+dpm_error DPM::get_browser_state(bool &allow)
+{
+ return get_state(dpm_restriction_get_browser_state, allow);
+}
+
+// application
+
+dpm_error DPM::set_package_restriction(package_mode mode, bool allow)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+
+ int m = 0;
+ if (mode == PACKAGE_INSTALL) m = DPM_PACKAGE_RESTRICTION_MODE_INSTALL;
+ else if (mode == PACKAGE_UNINSTALL) m = DPM_PACKAGE_RESTRICTION_MODE_UNINSTALL;
+ else if (mode == PACKAGE_REINSTALL) m = DPM_PACKAGE_RESTRICTION_MODE_REINSTALL;
+ else if (mode == PACKAGE_MOVE) m = DPM_PACKAGE_RESTRICTION_MODE_MOVE;
+ else
+ return DPM_INVALID_PARAMETER;
+
+ int res = allow ?
+ dpm_application_unset_mode_restriction((dpmh)handle, m) :
+ dpm_application_set_mode_restriction((dpmh)handle, m);
+
+ return convert_err(res);
+}
+
+dpm_error DPM::get_package_restriction(package_mode mode, bool &allow)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int is_allow = 0;
+ int res = dpm_application_get_mode_restriction((dpmh)handle, &is_allow);
+ allow = (is_allow != 0);
+ return convert_err(res);
+}
+
+dpm_error DPM::add_privilege_to_blacklist(const char* privilege)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_application_add_privilege_to_blacklist((dpmh)handle, 0, privilege);
+ return convert_err(res);
+}
+
+dpm_error DPM::remove_privilege_from_blacklist(const char* privilege)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_application_remove_privilege_from_blacklist((dpmh)handle, 0, privilege);
+ return convert_err(res);
+}
+
+dpm_error DPM::check_privilege_is_blacklisted(const char* privilege, bool &blacklisted)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int is_blacklisted;
+ int res = dpm_application_check_privilege_is_blacklisted((dpmh)handle, 0, privilege, &is_blacklisted);
+ blacklisted = (is_blacklisted == 1);
+ return convert_err(res);
+}
+
+// bluetooth
+
+dpm_error DPM::bluetooth_add_device_to_blacklist(const char* address)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_bluetooth_add_device_to_blacklist((dpmh)handle, address);
+ return convert_err(res);
+}
+
+dpm_error DPM::bluetooth_remove_device_from_blacklist(const char* address)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_bluetooth_remove_device_from_blacklist((dpmh)handle, address);
+ return convert_err(res);
+}
+
+dpm_error DPM::bluetooth_set_device_restriction(bool enable)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_bluetooth_set_device_restriction((dpmh)handle, enable ? 1 : 0);
+ return convert_err(res);
+}
+
+dpm_error DPM::bluetooth_is_device_restricted(bool &is_enabled)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int x = 0;
+ int res = dpm_bluetooth_is_device_restricted((dpmh)handle, &x);
+ is_enabled = (x != 0);
+ return convert_err(res);
+}
+
+dpm_error DPM::bluetooth_add_uuid_to_blacklist(const char* uuid)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_bluetooth_add_uuid_to_blacklist((dpmh)handle, uuid);
+ return convert_err(res);
+}
+
+dpm_error DPM::bluetooth_remove_uuid_from_blacklist(const char* uuid)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_bluetooth_remove_uuid_from_blacklist((dpmh)handle, uuid);
+ return convert_err(res);
+}
+
+dpm_error DPM::bluetooth_set_uuid_restriction(bool enable)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_bluetooth_set_uuid_restriction((dpmh)handle, enable);
+ return convert_err(res);
+}
+
+dpm_error DPM::bluetooth_is_uuid_restricted(bool &is_enabled)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int x = 0;
+ int res = dpm_bluetooth_is_uuid_restricted((dpmh)handle, &x);
+ is_enabled = (x != 0);
+ return convert_err(res);
+}
+
+dpm_error DPM::lockout_screen()
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_security_lockout_screen((dpmh)handle);
+ return convert_err(res);
+}
+dpm_error DPM::set_internal_storage_encryption(bool encrypt)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_security_set_internal_storage_encryption((dpmh)handle, encrypt ? 1 : 0);
+ return convert_err(res);
+}
+dpm_error DPM::is_internal_storage_encrypted(bool &is_encrypted)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int x = 0;
+ int res = dpm_security_is_internal_storage_encrypted((dpmh)handle, &x);
+ is_encrypted = (x != 0);
+ return convert_err(res);
+}
+dpm_error DPM::set_external_storage_encryption(bool encrypt)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_security_set_external_storage_encryption((dpmh)handle, encrypt ? 1 : 0);
+ return convert_err(res);
+}
+dpm_error DPM::is_external_storage_encrypted(bool &is_encrypted)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int x = 0;
+ int res = dpm_security_is_external_storage_encrypted((dpmh)handle, &x);
+ is_encrypted = (x != 0);
+ return convert_err(res);
+}
+dpm_error DPM::wipe_external_data()
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_security_wipe_data((dpmh)handle, DPM_SECURITY_WIPE_EXTERNAL_STORAGE);
+ return convert_err(res);
+}
+dpm_error DPM::wipe_internal_data()
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_security_wipe_data((dpmh)handle, DPM_SECURITY_WIPE_INTERNAL_STORAGE);
+ return convert_err(res);
+}
+
+dpm_error DPM::wifi_set_profile_change_restriction(bool enable)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_wifi_set_profile_change_restriction((dpmh)handle, enable ? 1 : 0);
+ return convert_err(res);
+}
+
+dpm_error DPM::wifi_is_profile_change_restricted(bool &is_enabled)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_wifi_is_profile_change_restricted((dpmh)handle, (int*)&is_enabled);
+ return convert_err(res);
+}
+
+dpm_error DPM::wifi_set_network_access_restriction(bool enable)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_wifi_set_network_access_restriction((dpmh)handle, enable ? 1 : 0);
+ return convert_err(res);
+}
+
+dpm_error DPM::wifi_is_network_access_restricted(bool &is_enabled)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_wifi_is_network_access_restricted((dpmh)handle, (int*)&is_enabled);
+ return convert_err(res);
+}
+
+dpm_error DPM::wifi_add_ssid_to_blocklist(const char* ssid)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_wifi_add_ssid_to_blocklist((dpmh)handle, ssid);
+ return convert_err(res);
+}
+
+dpm_error DPM::wifi_remove_ssid_from_blocklist(const char* ssid)
+{
+ if (!handle) return DPM_NOT_INITIALIZED;
+ int res = dpm_wifi_remove_ssid_from_blocklist((dpmh)handle, ssid);
+ return convert_err(res);
+}
#endif /* DPMLIB_CPP_ */
BuildRequires: gtest
BuildRequires: gtest-devel
%endif
+BuildRequires: pkgconfig(dpm)
+BuildRequires: pkgconfig(dlog)
%define _tests_dir /usr/apps/network-manager
Reference agent
%files agent
+%manifest %{_manifestdir}/agent.manifest
%attr(0755,root,root) %{_tests_dir}/agent