Apply implementation for /opt/usr lazy mount 12/84412/2 accepted/tizen/common/20160819.131314 accepted/tizen/ivi/20160821.235924 accepted/tizen/mobile/20160821.235834 accepted/tizen/tv/20160821.235851 accepted/tizen/wearable/20160821.235909 submit/tizen/20160819.082023
authorJihoon Jung <jh8801.jung@samsung.com>
Thu, 18 Aug 2016 11:02:00 +0000 (20:02 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Fri, 19 Aug 2016 02:33:44 +0000 (11:33 +0900)
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
Change-Id: I07725206ab00e6bee75faa1d089560d9694cb960

include/mtp_event_handler.h
include/util/mtp_util.h
src/entity/mtp_device.c
src/mtp_event_handler.c
src/mtp_init.c
src/util/mtp_util.c

index 2a20cea..e6d4c16 100755 (executable)
@@ -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);
 
index 45064be..b0c7bb2 100755 (executable)
@@ -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_ */
index 0539974..8bf6485 100755 (executable)
@@ -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;
index 72c3f3f..ccab66a 100755 (executable)
@@ -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(&current_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;
index 0cfe46f..85aa18a 100755 (executable)
@@ -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;
index 4518a1f..b9c8e18 100755 (executable)
@@ -29,6 +29,7 @@
 #include "mtp_support.h"
 #include "mtp_fs.h"
 #include <storage/storage.h>
+#include <sys/stat.h>
 
 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)
 {