--- /dev/null
+#
+# Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
+
+PROJECT(krate)
+
+IF(NOT DEFINED VERSION)
+ SET(VERSION "0.0.1")
+ENDIF(NOT DEFINED VERSION)
+
+INCLUDE(FindPkgConfig)
+
+IF(NOT CMAKE_BUILD_TYPE)
+ SET(CMAKE_BUILD_TYPE "DEBUG")
+ENDIF(NOT CMAKE_BUILD_TYPE)
+
+SET(KRATE_COMMON ${PROJECT_SOURCE_DIR}/common)
+SET(KRATE_API ${PROJECT_SOURCE_DIR}/api)
+SET(KRATE_LIB ${PROJECT_SOURCE_DIR}/lib)
+SET(KRATE_SERVER ${PROJECT_SOURCE_DIR}/server)
+SET(KRATE_VOLUME ${PROJECT_SOURCE_DIR}/volume)
+SET(KRATE_TOOLS ${PROJECT_SOURCE_DIR}/tools)
+SET(KRATE_MODULE ${PROJECT_SOURCE_DIR}/module)
+
+IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
+ SET(CXX_STD "c++0x")
+else()
+ SET(CXX_STD "c++11")
+endif()
+
+SET(COMPILE_BASE_FLAGS "-g -fPIC -Werror -Wall -Wl,--as-needed -Wl,--no-whole-archive")
+SET(CMAKE_C_FLAGS_PROFILING "${COMPILE_BASE_FLAGS} -O0 -pg")
+SET(CMAKE_CXX_FLAGS_PROFILING "${COMPILE_BASE_FLAGS} -O0 -pg -std=${CXX_STD} -fno-rtti")
+SET(CMAKE_C_FLAGS_DEBUG "${COMPILE_BASE_FLAGS} -O0 -ggdb")
+SET(CMAKE_CXX_FLAGS_DEBUG "${COMPILE_BASE_FLAGS} -O0 -ggdb -std=${CXX_STD} -fno-rtti")
+SET(CMAKE_C_FLAGS_RELEASE "${COMPILE_BASE_FLAGS} -O2 -DNDEBUG")
+SET(CMAKE_CXX_FLAGS_RELEASE "${COMPILE_BASE_FLAGS} -O2 -DNDEBUG -std=${CXX_STD} -fno-rtti")
+SET(CMAKE_C_FLAGS_CCOV "${COMPILE_BASE_FLAGS} -O0 --coverage")
+SET(CMAKE_CXX_FLAGS_CCOV "${COMPILE_BASE_FLAGS} -O0 --coverage -std=${CXX_STD} -fno-rtti")
+
+IF(NOT DEFINED LIB_DIR)
+ SET(LIB_DIR "${CMAKE_INSTALL_LIBDIR}")
+ENDIF(NOT DEFINED LIB_DIR)
+
+IF(NOT DEFINED INCLUDE_DIR)
+ SET(INCLUDE__DIR "${CMAKE_INSTALL_INCLUDEDIR}")
+ENDIF(NOT DEFINED INCLUDE_DIR)
+
+IF(NOT DEFINED RUN_DIR)
+ SET(RUN_DIR "/run")
+ENDIF(NOT DEFINED RUN_DIR)
+
+IF(NOT DEFINED BIN_DIR)
+ SET(BIN_DIR "${CMAKE_INSTALL_BINDIR}")
+ENDIF(NOT DEFINED BIN_DIR)
+
+IF(NOT DEFINED HOME_DIR)
+ SET(HOME_DIR "/home")
+ENDIF(NOT DEFINED HOME_DIR)
+
+IF(NOT DEFINED PAMD_DIR)
+ SET(PAMD_DIR "${SYSCONF_INSTALL_DIR}/pam.d")
+ENDIF(NOT DEFINED PAMD_DIR)
+
+IF(NOT DEFINED SYSTEMD_UNIT_DIR)
+ SET(SYSTEMD_UNIT_DIR "${CMAKE_INSTALL_PREFIX}/lib/systemd/system")
+ENDIF(NOT DEFINED SYSTEMD_UNIT_DIR)
+
+IF(NOT DEFINED CONF_DIR)
+ SET(CONF_INSTALL_DIR "${SYSCONF_INSTALL_DIR}/krate")
+ENDIF(NOT DEFINED CONF_DIR)
+
+ADD_DEFINITIONS(-DUG_WAYLAND)
+
+#ADD_SUBDIRECTORY(${KRATE_COMMON})
+ADD_SUBDIRECTORY(${KRATE_SERVER})
+#ADD_SUBDIRECTORY(${KRATE_VOLUME})
+#ADD_SUBDIRECTORY(${KRATE_LIB})
+#ADD_SUBDIRECTORY(${KRATE_MODULE})
+ADD_SUBDIRECTORY(${KRATE_TOOLS})
--- /dev/null
+Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_" />
+ </request>
+</manifest>
--- /dev/null
+#
+# Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+PROJECT(zone-provider)
+
+FILE(GLOB ZONE_PAM_SRCS zone-builder.cpp
+ session.cpp
+ zone.cpp
+)
+
+SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack")
+
+SET(ZONE_PAM_NAME "pam_zone")
+ADD_LIBRARY(${ZONE_PAM_NAME} MODULE ${ZONE_PAM_SRCS})
+SET_TARGET_PROPERTIES(${ZONE_PAM_NAME} PROPERTIES PREFIX ""
+ COMPILE_DEFINITIONS PID_FILE_PATH="${RUN_INSTALL_DIR}/zone"
+ COMPILE_FLAGS "-fvisibility=hidden"
+)
+
+FIND_PATH(PAM_INCLUDE_DIR NAMES security/pam_appl.h security/pam_ext.h security/pam_modules.h
+ HINTS ${PAM_ROOT_DIR} PATH_SUFFIXES include)
+FIND_LIBRARY(PAM_LIBRARY pam HINTS ${PAM_ROOT_DIR} PATH_SUFFIXES ${LIB_INSTALL_DIR})
+MARK_AS_ADVANCED(PAM_INCLUDE_DIR PAM_LIBRARY)
+
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PAM DEFAULT_MSG PAM_LIBRARY PAM_INCLUDE_DIR)
+
+INCLUDE_DIRECTORIES(${PAM_INCLUDE_DIR} ${DPM_COMMON})
+TARGET_LINK_LIBRARIES(${ZONE_PAM_NAME} ${PAM_LIBRARY} dpm-common pthread)
+
+TARGET_COMPILE_DEFINITIONS(${ZONE_PAM_NAME} PRIVATE
+ CONF_PATH="${CONF_INSTALL_DIR}"
+)
+
+INSTALL(TARGETS ${ZONE_PAM_NAME} DESTINATION ${LIB_INSTALL_DIR}/security)
+INSTALL(FILES data/DefaultZoneManifest.xml DESTINATION ${CONF_INSTALL_DIR}/zone RENAME owner.xml)
+INSTALL(FILES data/zone_indicator_icon.png DESTINATION /opt/data/dpm)
+INSTALL(FILES data/zone_noti_list_sub_icon.png DESTINATION /opt/data/dpm)
+INSTALL(FILES pam.d/systemd-user-zone DESTINATION ${PAMD_INSTALL_DIR})
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<manifest version="0.1.0">
+ <capability></capability>
+ <filesystem>
+ <!--<entry source="" target="" type="none" option="rw,bind" />-->
+ </filesystem>
+ <network>
+ <!--<interface name="eth0" address="10.254.34.232" netmask="" gateway="" />-->
+ </network>
+</manifest>
--- /dev/null
+account include system-auth
+session include system-auth
+session optional pam_systemd.so
+session required pam_zone.so
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/file.h>
+#include <string.h>
+#include <errno.h>
+#include <signal.h>
+
+#include "session.h"
+#include "exception.h"
+#include "filesystem.h"
+
+bool isValidSessionLeader(pid_t pid)
+{
+ runtime::File proc("/proc/" + std::to_string(pid));
+ return proc.exists();
+}
+
+void createSession(const runtime::User& user, const SessionBuilder& sessionBuilder)
+{
+ runtime::File file("/var/run/zone/" + user.getName());
+ if (file.exists()) {
+ if (isValidSessionLeader(getSessionLeader(user))) {
+ throw runtime::Exception("Session already opened");
+ }
+ file.remove();
+ } else {
+ file.makeBaseDirectory();
+ }
+
+ sessionBuilder(user);
+
+ file.create(0600);
+ file.lock();
+ file.chown(user.getUid(), user.getGid());
+ pid_t pid = ::getpid();
+ file.write(&pid, sizeof(pid_t));
+ file.unlock();
+}
+
+pid_t getSessionLeader(const runtime::User& user)
+{
+ runtime::File file("/var/run/zone/" + user.getName(), O_RDONLY);
+ file.lock();
+ pid_t pid = -1;
+ file.read(&pid, sizeof(pid_t));
+ file.unlock();
+
+ return pid;
+}
+
+void destroySession(const runtime::User& user)
+{
+ std::string path = "/var/run/zone/" + user.getName();
+ ::unlink(path.c_str());
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#ifndef __ZONE_SESSION_ENV_H__
+#define __ZONE_SESSION_ENV_H__
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <string>
+#include <functional>
+
+#include "auth/user.h"
+
+typedef std::function<void(const runtime::User& user)> SessionBuilder;
+
+bool isValidSessionLeader(pid_t pid);
+void createSession(const runtime::User& user, const SessionBuilder& sessionBuilder);
+pid_t getSessionLeader(const runtime::User& user);
+void destroySession(const runtime::User& user);
+
+#endif //!__ZONE_SESSION_ENV_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <sys/mount.h>
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <stdio.h>
+
+#include "zone-builder.h"
+
+#include "exception.h"
+#include "filesystem.h"
+
+ZoneBuilder::ZoneBuilder(const runtime::User& user, const std::string& manifestPath) :
+ name(user.getName()), uid(user.getUid()), gid(user.getGid())
+{
+ manifest.reset(xml::Parser::parseFile(manifestPath));
+}
+
+ZoneBuilder::~ZoneBuilder()
+{
+}
+
+void ZoneBuilder::bindFilesystemNode(const std::string& source, const std::string& target,
+ const std::string& type, const std::string& options,
+ bool create)
+{
+ if (create) {
+ runtime::File dir(target);
+ if (!dir.exists()) {
+ dir.makeDirectory(true, uid, gid);
+ }
+ }
+
+ runtime::Mount::mountEntry(source, target, type, options);
+}
+
+void ZoneBuilder::containerize(bool create)
+{
+ int nsFlags = CLONE_NEWIPC | CLONE_NEWNS;
+
+ if (::unshare(nsFlags)) {
+ throw runtime::Exception("Failed to unshare namespace");
+ }
+
+ if (::mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) == -1) {
+ throw runtime::Exception("Failed to mount root filesystem");
+ }
+
+ xml::Node::NodeList entries = manifest->evaluate("/manifest/filesystem/entry");
+ for (const xml::Node& entry : entries) {
+ bindFilesystemNode(entry.getProp("source"), entry.getProp("target"),
+ entry.getProp("type"), entry.getProp("options"));
+ }
+
+ bindFilesystemNode("/home/" + name,
+ "/home/" + name + "/.zone/" + name,
+ "none", "rw,bind");
+
+ bindFilesystemNode("/home/" + name + "/.zone", "/home",
+ "none", "rw,rbind");
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+ #ifndef __ZONE_BUILDER_H__
+ #define __ZONE_BUILDER_H__
+
+#include <string>
+#include <vector>
+#include <memory>
+
+#include "xml/parser.h"
+#include "xml/document.h"
+#include "auth/user.h"
+
+class ZoneBuilder {
+public:
+ ZoneBuilder(const runtime::User& user, const std::string& manifestPath);
+ virtual ~ZoneBuilder();
+
+ void containerize(bool create = true);
+
+protected:
+ void bindFilesystemNode(const std::string& source, const std::string& target,
+ const std::string& type, const std::string& options,
+ bool create = true);
+private:
+ std::string name;
+ uid_t uid;
+ gid_t gid;
+ std::unique_ptr<xml::Document> manifest;
+};
+
+ #endif //!__ZONE_BUILDER_H__
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __ZONE_GUARD_H__
+#define __ZONE_GUARD_H__
+
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <semaphore.h>
+
+#include <string>
+
+#include "exception.h"
+
+class ZoneGuard {
+public:
+ ZoneGuard(const std::string& name) :
+ zoneName(name),
+ semaphore(nullptr)
+ {
+ semaphore = ::sem_open(zoneName.c_str(), O_CREAT, 0700, 1);
+ if (semaphore == nullptr) {
+ throw runtime::Exception("Filed to create semaphore for zone guard");
+ }
+ }
+
+ ~ZoneGuard()
+ {
+ if (semaphore == nullptr) {
+ return;
+ }
+
+ ::sem_post(semaphore);
+ ::sem_close(semaphore);
+ ::sem_unlink(zoneName.c_str());
+ }
+
+ void wait()
+ {
+ while ((::sem_wait(semaphore) == -1) && (errno == EINTR));
+ }
+
+private:
+ std::string zoneName;
+ sem_t* semaphore;
+};
+
+#endif //!__ZONE_GUARD_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#include <security/pam_ext.h>
+#include <security/pam_modules.h>
+#include <syslog.h>
+
+#include <string>
+#include <vector>
+
+#include "zone-guard.h"
+#include "zone-builder.h"
+#include "session.h"
+
+#include "exception.h"
+#include "filesystem.h"
+#include "xml/parser.h"
+#include "xml/document.h"
+
+#define ZONE_MANIFEST_DIR CONF_PATH "/zone/"
+
+std::string buildZoneManifestPath(const std::string& name)
+{
+ return ZONE_MANIFEST_DIR + name + ".xml";
+}
+
+std::string getZoneName(pam_handle_t* handle)
+{
+ const void* retItem;
+ int error = ::pam_get_item(handle, PAM_USER, &retItem);
+ if (error != PAM_SUCCESS) {
+ throw runtime::Exception("Failed to get user");
+ }
+
+ return static_cast<const char*>(retItem);
+}
+
+void openZoneSession(const std::string& name)
+{
+ auto sessionBuilder = [](const runtime::User& user) {
+ ZoneBuilder builder(user, buildZoneManifestPath(user.getName()));
+ builder.containerize();
+ };
+
+ createSession(runtime::User(name), sessionBuilder);
+}
+
+void closeZoneSession(const std::string& name)
+{
+ destroySession(runtime::User(name));
+}
+
+extern "C" {
+PAM_EXTERN __attribute__((visibility("default")))
+int pam_sm_open_session(pam_handle_t* pamh, int flags, int argc, const char* argv[])
+{
+ try {
+ std::string name = getZoneName(pamh);
+ ZoneGuard zoneGuard(name);
+ zoneGuard.wait();
+
+ openZoneSession(name);
+ } catch (runtime::Exception& e) {
+ ::pam_syslog(pamh, LOG_ERR, "%s", e.what());
+ return PAM_SESSION_ERR;
+ }
+
+ return PAM_SUCCESS;
+}
+
+PAM_EXTERN __attribute__((visibility("default")))
+int pam_sm_close_session(pam_handle_t* pamh, int flags, int argc, const char* argv[])
+{
+ try {
+ std::string name = getZoneName(pamh);
+ ZoneGuard zoneGuard(name);
+ zoneGuard.wait();
+
+ closeZoneSession(name);
+ } catch (runtime::Exception& e) {
+ ::pam_syslog(pamh, LOG_ERR, "%s", e.what());
+ return PAM_SESSION_ERR;
+ }
+
+ return PAM_SUCCESS;
+}
+
+#ifdef PAM_MODULE_ENTRY
+PAM_MODULE_ENTRY("pam_zone");
+#endif
+
+}
--- /dev/null
+Name: krate
+Version: 0.0.1
+Release: 0
+License: Apache-2.0
+Source0: file://%{name}-%{version}.tar.gz
+Summary: Tizen Krate Manager
+Group: Security/Other
+BuildRequires: gcc
+BuildRequires: cmake
+BuildRequires: pam-devel
+BuildRequires: gettext-tools
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(libxml-2.0)
+BuildRequires: pkgconfig(bundle)
+BuildRequires: pkgconfig(pkgmgr)
+BuildRequires: pkgconfig(pkgmgr-info)
+BuildRequires: pkgconfig(aul)
+BuildRequires: pkgconfig(appsvc)
+BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(security-privilege-manager)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(capi-system-system-settings)
+BuildRequires: pkgconfig(notification)
+BuildRequires: pkgconfig(key-manager)
+BuildRequires: pkgconfig(auth-fw-admin)
+
+%description
+The krate package provides a daemon which is responsible for managing each of
+krates.
+
+%files
+%manifest krate.manifest
+%defattr(644,root,root,755)
+#%attr(700,root,root) %{_sbindir}/zone-volume-manager
+#%attr(755,root,root) %{_bindir}/krate
+%{_unitdir}/krate.service
+#%{_unitdir}/multi-user.target.wants/krate.service
+
+%prep
+%setup -q
+
+%build
+%{!?build_type:%define build_type "RELEASE"}
+
+%if %{build_type} == "DEBUG" || %{build_type} == "PROFILING" || %{build_type} == "CCOV"
+ CFLAGS="$CFLAGS -Wp,-U_FORTIFY_SOURCE"
+ CXXFLAGS="$CXXFLAGS -Wp,-U_FORTIFY_SOURCE"
+%endif
+
+%{!?profile:%define profile "mobile"}
+
+%cmake . -DVERSION=%{version} \
+ -DCMAKE_BUILD_TYPE=%{build_type} \
+ -DTIZEN_PROFILE_NAME=%{profile} \
+ -DRUN_DIR=%{TZ_SYS_RUN} \
+ -DBIN_DIR=%{TZ_SYS_BIN} \
+ -DHOME_DIR=%{TZ_SYS_HOME} \
+ -DSYSTEMD_UNIT_DIR=%{_unitdir} \
+ -DPAMD_DIR=/etc/pam.d \
+ -DCONF_DIR=%{TZ_SYS_ETC}/krate \
+ -DAPP_INSTALL_PREFIX="%{TZ_SYS_RO_APP}" \
+ -DAPP_ICON_DIR_PREFIX="%{TZ_SYS_RO_ICONS}" \
+ -DAPP_SHARE_PACKAGES_DIR="%{TZ_SYS_RO_PACKAGES}"
+
+make %{?jobs:-j%jobs}
+
+%install
+%make_install
+#mkdir -p %{buildroot}/%{_unitdir}/multi-user.target.wants
+#ln -s ../krate.service %{buildroot}/%{_unitdir}/multi-user.target.wants/krate.service
+
+%clean
+rm -rf %{buildroot}
+
+%preun
+
+%postun
+
+%if 0
+## Krate Client Package ########################################################
+%package -n libkrate
+Summary: Tizen Krate Client library
+Group: Development/Libraries
+BuildRequires: pkgconfig(capi-appfw-application)
+BuildRequires: pkgconfig(capi-appfw-package-manager)
+BuildRequires: pkgconfig(libtzplatform-config)
+Requires: %{name} = %{version}-%{release}
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+%description -n libkrate
+The libkrate package contains the libraries needed to control inside of the krate.
+
+%post -n libkrate -p /sbin/ldconfig
+
+%postun -n libkrate -p /sbin/ldconfig
+
+%files -n libkrate
+%manifest krate.manifest
+%defattr(644,root,root,755)
+%attr(755,root,root) %{_libdir}/libkrate.so.%{version}
+%{_libdir}/libkrate.so.0
+
+## Devel Package ##############################################################
+%package -n libkrate-devel
+Summary: Libraries and header files for krate client development
+Group: Development/Libraries
+Requires: libkrate = %{version}-%{release}
+
+%description -n libkrate-devel
+The libkrate-devel package includes the libraries and header files necessary for
+developing the krate client program.
+
+%files -n libkrate-devel
+%manifest krate.manifest
+%defattr(644,root,root,755)
+%{_libdir}/libkrate.so
+%{_includedir}/krate
+%{_libdir}/pkgconfig/krate.pc
+
+%endif
+
+## Krate Setup Wizard Package #################################################
+%package -n org.tizen.krate-setup-wizard
+Summary: Tizen Krate setup wizard Interface
+Group: Security/Other
+BuildRequires: pkgconfig(efl-extension)
+BuildRequires: pkgconfig(elementary)
+BuildRequires: pkgconfig(capi-appfw-application)
+BuildRequires: pkgconfig(evas)
+BuildRequires: pkgconfig(notification)
+BuildRequires: pkgconfig(zone)
+Requires: libzone = %{version}-%{release}
+
+%description -n org.tizen.krate-setup-wizard
+Tizen Krate setup wizard interface for zone
+
+%define setup_home %{TZ_SYS_RO_APP}/org.tizen.krate-setup-wizard
+
+%files -n org.tizen.krate-setup-wizard
+%defattr(-,root,root,-)
+%manifest tools/apps/setup-wizard/org.tizen.krate-setup-wizard.manifest
+%{setup_home}/bin/*
+%{setup_home}/res/*
+%{TZ_SYS_RO_PACKAGES}/org.tizen.krate-setup-wizard.xml
+
+## Kaskit package #####################################################
+%package -n org.tizen.kaskit
+Summary: Tizen Krate launcher Interface
+Group: Security/Other
+BuildRequires: pkgconfig(efl-extension)
+BuildRequires: pkgconfig(elementary)
+BuildRequires: pkgconfig(evas)
+BuildRequires: pkgconfig(capi-appfw-application)
+BuildRequires: pkgconfig(capi-appfw-package-manager)
+BuildRequires: pkgconfig(capi-appfw-app-manager)
+BuildRequires: pkgconfig(badge)
+
+%description -n org.tizen.kaskit
+Tizen Krate launcher interface
+
+%define launcher_home %{TZ_SYS_RO_APP}/org.tizen.kaskit
+
+%files -n org.tizen.kaskit
+%defattr(-,root,root,-)
+%manifest tools/apps/kaskit/org.tizen.kaskit.manifest
+%{launcher_home}/bin/*
+%{launcher_home}/res/*
+%{TZ_SYS_RO_PACKAGES}/org.tizen.kaskit.xml
+
+## Keyguard package #####################################################
+%package -n org.tizen.keyguard
+Summary: Tizen Krate keyguard Interface
+Group: Security/Other
+BuildRequires: pkgconfig(efl-extension)
+BuildRequires: pkgconfig(elementary)
+BuildRequires: pkgconfig(capi-appfw-application)
+BuildRequires: pkgconfig(evas)
+BuildRequires: pkgconfig(capi-ui-efl-util)
+BuildRequires: pkgconfig(auth-fw)
+BuildRequires: pkgconfig(shortcut)
+
+%description -n org.tizen.keyguard
+Tizen Krate keyguard interface
+
+%define keyguard_home %{TZ_SYS_RO_APP}/org.tizen.keyguard
+
+%files -n org.tizen.keyguard
+%defattr(-,root,root,-)
+%manifest tools/apps/keyguard/org.tizen.keyguard.manifest
+%{keyguard_home}/bin/*
+%{keyguard_home}/res/*
+%{TZ_SYS_RO_PACKAGES}/org.tizen.keyguard.xml
+
+%if 0
+## PAM Plugin Package ########################################################
+%package -n dpm-pam-krate
+Summary: PAM Plugin for zone policy in device policy manager
+Group: Development/Libraries
+Requires: systemd
+
+%description -n dpm-pam-krate
+PAM Plugin for zone policy in device policy manager and CLI tool
+
+%post -n dpm-pam-krate
+mv /etc/pam.d/systemd-user /etc/pam.d/systemd-user.keep
+cp /etc/pam.d/systemd-user-zone /etc/pam.d/systemd-user
+
+%postun -n dpm-pam-krate
+mv /etc/pam.d/systemd-user.keep /etc/pam.d/systemd-user
+
+%files -n dpm-pam-krate
+%manifest krate.manifest
+%defattr(600,root,root,700)
+%attr(700,root,root) %{_libdir}/security/pam_*.so
+%attr(700,root,root) %{_sbindir}/krate-admin-cli
+%attr(700,root,root) %dir %{TZ_SYS_ETC}/krate
+%attr(600,root,root) %config %{TZ_SYS_ETC}/krate/owner.xml
+%attr(700,root,root) /etc/gumd/useradd.d/20_pam-krate-add.post
+%attr(700,root,root) /etc/gumd/userdel.d/20_pam-krate-remove.post
+%attr(644,root,root) %{TZ_SYS_RO_ICONS}/krate/indicator_icon.png
+%attr(644,root,root) %{TZ_SYS_RO_ICONS}/krate/noti_list_sub_icon.png
+%config /etc/pam.d/*
+%endif
--- /dev/null
+#
+# Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+SET(TARGET ${PROJECT_NAME})
+
+CONFIGURE_FILE(systemd/krate.service.in systemd/krate.service)
+
+INSTALL(FILES systemd/krate.service DESTINATION ${SYSTEMD_UNIT_DIR})
--- /dev/null
+[Unit]
+Description=Krate
+
+[Service]
+Type=simple
+ExecStart=${TZ_SYS_BIN}/krate
+Restart=on-failure
+ExecReload=/bin/kill -HUP $MAINPID
+
+[Install]
+WantedBy=multi-user.target
--- /dev/null
+#
+# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+SET(KRATE_APPS ${KRATE_TOOLS}/apps)
+
+ADD_SUBDIRECTORY(${KRATE_APPS})
--- /dev/null
+#
+# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+FIND_PACKAGE(PkgConfig REQUIRED)
+PKG_CHECK_MODULES(EFL_APP REQUIRED
+ dlog
+ glib-2.0
+ bundle
+ efl-extension
+ elementary
+ capi-appfw-application
+ capi-ui-efl-util
+ evas
+)
+
+SET(KRATE_APPS_SETUP_WIZARD ${KRATE_APPS}/setup-wizard)
+SET(KRATE_APPS_LAUNCHER ${KRATE_APPS}/kaskit)
+SET(KRATE_APPS_KEYGUARD ${KRATE_APPS}/keyguard)
+
+ADD_SUBDIRECTORY(${KRATE_APPS_SETUP_WIZARD})
+ADD_SUBDIRECTORY(${KRATE_APPS_LAUNCHER})
+ADD_SUBDIRECTORY(${KRATE_APPS_KEYGUARD})
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(org.tizen.kaskit C)
+
+INCLUDE_DIRECTORIES(./include)
+
+FIND_PACKAGE(PkgConfig REQUIRED)
+PKG_CHECK_MODULES(KASKIT REQUIRED
+ capi-appfw-application
+ capi-appfw-package-manager
+ capi-appfw-app-manager
+ badge
+)
+
+INCLUDE_DIRECTORIES(${EFL_APP_INCLUDE_DIRS} ${KASKIT_INCLUDE_DIRS})
+LINK_DIRECTORIES(${EFL_APP_LIBRARY_DIRS} ${KASKIT_LIBRARY_DIRS})
+
+SET(PROJECT_SRC src/main.c
+ src/ui.c
+ src/widget.c)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${PROJECT_SRC})
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${APP_INSTALL_PREFIX}/${PROJECT_NAME}/bin)
+
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${EFL_APP_LIBRARIES} ${KASKIT_LIBRARIES})
+
+ADD_CUSTOM_TARGET(${PROJECT_NAME}.edj
+ COMMAND edje_cc -no-save -id ${CMAKE_CURRENT_SOURCE_DIR}/res/images
+ ${CMAKE_CURRENT_SOURCE_DIR}/res/edje/${PROJECT_NAME}.edc
+ ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.edj
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/res/edje/${PROJECT_NAME}.edc)
+
+ADD_DEPENDENCIES(${PROJECT_NAME} ${PROJECT_NAME}.edj)
+INSTALL(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.edj DESTINATION ${APP_INSTALL_PREFIX}/${PROJECT_NAME}/res)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/images/default_app_icon.png DESTINATION ${APP_INSTALL_PREFIX}/${PROJECT_NAME}/res/images)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.xml DESTINATION ${APP_SHARE_PACKAGES_DIR})
--- /dev/null
+/*
+ * Tizen Krate launcher application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef CONF_H_
+#define CONF_H_
+
+#define RESOLUTION_SCALE_W 1.0
+#define RESOLUTION_SCALE_H 1.0
+
+#define ICON_IMG_SIZE ((118) * (RESOLUTION_SCALE_W))
+#define ICON_TXT_SIZE_NORMAL ((int)((28) * (RESOLUTION_SCALE_H)))
+#define ICON_TXT_COLOR "000000FF"
+#define ICON_TXT_SHADOW_COLOR "88888888"
+
+#define ICON_SIZE_W ((720) * (RESOLUTION_SCALE_W) / 4)
+#define ICON_SIZE_H ((1060) * (RESOLUTION_SCALE_H) / 5)
+
+#define MAX_BADGE_DISPLAY_COUNT 999
+
+#define ALLOWED_ICON_DRAG_DISTANCE 100
+#define LONG_PRESS_TIME 0.75
+
+#endif /* CONF_H_ */
--- /dev/null
+/*
+ * Tizen Krate launcher application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __KASKIT_H__
+#define __KASKIT_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <app.h>
+#include <app_common.h>
+#include <bundle.h>
+#include <dlog.h>
+#include <Elementary.h>
+#include <efl_extension.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "org.tizen.kaskit"
+
+#if !defined(PACKAGE)
+#define PACKAGE "org.tizen.kaskit"
+#endif
+
+typedef struct {
+ Evas_Object* win;
+ Evas_Object* conform;
+ Evas_Object* layout;
+ Evas_Object* panel;
+ Evas_Object* scroller;
+ Evas_Object* app_view;
+ Eina_List* app_icon_list;
+ char* edj_path;
+} uidata_s;
+
+void _create_kaskit_window();
+void _set_kaskit_window_title(const char *title);
+
+void _create_app_icon(const char* pkg_id, const char* app_id, const char* label, const char* icon, bool removable);
+void _destroy_app_icon(const char* pkg_id);
+void _update_app_icon_badge(const char* app_id, unsigned int count);
+
+void _icon_clicked_cb(const char *app_id);
+void _icon_uninstalled_cb(const char *app_id);
+
+#endif /* __KASKIT_H__ */
--- /dev/null
+/*
+ * Tizen Krate launcher application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef WIDGET_H_
+#define WIDGET_H_
+
+#include <app.h>
+#include <dlog.h>
+#include <Elementary.h>
+#include <efl_extension.h>
+
+Evas_Object *_create_win(const char *package);
+Evas_Object *_create_conformant(Evas_Object *parent);
+Evas_Object *_create_layout(Evas_Object *parent, char *file, const char *group);
+
+#endif /* WIDGET_H_ */
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_" />
+ </request>
+</manifest>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest xmlns="http://tizen.org/ns/packages" api-version="3.0" package="org.tizen.kaskit" version="1.0.0">
+ <profile name="mobile"/>
+ <privileges>
+ <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+ <privilege>http://tizen.org/privilege/packagemanager.info</privilege>
+ <privilege>http://tizen.org/privilege/packagemanager.admin</privilege>
+ <privilege>http://tizen.org/privilege/notification</privilege>
+ </privileges>
+ <ui-application appid="org.tizen.kaskit" exec="/usr/apps/org.tizen.kaskit/bin/org.tizen.kaskit" multiple="false" nodisplay="true" taskmanage="true" type="capp">
+ <label>Kaskit</label>
+ </ui-application>
+</manifest>
--- /dev/null
+#include "../../include/conf.h"
+
+images {
+ image: "app_press_117.png" COMP;
+ image: "btn_delete_nor.png" COMP;
+ image: "btn_delete_press.png" COMP;
+ image: "icon_badge_container.png" COMP;
+ image: "folder_appicon_bg.png" COMP;
+ image: "sub_badge.png" COMP;
+}
+
+styles {
+ style{
+ name: "icon_label";
+ base: "font=Tizen:style=Regular align=center color=#FFFFFFFF style=shadow,bottom shadow_color=#000000FF font_size=26 ellipsis=1.0 wrap=mixed";
+ }
+ style{
+ name: "icon_label_edit";
+ base: "font=Tizen:style=Regular align=center color=#FFFFFFFF style=shadow,bottom shadow_color=#000000FF font_size=23 ellipsis=1.0 wrap=mixed";
+ }
+}
+
+group { name: "icon";
+ parts {
+ part { name: "bg";
+ type: RECT;
+ mouse_events: 1;
+ repeat_events: 1;
+ description {
+ state: "default" 0.0;
+ align: 0 0;
+ rel1{relative: 0.0 0.0; offset: 0 0;}
+ rel2{relative: 0.0 0.0; offset: ICON_SIZE_W ICON_SIZE_H;}
+ visible: 0;
+ }
+ } //"bg"
+
+ part { name: "icon_content";
+ type: SWALLOW;
+ description {
+ state: "default" 0.0;
+ rel1{relative: 0.16 0; to: "bg";}
+ rel2{relative: 0.84 0.6; to: "bg";}
+ align: 0.5 0.5;
+ }
+ } //"icon_content"
+
+ part { name: "icon_touch";
+ type: IMAGE;
+ mouse_events: 1;
+ repeat_events: 1;
+ scale: 1;
+ description {
+ state: "default" 0.0;
+ rel1{relative: 0.0 0.0; to: "icon_content";}
+ rel2{relative: 1.0 1.0; to: "icon_content";}
+ aspect: 1.0 1.0;
+ aspect_preference: BOTH;
+ color: 0 0 0 0;
+ image {
+ normal: "app_press_117.png";
+ }
+ }
+ description{
+ state: "icon_touched" 0.0;
+ inherit: "default" 0.0;
+ color: 0 0 0 250;
+ }
+ } //"icon_touch"
+
+ part { name: "app_icon_disable";
+ type: IMAGE;
+ mouse_events: 1;
+ repeat_events: 0;
+ scale: 1;
+ description {
+ state: "default" 0.0;
+ rel1{relative: 0.0 0.0; to: "icon_content";}
+ rel2{relative: 1.0 1.0; to: "icon_content";}
+ aspect: 1.0 1.0;
+ aspect_preference: BOTH;
+ color: 0 0 0 0;
+ image {
+ normal: "folder_appicon_bg.png";
+ }
+ visible: 0;
+ }
+ description{
+ state: "disable" 0.0;
+ inherit: "default" 0.0;
+ color: 0 0 0 150;
+ visible: 1;
+ }
+ } //"app_icon_disable"
+
+ part { name: "icon_name";
+ type: TEXTBLOCK;
+ mouse_events: 1;
+ repeat_events: 1;
+ description {
+ state: "default" 0.0;
+ rel1{relative: 0.04 0.6; to: "bg";}
+ rel2{relative: 0.95 0.98; to: "bg";}
+ color: 255 255 255 255;
+ text {
+ style: "icon_label";
+ align: 0.5 0.0;
+ }
+ }
+ description {
+ state: "disable" 0.0;
+ inherit: "default" 0.0;
+ color: 0 0 0 50;
+ }
+ description {
+ state: "hide" 0.0;
+ inherit: "default" 0.0;
+ visible: 0;
+ }
+ } //"icon_name"
+
+ part { name: "icon_badge";
+ type: IMAGE;
+ scale: 0;
+ description {
+ state: "default" 0.0;
+ rel1{relative: 0.0 0.0; offset: -10 -1; to: "badge_text";}
+ rel2{relative: 1.0 1.0; offset: 13 1; to: "badge_text";}
+ visible: 0;
+ image
+ {
+ normal: "icon_badge_container.png";
+ }
+ }
+ description {
+ state: "show" 0.0;
+ inherit: "default" 0.0;
+ visible: 1;
+ }
+ } //"icon_badge"
+
+ part { name: "badge_text";
+ type: TEXT;
+ scale: 1;
+ description {
+ state: "default" 0.0;
+ visible: 0;
+ fixed: 1 1;
+ color: 255 255 255 255;
+ rel1{relative: 0.95 -0.05; to: "icon_content";}
+ rel2{relative: 0.95 -0.05; to: "icon_content";}
+ align: 1.0 0.0;
+ text {
+ font: "arial";
+ size: 20;
+ text_class: "ATO002";
+ min: 1 1;
+ max: 1 1;
+ }
+ }
+ description {
+ state: "show" 0.0;
+ inherit: "default" 0.0;
+ visible: 1;
+ }
+ } //"badge_text"
+
+ part { name: "icon_sub_badge";
+ type: IMAGE;
+ scale: 0;
+ description {
+ state: "default" 0.0;
+ rel1{relative: 0.6 0.6; to: "icon_content";}
+ rel2{relative: 1.1 1.1; to: "icon_content";}
+ color: 255 255 255 255;
+ visible: 1;
+ aspect: 1.0 1.0;
+ aspect_preference: BOTH;
+ image
+ {
+ normal: "sub_badge.png";
+ }
+ }
+ description {
+ state: "hide" 0.0;
+ inherit: "default" 0.0;
+ visible: 0;
+ }
+ } //"icon_sub_badge"
+
+ part { name: "uninstall_btn";
+ type: IMAGE;
+ scale: 0;
+ description {
+ state: "default" 0.0;
+ rel1{relative: -0.1 -0.1; to: "icon_content";}
+ rel2{relative: 0.4 0.4; to: "icon_content";}
+ color: 255 255 255 0;
+ visible: 0;
+ aspect: 1.0 1.0;
+ aspect_preference: BOTH;
+ image {
+ normal: "btn_delete_nor.png";
+ }
+ }
+ description {
+ state: "show" 0.0;
+ inherit: "default" 0.0;
+ color: 255 255 255 255;
+ visible: 1;
+ }
+ description {
+ state: "press" 0.0;
+ inherit: "default" 0.0;
+ color: 255 255 255 255;
+ image {
+ normal: "btn_delete_press.png";
+ }
+ visible: 1;
+ }
+ } //"uninstall_btn"
+ }
+
+ programs {
+ program { name: "icon_touch_program";
+ signal: "mouse,down,1";
+ source: "icon_touch";
+ action: STATE_SET "icon_touched" 0.0;
+ target: "icon_touch";
+ transition: LINEAR 0.1;
+ }
+ program { name: "icon_touch_release_program";
+ signal: "mouse,up,1";
+ source: "icon_touch";
+ action: STATE_SET "default" 0.0;
+ target: "icon_touch";
+ transition: LINEAR 0.1;
+ }
+ program { name: "icon_sub_badge_show";
+ signal: "icon_sub_badge_show";
+ source: "source";
+ action: STATE_SET "default" 0.0;
+ target: "icon_sub_badge";
+ }
+ program { name: "icon_sub_badge_hide";
+ signal: "icon_sub_badge_hide";
+ source: "source";
+ action: STATE_SET "hide" 0.0;
+ target: "icon_sub_badge";
+ }
+ program { name: "uninstall_button_show";
+ signal: "uninstall_button_show";
+ source: "source";
+ action: STATE_SET "show" 0.0;
+ target: "uninstall_btn";
+ }
+ program { name: "uninstall_button_hide";
+ signal: "uninstall_button_hide";
+ source: "source";
+ action: STATE_SET "default" 0.0;
+ target: "uninstall_btn";
+ }
+ program { name: "uninstall_button_clicked";
+ signal: "mouse,clicked,1";
+ source: "uninstall_btn";
+ action: SIGNAL_EMIT "uninstall_button_clicked" "source";
+ }
+ program { name: "uninstall_button_mouse_down";
+ signal: "mouse,down,1";
+ source: "uninstall_btn";
+ action: STATE_SET "press" 0.0;
+ target: "uninstall_btn";
+ transition: DECELERATE 0.4;
+ }
+ program { name: "uninstall_button_mouse_up";
+ signal: "mouse,up,1";
+ source: "uninstall_btn";
+ action: STATE_SET "show" 0.0;
+ target: "uninstall_btn";
+ transition: DECELERATE 0.4;
+ }
+ program { name: "icon_badge_show";
+ signal: "icon_badge_show";
+ source: "source";
+ action: STATE_SET "show" 0.0;
+ target: "icon_badge";
+ target: "badge_text";
+ }
+ program { name: "icon_badge_hide";
+ signal: "icon_badge_hide";
+ source: "source";
+ action: STATE_SET "default" 0.0;
+ target: "icon_badge";
+ target: "badge_text";
+ }
+ program { name: "icon_disable";
+ signal: "icon_disable";
+ source: "source";
+ action: STATE_SET "disable" 0.0;
+ target: "app_icon_disable";
+ target: "icon_name";
+ }
+ program { name: "icon_enable";
+ signal: "icon_enable";
+ source: "source";
+ action: STATE_SET "default" 0.0;
+ target: "icon_name";
+ target: "app_icon_disable";
+ }
+ }
+}
--- /dev/null
+group { name: "main_window";
+ parts {
+ part { name: "bg";
+ type: RECT;
+ mouse_events: 1;
+ repeat_events: 0;
+ description { state: "default" 0.0;
+ color: 0 0 0 0;
+ rel1 {relative: 0.0 0.0;}
+ rel2 {relative: 1.0 1.0;}
+ }
+ }
+ part { name: "popup_window";
+ type: SWALLOW;
+ description { state: "default" 0.0;
+ rel1 {relative: 0.0 0.2; to: "bg"; offset: 22 0;}
+ rel2 {relative: 1.0 0.8; to: "bg"; offset: -22 0;}
+ }
+ }
+ programs {
+ program { name: "background_clicked_cb";
+ signal: "mouse,clicked,1";
+ source: "bg";
+ action: SIGNAL_EMIT "bg_clicked" "layout";
+ }
+ }
+ }
+}
+
+group { name: "popup_layout";
+ images{
+ image: "popup_bg.png" COMP;
+ }
+ parts {
+ part { name: "bg";
+ type: IMAGE;
+ description { state: "default" 0.0;
+ rel1 {relative: 0.0 0.0;}
+ rel2 {relative: 1.0 1.0;}
+ image {
+ normal: "popup_bg.png";
+ border: 5 5 5 5;
+ }
+ }
+ }
+ part { name: "separator";
+ type: RECT;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.07 62/569; to: "bg";}
+ rel2 {relative: 0.93 64/569; to: "bg";}
+ color: 7 180 211 250;
+ }
+ }
+ part { name: "popup_title_bg";
+ type: SWALLOW;
+ description { state: "default" 0.0;
+ rel1 {relative: 0.15 0; to: "bg";}
+ rel2 {relative: 0.85 62/569; to: "bg";}
+ color: 0 0 0 0;
+ visible: 0;
+ }
+ description { state: "done" 0.0;
+ inherit: "default" 0.0;
+ visible: 1;
+ }
+ }
+ part { name: "popup_title";
+ type: TEXT;
+ mouse_events: 1;
+ repeat_events: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 0.0; to: "popup_title_bg";}
+ rel2 { relative: 1.0 1.0; to: "popup_title_bg";}
+ color: 7 180 211 250;
+ visible: 1;
+ text {
+ text: "";
+ size: 40;
+ }
+ }
+ }
+ part { name: "popup_content";
+ type: SWALLOW;
+ description { state: "default";
+ rel1 {relative: 0.0 0.0; to_x: "bg"; to_y: "separator"; offset: 22 22;}
+ rel2 {relative: 1.0 1.0; to: "bg"; offset: -22 -22;}
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+collections {
+ base_scale: 1.8;
+ #include "launcher.edc"
+ #include "app_icon.edc"
+}
--- /dev/null
+/*
+ * Tizen Krate launcher application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <badge.h>
+#include <app_control.h>
+#include <app_manager.h>
+#include <package_manager.h>
+
+#include "kaskit.h"
+#include "widget.h"
+
+static package_manager_h __pkg_mgr;
+
+static const char* __pkg_blacklist[] = {
+ "org.tizen.setting",
+ "org.tizen.dpm-toolkit",
+ NULL
+};
+
+struct app_icon_s{
+ char* id;
+ char* label;
+ char* icon;
+ char* package;
+ bool removable;
+};
+
+static void* __create_app_icon(void* data)
+{
+ struct app_icon_s* app = (struct app_icon_s*)data;
+ unsigned int badge_show = 0, badge_count = 0;
+
+ _create_app_icon(app->package, app->id, app->label, app->icon, app->removable);
+
+ int ret = badge_get_display(app->id, &badge_show);
+ dlog_print(DLOG_ERROR, LOG_TAG, "badge_get_display err = %d", ret);
+ if (badge_show) {
+ ret =badge_get_count(app->id, &badge_count);
+ dlog_print(DLOG_ERROR, LOG_TAG, "badge_get_count err = %d", ret);
+ if (badge_count > 0) {
+ _update_app_icon_badge(app->id, badge_count);
+ }
+ }
+
+ return NULL;
+}
+
+static bool __pkg_is_removable(const char* pkg_id)
+{
+ bool removable = false;
+
+ package_info_h pkg_h;
+
+ package_info_create(pkg_id, &pkg_h);
+ package_info_is_removable_package(pkg_h, &removable);
+ package_info_destroy(pkg_h);
+
+ return removable;
+}
+
+static bool __pkg_is_in_blacklist(const char* pkg_id)
+{
+ int i;
+ for (i = 0; __pkg_blacklist[i] != NULL; i++) {
+ if (strcmp(pkg_id, __pkg_blacklist[i]) == 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+static bool __get_app_info_cb(app_info_h app_h, void* user_data)
+{
+ struct app_icon_s app = {NULL, };
+ bool nodisplay = true;
+
+ app_info_is_nodisplay(app_h, &nodisplay);
+ if (nodisplay) {
+ return true;
+ }
+
+ app_info_get_package(app_h, &app.package);
+
+ if (__pkg_is_in_blacklist(app.package)) {
+ free(app.package);
+ return true;
+ }
+
+ if (user_data == NULL || !strncmp(user_data, app.package, PATH_MAX)) {
+ app_info_get_app_id(app_h, &app.id);
+ app_info_get_label(app_h, &app.label);
+ app_info_get_icon(app_h, &app.icon);
+ app.removable = __pkg_is_removable(app.package);
+
+ ecore_main_loop_thread_safe_call_sync(__create_app_icon, &app);
+
+ free(app.id);
+ if (app.label != NULL) {
+ free(app.label);
+ }
+ if (app.icon != NULL) {
+ free(app.icon);
+ }
+ }
+
+ free(app.package);
+ return true;
+}
+
+static void __create_icon_thread(void* data, Ecore_Thread* thread) {
+ app_manager_foreach_app_info(__get_app_info_cb, data);
+ if (data != NULL) {
+ free(data);
+ }
+}
+
+static void __pkg_event_cb(const char* type,
+ const char* pkg_id,
+ package_manager_event_type_e event_type,
+ package_manager_event_state_e event_state, int progress,
+ package_manager_error_e error, void* user_data)
+{
+ if (event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) {
+ if (event_type == PACKAGE_MANAGER_EVENT_TYPE_INSTALL) {
+ ecore_thread_run(__create_icon_thread, NULL, NULL, strdup(pkg_id));
+ } else if (event_type == PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL) {
+ _destroy_app_icon(pkg_id);
+ }
+ }
+}
+
+static void __badge_changed_cb(unsigned int action, const char *app_id, unsigned int count, void *user_data) {
+ _update_app_icon_badge(app_id, count);
+}
+
+
+static char* __get_current_zone_name() {
+ struct passwd pwd, *result;
+ int bufsize;
+
+ bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
+ if (bufsize == -1) {
+ bufsize = 16384;
+ }
+
+ char* ret, *buf = malloc(bufsize * sizeof(char));
+
+ getpwuid_r(getuid(), &pwd, buf, bufsize, &result);
+ if (result == NULL) {
+ ret = NULL;
+ } else {
+ ret = strdup(result->pw_name);
+ }
+ free(buf);
+ return ret;
+}
+
+void _icon_clicked_cb(const char *app_id)
+{
+ app_control_h app_control;
+ app_control_create(&app_control);
+ app_control_set_app_id(app_control, app_id);
+ app_control_send_launch_request(app_control, NULL, NULL);
+ app_control_destroy(app_control);
+}
+
+void _icon_uninstalled_cb(const char *pkg_id)
+{
+ package_manager_request_h pkg_mgr_req;
+ int id;
+
+ package_manager_request_create(&pkg_mgr_req);
+ package_manager_request_uninstall(pkg_mgr_req, pkg_id, &id);
+ package_manager_request_destroy(pkg_mgr_req);
+}
+
+static void __show_launcher()
+{
+ char *zone_name = __get_current_zone_name();
+
+ _set_kaskit_window_title(zone_name);
+
+ package_manager_set_event_status(__pkg_mgr,
+ PACKAGE_MANAGER_STATUS_TYPE_INSTALL |
+ PACKAGE_MANAGER_STATUS_TYPE_UNINSTALL);
+ package_manager_set_event_cb(__pkg_mgr, __pkg_event_cb, NULL);
+
+ badge_register_changed_cb(__badge_changed_cb, NULL);
+
+ ecore_thread_run(__create_icon_thread, NULL, NULL, NULL);
+
+ free(zone_name);
+}
+
+static bool __app_create(void *data)
+{
+ package_manager_create(&__pkg_mgr);
+
+ _create_kaskit_window();
+ __show_launcher();
+
+ return true;
+}
+
+static void __app_control(app_control_h app_control, void *data)
+{
+}
+
+static void __app_pause(void *data)
+{
+}
+
+static void __app_resume(void *data)
+{
+}
+
+static void __app_terminate(void *data)
+{
+ package_manager_destroy(__pkg_mgr);
+}
+
+int main(int argc, char *argv[])
+{
+ int ret = 0;
+
+ ui_app_lifecycle_callback_s event_callback = {0, };
+
+ event_callback.create = __app_create;
+ event_callback.terminate = __app_terminate;
+ event_callback.pause = __app_pause;
+ event_callback.resume = __app_resume;
+ event_callback.app_control = __app_control;
+
+ ret = ui_app_main(argc, argv, &event_callback, NULL);
+ if (ret != APP_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main is failed. err = %d", ret);
+
+ return ret;
+}
--- /dev/null
+/*
+ * Tizen Krate launcher application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include "kaskit.h"
+#include "widget.h"
+#include "conf.h"
+
+static uidata_s ud = {0, };
+
+static int __num_of_apps = 0;
+static bool __is_edit_mode = false;
+static Ecore_Timer* __app_icon_long_press_timer = NULL;
+
+static void __block_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
+{
+ ui_app_exit();
+}
+
+static void __app_view_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ eina_list_free(ud.app_icon_list);
+}
+
+static void __set_kaskit_layout()
+{
+ ud.panel = _create_layout(ud.layout, ud.edj_path, "popup_layout");
+
+ elm_object_part_content_set(ud.layout, "popup_window", ud.panel);
+
+ ud.scroller = elm_scroller_add(ud.panel);
+ elm_scroller_bounce_set(ud.scroller, EINA_FALSE, EINA_TRUE);
+ elm_scroller_policy_set(ud.scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+ elm_object_part_content_set(ud.panel, "popup_content", ud.scroller);
+
+ ud.app_view = elm_table_add(ud.scroller);
+ elm_table_homogeneous_set(ud.app_view, EINA_TRUE);
+ elm_object_content_set(ud.scroller, ud.app_view);
+
+ evas_object_event_callback_add(ud.app_view, EVAS_CALLBACK_DEL, __app_view_del_cb, NULL);
+
+ return;
+}
+
+static char* __get_res_path(const char* file)
+{
+ char *res_path = NULL;
+ char edj_path[PATH_MAX] = "\0";
+
+ res_path = app_get_resource_path();
+ if (res_path == NULL) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed get resource path");
+ ui_app_exit();
+ }
+ snprintf(edj_path, PATH_MAX, "%s%s", res_path, file);
+
+ free(res_path);
+
+ return strdup(edj_path);
+}
+
+static void __back_key_cb(void *data , Evas_Object *obj , void *event_info)
+{
+ Evas_Object* icon;
+ Eina_List* i;
+
+ if (__is_edit_mode) {
+ __is_edit_mode = false;
+
+ EINA_LIST_FOREACH(ud.app_icon_list, i, icon) {
+ elm_object_signal_emit(icon, "uninstall_button_hide", "source");
+ elm_object_signal_emit(icon, "icon_sub_badge_show", "source");
+ }
+ } else {
+ ui_app_exit();
+ }
+}
+
+void _create_kaskit_window()
+{
+ ud.edj_path = __get_res_path(PACKAGE ".edj");
+ ud.win = _create_win(PACKAGE);
+ ud.conform = _create_conformant(ud.win);
+ ud.layout = _create_layout(ud.conform, ud.edj_path, "main_window");
+ elm_object_content_set(ud.conform, ud.layout);
+ eext_object_event_callback_add(ud.win, EEXT_CALLBACK_BACK, __back_key_cb, NULL);
+
+ elm_object_signal_callback_add(ud.layout, "bg_clicked", "layout", __block_clicked_cb, NULL);
+
+ __set_kaskit_layout();
+
+ evas_object_show(ud.win);
+
+ return;
+}
+
+static Eina_Bool __app_icon_long_press_cb(void *data)
+{
+ Evas_Object* icon;
+ Eina_List* i;
+
+ EINA_LIST_FOREACH(ud.app_icon_list, i, icon) {
+ if (evas_object_data_get(icon, "removable")) {
+ elm_object_signal_emit(icon, "uninstall_button_show", "source");
+ }
+ elm_object_signal_emit(icon, "icon_sub_badge_hide", "source");
+ }
+
+ __is_edit_mode = true;
+
+ return ECORE_CALLBACK_CANCEL;
+}
+
+void _set_kaskit_window_title(const char *title)
+{
+ elm_object_part_text_set(ud.panel, "popup_title", title);
+}
+
+static int __icon_down_x, __icon_down_y;
+static void __app_icon_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) {
+ Evas_Event_Mouse_Up* ev = event_info;
+
+ __icon_down_x = ev->output.x;
+ __icon_down_y = ev->output.y;
+
+ __app_icon_long_press_timer = ecore_timer_add(LONG_PRESS_TIME, __app_icon_long_press_cb, NULL);
+}
+
+static void __app_icon_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ Evas_Event_Mouse_Up* ev = event_info;
+
+ int distance_x = (ev->output.x - __icon_down_x);
+ int distance_y = (ev->output.y - __icon_down_y);
+ int distance = distance_x * distance_x + distance_y * distance_y;
+
+ if (distance > ALLOWED_ICON_DRAG_DISTANCE) {
+ if (__app_icon_long_press_timer != NULL) {
+ ecore_timer_del(__app_icon_long_press_timer);
+ __app_icon_long_press_timer = NULL;
+ }
+ }
+}
+
+static void __app_icon_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ Evas_Event_Mouse_Up* ev = event_info;
+
+ int distance_x = (ev->output.x - __icon_down_x);
+ int distance_y = (ev->output.y - __icon_down_y);
+ int distance = distance_x * distance_x + distance_y * distance_y;
+
+ if (distance <= ALLOWED_ICON_DRAG_DISTANCE && !__is_edit_mode) {
+ _icon_clicked_cb(evas_object_data_get(obj, "id"));
+ }
+
+ if (__app_icon_long_press_timer != NULL) {
+ ecore_timer_del(__app_icon_long_press_timer);
+ __app_icon_long_press_timer = NULL;
+ }
+}
+
+static void __app_icon_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ free(evas_object_data_get(obj, "id"));
+ free(evas_object_data_get(obj, "package"));
+}
+
+static void __app_icon_uninstall_btn_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
+{
+ _icon_uninstalled_cb(evas_object_data_get(obj, "package"));
+}
+
+void _create_app_icon(const char* pkg_id, const char* app_id, const char* label, const char* icon, bool removable)
+{
+ char string[1024] = {0, }, *default_icon;
+ Evas_Object *icon_layout;
+ Evas_Object *icon_image;
+
+ icon_layout = _create_layout(ud.app_view, ud.edj_path, "icon");
+ evas_object_size_hint_weight_set(icon_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(icon_layout, 0.0, 0.0);
+
+ icon_image = elm_image_add(icon_layout);
+ if (ecore_file_can_read(icon)) {
+ elm_image_file_set(icon_image, icon, NULL);
+ } else {
+ default_icon = __get_res_path("images/default_app_icon.png");
+ elm_image_file_set(icon_image, default_icon, NULL);
+ free(default_icon);
+ }
+ evas_object_size_hint_min_set(icon_image, ICON_IMG_SIZE, ICON_IMG_SIZE);
+ evas_object_size_hint_max_set(icon_image, ICON_IMG_SIZE, ICON_IMG_SIZE);
+
+ snprintf(string, sizeof(string), "<font_size=%d><color=#%s><shadow_color=#%s>%s</shadow_color></color></font_size>",
+ ICON_TXT_SIZE_NORMAL, ICON_TXT_COLOR, ICON_TXT_SHADOW_COLOR,
+ label);
+ elm_object_part_text_set(icon_layout, "icon_name", string);
+
+ elm_object_part_content_set(icon_layout, "icon_content", icon_image);
+
+ evas_object_data_set(icon_layout, "id", strdup(app_id));
+ evas_object_data_set(icon_layout, "package", strdup(pkg_id));
+ evas_object_data_set(icon_layout, "removable", (const void*)removable);
+
+ evas_object_event_callback_add(icon_layout, EVAS_CALLBACK_DEL, __app_icon_del_cb, NULL);
+ evas_object_event_callback_add(icon_layout, EVAS_CALLBACK_MOUSE_DOWN, __app_icon_down_cb, NULL);
+ evas_object_event_callback_add(icon_layout, EVAS_CALLBACK_MOUSE_MOVE, __app_icon_move_cb, NULL);
+ evas_object_event_callback_add(icon_layout, EVAS_CALLBACK_MOUSE_UP, __app_icon_up_cb, NULL);
+
+ elm_object_signal_callback_add(icon_layout, "uninstall_button_clicked", "source", __app_icon_uninstall_btn_clicked_cb, NULL);
+
+ elm_table_pack(ud.app_view, icon_layout, __num_of_apps % 3, __num_of_apps / 3, 1, 1);
+ evas_object_size_hint_min_set(ud.app_view, 0, (__num_of_apps / 3 + 1) * ICON_SIZE_H);
+
+ ud.app_icon_list = eina_list_append(ud.app_icon_list, icon_layout);
+
+ __num_of_apps++;
+
+ evas_object_show(icon_image);
+ evas_object_show(icon_layout);
+
+ if (__is_edit_mode && removable) {
+ elm_object_signal_emit(icon_layout, "uninstall_button_show", "source");
+ }
+}
+
+void _destroy_app_icon(const char* pkg_id)
+{
+ int index = 0;
+ Eina_List* i, *i_next;
+ Evas_Object* app_icon;
+ char *app_pkg_id;
+
+ EINA_LIST_FOREACH_SAFE(ud.app_icon_list, i, i_next, app_icon) {
+ app_pkg_id = evas_object_data_get(app_icon, "package");
+ if (strncmp(app_pkg_id, pkg_id, PATH_MAX)) {
+ elm_table_pack(ud.app_view, app_icon, index % 3, index / 3, 1, 1);
+ evas_object_size_hint_min_set(ud.app_view, 0, (__num_of_apps / 3 + 1) * ICON_SIZE_H);
+ index++;
+ continue;
+ }
+ elm_table_unpack(ud.app_view, app_icon);
+ evas_object_del(app_icon);
+ evas_object_size_hint_min_set(ud.app_view, 0, (__num_of_apps / 3 + 1) * ICON_SIZE_H);
+ ud.app_icon_list = eina_list_remove_list(ud.app_icon_list, i);
+ }
+ __num_of_apps--;
+ evas_object_size_hint_min_set(ud.app_view, 0, (__num_of_apps / 3 + 1) * ICON_SIZE_H);
+}
+
+void _update_app_icon_badge(const char* app_id, unsigned int count)
+{
+ Eina_List* i, *i_next;
+ Evas_Object* app_icon;
+ char str[8], *icon_app_id;
+
+ EINA_LIST_FOREACH_SAFE(ud.app_icon_list, i, i_next, app_icon) {
+ icon_app_id = evas_object_data_get(app_icon, "id");
+ if (strncmp(icon_app_id, app_id, PATH_MAX) == 0) {
+ if (count == 0) {
+ elm_object_signal_emit(app_icon, "icon_badge_hide", "source");
+ break;
+ }
+
+ if (count > MAX_BADGE_DISPLAY_COUNT) {
+ snprintf(str, 8, "%d+", MAX_BADGE_DISPLAY_COUNT);
+ } else {
+ snprintf(str, 8, "%d", count);
+ }
+ elm_layout_text_set(app_icon, "badge_text", str);
+ elm_object_signal_emit(app_icon, "icon_badge_show", "source");
+ break;
+ }
+ }
+}
--- /dev/null
+/*
+ * Tizen Zone Setup-Wizard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "widget.h"
+
+static void __win_delete_request_cb(void *data , Evas_Object *obj , void *event_info)
+{
+ ui_app_exit();
+}
+
+Evas_Object *_create_win(const char *package)
+{
+ Evas_Object *win;
+
+ elm_app_base_scale_set(1.8);
+
+ win = elm_win_add(NULL, package, ELM_WIN_BASIC);
+ elm_win_conformant_set(win, EINA_TRUE);
+ elm_win_autodel_set(win, EINA_TRUE);
+ elm_win_alpha_set(win, EINA_TRUE);
+
+ evas_object_smart_callback_add(win, "delete,request", __win_delete_request_cb, NULL);
+
+ return win;
+}
+
+Evas_Object *_create_conformant(Evas_Object *parent)
+{
+ Evas_Object *conform = elm_conformant_add(parent);
+
+ evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(parent, conform);
+
+ evas_object_show(conform);
+
+ return conform;
+}
+
+Evas_Object *_create_layout(Evas_Object *parent, char *file, const char *group)
+{
+ Evas_Object *layout = elm_layout_add(parent);
+
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ if (file == NULL)
+ elm_layout_theme_set(layout, "layout", "application", "default");
+ else
+ elm_layout_file_set(layout, file, group);
+
+ evas_object_show(layout);
+
+ return layout;
+}
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(org.tizen.keyguard C)
+
+INCLUDE_DIRECTORIES(./include)
+
+FIND_PACKAGE(PkgConfig REQUIRED)
+PKG_CHECK_MODULES(KEYGUARD REQUIRED
+ auth-fw
+ shortcut
+ zone
+)
+
+INCLUDE_DIRECTORIES(${EFL_APP_INCLUDE_DIRS} ${KEYGUARD_INCLUDE_DIRS})
+LINK_DIRECTORIES(${EFL_APP_LIBRARY_DIRS} ${KEYGUARD_LIBRARY_DIRS})
+
+SET(PROJECT_SRC src/main.c
+ src/ui.c
+ src/widget.c)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${PROJECT_SRC})
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${APP_INSTALL_PREFIX}/${PROJECT_NAME}/bin)
+
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${EFL_APP_LIBRARIES} ${KEYGUARD_LIBRARIES})
+
+ADD_CUSTOM_TARGET(${PROJECT_NAME}.edj
+ COMMAND edje_cc -no-save -id ${CMAKE_CURRENT_SOURCE_DIR}/res/images
+ ${CMAKE_CURRENT_SOURCE_DIR}/res/edje/${PROJECT_NAME}.edc
+ ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.edj
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/res/edje/${PROJECT_NAME}.edc)
+
+ADD_DEPENDENCIES(${PROJECT_NAME} ${PROJECT_NAME}.edj)
+INSTALL(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.edj DESTINATION ${APP_INSTALL_PREFIX}/${PROJECT_NAME}/res)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.xml DESTINATION ${APP_SHARE_PACKAGES_DIR})
--- /dev/null
+/*
+ * Tizen Zone Keyguard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __ZONE_KEYGUARD_H__
+#define __ZONE_KEYGUARD_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <app.h>
+#include <app_common.h>
+#include <bundle.h>
+#include <dlog.h>
+#include <Elementary.h>
+#include <efl_extension.h>
+#include <shortcut_manager.h>
+#include <auth-passwd.h>
+#include <zone/zone.h>
+#include <zone/app-proxy.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "keyguard"
+
+#if !defined(PACKAGE)
+#define PACKAGE "org.tizen.keyguard"
+#endif
+
+#define KEYGUARD_PACKAGE "org.tizen.keyguard"
+#define KASKIT_PACKAGE "org.tizen.kaskit"
+
+void _create_keyguard_window(void);
+void _launch_req_app(void);
+
+bool _has_password(void);
+bool _check_password(const char* password);
+unsigned int _get_left_attempts(void);
+
+#endif /* __ZONE_KEYGUARD_H__ */
--- /dev/null
+/*
+ * Tizen Zone Keyguard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef WIDGET_H_
+#define WIDGET_H_
+
+#include <app.h>
+#include <dlog.h>
+#include <Elementary.h>
+#include <efl_extension.h>
+
+Evas_Object *_create_win(const char *package);
+Evas_Object *_create_conformant(Evas_Object *parent);
+Evas_Object *_create_layout(Evas_Object *parent, char *file, const char *group);
+Evas_Object *_create_entry(Evas_Object *parent);
+Evas_Object *_create_popup(Evas_Object *parent, const char *title, const char *content, char *style);
+//Evas_Object *_create_button(Evas_Object *parent, const char *text, const char *style);
+
+#endif /* WIDGET_H_ */
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_" />
+ </request>
+</manifest>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest xmlns="http://tizen.org/ns/packages" api-version="3.0" package="org.tizen.keyguard" version="1.0.0">
+ <profile name="mobile"/>
+ <privileges>
+ <privilege>http://tizen.org/privilege/shortcut</privilege>
+ <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+ </privileges>
+ <ui-application appid="org.tizen.keyguard" exec="/usr/apps/org.tizen.keyguard/bin/org.tizen.keyguard" multiple="false" nodisplay="true" taskmanage="false" type="capp">
+ <label>Keyguard</label>
+ </ui-application>
+</manifest>
--- /dev/null
+/*
+ * Tizen Zone Keyguard Layout
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+group { name: "base_layout";
+ images {
+ image: "../images/theme_bg.png" COMP;
+ image: "../images/icon.png" COMP;
+ }
+ parts {
+ part { name: "bg";
+ type: IMAGE;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative : 0.0 0.0;}
+ rel2 { relative : 1.0 1.0;}
+ image.normal: "../images/theme_bg.png";
+ }
+ }
+ part { name: "icon";
+ type:IMAGE;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative : 0.0 0.0; to: "bg"; offset: 0 50;}
+ rel2 { relative : 1.0 0.2; to: "bg"; offset: 0 0;}
+ max: 110 110;
+ align: 0.5 0.5;
+ image.normal: "../images/icon.png";
+ }
+ }
+ part { name: "title";
+ type: TEXT;
+ scale: 1;
+ effect: SHADOW;
+ description { state: "default" 0.0;
+ color: 255 255 255 255;
+ color3: 85 88 88 255;
+ rel1 { relative: 0.0 1.0; to_x: "bg"; to_y: "icon"; offset: 22 22;}
+ rel2 { relative: 1.0 1.0; to_x: "bg"; to_y: "icon"; offset: -22 72;}
+ text { font: "Tizen:style=Regular"; size: "40"; align: 0.5 0.5; text: "Krate";}
+ }
+ }
+ part { name: "entry_info_text";
+ type: TEXT;
+ scale: 1;
+ description { state: "default" 0.0;
+ color: 255 255 255 255;
+ rel1 { relative: 0.0 1.0; to: "title"; offset: 0 80;}
+ rel2 { relative: 1.0 1.0; to: "title"; offset: 0 120;}
+ text { font: "Tizen:style=Regular"; size: "24"; align: 0.0 0.5; text: "Enter password";}
+ }
+ }
+ part { name: "entry_bg";
+ type: RECT;
+ scale: 1;
+ description { state: "default" 0.0;
+ color: 255 255 255 255;
+ rel1 { relative: 0.0 1.0; to: "entry_info_text"; offset: 0 22;}
+ rel2 { relative: 1.0 1.0; to: "entry_info_text"; offset: 0 82;}
+ }
+ }
+ part { name: "entry";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 0.0; to: "entry_bg";}
+ rel2 { relative: 1.0 1.0; to: "entry_bg";}
+ }
+ }
+ part { name: "check_box";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 0.4; to: "bg"; offset: 22 22;}
+ rel2 { relative: 0.1 0.4; to: "bg"; offset: 0 82;}
+ }
+ }
+ part { name: "check_text";
+ type: TEXT;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 1.0 0.0; to: "check_box"; offset: 22 0;}
+ rel2 { relative: 1.0 1.0; to_x: "bg"; to_y: "check_box"; offset: -22 0;}
+ text { font: "Tizen:style=Regular"; size: "24"; align: 0.0 0.5; text: "Show password";}
+ }
+ }
+ part { name: "bottom_text";
+ type: TEXT;
+ scale: 1;
+ description { state: "default" 0.0;
+ color: 255 255 255 255;
+ rel1 { relative: 0.0 0.6; to: "bg"; offset: 22 0;}
+ rel2 { relative: 1.0 0.6; to: "bg"; offset: -22 40;}
+ text { font: "Tizen:style=Regular"; size: "24"; align: 0.0 0.5; text: "Forgot your Krate unlock method?";}
+ }
+ }
+ programs {
+ program { name: "text_clicked_cb";
+ signal: "mouse,clicked,1";
+ source: "bottom_text";
+ action: SIGNAL_EMIT "text_clicked" "layout";
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+collections {
+ base_scale: 1.8;
+ #include "keyguard.edc"
+}
--- /dev/null
+/*
+ * Tizen Zone Keyguard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include "keyguard.h"
+#include "widget.h"
+
+static app_control_h __req_app_control;
+
+void _launch_req_app()
+{
+ app_control_send_launch_request(__req_app_control, NULL, NULL);
+ app_control_destroy(__req_app_control);
+}
+
+bool _check_password(const char* password)
+{
+ unsigned int attempt, max_attempt, expire_sec;
+ int ret;
+
+ ret = auth_passwd_check_passwd(AUTH_PWD_NORMAL, password, &attempt, &max_attempt, &expire_sec);
+
+ return ret == AUTH_PASSWD_API_SUCCESS;
+}
+
+bool _has_password()
+{
+ unsigned int attempt, max_attempt, expire_sec;
+ int ret;
+
+ ret = auth_passwd_check_passwd_state(AUTH_PWD_NORMAL, &attempt, &max_attempt, &expire_sec);
+
+ return ret != AUTH_PASSWD_API_ERROR_NO_PASSWORD;
+}
+
+unsigned int _get_left_attempts()
+{
+ unsigned int attempt = 0, max_attempt = 0, expire_sec;
+
+ auth_passwd_check_passwd_state(AUTH_PWD_NORMAL, &attempt, &max_attempt, &expire_sec);
+
+ if (max_attempt == 0) {
+ return 0xffffffff;
+ }
+
+ return max_attempt - attempt;
+}
+
+static void __launch_zone_app(const char* zone_name, app_control_h app_control)
+{
+ zone_manager_h zone_mgr;
+ zone_app_proxy_h zone_app;
+
+ zone_manager_create(&zone_mgr);
+ zone_app_proxy_create(zone_mgr, zone_name, &zone_app);
+ zone_app_proxy_send_launch_request(zone_app, app_control);
+ zone_app_proxy_destroy(zone_app);
+ zone_manager_destroy(zone_mgr);
+}
+
+static void __add_shortcut(const char* zone_name)
+{
+ char uri[PATH_MAX];
+
+ snprintf(uri, sizeof(uri), "zone://enter/%s", zone_name);
+ shortcut_add_to_home(zone_name, LAUNCH_BY_URI, uri, "", 0, NULL, NULL);
+}
+
+static bool __app_create(void *data)
+{
+ return true;
+}
+
+static void __app_pause(void *data)
+{
+ return;
+}
+
+static void __app_resume(void *data)
+{
+ return;
+}
+
+static void __app_terminate(void *data)
+{
+ return ;
+}
+
+static void __app_control(app_control_h app_control, void *data)
+{
+ char* uri, *tmp;
+ int ret = 0;
+
+ ret = app_control_get_uri(app_control, &uri);
+ if (ret != APP_CONTROL_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get URI");
+ ui_app_exit();
+ return;
+ }
+
+ if (strncmp(uri, "zone://", sizeof("zone://") - 1) != 0) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Mismatched URI");
+ free(uri);
+ ui_app_exit();
+ return;
+ }
+
+ tmp = uri + sizeof("zone://") - 1;
+
+ if (strncmp(tmp, "setup/", sizeof("setup/") - 1) == 0) {
+ char *zone_name;
+
+ zone_name = tmp + sizeof("setup/") - 1;
+ __add_shortcut(zone_name);
+ ui_app_exit();
+ return;
+ } else if (strncmp(tmp, "enter/", sizeof("enter/") - 1) == 0) {
+ char* zone_name, *launch_parameter;
+ char new_uri[PATH_MAX];
+
+ zone_name = tmp + sizeof("enter/") - 1;
+ launch_parameter = strchr(zone_name, '/');
+ if (launch_parameter != NULL) {
+ *(launch_parameter++) = '\0';
+ if (launch_parameter[0] == '\0') {
+ launch_parameter = KASKIT_PACKAGE;
+ }
+ } else {
+ launch_parameter = KASKIT_PACKAGE;
+ }
+ snprintf(new_uri, PATH_MAX, "zone://launch/%s", launch_parameter);
+ app_control_set_uri(app_control, new_uri);
+ app_control_set_app_id(app_control, PACKAGE);
+
+ dlog_print(DLOG_ERROR, LOG_TAG, "Wow");
+ dlog_print(DLOG_ERROR, LOG_TAG, PACKAGE);
+ dlog_print(DLOG_ERROR, LOG_TAG, new_uri);
+ dlog_print(DLOG_ERROR, LOG_TAG, zone_name);
+
+ __launch_zone_app(zone_name, app_control);
+ ui_app_exit();
+ return;
+ }else if (strncmp(tmp, "launch/", sizeof("launch/") - 1) == 0) {
+ char* app_id;
+
+ app_id = tmp + sizeof("launch/") - 1;
+ uri = strchr(app_id, '?');
+ if (uri != NULL) {
+ *(uri++) = '\0';
+ if (strncmp(uri, "uri=", sizeof("uri=") - 1) == 0) {
+ tmp += sizeof("uri=") - 1;
+ }
+ }
+ app_control_clone(&__req_app_control, app_control);
+ app_control_set_uri(__req_app_control, uri);
+ app_control_set_app_id(__req_app_control, app_id);
+
+ if (_has_password()) {
+ _create_keyguard_window();
+ } else {
+ _launch_req_app();
+ }
+ return;
+ } else {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Invalid URI");
+ ui_app_exit();
+ }
+ free(uri);
+}
+
+int main(int argc, char *argv[])
+{
+ int ret = 0;
+
+ ui_app_lifecycle_callback_s event_callback = {0, };
+
+ event_callback.create = __app_create;
+ event_callback.terminate = __app_terminate;
+ event_callback.pause = __app_pause;
+ event_callback.resume = __app_resume;
+ event_callback.app_control = __app_control;
+
+ ret = ui_app_main(argc, argv, &event_callback, NULL);
+ if (ret != APP_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main is failed. err = %d", ret);
+
+ return ret;
+}
--- /dev/null
+/*
+ * Tizen Zone Keyguard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include "keyguard.h"
+#include "widget.h"
+
+typedef struct {
+ Evas_Object *win;
+ Evas_Object *layout;
+ char *edj_path;
+} uidata_s;
+
+uidata_s ud = {0, };
+
+static void __change_info_text(const char *text)
+{
+ elm_object_part_text_set(ud.layout, "entry_info_text", text);
+}
+
+static void __entry_change_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ char text[32];
+ unsigned int attempts = _get_left_attempts();
+
+ if (attempts == 0xffffffff) {
+ snprintf(text, 32, "No limit to attempt");
+ } else {
+ snprintf(text, 32, "%u attempts left", attempts);
+ }
+ __change_info_text(text);
+}
+
+static void __checkbox_change_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *entry = (Evas_Object *)data;
+
+ if (elm_check_state_get(obj) == EINA_TRUE) {
+ elm_entry_password_set(entry, EINA_FALSE);
+ } else {
+ elm_entry_password_set(entry, EINA_TRUE);
+ }
+}
+
+static void __entry_activate_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ const char *input = elm_object_text_get(obj);
+
+ if (_check_password(input)) {
+ _launch_req_app();
+ ui_app_exit();
+ } else {
+ elm_entry_input_panel_hide(obj);
+ __change_info_text("Incorrect Password. Try again.");
+ if (_get_left_attempts() == 0) {
+ ui_app_exit();
+ }
+ }
+}
+
+static void __text_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
+{
+ Evas_Object *popup = _create_popup(ud.win, "Reset unlock method", "Contact your administrator to reset your Krate unlock method.", "default");
+ evas_object_show(popup);
+}
+
+void _create_keyguard_window(void)
+{
+ Evas_Object *conform;
+ Evas_Object *entry;
+ Evas_Object *checkbox;
+
+ char edj_path[PATH_MAX] = "\0";
+ char *res_path = NULL;
+
+ /* Get EDJ path */
+ res_path = app_get_resource_path();
+ if (res_path == NULL) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed get resource path");
+ ui_app_exit();
+ }
+ snprintf(edj_path, PATH_MAX, "%s%s", res_path, "org.tizen.keyguard.edj");
+
+ ud.edj_path = strdup(edj_path);
+ free(res_path);
+
+ /* Create main UI widget */
+ ud.win = _create_win(PACKAGE);
+ conform = _create_conformant(ud.win);
+ ud.layout = _create_layout(conform, ud.edj_path, "base_layout");
+
+ entry = _create_entry(ud.layout);
+ elm_object_part_content_set(ud.layout, "entry", entry);
+
+ evas_object_smart_callback_add(entry, "activated", __entry_activate_cb, NULL);
+ evas_object_smart_callback_add(entry, "press", __entry_change_cb, NULL);
+
+ checkbox = elm_check_add(ud.layout);
+ evas_object_smart_callback_add(checkbox, "changed", __checkbox_change_cb, entry);
+ elm_object_part_content_set(ud.layout, "check_box", checkbox);
+
+ elm_object_signal_callback_add(ud.layout, "text_clicked", "layout", __text_clicked_cb, NULL);
+
+ elm_object_content_set(conform, ud.layout);
+
+ evas_object_show(ud.win);
+ return;
+}
--- /dev/null
+/*
+ * Tizen Zone Keyguard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <efl_util.h>
+#include "widget.h"
+
+static void __win_delete_request_cb(void *data , Evas_Object *obj , void *event_info)
+{
+ ui_app_exit();
+}
+
+Evas_Object *_create_win(const char *package)
+{
+ Evas_Object *win;
+ elm_app_base_scale_set(1.8);
+
+ win = elm_win_add(NULL, package, ELM_WIN_NOTIFICATION);
+ efl_util_set_notification_window_level(win, EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT);
+ /* [TBD] enable : eext_win_keygrab_set(win, "XF86Home"); */
+
+ elm_win_conformant_set(win, EINA_FALSE);
+
+ evas_object_smart_callback_add(win, "delete,request", __win_delete_request_cb, NULL);
+
+ elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW);
+ elm_win_indicator_opacity_set(win, ELM_WIN_INDICATOR_TRANSPARENT);
+ eext_object_event_callback_add(win, EEXT_CALLBACK_BACK, __win_delete_request_cb, NULL);
+ return win;
+}
+
+Evas_Object *_create_conformant(Evas_Object *parent)
+{
+ Evas_Object *conform = elm_conformant_add(parent);
+
+ evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(parent, conform);
+ elm_object_signal_emit(conform, "elm,state,indicator,overlap", "elm");
+ evas_object_show(conform);
+
+ return conform;
+}
+
+Evas_Object *_create_layout(Evas_Object *parent, char *file, const char *group)
+{
+ Evas_Object *layout = elm_layout_add(parent);
+
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ if (file == NULL)
+ elm_layout_theme_set(layout, "layout", "application", "default");
+ else
+ elm_layout_file_set(layout, file, group);
+
+ evas_object_show(layout);
+
+ return layout;
+}
+
+Evas_Object *_create_entry(Evas_Object *parent)
+{
+ Evas_Object *entry = elm_entry_add(parent);
+ static Elm_Entry_Filter_Limit_Size limit_size = {
+ .max_char_count = 20,
+ .max_byte_count = 0,
+ };
+
+ evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_entry_password_set(entry, EINA_TRUE);
+ elm_entry_single_line_set(entry, EINA_TRUE);
+ elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_size);
+
+ evas_object_show(entry);
+ return entry;
+}
+
+Evas_Object *_create_button(Evas_Object *parent, const char *text)
+{
+ Evas_Object *btn = elm_button_add(parent);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, text);
+ return btn;
+}
+
+static void __popup_timeout_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ evas_object_del(obj);
+}
+
+static void __block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ evas_object_del(obj);
+}
+
+static void __popup_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *popup = (Evas_Object *)data;
+ evas_object_del(popup);
+}
+
+Evas_Object *_create_popup(Evas_Object *parent, const char *title, const char *content, char *style)
+{
+ Evas_Object *popup = elm_popup_add(parent);
+
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_object_style_set(popup, style);
+ elm_object_text_set(popup, content);
+
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, parent);
+ if (!strcmp(style, "toast")) {
+ elm_popup_timeout_set(popup, 3.0);
+ evas_object_smart_callback_add(popup, "timeout", __popup_timeout_cb, NULL);
+ evas_object_smart_callback_add(popup, "block,clicked", __block_clicked_cb, NULL);
+ } else if (!strcmp(style, "default")) {
+ elm_object_part_text_set(popup, "title,text", title);
+ elm_object_item_part_text_translatable_set(popup, "title,text", EINA_TRUE);
+
+ Evas_Object *btn = _create_button(popup, "OK");
+ elm_object_part_content_set(popup, "button1", btn);
+ evas_object_smart_callback_add(btn, "clicked", __popup_btn_clicked_cb, popup);
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
+ }
+
+ return popup;
+}
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(org.tizen.krate-setup-wizard C)
+
+INCLUDE_DIRECTORIES(./include)
+
+FIND_PACKAGE(PkgConfig REQUIRED)
+PKG_CHECK_MODULES(SETUP_WIZARD REQUIRED
+ notification
+ zone
+)
+
+INCLUDE_DIRECTORIES(${EFL_APP_INCLUDE_DIRS} ${SETUP_WIZARD_INCLUDE_DIRS})
+LINK_DIRECTORIES(${EFL_APP_LIBRARY_DIRS} ${SETUP_WIZARD_LIBRARY_DIRS})
+
+SET(PACKAGE_SRC src/main.c
+ src/ui.c
+ src/security.c
+ src/util.c
+ src/widget.c)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${PACKAGE_SRC})
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${APP_INSTALL_PREFIX}/${PROJECT_NAME}/bin)
+
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${EFL_APP_LIBRARIES} ${SETUP_WIZARD_LIBRARIES})
+
+ADD_CUSTOM_TARGET(${PROJECT_NAME}.edj
+ COMMAND edje_cc -no-save -id ${CMAKE_CURRENT_SOURCE_DIR}/res/images
+ ${CMAKE_CURRENT_SOURCE_DIR}/res/edje/${PROJECT_NAME}.edc
+ ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.edj
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/res/edje/${PROJECT_NAME}.edc)
+
+ADD_DEPENDENCIES(${PROJECT_NAME} ${PROJECT_NAME}.edj)
+INSTALL(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.edj DESTINATION ${APP_INSTALL_PREFIX}/${PROJECT_NAME}/res)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/data/KrateManifest.xml DESTINATION ${APP_INSTALL_PREFIX}/${PROJECT_NAME}/res/data)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.xml DESTINATION ${APP_SHARE_PACKAGES_DIR})
--- /dev/null
+/*
+ * Tizen Zone Setup-Wizard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SETUP_TEXT_H__
+#define __SETUP_TEXT_H__
+
+#define SUB_TITLE_STYLE_B "DEFAULT='font=Tizen:style=Regular font_size=40 color=#ffffff wrap=mixed align=center'"
+#define SUB_CONTENT_STYLE_B "DEFAULT='font=Tizen:style=Regular font_size=34 color=#ffffff wrap=mixed align=center'"
+
+#define SUB_TITLE_STYLE_W "DEFAULT='font=Tizen:style=Regular font_size=40 color=#000000 wrap=mixed align=center'"
+#define SUB_CONTENT_STYLE_W "DEFAULT='font=Tizen:style=Regular font_size=34 color=#000000 wrap=mixed align=center'"
+
+#define WELCOME_MESSAGE_TITLE "Welcome"
+#define WELCOME_MESSAGE_CONTENT "Use your applications separately<br>with SZ.<br>The folder will be created on your<br>personal home screen."
+
+#define DELETE_MESSAGE_TITLE "Deletion"
+#define DELETE_MESSAGE_CONTENT "The folder will be removed from<br> your personal home screen."
+
+#define SETUP_MESSAGE_TITLE "Creating Folder instance..."
+#define SETUP_MESSAGE_CONTENT "The folder will be created on your<br>presonal home screen."
+
+#define DELETE_ONGOING_TITLE "Deleting a folder..."
+#define DELETE_ONGOING_CONTENT "The folder will be removed from<br> your personal home screen."
+
+#define NOTI_CREATE_ZONE "Separated zone creation"
+#define NOTI_BODY_CREATE_ZONE "Tap heare to create Separated Zone."
+
+#define NOTI_REMOVE_ZONE "Separated Zone deletion"
+#define NOTI_BODY_REMOVE_ZONE "Tap here to delete Separated Zone."
+
+#define CANCEL_BUTTON "Cancel"
+#define NEXT_BUTTON "Next"
+#define SETUP_BUTTON "Set up"
+#define PREV_BUTTON "Previous"
+#define REMOVE_BUTTON "Remove"
+
+#endif /*__SETUP_TEXT_H__*/
--- /dev/null
+/*
+ * Tizen Zone Setup-Wizard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef WIDGET_H_
+#define WIDGET_H_
+
+#include <app.h>
+#include <dlog.h>
+#include <Elementary.h>
+#include <efl_extension.h>
+
+Evas_Object *_create_win(const char *package);
+Evas_Object *_create_conformant(Evas_Object *parent);
+Evas_Object *_create_layout(Evas_Object *parent, char *file, const char *group);
+Evas_Object *_create_button(Evas_Object *parent, const char *text, Evas_Smart_Cb callback, void *user_data);
+Evas_Object *_create_textblock(Evas_Object *parent, const char *text, char *style);
+Evas_Object *_create_progressbar(Evas_Object *parent, const char *style);
+Evas_Object *_create_entry(Evas_Object *parent);
+
+Elm_Genlist_Item_Class *_create_genlist_item_class(char *style, Elm_Genlist_Item_Text_Get_Cb text_func, Elm_Genlist_Item_Content_Get_Cb content_func);
+Elm_Object_Item *_append_genlist_item(Evas_Object *genlist, Elm_Genlist_Item_Class *itc, Elm_Object_Select_Mode select_mode, void* data);
+
+#endif /* WIDGET_H_ */
--- /dev/null
+/*
+ * Tizen Zone Setup-Wizard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __ZONE_SETUP_H__
+#define __ZONE_SETUP_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <app.h>
+#include <app_common.h>
+#include <bundle.h>
+#include <dlog.h>
+#include <Elementary.h>
+#include <efl_extension.h>
+#include <zone/zone.h>
+#include <zone/app-proxy.h>
+
+#include "setup-text.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "zone-setup-wizard"
+
+#if !defined(PACKAGE)
+#define PACKAGE "org.tizen.zone-setup-wizard"
+#endif
+
+#define KEYGUARD_PACKAGE "org.tizen.keyguard"
+#define KASKIT_PACKAGE "org.tizen.kaskit"
+
+#define DPM_SYSPOPUP_ICON_PATH "/usr/share/icons/default/small/org.tizen.dpm-syspopup.png"
+
+typedef struct {
+ char *mode;
+ char *zone_name;
+ char *zone_password;
+
+ zone_manager_h zone_manager;
+ int zone_event_cb_id;
+ bool request_done;
+
+ app_control_h app_control;
+} appdata_s;
+
+typedef struct {
+ Evas_Object *conform;
+ Evas_Object *nf;
+ char *edj_path;
+} uidata_s;
+
+void _create_base_window(appdata_s *data);
+void _create_security_view(appdata_s *data);
+void _create_setup_view(appdata_s *data);
+void _create_two_button_layout(Evas_Object *parent, Evas_Object *left_button, Evas_Object *right_button);
+
+int _send_zone_create_request(appdata_s *ad);
+int _send_zone_remove_request(appdata_s *ad);
+void _create_notification(app_control_h app_control);
+
+#endif /* __ZONE_SETUP_H__ */
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_" />
+ </request>
+</manifest>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest xmlns="http://tizen.org/ns/packages" api-version="3.0" package="org.tizen.krate-setup-wizard" version="1.0.0">
+ <profile name="mobile"/>
+ <privileges>
+ <privilege>http://tizen.org/privilege/notification</privilege>
+ <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+ </privileges>
+ <ui-application appid="org.tizen.krate-setup-wizard" exec="/usr/apps/org.tizen.krate-setup-wizard/bin/org.tizen.krate-setup-wizard" multiple="false" nodisplay="true" taskmanage="false" type="capp">
+ <label>Krate setup wzard</label>
+ </ui-application>
+</manifest>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<manifest version="0.1.0">
+ <capability></capability>
+ <filesystem>
+ <!--<entry source="" target="" type="none" option="rw,rbind" />-->
+ </filesystem>
+ <network>
+ <!--<interface name="eth0" address="10.254.34.232" netmask="" gateway="" />-->
+ </network>
+</manifest>
--- /dev/null
+/*
+ * Tizen Zone Setup-Wizard Layout
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+group { name: "base_layout";
+ parts {
+ part { name: "base";
+ type: RECT;
+ scale: 0;
+ repeat_events: 0;
+ description { state: "default" 0.0;
+ rel1 { relative : 0.0 0.0;}
+ rel2 { relative : 1.0 1.0;}
+ }
+ }
+ part { name: "content_layout";
+ type: SWALLOW;
+ scale: 0;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 0.0; to: "base";}
+ rel2 { relative: 1.0 0.0; to: "bottom_layout";}
+ }
+ }
+ part { name: "bottom_layout";
+ type: SWALLOW;
+ scale: 0;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 1.0; to: "base"; offset: 0 -162;}
+ rel2 { relative: 1.0 1.0; to: "base";}
+ }
+ }
+ }
+}
+
+group { name: "two_button_layout";
+ parts {
+ part { name: "base";
+ type: RECT;
+ scale: 0;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 0.0; }
+ rel2 { relative: 1.0 1.0; }
+ color: 255 255 255 255;
+ }
+ }
+ part { name: "prev_button";
+ type: SWALLOW;
+ scale: 0;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 0.0; to: "base"; offset: 22 22;}
+ rel2 { relative: 0.5 1.0; to: "base"; offset: -22 -22;}
+ }
+ }
+ part { name: "next_button";
+ type: SWALLOW;
+ scale: 0;
+ description { state: "default" 0.0;
+ rel1 { relative: 1.0 0.0; to_x: "prev_button"; to_y: "base"; offset: 22 22;}
+ rel2 { relative: 1.0 1.0; to: "base"; offset: -22 -22;}
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+collections {
+ base_scale: 1.8;
+ #include "layout.edc"
+ #include "welcome.edc"
+ #include "setup.edc"
+ #include "security.edc"
+}
--- /dev/null
+group { name: "security_layout";
+ parts {
+ part { name: "bg";
+ type: RECT;
+ scale: 0;
+ repeat_events: 0;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 0.0;}
+ rel2 { relative: 1.0 1.0;}
+ min: 720 600;
+ max: 720 800;
+ visible: 0;
+ }
+ }
+ part { name: "title";
+ type: TEXT;
+ scale: 0;
+ description { state: "default" 0.0;
+ color: 0 0 0 255;
+ rel1 { relative: 0.0 0.1; to: "bg"; offset: 45 0;}
+ rel2 { relative: 1.0 0.1; to: "bg"; offset: -45 40;}
+ text { font: "Tizen:style=Regular"; size: "32"; align: 0.0 0.5; }
+ }
+ }
+ part { name: "entry_bg";
+ type: RECT;
+ scale: 0;
+ description { state: "default" 0.0;
+ color: 255 255 255 0;
+ rel1 { relative: 0.0 0.2; to: "bg"; offset: 45 0;}
+ rel2 { relative: 1.0 0.2; to: "bg"; offset: -45 60;}
+ }
+ }
+ part { name: "entry";
+ type: SWALLOW;
+ scale: 0;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 0.0; to: "entry_bg";}
+ rel2 { relative: 1.0 1.0; to: "entry_bg";}
+ }
+ }
+ part { name: "entry_separator";
+ type: RECT;
+ scale: 0;
+ description { state: "default" 0.0;
+ color: 7 180 211 250;
+ rel1 { relative: 0.0 1.0; to: "entry";}
+ rel2 { relative: 1.0 1.0; to: "entry"; offset: 0 2;}
+ }
+ }
+ }
+}
--- /dev/null
+group { name: "setup_layout";
+ images {
+ image: "../images/icon.png" COMP;
+ }
+ parts {
+ part { name: "bg";
+ type: RECT;
+ scale: 1;
+ description { state: "default" 0.0;
+ color: 228 228 228 255;
+ rel1 { relative: 0.0 0.0; }
+ rel2 { relative: 1.0 1.0; }
+ }
+ }
+ part { name: "title";
+ type: TEXT;
+ scale: 1;
+ description { state: "default" 0.0;
+ color: 0 0 0 255;
+ rel1 { relative: 0.0 0.0; to: "bg"; offset: 22 150;}
+ rel2 { relative: 1.0 0.0; to: "bg"; offset: -22 300;}
+ text { font: "Tizen:style=Regular"; size: "48"; align: 0.5 0.5; text: "Separated Zone";}
+ }
+ }
+ part { name: "icon_base";
+ type: RECT;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 1.0; to_x: "bg"; to_y: "title"; offset: 0 80;}
+ rel2 { relative: 1.0 1.0; to_x: "bg"; to_y: "title"; offset: 0 350;}
+ visible: 0;
+ }
+ }
+ part { name: "icon";
+ type: IMAGE;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 0.0; to: "icon_base";}
+ rel2 { relative: 1.0 1.0; to: "icon_base";}
+ align: 0.5 0.0;
+ max: 170 170;
+ image.normal: "../images/icon.png";
+ }
+ }
+ part { name: "progressbar_msg";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 1.0; to_x: "bg"; to_y: "icon_base"; offset: 22 50;}
+ rel2 { relative: 1.0 1.0; to_x: "bg"; to_y: "icon_base"; offset: -22 150;}
+ }
+ }
+ part { name: "progressbar";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 1.0; to_x: "bg"; to_y: "progressbar_msg"; offset: 22 22;}
+ rel2 { relative: 1.0 1.0; to_x: "bg"; to_y: "progressbar_msg"; offset: -22 52;}
+ }
+ }
+ part { name: "content_text";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 1.0; to_x: "bg"; to_y: "progressbar"; offset: 22 0;}
+ rel2 { relative: 1.0 1.0; to: "bg"; offset: -22 0;}
+ }
+ }
+ part { name: "bottom_pending";
+ type: SPACER;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 1.0; to: "bg"; offset: 0 -162;}
+ rel2 { relative: 1.0 1.0; to: "bg";}
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Tizen Zone Setup-Wizard Layout
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+group { name: "welcome_layout";
+ images {
+ image: "../images/icon.png" COMP;
+ image: "../images/theme_bg.png" COMP;
+ }
+ parts {
+ part { name: "bg";
+ type: IMAGE;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 0.0; }
+ rel2 { relative: 1.0 1.0; }
+ image.normal: "../images/theme_bg.png";
+ }
+ }
+ part { name: "title";
+ type: TEXT;
+ scale: 1;
+ effect: SHADOW;
+ description { state: "default" 0.0;
+ color: 255 255 255 255;
+ color3: 85 88 88 255;
+ rel1 { relative: 0.0 0.0; to: "bg"; offset: 22 150;}
+ rel2 { relative: 1.0 0.0; to: "bg"; offset: -22 300;}
+ text { font: "Tizen:style=Regular"; size: "48"; align: 0.5 0.5; text: "Separated Zone";}
+ }
+ }
+ part { name: "icon_base";
+ type: RECT;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 1.0; to_x: "bg"; to_y: "title"; offset: 0 80;}
+ rel2 { relative: 1.0 1.0; to_x: "bg"; to_y: "title"; offset: 0 350;}
+ visible: 0;
+ }
+ }
+ part { name: "icon";
+ type: IMAGE;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 0.0; to: "icon_base";}
+ rel2 { relative: 1.0 1.0; to: "icon_base";}
+ align: 0.5 0.0;
+ max: 170 170;
+ image.normal: "../images/icon.png";
+ }
+ }
+ part { name: "top_padding";
+ type: RECT;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 1.0; to: "icon_base"; }
+ rel2 { relative: 1.0 1.0; to: "icon_base"; offset: 0 80;}
+ visible: 0;
+ }
+ }
+ part { name: "message_title";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 1.0; to: "top_padding";}
+ rel2 { relative: 1.0 1.0; to: "top_padding"; offset: 0 50;}
+ }
+ }
+ part { name: "message_content";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 { relative: 0.0 1.0; to: "message_title"; offset: 0 22;}
+ rel2 { relative: 1.0 1.0; to: "bg";}
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Tizen Zone Setup-Wizard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include "zone-setup.h"
+#include "widget.h"
+
+static void __launch_zone_app(zone_manager_h zone_mgr, const char* zone_name, app_control_h app_control)
+{
+ zone_app_proxy_h zone_app;
+
+ zone_app_proxy_create(zone_mgr, zone_name, &zone_app);
+ zone_app_proxy_send_launch_request(zone_app, app_control);
+ zone_app_proxy_destroy(zone_app);
+}
+
+static void __zone_request_done(const char *from, const char *info, void *user_data)
+{
+ app_control_h app_control;
+ char uri[PATH_MAX];
+
+ appdata_s *ad = (appdata_s *) user_data;
+
+ if (!strcmp(ad->mode, "create")) {
+ zone_manager_reset_zone_password(ad->zone_manager, ad->zone_name, ad->zone_password);
+
+ app_control_create(&app_control);
+ app_control_set_app_id(app_control, KEYGUARD_PACKAGE);
+ snprintf(uri, sizeof(uri), "zone://setup/%s", ad->zone_name);
+ app_control_set_uri(app_control, uri);
+ app_control_send_launch_request(app_control, NULL, NULL);
+ app_control_destroy(app_control);
+
+ app_control_create(&app_control);
+ app_control_set_app_id(app_control, KASKIT_PACKAGE);
+ __launch_zone_app(ad->zone_manager, ad->zone_name, app_control);
+ app_control_destroy(app_control);
+ }
+
+ ad->request_done = true;
+}
+
+static bool __app_create(void *data)
+{
+ appdata_s *ad = (appdata_s *) data;
+
+ if (zone_manager_create(&ad->zone_manager) != ZONE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to get zone manager handle");
+ ui_app_exit();
+ return false;
+ }
+
+ return true;
+}
+
+static void __app_pause(void *data)
+{
+}
+
+static void __app_resume(void *data)
+{
+}
+
+static void __free_data(appdata_s *ad)
+{
+ free(ad->zone_name);
+ free(ad->mode);
+}
+
+static void __app_terminate(void *data)
+{
+ appdata_s *ad = (appdata_s *) data;
+
+ zone_manager_remove_event_cb(ad->zone_manager, ad->zone_event_cb_id);
+ zone_manager_destroy(ad->zone_manager);
+
+ __free_data(ad);
+
+ return ;
+}
+
+static void __set_zone_callback(appdata_s *ad)
+{
+ char *cb_event_list[2] = {"created", "removed"};
+ char *cb_event = NULL;
+
+ if (!strcmp(ad->mode, "create"))
+ cb_event = cb_event_list[0];
+ else
+ cb_event = cb_event_list[1];
+
+ if (zone_manager_add_event_cb(ad->zone_manager, cb_event, __zone_request_done, ad, &ad->zone_event_cb_id) != ZONE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add zone signal callback");
+ ui_app_exit();
+ }
+
+ return;
+}
+
+static void __app_control(app_control_h app_control, void *data)
+{
+ appdata_s *ad = (appdata_s *) data;
+ int ret = 0;
+
+ ret = app_control_get_extra_data(app_control, "mode", &ad->mode);
+ if (ret != APP_CONTROL_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get mode");
+ ui_app_exit();
+ return;
+ }
+
+ if (strcmp(ad->mode, "create") && strcmp(ad->mode, "remove")) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Invalid mode");
+ ui_app_exit();
+ return;
+ }
+
+ ret = app_control_get_extra_data(app_control, "zone", &ad->zone_name);
+ if (ret != APP_CONTROL_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to get zone name");
+ ui_app_exit();
+ return;
+ }
+
+ __set_zone_callback(ad);
+
+ if (app_control_clone(&ad->app_control, app_control) != APP_CONTROL_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to clone app control handler");
+ ui_app_exit();
+ return;
+ }
+
+ _create_base_window(ad);
+
+ return;
+}
+
+int main(int argc, char *argv[])
+{
+ appdata_s ad = {0, };
+ int ret = 0;
+
+ ui_app_lifecycle_callback_s event_callback = {0, };
+
+ event_callback.create = __app_create;
+ event_callback.terminate = __app_terminate;
+ event_callback.pause = __app_pause;
+ event_callback.resume = __app_resume;
+ event_callback.app_control = __app_control;
+
+ ret = ui_app_main(argc, argv, &event_callback, &ad);
+ if (ret != APP_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main is failed. err = %d", ret);
+
+ return ret;
+}
--- /dev/null
+/*
+ * Tizen Zone Setup-Wizard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "zone-setup.h"
+#include "widget.h"
+
+#define PASSPHRASE_STATE_UNDEFINED 0
+#define PASSPHRASE_STATE_SETUP 1
+#define PASSPHRASE_STATE_VERIFY 2
+
+extern uidata_s ud;
+
+struct security_lock_type {
+ const char* text;
+ int index;
+};
+
+struct security_lock_type security_lock_types[2] = {
+ { "Password", 0 },
+ { "PIN", 1 }
+};
+
+char* security_group_text[2] = {
+ "Unlock method",
+ "Security options"
+};
+
+static char* security_password_setup_data = NULL;
+static char* security_password_verify_data = NULL;
+
+static unsigned int security_passphrase_mode = PASSPHRASE_STATE_UNDEFINED;
+static int security_lock_type_selected = 0;
+
+static void create_password_setup_view(appdata_s *ad);
+
+static char *security_multiline_text_get(void *data, Evas_Object *obj, const char *part)
+{
+ char text[PATH_MAX] = "\0";
+
+ if (!strcmp(part, "elm.text.multiline")) {
+ snprintf(text, PATH_MAX, "Select a Krate unlock method and a timeout option.");
+ return strdup(text);
+ }
+
+ return NULL;
+}
+
+static char *security_group_text_get(void *data, Evas_Object *obj, const char *part)
+{
+ char *text = (char *)data;
+
+ if (!strcmp(part, "elm.text")) {
+ return strdup(text);
+ }
+
+ return NULL;
+}
+
+static char *security_double_label_text_get(void *data, Evas_Object *obj, const char *part)
+{
+ char text[PATH_MAX] = "\0";
+ int timeout = 10; /*[TBD] get value of timeout */
+
+ if (!strcmp(part, "elm.text"))
+ snprintf(text, PATH_MAX, "Security Timeout");
+ else if (!strcmp(part, "elm.text.sub"))
+ snprintf(text, PATH_MAX, "After %d minuates of inactivity", timeout);
+
+ return strdup(text);
+}
+
+static char *security_lock_type_text_get(void *data, Evas_Object *obj, const char *part)
+{
+ struct security_lock_type *locktype = (struct security_lock_type *)data;
+
+ if (!strcmp(part, "elm.text")) {
+ return strdup(locktype->text);
+ }
+
+ return NULL;
+}
+
+static Evas_Object *security_lock_type_content_get(void *data, Evas_Object *obj, const char *part)
+{
+ static Evas_Object *group = NULL;
+ struct security_lock_type* locktype = (struct security_lock_type *)data;
+
+ if (group == NULL) {
+ group = elm_radio_add(obj);
+ elm_radio_state_value_set(group, 0);
+ elm_radio_value_set(group, 0);
+ }
+
+ if (!strcmp(part, "elm.swallow.icon")) {
+ Evas_Object* radio = elm_radio_add(obj);
+ elm_radio_state_value_set(radio, locktype->index);
+
+ if (locktype->index == security_lock_type_selected) {
+ elm_radio_value_set(radio, locktype->index);
+ }
+
+ elm_radio_group_add(radio, group);
+ evas_object_propagate_events_set(radio, EINA_FALSE);
+ evas_object_repeat_events_set(radio, EINA_TRUE);
+
+ return radio;
+ }
+
+ return NULL;
+}
+
+static void security_lock_type_select_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ struct security_lock_type* locktype = (struct security_lock_type *)data;
+
+ elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
+ elm_radio_value_set(obj, locktype->index);
+ security_lock_type_selected = locktype->index;
+}
+
+static Eina_Bool security_pop_cb(void *data, Elm_Object_Item *it)
+{
+ elm_object_signal_emit(ud.conform, "elm,state,indicator,overlap", "elm");
+
+ return EINA_TRUE;
+}
+
+static void security_previous_view_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ if (security_passphrase_mode != PASSPHRASE_STATE_UNDEFINED) {
+ security_passphrase_mode--;
+ }
+ elm_naviframe_item_pop(ud.nf);
+}
+
+static void security_password_setup_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = (appdata_s *)data;
+ if (security_passphrase_mode < PASSPHRASE_STATE_VERIFY) {
+ security_passphrase_mode++;
+ create_password_setup_view(ad);
+ return;
+ }
+
+ if (strcmp(security_password_setup_data, security_password_verify_data) != 0) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Password not matched");
+ return;
+ }
+
+ ad->zone_password = security_password_setup_data;
+
+ if (_send_zone_create_request(ad) != 0) {
+ ui_app_exit();
+ }
+
+ elm_object_signal_emit(ud.conform, "elm,state,indicator,overlap", "elm");
+ _create_setup_view(ad);
+}
+
+static void security_password_entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ char **password = (char **)data;
+ *password = strdup(elm_entry_entry_get(obj));
+}
+
+static Evas_Object *security_password_setup_content_get(void *data, Evas_Object *obj, const char *part)
+{
+ if (!strcmp(part, "elm.swallow.content")) {
+ Evas_Object *layout, *entry;
+
+ layout = _create_layout(obj, ud.edj_path, "security_layout");
+
+ entry = _create_entry(obj);
+ elm_object_part_text_set(layout, "title", "Enter password");
+ elm_object_part_content_set(layout, "entry", entry);
+ evas_object_smart_callback_add(entry, "unfocused", security_password_entry_unfocused_cb, data);
+
+ return layout;
+ }
+
+ return NULL;
+}
+
+static void create_password_setup_view(appdata_s *ad)
+{
+ char** entry;
+ const char* title;
+ Elm_Object_Item *item;
+ Elm_Genlist_Item_Class *itc;
+ Evas_Object *genlist, *layout, *left_button, *right_button;
+
+ layout = _create_layout(ud.nf, ud.edj_path, "base_layout");
+ genlist = elm_genlist_add(layout);
+ elm_layout_content_set(layout, "content_layout", genlist);
+ elm_object_style_set(genlist, "solid/default");
+ elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
+
+ left_button = _create_button(layout, PREV_BUTTON, security_previous_view_cb, NULL);
+ right_button = _create_button(layout, NEXT_BUTTON, security_password_setup_cb, ad);
+
+ //elm_object_disabled_set(right_button, EINA_TRUE);
+ _create_two_button_layout(layout, left_button, right_button);
+
+ if (security_passphrase_mode == 1) {
+ entry = &security_password_setup_data;
+ title = "Setup Password";
+ } else {
+ entry = &security_password_verify_data;
+ title = "Verify Password";
+ }
+
+ itc = _create_genlist_item_class("full", NULL, security_password_setup_content_get);
+ item = _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, (void **)entry);
+
+ item = elm_naviframe_item_push(ud.nf, title, NULL, NULL, layout, NULL);
+ elm_naviframe_item_title_enabled_set(item, EINA_TRUE, EINA_TRUE);
+}
+
+void _create_security_view(appdata_s *ad)
+{
+ int index;
+ Elm_Object_Item *item;
+ Elm_Genlist_Item_Class *itc;
+ Evas_Object *genlist, *layout, *left_button, *right_button;
+
+ elm_object_signal_emit(ud.conform, "elm,state,indicator,nooverlap", "elm");
+
+ layout = _create_layout(ud.nf, ud.edj_path, "base_layout");
+ genlist = elm_genlist_add(layout);
+ elm_object_style_set(genlist, "solid/default");
+ elm_layout_content_set(layout, "content_layout", genlist);
+ elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
+
+ itc = _create_genlist_item_class("multiline", security_multiline_text_get, NULL);
+ _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, NULL);
+
+ itc = _create_genlist_item_class("group_index", security_group_text_get, NULL);
+ _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, security_group_text[0]);
+
+ itc = _create_genlist_item_class("one_icon", security_lock_type_text_get, security_lock_type_content_get);
+ for (index = 0; index < 2; index++) {
+ item = elm_genlist_item_append(genlist,
+ itc,
+ &security_lock_types[index],
+ NULL,
+ ELM_GENLIST_ITEM_NONE,
+ security_lock_type_select_cb,
+ &security_lock_types[index]);
+ if (index == 1) {
+ elm_object_item_disabled_set(item, EINA_TRUE);
+ }
+ }
+
+ /* Timeout list group*/
+ itc = _create_genlist_item_class("group_index", security_group_text_get, NULL);
+ _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, security_group_text[1]);
+
+ itc = _create_genlist_item_class("double_label", security_double_label_text_get, NULL);
+ item = _append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, NULL);
+ elm_object_item_disabled_set(item, EINA_TRUE); /* [TBD] enable timeout options */
+
+ left_button = _create_button(layout, PREV_BUTTON, security_previous_view_cb, NULL);
+ right_button = _create_button(layout, NEXT_BUTTON, security_password_setup_cb, ad);
+ _create_two_button_layout(layout, left_button, right_button);
+
+ item = elm_naviframe_item_push(ud.nf, "Krate Security", NULL, NULL, layout, NULL);
+ elm_naviframe_item_title_enabled_set(item, EINA_TRUE, EINA_TRUE);
+ elm_naviframe_item_pop_cb_set(item, security_pop_cb, NULL);
+}
--- /dev/null
+/*
+ * Tizen Zone Setup-Wizard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include "zone-setup.h"
+#include "widget.h"
+
+static void __create_welcome_view(appdata_s *ad);
+
+uidata_s ud = {0, };
+
+static Eina_Bool __naviframe_pop_cb(void *data, Elm_Object_Item *it)
+{
+ app_control_h svc = (app_control_h) data;
+
+ _create_notification(svc);
+ ui_app_exit();
+
+ return EINA_FALSE;
+}
+
+static void __welcome_cancel_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = (appdata_s *)data;
+
+ _create_notification(ad->app_control);
+ ui_app_exit();
+
+ return;
+}
+
+static void __welcome_next_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = (appdata_s *)data;
+
+ if (!strcmp(ad->mode, "create")) {
+ _create_security_view(ad);
+ } else {
+ if (_send_zone_remove_request(ad) != 0)
+ ui_app_exit();
+ _create_setup_view(ad);
+ }
+
+ return;
+}
+
+static Eina_Bool __home_key_cb(void *data, int type, void *event)
+{
+ app_control_h app_control = (app_control_h) data;
+ Evas_Event_Key_Down *ev = event;
+
+ if (!strcmp(ev->keyname, "XF86Home")) {
+ _create_notification(app_control);
+ ui_app_exit();
+ }
+
+ return EINA_TRUE;
+}
+
+void _create_two_button_layout(Evas_Object *parent, Evas_Object *left_button, Evas_Object *right_button)
+{
+ Evas_Object *layout;
+
+ layout = _create_layout(parent, ud.edj_path, "two_button_layout");
+
+ elm_object_part_content_set(layout, "prev_button", left_button);
+ elm_object_part_content_set(layout, "next_button", right_button);
+ elm_object_part_content_set(parent, "bottom_layout", layout);
+ return;
+}
+
+static Eina_Bool __progressbar_timer_cb(void *data)
+{
+ appdata_s *ad = (appdata_s *)data;
+ if (ad->request_done) {
+ ui_app_exit();
+ return ECORE_CALLBACK_CANCEL;
+ }
+
+ return ECORE_CALLBACK_RENEW;
+}
+
+void _create_base_window(appdata_s *ad)
+{
+ Evas_Object *win;
+ Evas_Object *layout;
+
+ char edj_path[PATH_MAX] = "\0";
+ char *res_path = NULL;
+
+ /* Initialize data */
+ ad->request_done = false;
+
+ /* Get EDJ path */
+ res_path = app_get_resource_path();
+ if (res_path == NULL) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed get resource path");
+ ui_app_exit();
+ }
+ snprintf(edj_path, PATH_MAX, "%s%s", res_path, "org.tizen.zone-setup-wizard.edj");
+
+ ud.edj_path = strdup(edj_path);
+ free(res_path);
+
+ /* Create main UI widget */
+ win = _create_win(PACKAGE);
+ ud.conform = _create_conformant(win);
+ layout = _create_layout(ud.conform, NULL, NULL);
+ elm_object_content_set(ud.conform, layout);
+ ud.nf = elm_naviframe_add(layout);
+
+ ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __home_key_cb, ad->app_control);
+
+ __create_welcome_view(ad);
+
+ elm_object_part_content_set(layout, "elm.swallow.content", ud.nf);
+ eext_object_event_callback_add(ud.nf, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
+
+ evas_object_show(win);
+ return;
+}
+
+static void __create_welcome_view(appdata_s *ad)
+{
+ Elm_Object_Item *nf_it;
+ Evas_Object *layout, *welcome_layout;
+ Evas_Object *title, *content;
+ Evas_Object *left_button, *right_button;
+
+ char *welcome_text[2][4] = {
+ {WELCOME_MESSAGE_TITLE, WELCOME_MESSAGE_CONTENT, CANCEL_BUTTON, NEXT_BUTTON},
+ {DELETE_MESSAGE_TITLE, DELETE_MESSAGE_CONTENT, CANCEL_BUTTON, REMOVE_BUTTON}
+ };
+ char **text = NULL;
+
+ if (!strcmp(ad->mode, "create"))
+ text = welcome_text[0];
+ else
+ text = welcome_text[1];
+
+ elm_object_signal_emit(ud.conform, "elm,state,indicator,overlap", "elm");
+
+ layout = _create_layout(ud.nf, ud.edj_path, "base_layout");
+ welcome_layout = _create_layout(layout, ud.edj_path, "welcome_layout");
+
+ title = _create_textblock(welcome_layout, text[0], SUB_TITLE_STYLE_B);
+ content = _create_textblock(welcome_layout, text[1], SUB_CONTENT_STYLE_B);
+
+ elm_object_part_content_set(welcome_layout, "message_title", title);
+ elm_object_part_content_set(welcome_layout, "message_content", content);
+
+ elm_object_part_content_set(layout, "content_layout", welcome_layout);
+
+ left_button = _create_button(layout, text[2], __welcome_cancel_cb, ad);
+ right_button = _create_button(layout, text[3], __welcome_next_cb, ad);
+
+ _create_two_button_layout(layout, left_button, right_button);
+
+ nf_it = elm_naviframe_item_push(ud.nf, NULL, NULL, NULL, layout, NULL);
+ elm_naviframe_item_title_enabled_set(nf_it, EINA_FALSE, EINA_TRUE);
+ elm_naviframe_item_pop_cb_set(nf_it, __naviframe_pop_cb, ad->app_control);
+
+ return;
+}
+
+void _create_setup_view(appdata_s *ad)
+{
+ Elm_Object_Item *nf_it;
+ Evas_Object *setup_layout;
+ Evas_Object *progressbar;
+ Evas_Object *title, *content;
+
+ char *setup_text[2][2] = {
+ {SETUP_MESSAGE_TITLE, SETUP_MESSAGE_CONTENT},
+ {DELETE_ONGOING_TITLE, DELETE_ONGOING_CONTENT}
+ };
+ char **text = NULL;
+
+ if (!strcmp(ad->mode, "create"))
+ text = setup_text[0];
+ else
+ text = setup_text[1];
+
+ eext_object_event_callback_del(ud.nf, EEXT_CALLBACK_BACK, eext_naviframe_back_cb);
+
+ setup_layout = _create_layout(ud.nf, ud.edj_path, "setup_layout");
+
+ title = _create_textblock(setup_layout, text[0], SUB_TITLE_STYLE_W);
+ content = _create_textblock(setup_layout, text[1], SUB_CONTENT_STYLE_W);
+
+ elm_object_part_content_set(setup_layout, "progressbar_msg", title);
+
+ progressbar = _create_progressbar(setup_layout, "pending");
+ elm_object_part_content_set(setup_layout, "progressbar", progressbar);
+
+ elm_object_part_content_set(setup_layout, "content_text", content);
+
+ nf_it = elm_naviframe_item_push(ud.nf, NULL, NULL, NULL, setup_layout, NULL);
+ elm_naviframe_item_title_enabled_set(nf_it, EINA_FALSE, EINA_TRUE);
+
+ /* set progressbar timer callback */
+ ecore_timer_add(0.1, __progressbar_timer_cb, ad);
+
+ return;
+}
--- /dev/null
+/*
+ * Tizen Zone Setup-Wizard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <notification.h>
+#include "zone-setup.h"
+
+#define ZONE_METADATA_PATH "data/ZoneManifest.xml"
+
+static char *__get_zone_metadata(void)
+{
+ FILE *fp = NULL;
+ char *res_path = NULL;
+ char *metadata = NULL;
+ char metadata_path[PATH_MAX] = "\0";
+ long fsize = 0;
+ int ret = -1;
+
+ res_path = app_get_resource_path();
+ if (res_path == NULL) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to get resource path");
+ return NULL;
+ }
+ snprintf(metadata_path, PATH_MAX, "%s%s", res_path, ZONE_METADATA_PATH);
+ free(res_path);
+
+ fp = fopen(metadata_path, "r");
+ if (fp != NULL) {
+ if (fseek(fp, 0, SEEK_END) == -1)
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to fseek");
+
+ fsize = ftell(fp);
+ if (fsize == -1) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to get file size");
+ fclose(fp);
+ return NULL;
+ }
+
+ metadata = malloc(fsize + 1);
+ if (metadata == NULL) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to allocate memory");
+ fclose(fp);
+ return NULL;
+ }
+ memset(metadata, 0, fsize + 1);
+ if (fseek(fp, 0, SEEK_SET) == -1) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to fseek");
+ fclose(fp);
+ free(metadata);
+ return NULL;
+ }
+
+ ret = fread(metadata, fsize, 1, fp);
+ if (ret < 0) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to read metadata file");
+ fclose(fp);
+ free(metadata);
+ return NULL;
+ }
+ } else {
+ dlog_print(DLOG_ERROR, LOG_TAG, "failed to open metadata file");
+ return NULL;
+ }
+
+ fclose(fp);
+
+ return metadata;
+}
+
+int _send_zone_create_request(appdata_s *ad)
+{
+ int ret;
+ char *metadata = NULL;
+
+ metadata = __get_zone_metadata();
+ if (metadata == NULL) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get zone metadata");
+ return -1;
+ }
+
+ ret = zone_manager_create_zone(ad->zone_manager, ad->zone_name, metadata);
+ if (ret != ZONE_ERROR_NONE) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int _send_zone_remove_request(appdata_s *ad)
+{
+ int ret;
+
+ ret = zone_manager_destroy_zone(ad->zone_manager, ad->zone_name);
+ if (ret != ZONE_ERROR_NONE) {
+ return -1;
+ }
+
+ return 0;
+}
+
+static int __set_notification(notification_h noti_handle, app_control_h app_control)
+{
+ int ret = 0;
+ char *mode = NULL;
+ char *noti_text[2][2] = {
+ {NOTI_CREATE_ZONE, NOTI_BODY_CREATE_ZONE},
+ {NOTI_REMOVE_ZONE, NOTI_BODY_REMOVE_ZONE}
+ };
+ char **text = NULL;
+
+ if (app_control_get_extra_data(app_control, "mode", &mode) != APP_CONTROL_ERROR_NONE)
+ return -1;
+
+ if (!strcmp(mode, "create"))
+ text = noti_text[0];
+ else
+ text = noti_text[1];
+
+ ret = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, text[0], NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ if (ret != NOTIFICATION_ERROR_NONE)
+ return -1;
+
+ ret = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, text[1], NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ if (ret != NOTIFICATION_ERROR_NONE)
+ return -1;
+
+ ret = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_ALL);
+ if (ret != NOTIFICATION_ERROR_NONE)
+ return -1;
+
+ ret = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_THUMBNAIL, DPM_SYSPOPUP_ICON_PATH);
+ if (ret != NOTIFICATION_ERROR_NONE)
+ return -1;
+
+ ret = notification_set_launch_option(noti_handle, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, app_control);
+ if (ret != NOTIFICATION_ERROR_NONE)
+ return -1;
+
+ return ret;
+}
+
+void _create_notification(app_control_h app_control)
+{
+ notification_h noti_handle = NULL;
+ int ret = 0;
+
+ noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
+
+ ret = __set_notification(noti_handle, app_control);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ notification_free(noti_handle);
+ app_control_destroy(app_control);
+ return;
+ }
+
+ notification_post(noti_handle);
+ notification_free(noti_handle);
+ app_control_destroy(app_control);
+
+ return;
+}
--- /dev/null
+/*
+ * Tizen Zone Setup-Wizard application
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "widget.h"
+
+static void __win_delete_request_cb(void *data , Evas_Object *obj , void *event_info)
+{
+ ui_app_exit();
+}
+
+Evas_Object *_create_win(const char *package)
+{
+ Evas_Object *win;
+
+ elm_app_base_scale_set(1.8);
+
+ win = elm_win_util_standard_add(package, package);
+ elm_win_conformant_set(win, EINA_TRUE);
+ elm_win_autodel_set(win, EINA_TRUE);
+ elm_win_alpha_set(win, EINA_TRUE);
+
+ evas_object_smart_callback_add(win, "delete,request", __win_delete_request_cb, NULL);
+
+ return win;
+}
+
+Evas_Object *_create_conformant(Evas_Object *parent)
+{
+ Evas_Object *conform = elm_conformant_add(parent);
+
+ evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(parent, conform);
+
+ evas_object_show(conform);
+
+ return conform;
+}
+
+Evas_Object *_create_layout(Evas_Object *parent, char *file, const char *group)
+{
+ Evas_Object *layout = elm_layout_add(parent);
+
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ if (file == NULL)
+ elm_layout_theme_set(layout, "layout", "application", "default");
+ else
+ elm_layout_file_set(layout, file, group);
+
+ evas_object_show(layout);
+
+ return layout;
+}
+
+Evas_Object *_create_button(Evas_Object *parent, const char *text, Evas_Smart_Cb callback, void *user_data)
+{
+ Evas_Object *btn = elm_button_add(parent);
+
+ evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_object_text_set(btn, text);
+ elm_object_style_set(btn, "bottom");
+ evas_object_smart_callback_add(btn, "clicked", callback, user_data);
+
+ evas_object_show(btn);
+
+ return btn;
+}
+
+Evas_Object *_create_textblock(Evas_Object *parent, const char *text, char *style)
+{
+ Evas_Object *txt = evas_object_textblock_add(parent);
+ Evas_Textblock_Style *text_st = NULL;
+
+ if (style != NULL) {
+ text_st = evas_textblock_style_new();
+ evas_textblock_style_set(text_st, style);
+ evas_object_textblock_style_set(txt, text_st);
+ }
+
+ evas_object_textblock_text_markup_set(txt, text);
+ evas_object_show(txt);
+
+ if (text_st != NULL)
+ evas_textblock_style_free(text_st);
+
+ return txt;
+}
+
+Evas_Object *_create_progressbar(Evas_Object *parent, const char *style)
+{
+ Evas_Object *progressbar = elm_progressbar_add(parent);
+
+ if (style != NULL)
+ elm_object_style_set(progressbar, style);
+
+ evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.5);
+ evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_progressbar_pulse(progressbar, EINA_TRUE);
+ elm_progressbar_pulse_set(progressbar, EINA_TRUE);
+ evas_object_show(progressbar);
+
+ return progressbar;
+}
+
+Elm_Genlist_Item_Class *_create_genlist_item_class(char *style, Elm_Gen_Item_Text_Get_Cb text_func, Elm_Gen_Item_Content_Get_Cb content_func)
+{
+ Elm_Genlist_Item_Class *itc;
+
+ itc = elm_genlist_item_class_new();
+ itc->item_style = style;
+ itc->func.text_get = text_func;
+ itc->func.content_get = content_func;
+
+ return itc;
+}
+
+Elm_Object_Item *_append_genlist_item(Evas_Object *genlist, Elm_Genlist_Item_Class *itc, Elm_Object_Select_Mode select_mode, void* data)
+{
+ Elm_Object_Item *gl_item;
+
+ gl_item = elm_genlist_item_append(genlist, itc, data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
+
+ elm_genlist_item_select_mode_set(gl_item, select_mode);
+ elm_genlist_item_class_free(itc);
+
+ return gl_item;
+}
+
+Evas_Object *_create_entry(Evas_Object *parent)
+{
+ Evas_Object *entry = elm_entry_add(parent);
+ static Elm_Entry_Filter_Limit_Size limit_size = {
+ .max_char_count = 20,
+ .max_byte_count = 0
+ };
+
+ evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_entry_password_set(entry, EINA_TRUE);
+ elm_entry_single_line_set(entry, EINA_TRUE);
+ elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_size);
+
+ evas_object_show(entry);
+ return entry;
+}
--- /dev/null
+#
+# Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+PROJECT(krate-admin-cli)
+
+FILE(GLOB KRATE_ADMIN_CLI_SRCS krate-admin-cli.cpp
+ ${KRATE_MODULE}/session.cpp
+ ${KRATE_MODULE}/zone-builder.cpp
+)
+
+SET(KRATE_ADMIN_CLI_NAME "zone-admin-cli")
+
+ADD_EXECUTABLE(${ZONE_CLI_NAME} ${ZONE_CLI_SRCS})
+SET_TARGET_PROPERTIES(${ZONE_CLI_NAME} PROPERTIES PREFIX ""
+ COMPILE_DEFINITIONS PID_FILE_PATH="${RUN_INSTALL_DIR}/zone"
+ COMPILE_FLAGS "-fPIE"
+ LINK_FLAGS "-pie"
+)
+
+PKG_CHECK_MODULES(ZONE_CLI_DEPS REQUIRED
+ glib-2.0
+ capi-appfw-package-manager
+ capi-appfw-app-manager
+)
+
+INCLUDE_DIRECTORIES(SYSTEM ${ZONE_CLI_DEPS_INCLUDE_DIRS} ${DPM_COMMON} ${ZONE_MODULE} ${ZONE_LIBS})
+TARGET_LINK_LIBRARIES(${ZONE_CLI_NAME} ${ZONE_CLI_DEPS_LIBRARIES} dpm-common zone)
+
+INSTALL(TARGETS ${ZONE_CLI_NAME} DESTINATION sbin)
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Sungbae Yoo <sungbae.yoo@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * @file
+ * @author Sungbae Yoo (sungbae.yoo@samsung.com)
+ * @brief CLI tool to attach to existing namespace by pam-attach.so
+ */
+#define _XOPEN_SOURCE
+#include <glib.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+
+#include <grp.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <fcntl.h>
+
+#include <string>
+#include <vector>
+#include <iostream>
+#include <utility>
+
+#include <zone/package-proxy.h>
+#include <zone/app-proxy.h>
+
+#include "session.h"
+
+#include "error.h"
+#include "exception.h"
+#include "filesystem.h"
+#include "auth/user.h"
+
+
+#define DEFAULT_SHELL "/bin/bash"
+
+typedef std::pair<std::string, int> NamespacePair;
+
+std::vector<NamespacePair> namespaces = {
+ {"mnt", CLONE_NEWNS},
+ {"net", CLONE_NEWNET},
+ {"uts", CLONE_NEWUTS},
+ {"user", CLONE_NEWUSER},
+ {"ipc", CLONE_NEWIPC},
+ {"pid", CLONE_NEWPID}
+};
+
+extern char** environ;
+
+static inline void usage(const std::string name)
+{
+ std::cout << "Usage: " << name << " [Option] -- COMMAND" << std::endl
+ << "Run a program in the zone" << std::endl
+ << std::endl
+ << "Options :" << std::endl
+ << " -a, --attach=zone execute command in the zone" << std::endl
+ << " -p, --pkginfo=zone show all packages in the zone" << std::endl
+ << " -q, --appinfo=zone show all applications in the zone" << std::endl
+ << " -m, --zone-monitor monitor all zone events" << std::endl
+ << " -n, --pkg-monitor monitor all package events in the zone" << std::endl
+ << " -l, --list show all zone instances" << std::endl
+ << " -h, --help show this" << std::endl
+ << std::endl;
+}
+
+int showZoneInstances()
+{
+ try {
+ runtime::DirectoryIterator iter(runtime::Path("/var/run/zone")), end;
+
+ while (iter != end) {
+ const std::string& path = (*iter).getPath();
+ size_t name = path.rfind('/') + 1;
+ std::cout << path.substr(name) << std::endl;
+ ++iter;
+ }
+ } catch (runtime::Exception& e) {
+ std::cerr << e.what() << std::endl;
+ return -1;
+ }
+
+ return 0;
+}
+
+void attachNamespaces(pid_t pid)
+{
+ int fd;
+ for (const NamespacePair& ns : namespaces) {
+ std::string nspath = "/proc/" + std::to_string(pid) + "/ns/" + ns.first;
+
+ do {
+ fd = ::open(nspath.c_str(), O_RDONLY);
+ } while (fd == -1 && errno == EINTR);
+
+ if (fd == -1) {
+ if (errno != ENOENT) {
+ throw runtime::Exception("Failed to open namesapce: " + nspath);
+ }
+ } else {
+ if (::setns(fd, ns.second)) {
+ ::close(fd);
+ throw runtime::Exception("Failed to attach namespace: " + nspath);
+ }
+ ::close(fd);
+ }
+ }
+}
+
+void launchProcess(runtime::User& user, char** args)
+{
+ int status;
+
+ pid_t pid = ::fork();
+ if (pid == -1) {
+ throw runtime::Exception("Failed to create child process");
+ }
+
+ if (pid != 0) {
+ ::waitpid(pid, &status, 0);
+ if (WEXITSTATUS(status) != EXIT_SUCCESS) {
+ throw runtime::Exception("Child process terminated abnormally");
+ }
+ return;
+ }
+
+ if (::initgroups(user.getName().c_str(), user.getGid()) == -1) {
+ std::cerr << "Failed to initgroups()" << std::endl;
+ ::exit(EXIT_FAILURE);
+ }
+
+ if (::setgid(user.getGid()) == -1) {
+ std::cerr << "Failed to setgid()" << std::endl;
+ ::exit(EXIT_FAILURE);
+ }
+
+ if (::setuid(user.getUid()) == -1) {
+ std::cerr << "Failed to setuid()" << std::endl;
+ ::exit(EXIT_FAILURE);
+ }
+
+ char *default_args[2];
+ default_args[0] = ::strdup(DEFAULT_SHELL);
+ default_args[1] = NULL;
+
+ if (args == NULL) {
+ args = default_args;
+ }
+
+ ::execve(*args, args, environ);
+ std::cerr << "Failed to execute " << args[0] << std::endl;
+
+ ::free(default_args[0]);
+
+ ::exit(EXIT_FAILURE);
+}
+
+int attachToZone(const std::string& name, char* args[])
+{
+ try {
+ runtime::User user(name);
+
+ attachNamespaces(getSessionLeader(user));
+ launchProcess(user, args);
+ } catch (runtime::Exception& e) {
+ std::cerr << e.what() << std::endl;
+ return -1;
+ }
+
+ return 0;
+}
+
+bool packgeListCallback(package_info_h info, void *user_data)
+{
+ bool checked;
+ char *val;
+
+ std::cout << "Package #" << (*(int*)user_data)++ << " :" << std::endl;
+
+ package_info_get_package(info, &val);
+ std::cout << val;
+ free(val);
+
+ package_info_get_version(info, &val);
+ std::cout << " (" << val << ")" << std::endl;
+ free(val);
+
+ package_info_get_type(info, &val);
+ std::cout << " Type : " << val << " (";
+ free(val);
+
+ package_info_is_system_package(info, &checked);
+ if (checked) {
+ std::cout <<" System ";
+ }
+ package_info_is_removable_package(info, &checked);
+ if (checked) {
+ std::cout <<" Removable ";
+ }
+ package_info_is_preload_package(info, &checked);
+ if (checked) {
+ std::cout <<" Preload ";
+ }
+ std::cout << ")" << std::endl;
+
+ package_info_get_label(info, &val);
+ std::cout << " Label : " << val << std::endl;
+ free(val);
+
+ package_info_get_icon(info, &val);
+ std::cout << " Icon : " << val << std::endl;
+ free(val);
+
+ std::cout << std::endl;
+
+ return true;
+}
+
+int showPkgInfo(const std::string& name)
+{
+ int num = 0;
+
+ zone_manager_h zoneMgr;
+ zone_package_proxy_h pkgProxy;
+
+ zone_manager_create(&zoneMgr);
+ zone_package_proxy_create(zoneMgr, name.c_str(), &pkgProxy);
+ zone_package_proxy_foreach_package_info(pkgProxy, packgeListCallback, &num);
+ std::cout << num << " packages are found" << std::endl;
+ zone_package_proxy_destroy(pkgProxy);
+ zone_manager_destroy(zoneMgr);
+
+ return 0;
+}
+
+bool applicationListCallback(app_info_h info, void *user_data)
+{
+ bool checked;
+ char *val;
+
+ std::cout << "Application #" << (*(int*)user_data)++ << " :" << std::endl;
+
+ app_info_get_app_id(info, &val);
+ std::cout << val;
+ free(val);
+
+ app_info_get_package(info, &val);
+ std::cout << " (" << val << ")" << std::endl;
+ free(val);
+
+ app_info_get_type(info, &val);
+ std::cout << " Type : " << val << " (";
+ free(val);
+
+ app_info_is_nodisplay(info, &checked);
+ if (checked) {
+ std::cout <<" NoDisplay ";
+ }
+ std::cout << ")"<< std::endl;
+
+ app_info_get_label(info, &val);
+ std::cout << " Label : " << val << std::endl;
+ free(val);
+
+ if (app_info_get_icon(info, &val) == APP_MANAGER_ERROR_NONE) {
+ std::cout << " Icon : " << val << std::endl;
+ free(val);
+ } else {
+ std::cout << "App Manager error" << std::endl;
+ }
+
+ std::cout << std::endl;
+
+ return true;
+}
+
+int showAppInfo(const std::string& name)
+{
+ int num = 0;
+
+ zone_manager_h zoneMgr;
+ zone_app_proxy_h appMgr;
+
+ zone_manager_create(&zoneMgr);
+ zone_app_proxy_create(zoneMgr, name.c_str(), &appMgr);
+ zone_app_proxy_foreach_app_info(appMgr, applicationListCallback, &num);
+ std::cout << num << " applications are found" << std::endl;
+ zone_app_proxy_destroy(appMgr);
+ zone_manager_destroy(zoneMgr);
+
+ return 0;
+}
+
+GMainLoop *gmainloop = NULL;
+
+void monitorSigHandler(int sig)
+{
+ g_main_loop_quit(gmainloop);
+}
+
+void zoneCallback(const char* name, const char* object, void *user_data)
+{
+ std::cout << "--- Zone event ---" << std::endl;
+ std::cout << "Type : " << (char*)user_data << std::endl;
+ std::cout << "Name : " << name <<std::endl;
+ std::cout << std::endl;
+}
+
+int monitorEvent()
+{
+ int zoneCallbackId[2];
+ zone_manager_h zoneMgr;
+ zone_manager_create(&zoneMgr);
+
+ zone_manager_add_event_cb(zoneMgr, "created", zoneCallback,
+ (void*)"created", &zoneCallbackId[0]);
+ zone_manager_add_event_cb(zoneMgr, "removed", zoneCallback,
+ (void*)"removed", &zoneCallbackId[1]);
+
+ std::cout << "=== Monitoring start ===" << std::endl << std::endl;
+
+ signal(SIGINT, monitorSigHandler);
+
+ gmainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(gmainloop);
+ g_main_loop_unref(gmainloop);
+
+ zone_manager_remove_event_cb(zoneMgr, zoneCallbackId[0]);
+ zone_manager_remove_event_cb(zoneMgr, zoneCallbackId[1]);
+
+ std::cout << "=== Monitoring end ===" << std::endl;
+
+ zone_manager_destroy(zoneMgr);
+
+ return 0;
+}
+
+void packageEventCallback(const char *type,
+ const char *package,
+ package_manager_event_type_e event_type,
+ package_manager_event_state_e event_state,
+ int progress, package_manager_error_e error,
+ void *user_data)
+{
+ std::cout << "--- Package event ---" << std::endl;
+ std::cout << "Pacakge : " << package << std::endl;
+ std::cout << "Pacakge type : " << type << std::endl;
+
+ std::cout << "Event state : ";
+ switch (event_state) {
+ case PACKAGE_MANAGER_EVENT_STATE_STARTED:
+ std::cout << "started" << std::endl;
+ std::cout << "Event type : ";
+ switch (event_type) {
+ case PACKAGE_MANAGER_EVENT_TYPE_INSTALL:
+ std::cout << "install";
+ break;
+ case PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL:
+ std::cout << "uninstall";
+ break;
+ case PACKAGE_MANAGER_EVENT_TYPE_UPDATE:
+ std::cout << "update";
+ break;
+ }
+ break;
+ case PACKAGE_MANAGER_EVENT_STATE_PROCESSING:
+ std::cout << "processing" << std::endl;
+ std::cout << "Progress : " << std::to_string(progress) << "%";
+ break;
+ case PACKAGE_MANAGER_EVENT_STATE_FAILED:
+ std::cout << "failed";
+ break;
+ case PACKAGE_MANAGER_EVENT_STATE_COMPLETED:
+ std::cout << "completed";
+ break;
+ }
+ std::cout << std::endl;
+
+ std::cout << std::endl;
+}
+
+int monitorPkgEvent(const std::string& name)
+{
+ zone_manager_h zoneMgr;
+ zone_package_proxy_h pkgProxy;
+
+ zone_manager_create(&zoneMgr);
+ zone_package_proxy_create(zoneMgr, name.c_str(), &pkgProxy);
+
+ zone_package_proxy_set_event_cb(pkgProxy, packageEventCallback, NULL);
+
+ std::cout << "=== Monitoring start ===" << std::endl << std::endl;
+
+ signal(SIGINT, monitorSigHandler);
+
+ gmainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(gmainloop);
+ g_main_loop_unref(gmainloop);
+
+ zone_package_proxy_unset_event_cb(pkgProxy);
+
+ std::cout << "=== Monitoring end ===" << std::endl;
+
+ zone_package_proxy_destroy(pkgProxy);
+ zone_manager_destroy(zoneMgr);
+
+ return 0;
+}
+
+int main(int argc, char* argv[])
+{
+ int opt = 0, index, ret = 0;
+
+ struct option options[] = {
+ {"attach", required_argument, 0, 'a'},
+ {"list", no_argument, 0, 'l'},
+ {"pkginfo", required_argument, 0, 'p'},
+ {"appinfo", required_argument, 0, 'q'},
+ {"zone-monitor", no_argument, 0, 'm'},
+ {"pkg-monitor", no_argument, 0, 'n'},
+ {"help", no_argument, 0, 'h'},
+ {0, 0, 0, 0}
+ };
+
+ if (argc <= 1) {
+ usage(argv[0]);
+ return EXIT_SUCCESS;
+ }
+
+ while ((opt = getopt_long(argc, argv, "a:p:q:mn:lh", options, &index)) != -1) {
+ switch (opt) {
+ case 'a':
+ ret = attachToZone(optarg, optind >= argc ? NULL : argv + optind);
+ break;
+ case 'p':
+ ret = showPkgInfo(optarg);
+ break;
+ case 'q':
+ ret = showAppInfo(optarg);
+ break;
+ case 'm':
+ ret = monitorEvent();
+ break;
+ case 'n':
+ ret = monitorPkgEvent(optarg);
+ break;
+ case 'l':
+ ret = showZoneInstances();
+ break;
+ case 'h':
+ usage(argv[0]);
+ break;
+ default:
+ usage(argv[0]);
+ ret = -1;
+ }
+ }
+
+ return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
--- /dev/null
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+export `tzplatform-get TZ_SYS_ETC`
+cp ${TZ_SYS_ETC}/dpm/zone/owner.xml ${TZ_SYS_ETC}/dpm/zone/${1}.xml
--- /dev/null
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+export `tzplatform-get TZ_SYS_ETC`
+rm ${TZ_SYS_ETC}/dpm/zone/${1}.xml