From 7628c4859c56b988ac5b6a6b2bfc391b8d890167 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Thu, 18 Aug 2016 20:02:00 +0900 Subject: [PATCH] Apply implementation for /opt/usr lazy mount Signed-off-by: Jihoon Jung Change-Id: I07725206ab00e6bee75faa1d089560d9694cb960 --- include/mtp_event_handler.h | 1 + include/util/mtp_util.h | 5 ++++ src/entity/mtp_device.c | 13 ++++++++--- src/mtp_event_handler.c | 39 ++++++++++++++++++++++++++++--- src/mtp_init.c | 57 ++++++++++++++++++++++++++++----------------- src/util/mtp_util.c | 32 +++++++++++++++++++++++++ 6 files changed, 119 insertions(+), 28 deletions(-) diff --git a/include/mtp_event_handler.h b/include/mtp_event_handler.h index 2a20cea..e6d4c16 100755 --- a/include/mtp_event_handler.h +++ b/include/mtp_event_handler.h @@ -58,6 +58,7 @@ mtp_bool _eh_register_notification_callbacks(void); mtp_bool _eh_handle_usb_events(mtp_uint32 type); void _eh_deregister_notification_callbacks(void); void _handle_mmc_notification(keynode_t *key, void *data); +void _handle_lock_status_notification(keynode_t *key, void *data); void _eh_send_event_req_to_eh_thread(event_code_t action, mtp_ulong param1, mtp_ulong param2, void *param3); diff --git a/include/util/mtp_util.h b/include/util/mtp_util.h index 45064be..b0c7bb2 100755 --- a/include/util/mtp_util.h +++ b/include/util/mtp_util.h @@ -76,6 +76,8 @@ typedef enum { MTP_PHONE_MMC_INSERTED, MTP_PHONE_MMC_NONE, MTP_PHONE_USB_MODE_OTHER, + MTP_PHONE_LOCK_ON, + MTP_PHONE_LOCK_OFF, } phone_status_t; typedef struct { @@ -141,6 +143,9 @@ void _util_set_local_mmc_status(const phone_status_t val); void _util_get_usbmode_status(phone_status_t *val); phone_status_t _util_get_local_usbmode_status(void); void _util_set_local_usbmode_status(const phone_status_t val); +void _util_get_lock_status(phone_status_t *val); +phone_status_t _util_get_local_lock_status(void); +void _util_set_local_lock_status(const phone_status_t val); void _util_get_external_path(char *external_path); void _util_get_internal_path(char *internal_path); #endif /* _MTP_UTIL_H_ */ diff --git a/src/entity/mtp_device.c b/src/entity/mtp_device.c index 0539974..8bf6485 100755 --- a/src/entity/mtp_device.c +++ b/src/entity/mtp_device.c @@ -705,13 +705,18 @@ mtp_bool _device_install_storage(mtp_int32 type) mtp_int32 int_status = TRUE; mtp_int32 ext_status = TRUE; mtp_bool mounted; + mtp_bool lock_status; switch (type) { case MTP_ADDREM_AUTO: DBG(" case MTP_ADDREM_AUTO:"); - int_status = _device_is_store_mounted(MTP_STORAGE_INTERNAL); - if (int_status == FALSE) - __add_store_to_device(MTP_STORAGE_INTERNAL); + + lock_status = _util_get_local_lock_status(); + if (lock_status == MTP_PHONE_LOCK_OFF) { + int_status = _device_is_store_mounted(MTP_STORAGE_INTERNAL); + if (int_status == FALSE) + __add_store_to_device(MTP_STORAGE_INTERNAL); + } mounted = _util_get_local_mmc_status(); if (mounted == MTP_PHONE_MMC_INSERTED) { @@ -725,6 +730,8 @@ mtp_bool _device_install_storage(mtp_int32 type) case MTP_ADDREM_INTERNAL: DBG("case MTP_ADDREM_INTERNAL:"); + if (MTP_PHONE_LOCK_OFF != _util_get_local_lock_status()) + break; if (FALSE == _device_is_store_mounted(MTP_STORAGE_INTERNAL)) __add_store_to_device(MTP_STORAGE_INTERNAL); break; diff --git a/src/mtp_event_handler.c b/src/mtp_event_handler.c index 72c3f3f..ccab66a 100755 --- a/src/mtp_event_handler.c +++ b/src/mtp_event_handler.c @@ -78,13 +78,14 @@ mtp_bool _eh_register_notification_callbacks(void) return FALSE; } + _util_get_lock_status(&val); + _util_set_local_lock_status(val); _util_get_mmc_status(&val); _util_set_local_mmc_status(val); - DBG("Phone status: USB = [%d] MMC = [%d] USB_MODE = [%d]\n", + DBG("Phone status: USB = [%d] MMC = [%d] USB_MODE = [%d] LOCK_STATUS = [%d]\n", _util_get_local_usb_status(), _util_get_local_mmc_status(), - _util_get_local_usbmode_status()); - + _util_get_local_usbmode_status(), _util_get_local_lock_status()); return TRUE; } @@ -371,6 +372,38 @@ static void __handle_usb_mode_notification(keynode_t *key, void *data) return; } +void _handle_lock_status_notification(keynode_t *key, void *data) +{ + phone_status_t previous_val = MTP_PHONE_LOCK_ON; + phone_status_t current_val = MTP_PHONE_LOCK_ON; + + previous_val = _util_get_local_lock_status(); + _util_get_lock_status(¤t_val); + + if (previous_val == current_val) { + return; + } + + _util_set_local_lock_status(current_val); + + if (MTP_PHONE_LOCK_OFF == current_val) { + _device_install_storage(MTP_ADDREM_INTERNAL); + __send_events_from_device_to_pc(MTP_INTERNAL_STORE_ID, + PTP_EVENTCODE_STOREADDED, 0, 0); + + media_content_connect(); + } else if (MTP_PHONE_LOCK_ON == current_val) { + _device_uninstall_storage(MTP_ADDREM_INTERNAL); + + __send_events_from_device_to_pc(MTP_INTERNAL_STORE_ID, + PTP_EVENTCODE_STOREREMOVED, 0, 0); + + media_content_disconnect(); + } + + return; +} + void _handle_mmc_notification(keynode_t *key, void *data) { phone_status_t val = MTP_PHONE_MMC_NONE; diff --git a/src/mtp_init.c b/src/mtp_init.c index 0cfe46f..85aa18a 100755 --- a/src/mtp_init.c +++ b/src/mtp_init.c @@ -87,15 +87,20 @@ static void __mtp_exit(void) return; } +static gboolean __check_internal_storage (gpointer user_data) +{ + _handle_lock_status_notification(NULL, NULL); + + return true; +} + void _mtp_init(add_rem_store_t sel) { - mtp_char wmpinfopath[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; mtp_char *device_name = NULL; mtp_char *sync_partner = NULL; mtp_bool ret = 0; int vconf_ret = 0; mtp_int32 error = 0; - char inter_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; DBG("Initialization start!"); @@ -147,13 +152,24 @@ void _mtp_init(add_rem_store_t sel) } /* Internal Storage */ - _util_get_internal_path(inter_path); - if (access(inter_path, F_OK) < 0) { - if (FALSE == _util_dir_create((const mtp_char *)inter_path, &error)) { - ERR("Cannot make directory!! [%s]\n", - inter_path); + if (MTP_PHONE_LOCK_OFF == _util_get_local_lock_status()) { + mtp_int32 ret; + char inter_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 }; + + ret = media_content_connect(); + if (MEDIA_CONTENT_ERROR_NONE != ret) { + ERR("media_content_connect() Fail(%d)", ret); goto MTP_INIT_FAIL; } + + _util_get_internal_path(inter_path); + if (access(inter_path, F_OK) < 0) { + if (FALSE == _util_dir_create((const mtp_char *)inter_path, &error)) { + ERR("Cannot make directory!! [%s]\n", + inter_path); + goto MTP_INIT_FAIL; + } + } } /* External Storage */ if (MTP_PHONE_MMC_INSERTED == _util_get_local_mmc_status()) { @@ -167,15 +183,6 @@ void _mtp_init(add_rem_store_t sel) } } } -#ifndef MTP_SUPPORT_HIDE_WMPINFO_XML - /* Update WMPInfo.xml for preventing frequent saving */ - ret = _util_create_path(wmpinfopath, sizeof(wmpinfopath), - (const mtp_char *)inter_path, MTP_FILE_NAME_WMPINFO_XML); - if (FALSE == ret) { - ERR("szWMPInfoPath is too long"); - goto MTP_INIT_FAIL; - } -#endif /*MTP_SUPPORT_HIDE_WMPINFO_XML*/ /* Set mtpdeviceinfo */ _init_mtp_device(); @@ -189,6 +196,15 @@ void _mtp_init(add_rem_store_t sel) _inoti_init_filesystem_evnts(); #endif /*MTP_SUPPORT_OBJECTADDDELETE_EVENT*/ + vconf_ret = vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE_READ_ONLY, + _handle_lock_status_notification, NULL); + if (vconf_ret < 0) { + ERR("vconf_notify_key_changed(%s) Fail", VCONFKEY_IDLE_LOCK_STATE_READ_ONLY); + goto MTP_INIT_FAIL; + } + + g_timeout_add(1000, __check_internal_storage, NULL); + vconf_ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, _handle_mmc_notification, NULL); if (vconf_ret < 0) { @@ -220,6 +236,9 @@ void _mtp_deinit(void) _inoti_deinit_filesystem_events(); #endif /*MTP_SUPPORT_OBJECTADDDELETE_EVENT*/ + vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE_READ_ONLY, + _handle_lock_status_notification); + vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, _handle_mmc_notification); @@ -470,12 +489,6 @@ int main(int argc, char *argv[]) { mtp_int32 ret; - ret = media_content_connect(); - if (MEDIA_CONTENT_ERROR_NONE != ret) { - ERR("media_content_connect() Fail(%d)", ret); - return MTP_ERROR_GENERAL; - } - if (_eh_register_notification_callbacks() == FALSE) { ERR("_eh_register_notification_callbacks() Fail"); return MTP_ERROR_GENERAL; diff --git a/src/util/mtp_util.c b/src/util/mtp_util.c index 4518a1f..b9c8e18 100755 --- a/src/util/mtp_util.c +++ b/src/util/mtp_util.c @@ -29,6 +29,7 @@ #include "mtp_support.h" #include "mtp_fs.h" #include +#include static phone_state_t g_ph_status = { 0 }; @@ -298,6 +299,37 @@ void _util_set_local_usbmode_status(const phone_status_t val) return; } +void _util_get_lock_status(phone_status_t *val) +{ + mtp_int32 ret = 0; + + struct stat st; +/* + mtp_int32 state = 0; + + ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE_READ_ONLY, + &state); +*/ + ret = stat("/opt/usr/home", &st); + + if (ret == -1) + *val = MTP_PHONE_LOCK_ON; + else + *val = MTP_PHONE_LOCK_OFF; + return; +} + +phone_status_t _util_get_local_lock_status(void) +{ + return g_ph_status.lock_state; +} + +void _util_set_local_lock_status(const phone_status_t val) +{ + g_ph_status.lock_state = val; + return; +} + static bool _util_device_external_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data) { -- 2.7.4