#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <time.h>
#include <sys/time.h>
#include <ctype.h>
#include <pwd.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include <gio/gio.h>

#define LIBPHONE_PLUGIN_SO "/usr/lib/phone/libphone_plugin.so"

struct kdk_phone_dev {
    unsigned char pid[5];
    unsigned char vid[5];
    unsigned char serial[129];
};

typedef struct {
    unsigned int (*phone_dev_control)(struct kdk_phone_dev *dev);
    unsigned int (*phone_dev_file_control)(const char *process_name, struct kdk_phone_dev *dev);
} PhonePluginInterface;

void kylin_device_control_init();
void kylin_device_control_fini();
unsigned int phonectl_dev_control(const char *pid, const char *vid, const char *serial);
unsigned int phonectl_dev_file_control(const pid_t process_id, const char *pid, const char *vid, const char *serial);

int phonectl_init();
int phonectl_uninit();
int get_process_path_by_pid(char *path, const pid_t pid, size_t len);
int kysec_devctl_set_adb_status_api(int status);

typedef struct{
  char *path;
  char *vendor;
  char *model;
  char *vid;
  char *pid;
  char *serial;
} PhoneInfo;

//手机管控三种模式，非管控模式，只读模式，管控模式
#define  PHONE_NONE_CTRL_MODE         (access("/etc/read.perm" , 0) != -1)
#define  PHONE_READONLY_MODE          ((access("/etc/read.perm" , 0) != 0) && (access("/etc/phone.perm" , 0) != -1) )
#define  PHONE_CTRL_MODE              (access("/etc/phone.perm" , 0) != 0) 

#define MESSAGE_MAX_LEN  2048
#define BUF_MAX_LEN   512
#define SEPARATOR_LEN 16

void send_message(const char *module_name, const char *log_level, const char *device_status, const PhoneInfo *phone_info, const char *action, const char *device_control);
void kysec_security_free(PhoneInfo *info);
