From: Sergei Kobec Date: Thu, 8 Sep 2016 10:19:34 +0000 (+0300) Subject: TizenRefApp-6920 Implement DPM support in Contacts Export/Import X-Git-Tag: submit/tizen/20160909.115235~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fe6c23a332675ca20b2528a1494d0d1b3a6f9573;p=profile%2Fmobile%2Fapps%2Fnative%2Fphone-contacts.git TizenRefApp-6920 Implement DPM support in Contacts Export/Import Implemented closing of app control during contacts import Change-Id: I5a0d74d8f981724b1da704fc3e35287d50b922d6 Signed-off-by: Sergei Kobec --- diff --git a/lib-contacts/inc/Contacts/Settings/ImportItem.h b/lib-contacts/inc/Contacts/Settings/ImportItem.h index 01443a0..0f65108 100644 --- a/lib-contacts/inc/Contacts/Settings/ImportItem.h +++ b/lib-contacts/inc/Contacts/Settings/ImportItem.h @@ -21,6 +21,8 @@ #include "App/AppControl.h" #include "Ui/GenItem.h" +#include + namespace Contacts { namespace Settings @@ -32,6 +34,13 @@ namespace Contacts */ class ImportItem : public Ui::GenItem { + public: + /** + * @brief Create genlist import item + * @param[in] handle DPM handle + */ + explicit ImportItem(device_policy_manager_h handle); + private: virtual char *getText(Evas_Object *parent, const char *part) override; virtual void onSelected() override; @@ -40,10 +49,14 @@ namespace Contacts void onImportFinish(ImportController *importer); void onStorageSelected(void *data); void onSimContactImport(int totalCount, int importedCount); + void onSdCardStateChanged(const char* name, const char* state); void importFromSim(); + void showPolicyPopup(); App::AppControl m_AppControl; + device_policy_manager_h m_DpmHandle; + int m_DpmCallbackId; }; } } diff --git a/lib-contacts/src/Contacts/Settings/ImportItem.cpp b/lib-contacts/src/Contacts/Settings/ImportItem.cpp index cc615f5..200eeed 100644 --- a/lib-contacts/src/Contacts/Settings/ImportItem.cpp +++ b/lib-contacts/src/Contacts/Settings/ImportItem.cpp @@ -20,6 +20,7 @@ #include "Contacts/Settings/Model/Storage.h" #include "App/AppControlRequest.h" +#include "Common/Dpm.h" #include "Ui/Genlist.h" #include "Ui/ListPopup.h" #include "Ui/ProcessPopup.h" @@ -32,6 +33,7 @@ using namespace Contacts::Settings; using namespace Contacts::Settings::Model; +using namespace Common::Dpm; using namespace std::placeholders; using namespace Ui; @@ -44,6 +46,11 @@ enum ImportStorageType ImportStorageSimCard }; +ImportItem::ImportItem(device_policy_manager_h handle) + : m_DpmHandle(handle), m_DpmCallbackId(0) +{ +} + char *ImportItem::getText(Evas_Object *parent, const char *part) { if (strcmp(part, "elm.text") == 0) { @@ -55,24 +62,22 @@ char *ImportItem::getText(Evas_Object *parent, const char *part) void ImportItem::onSelected() { - if (isAccessGranted(STORAGE_TYPE_EXTERNAL, StorageAccessRead)) { - ListPopup *popup = new ListPopup(); - popup->create(getParent()->getEvasObject()); - popup->setTitle("IDS_PB_HEADER_IMPORT"); + ListPopup *popup = new ListPopup(); + popup->create(getParent()->getEvasObject()); + popup->setTitle("IDS_PB_HEADER_IMPORT"); + if (isAllowed(m_DpmHandle, PolicySdCard) && isAccessGranted(STORAGE_TYPE_EXTERNAL, StorageAccessRead)) { popup->addItem("IDS_PB_OPT_SD_CARD", (void *) ImportStorageSdCard); - popup->addItem("IDS_PB_OPT_DEVICE", (void *) ImportStorageDevice); - - bool isSimInitialized = false; - contacts_sim_get_initialization_status_by_sim_slot_no(0, &isSimInitialized); - if (isSimInitialized) { - popup->addItem("IDS_PB_OPT_SIM_CARD", (void *) ImportStorageSimCard); - } + } + popup->addItem("IDS_PB_OPT_DEVICE", (void *) ImportStorageDevice); - popup->setSelectCallback(std::bind(&ImportItem::onStorageSelected, this, _1)); - popup->show(); - } else { - onStorageSelected((void *) ImportStorageDevice); + bool isSimInitialized = false; + contacts_sim_get_initialization_status_by_sim_slot_no(0, &isSimInitialized); + if (isSimInitialized) { + popup->addItem("IDS_PB_OPT_SIM_CARD", (void *) ImportStorageSimCard); } + + popup->setSelectCallback(std::bind(&ImportItem::onStorageSelected, this, _1)); + popup->show(); } void ImportItem::onPickResult(app_control_h request, app_control_h reply, @@ -107,12 +112,23 @@ void ImportItem::onStorageSelected(void *data) { ImportStorageType storageType = (ImportStorageType) (long) data; - if (storageType == ImportStorageSimCard) { - importFromSim(); - } else { - m_AppControl = App::requestPickVcard(getDirectoryPath((storage_type_e) storageType, - STORAGE_DIRECTORY_MAX).c_str()); - m_AppControl.launch(makeCallbackWithLastParam(&ImportItem::onPickResult), this); + switch (storageType) { + case ImportStorageSimCard: + importFromSim(); + break; + case ImportStorageSdCard: + if (!isAllowed(m_DpmHandle, PolicySdCard)) { + showPolicyPopup(); + return; + } + m_DpmCallbackId = addPolicyChangedCallback(m_DpmHandle, PolicySdCard, + makeCallbackWithLastParam(&ImportItem::onSdCardStateChanged), this); + //break is absent because launch of app control is also needed for SD card + case ImportStorageDevice: + m_AppControl = App::requestPickVcard(getDirectoryPath((storage_type_e) storageType, + STORAGE_DIRECTORY_MAX).c_str()); + m_AppControl.launch(makeCallbackWithLastParam(&ImportItem::onPickResult), this); + break; } } @@ -121,6 +137,17 @@ void ImportItem::onSimContactImport(int totalCount, int importedCount) //TODO Implement show of progress popup } +void ImportItem::onSdCardStateChanged(const char* name, const char* state) +{ + if (m_DpmCallbackId) { + m_AppControl.terminate(); + dpm_remove_policy_changed_cb(m_DpmHandle, m_DpmCallbackId); + m_DpmCallbackId = 0; + + showPolicyPopup(); + } +} + void ImportItem::importFromSim() { Ui::ProcessPopup *popup = Ui::ProcessPopup::create(getParent()->getEvasObject(), @@ -136,3 +163,13 @@ void ImportItem::importFromSim() WARN_IF_ERR(err, "notification_status_message_post() failed."); }); } + +void ImportItem::showPolicyPopup() +{ + char buf[BUFFER_SIZE] = { 0, }; + snprintf(buf, sizeof(buf), _("IDS_IDLE_TPOP_SECURITY_POLICY_PREVENTS_USE_OF_PS"), + _("IDS_PB_OPT_SD_CARD")); + + int err = notification_status_message_post(buf); + WARN_IF_ERR(err, "notification_status_message_post() failed."); +} diff --git a/lib-contacts/src/Contacts/Settings/MainView.cpp b/lib-contacts/src/Contacts/Settings/MainView.cpp index 43e60e1..3004e1a 100644 --- a/lib-contacts/src/Contacts/Settings/MainView.cpp +++ b/lib-contacts/src/Contacts/Settings/MainView.cpp @@ -44,7 +44,7 @@ Evas_Object *MainView::onCreate(Evas_Object *parent) auto groupItem = new Ui::GenGroupItem("IDS_PB_HEADER_MANAGE_AND_BACK_UP_CONTACTS_ABB2"); m_Genlist->insert(groupItem); m_Genlist->insert(new ExportItem(m_DpmHandle), groupItem); - m_Genlist->insert(new ImportItem(), groupItem); + m_Genlist->insert(new ImportItem(m_DpmHandle), groupItem); groupItem = new Ui::GenGroupItem("IDS_PB_HEADER_DISPLAY"); m_Genlist->insert(groupItem);