--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+SET (this_target osp-app-service)
+SET (APPID aospd00043)
+
+SET(CMAKE_EXECUTABLE_SUFFIX ".exe")
+SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/output")
+
+ADD_SUBDIRECTORY(plugins)
+
+INCLUDE_DIRECTORIES (
+ /usr/include/glib-2.0
+ /usr/lib/glib-2.0/include
+ /usr/include/sysman
+ /usr/include/vconf
+ /usr/include/appfw
+ /usr/include/network
+ /usr/include/notification
+ /usr/include/osp
+ /usr/include/osp/app
+ /usr/include/osp/base
+ /usr/include/osp/io
+ /usr/include/osp/system
+ /usr/include/osp/security
+ /usr/include/osp/shell
+ /usr/include/chromium
+ /usr/include/system
+ /usr/include/calendar-service2
+ inc
+ )
+
+SET (${this_target}_SOURCE_FILES
+ src/FApp_AppManagerService.cpp
+ src/FApp_AppManagerStub.cpp
+ src/FApp_ConditionManagerService.cpp
+ src/FApp_ConditionManagerStub.cpp
+ src/FApp_ConditionHandler.cpp
+ src/FApp_ContextManager.cpp
+ src/FApp_CommunicationDispatcher.cpp
+ src/FApp_PackageManagerStub.cpp
+ src/FApp_NotificationManagerStub.cpp
+ src/FApp_NotificationManagerService.cpp
+ src/FSys_DeviceManagerService.cpp
+ src/FSys_SystemService.cpp
+ src/FSys_AccessoryManagerService.cpp
+ src/FSys_AlarmService.cpp
+ src/AppService.cpp
+ src/AppServiceEntry.cpp
+ src/FIo_MmcStorageManagerService.cpp
+ src/FIo_MmcStorageManagerStub.cpp
+ )
+
+## SET EXTRA COMPILER FLAGS
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE -Wall -pthread -g3" )
+#SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fstack-protector -Wstack-protector" )
+
+## SET C COMPILER FLAGS
+SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## SET CPP COMPILER FLAGS
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## Create Library
+ADD_EXECUTABLE (${this_target} ${${this_target}_SOURCE_FILES})
+
+TARGET_LINK_LIBRARIES(${this_target} -Xlinker --no-undefined -Xlinker --as-needed -pie)
+TARGET_LINK_LIBRARIES(${this_target} -Xlinker --version-script=${CMAKE_CURRENT_SOURCE_DIR}/system-service-export.ver)
+TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-appfw -lchromium -losp-shell-core")
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-system-media-key" )
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-network-bluetooth" )
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-system-device" )
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-system-info" )
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-appfw-application" )
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-appfw-app-manager" )
+TARGET_LINK_LIBRARIES(${this_target} "-lnotification" )
+TARGET_LINK_LIBRARIES(${this_target} "-lsysman" )
+TARGET_LINK_LIBRARIES(${this_target} "-lvconf" )
+TARGET_LINK_LIBRARIES(${this_target} "-lcalendar-service2" )
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/etc/rc.d/init.d/boot-osp.sh DESTINATION ../etc/rc.d/init.d)
+INSTALL(TARGETS ${this_target} DESTINATION ../usr/apps/${APPID}/bin)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/manifest.xml DESTINATION ../usr/apps/${APPID}/info)
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/ DESTINATION ../usr/apps/${APPID}/data)
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/ DESTINATION ../usr/apps/${APPID}/lib)
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/res/ DESTINATION ../usr/apps/${APPID}/res)
+
--- /dev/null
+
+ 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
+Flora License
+
+Version 1.0, May, 2012
+
+http://floralicense.org/license/
+
+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.
+
+"Tizen Certified Platform" shall mean a software platform that complies
+with the standards set forth in the Compatibility Definition Document
+and passes the Compatibility Test Suite as defined from time to time
+by the Tizen Technical Steering Group and certified by the Tizen
+Association or its designated agent.
+
+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
+solely as incorporated into a Tizen Certified Platform, 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 solely
+as incorporated into a Tizen Certified Platform 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 pursuant to the copyright license
+above, in any medium, with or without modifications, and in Source or
+Object form, provided that You meet the following conditions:
+
+ 1. You must give any other recipients of the Work or Derivative Works
+ a copy of this License; and
+ 2. You must cause any modified files to carry prominent notices stating
+ that You changed the files; and
+ 3. 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
+ 4. 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 Flora License to your work
+
+To apply the Flora 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 Flora License, Version 1.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://floralicense.org/license/
+
+ 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
+Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE.APLv2 file for Apache License, Version 2 terms and conditions.
+
+Several source codes may have its original copyright owner and/or
+be licensed under other than Apache License, Version 2, say, Flora License, Version 1.
+Please, see copyright and license comments section in the header of each file,
+and the LICENSE.Flora for Flora License, Version 1 terms and conditions.
+
--- /dev/null
+#!/bin/sh
+
+OSP_DAEMON_NAME=osp-app-service
+OSP_DAEMON_APPID=aospd00043
+OSP_DAEMON_PATH=/opt/apps/aospd00043/bin/osp-app-service
+
+if [ ! -e /opt/share/.ospfirstboot ]
+then
+ if [ ! -e /opt/usr/dbspace/.app-package.db ]
+ then
+ /usr/etc/package-manager/backend/tpk -r /opt/apps
+ fi
+ /bin/touch /opt/share/.ospfirstboot
+fi
+
+case "$1" in
+ start)
+ echo "Starting OSP app-service"
+ $OSP_DAEMON_PATH &
+ PID=`pidof $OSP_DAEMON_NAME`
+ if [ -n "$PID" ]; then
+ aul_test update_list $OSP_DAEMON_APPID.$OSP_DAEMON_NAME $OSP_DAEMON_PATH $PID
+ fi
+ ;;
+ stop)
+ echo "Stopping OSP app-service"
+ PID=`pidof $OSP_DAEMON_NAME`
+ if [ -n "$PID" ]; then
+ kill $PID
+ fi
+ ;;
+ *)
+ echo "Usage: osp-app-service.sh {start|stop}" >&2
+ exit 3
+ ;;
+esac
+
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 _APP_SERVICE_H_
+#define _APP_SERVICE_H_
+
+
+#include <FSystem.h>
+#include <FAppTypes.h>
+
+#include <FApp_IAppManagerEventListener.h>
+
+namespace Tizen { namespace App
+{
+class _AppManagerStub;
+class _ConditionManagerStub;
+class _ContextManager;
+class _CommunicationDispatcher;
+class _PackageManagerStub;
+class _NotificationManagerStub;
+}}
+
+namespace Tizen { namespace Io
+{
+class _IpcServer;
+class _MmcStorageManagerStub;
+}}
+
+namespace Tizen { namespace System
+{
+class _DeviceManagerService;
+class _SystemService;
+class _AlarmService;
+class _AccessoryManagerService;
+}}
+
+/**
+ * @class AppService
+ * @brief This creates and initializes major system services such as channel, appmanager, and others.
+ * And ContextManager watchs running apps(processes) and callbacks to appmanager when app destroyed.
+ *
+ * @ remarks AppService is system service of OSP, and starts at first among them.
+ */
+class AppService
+ : public Tizen::App::ServiceApp
+ , public Tizen::App::Package::IPackageInstallationEventListener
+ , public Tizen::App::_IAppManagerEventListener
+ , virtual public Tizen::Base::Runtime::IEventListener
+{
+public:
+ static Tizen::App::ServiceApp* CreateInstance(void);
+
+ AppService();
+ virtual ~AppService();
+
+ virtual bool OnAppInitializing(Tizen::App::AppRegistry& appRegistry);
+ virtual bool OnAppInitialized(void);
+ virtual bool OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination = false);
+ virtual void OnLowMemory(void);
+ virtual void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel);
+ virtual void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList *pArgs);
+
+ // IPackageInstallationEventListener
+ virtual void OnPackageInstallationCompleted(const Tizen::App::PackageId& packageId, Tizen::App::Package::PackageInstallationResult installationResult);
+ virtual void OnPackageUninstallationCompleted(const Tizen::App::PackageId& packageId, bool uninstallationResult);
+ virtual void OnPackageInstallationInProgress(const Tizen::App::PackageId& packageId, int progress);
+
+ static void OnPowerOffNotiReceived(void* pData);
+
+private:
+ bool InitializeIpc(void);
+ bool InitializeServices(void);
+
+ bool LaunchSystemServices(void);
+ bool LaunchUserServices(void);
+ bool LaunchChannelService(void);
+ bool LaunchSecurityService(void);
+ Tizen::Base::Collection::ArrayList* GetPackageEventArgsN(const Tizen::App::AppId& appId);
+ virtual void OnApplicationLaunched(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
+ virtual void OnApplicationTerminated(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
+
+ static int CreateProcess(const Tizen::Base::String& appId);
+ static result SetOomAdj(int pid, int adj);
+
+private:
+ class _TaskHandlerThread
+ : public Tizen::Base::Runtime::Thread
+ {
+ public:
+ _TaskHandlerThread(AppService& mgr);
+ virtual ~_TaskHandlerThread(void);
+
+ virtual bool OnStart(void);
+ virtual void OnStop(void);
+ virtual void OnUserEventReceivedN(RequestId reqId, Tizen::Base::Collection::IList* pArgs);
+
+ private:
+ AppService& __mgr;
+ };
+
+ Tizen::App::_CommunicationDispatcher* __pCommunicationDispatcher;
+ Tizen::App::_ContextManager* __pContextMgr;
+ Tizen::App::_AppManagerStub* __pAppManagerStub;
+ Tizen::App::_ConditionManagerStub* __pConditionManagerStub;
+ _TaskHandlerThread __handlerThread;
+ Tizen::System::_DeviceManagerService* __pDeviceManagerService;
+ Tizen::System::_SystemService* __pSystemService;
+ Tizen::System::_AccessoryManagerService* __pAccessoryManagerService;
+ Tizen::System::_AlarmService* __pAlarmService;
+ Tizen::App::_PackageManagerStub* __pPackageManagerStub;
+ Tizen::App::_NotificationManagerStub* __pNotificationManagerStub;
+ Tizen::Io::_MmcStorageManagerStub* __pMmcStorageManagerStub;
+}; // AppService
+
+#endif
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_AppManagerService.h
+ * @brief This is the header file of the _AppManagerService class.
+ *
+ * This header file contains the declarations of the _AppManagerService class.
+ */
+
+#ifndef _FAPP_INTERNAL_APP_MANAGER_SERVICE_H_
+#define _FAPP_INTERNAL_APP_MANAGER_SERVICE_H_
+
+#include <FBase.h>
+#include <FSystem.h>
+#include <FIo.h>
+#include <FAppTypes.h>
+
+#include <FApp_IAppManager.h>
+
+#include "FApp_ContextManager.h"
+
+
+namespace Tizen { namespace App {
+
+class _IAppManagerServiceEventListener;
+
+/**
+ * @class _AppManagerService
+ * @brief Manages and control applications.
+ * @since 2.1
+ */
+class _AppManagerService
+ : public Tizen::Base::Object
+ , public _IAppManager
+ , public _IContextManagerEventListener
+ , virtual public Tizen::Base::Runtime::IEventListener
+{
+public:
+ _AppManagerService(void);
+
+ virtual ~_AppManagerService(void);
+
+ result Construct(_ContextManager* pContextMgr, _IAppManagerServiceEventListener* pStub);
+
+ virtual result LaunchApplication(const AppId& appId, const Tizen::Base::String& executableName, int req);
+ virtual result TerminateApplication(const AppId& appId, const Tizen::Base::String& executableName);
+ virtual bool IsRunning(const AppId& appId, const Tizen::Base::String& executableName);
+ virtual result GetRunningAppList(Tizen::Base::Collection::ArrayList* pArray);
+ virtual result RegisterApplication(const AppId& appId, const Tizen::Base::String& executableName, _AppType appType, int pid);
+ virtual result RegisterApplication(const AppId& appId, const Tizen::Base::String& executableName, _AppType appType, int pid, int clientId);
+ virtual result UnregisterApplication(int pid);
+
+ virtual result InitEventListener( _IAppManagerServiceEventListener* pListener);
+ virtual result AddEventListener(int clientId);//, _IAppManagerServiceEventListener* pListener);
+ virtual result RemoveEventListener(int clientId);//, _IAppManagerServiceEventListener* pListener);
+ virtual void OnApplicationTerminated(const _AppContext& appInfo);
+
+ // helper
+// const _AppContext* GetAppInfoSimple(const AppId& appId) const;
+
+private:
+ result SendEventToAllListeners(const _AppManagerEventArg& arg);
+
+private:
+ typedef Tizen::Base::Collection::HashMapT<int, _IAppManagerServiceEventListener*> _AppManagerServiceEventListeners;
+ typedef Tizen::Base::Collection::IMapEnumeratorT <int, _IAppManagerServiceEventListener*> _AppManagerServiceEventListenerEnum;
+
+ _ContextManager* __pContextMgr;
+ _AppManagerServiceEventListeners __eventListeners;
+ _IAppManagerServiceEventListener* __pStub;
+ _IAppManagerServiceEventListener* __pProxy;
+
+ void Dump(void);
+
+friend class UTs_AppManagerServiceP;
+}; //_AppManagerService
+
+}}//Tizen::App
+
+#endif//_APP_MANAGER_SERVICE_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_AppManagerStub.h
+ * @brief This is the header file of the _AppManagerStub class.
+ *
+ * This header file contains the declarations of the _AppManagerStub class.
+ */
+
+#ifndef _FAPP_INTERNAL_APP_MANAGER_STUB_H_
+#define _FAPP_INTERNAL_APP_MANAGER_STUB_H_
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FBaseRtIEventListener.h>
+#include <FSystem.h>
+#include <FIo.h>
+#include <FAppTypes.h>
+
+#include <FIo_IIpcServerEventListener.h>
+#include <FApp_IAppManager.h>
+#include <FApp_IAppManagerServiceEventListener.h>
+
+
+namespace Tizen { namespace App {
+
+class _AppManagerService;
+class _ContextManager;
+
+/**
+ * @class _AppManagerStub
+ * @brief Handles IPC requests and calls real methods.
+ * @since 2.1
+ */
+class _AppManagerStub
+ : public Tizen::Base::Object
+ , public Tizen::Io::_IIpcServerEventListener
+ , public _IAppManagerServiceEventListener
+ , virtual public Tizen::Base::Runtime::IEventListener
+{
+public:
+ _AppManagerStub(void);
+
+ virtual ~_AppManagerStub(void);
+
+ result Construct(_ContextManager* pContextMgr);
+
+ // handlers
+ bool OnLaunchApplication(const AppId& appID, const Tizen::Base::String& serviceId, int req);
+ bool OnTerminateApplication(const AppId& appID, const Tizen::Base::String& executableName, result *pRes);
+ bool OnIsRunning(const AppId& appID, const Tizen::Base::String& executableName, bool *pRes);
+ bool OnGetRunningAppList(Tizen::Base::Collection::ArrayList* pArray, result *pRes);
+ bool OnRegisterApplication(const AppId& appID, const Tizen::Base::String& executableName, int appType, int pid);
+ bool OnUnregisterApplication(int pid);
+ bool OnAddEventListener(int pid);
+ bool OnRemoveEventListener(int pid);
+
+ // send message to client
+
+ // _IIpcServerEventListener
+ virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server);
+ virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server);
+ virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId);
+ virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId);
+ virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
+
+ // to client
+ virtual result OnServiceEventReceived(int clientId, const _AppManagerEventArg& arg);
+ virtual result OnTerminateApplicationRequested(int clientId);
+
+private:
+ result StartIpcServer(void);
+ _AppManagerStub(const _AppManagerStub& value);
+ _AppManagerStub& operator =(const _AppManagerStub& source);
+
+private:
+ typedef Tizen::Base::Collection::HashMapT<int, Tizen::Base::String*> _AppManagerEventListeners;
+ typedef Tizen::Base::Collection::IMapEnumeratorT <int, Tizen::Base::String*> _AppManagerEventListenersEnumerator;
+
+ Tizen::Io::_IpcServer *__pIpcServer;
+ _AppManagerService* __pAppManagerService;
+}; //_AppManagerStub
+
+}}//Tizen::App
+
+#endif//_FAPP_INTERNAL_APP_MANAGER_STUB_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_CommunicationDispatcher.h
+ * @brief This is the header file of the _CommunicationDispatcher class.
+ *
+ * This header file contains the declarations of the _CommunicationDispatcher class.
+ */
+#include <FApp.h>
+#include <FBase.h>
+#include <FIo.h>
+
+#include <FApp_IAppManagerEventListener.h>
+#include <FIo_IIpcServerEventListener.h>
+#include "FApp_ICommunicationRequestListener.h"
+
+#ifndef _FAPP_INTERNAL_COMMNUICATION_DISPATCHER_H_
+#define _FAPP_INTERNAL_COMMNUICATION_DISPATCHER_H_
+
+namespace Tizen { namespace App
+{
+class _AppManagerImpl;
+}}
+
+namespace Tizen { namespace Base
+{
+namespace Runtime
+{
+class Mutex;
+}
+}}
+
+namespace Tizen { namespace Io
+{
+class _IpcServer;
+}}
+
+namespace Tizen { namespace App {
+
+/**
+ * @class _CommunicationDispatcher
+ * @brief This class contains implementaion of communication feature for external application.
+ * @since 2.1
+ */
+class _CommunicationDispatcher
+ : public Tizen::Io::_IIpcServerEventListener
+ , public _IAppManagerEventListener
+ , virtual public Tizen::Base::Runtime::IEventListener
+{
+
+public:
+ static _CommunicationDispatcher* GetInstance(void);
+
+ result AddCommunicationEventListener(Tizen::App::_ICommunicationRequestListener& listener);
+ result RemoveCommunicationEventListener(Tizen::App::_ICommunicationRequestListener& listener);
+
+ virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server) {}
+ virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server) {}
+ virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId) {}
+ virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer& server, int clientId) {}
+ virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
+
+ virtual void OnApplicationLaunched(const AppId& appId, _AppType type);
+ virtual void OnApplicationTerminated(const AppId& appId, _AppType type);
+
+ bool OnRequestOccured(const Tizen::Base::Collection::ArrayList& request, Tizen::Base::Collection::ArrayList* response);
+ result SendData(const Tizen::App::AppId appId, Tizen::Base::Collection::ArrayList& data);
+
+private:
+ _CommunicationDispatcher(void);
+ virtual ~_CommunicationDispatcher(void);
+ Tizen::Base::Integer* GetClientId(const Tizen::App::AppId& appId, const Tizen::Base::String& componentId) const;
+ result AddClientId(Tizen::App::AppId appId, Tizen::Base::String componentId, Tizen::Base::Integer clientId);
+ result RemoveClientId(Tizen::App::AppId appId, Tizen::Base::String componentId, Tizen::Base::Integer clientId);
+ result RemoveClientId(Tizen::App::AppId appId, Tizen::Base::String componentId);
+ result RemoveClientId(Tizen::App::AppId appId);
+
+private:
+ Tizen::Io::_IpcServer* __pIpcServer;
+ Tizen::Base::Collection::ArrayList* __pRegisteredAppList;
+ Tizen::App::AppId __currentAppId;
+ Tizen::Base::Integer __currentClientId;
+ Tizen::Base::Runtime::Mutex __Mutex;
+ _AppManagerImpl* __pAppManagerImpl;
+}; //_CommunicationDispatcher
+
+}} //Tizen::App
+#endif /* _FAPP_INTERNAL_COMMNUICATION_DISPATCHER_H_ */
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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 FApp_ConditionHandler.h
+ * @brief This is the header file of the _ConditionHandler class.
+ *
+ * This header file contains the declarations of the _ConditionManagerService class.
+ */
+
+#ifndef _FAPP_INTERNAL_CONDITION_HANDLER_H_
+#define _FAPP_INTERNAL_CONDITION_HANDLER_H_
+
+
+#include <FBase.h>
+#include <FBaseCol.h>
+#include <FAppTypes.h>
+
+#include <FApp_AppLaunchConditionHandlerBase.h>
+#include "FApp_StringKeyHashMapUtil.h"
+
+namespace Tizen { namespace Base { namespace Runtime { class Library; }}}
+namespace Tizen { namespace App {
+
+
+class _ConditionHandler;
+
+/**
+ * @class _ConditionPlugInInfo
+ * @brief Contains plugin info of registry.(ConditionHandlerPlugins.ini)
+ * @since 2.1
+ */
+class _ConditionPlugInInfo :
+ public Tizen::Base::Object
+{
+public:
+ const Tizen::Base::String typeString;
+ const Tizen::Base::String name; // or fileName
+ const _ConditionHandler* pHandler;
+public:
+ _ConditionPlugInInfo(const Tizen::Base::String _typeString, const Tizen::Base::String _name, const _ConditionHandler* _pHandler)
+ :typeString(_typeString), name(_name),pHandler(_pHandler) {}
+
+}; //_ConditionPlugInInfo
+
+typedef _AppLaunchConditionHandlerBase* (*create_plugin)(void);
+typedef void (*destroy_plugin)(_AppLaunchConditionHandlerBase* p);
+
+/**
+ * @class _ConditionHandler
+ * @brief Manages each conditional operations and handler instance.
+ * @since 2.1
+ */
+class _ConditionHandler
+ : public Tizen::Base::Object
+ , public Tizen::App::_IAppLaunchConditionEventListener
+ , virtual public Tizen::Base::Runtime::IEventListener
+{
+ typedef Tizen::Base::Collection::MultiHashMapT<Tizen::Base::String, _AppLaunchCondition*> _AppLaunchConditions;
+// typedef Tizen::Base::Collection::IMapEnumeratorT <Tizen::Base::String, _AppLaunchCondition*> _AppLaunchConditionEnumerator;
+ typedef Tizen::Base::Collection::IEnumeratorT <_AppLaunchCondition*> _AppLaunchConditionEnumerator;
+
+public :
+ _ConditionHandler(const Tizen::Base::String& fileName, const Tizen::Base::String& typesString);
+ virtual ~_ConditionHandler(void);
+ result Construct(void);
+ result AddCondition( _AppLaunchCondition& operation);
+ result RemoveCondition(const Tizen::Base::String& packageId, const Tizen::Base::String* pExecutableName, const Tizen::Base::String* pCondition);
+ _AppLaunchCondition* Find(const Tizen::Base::String& packageId, const Tizen::Base::String *pCondition);
+ result CreateUniqueId(Tizen::Base::String& uniqueId);
+ bool HasCondition(const Tizen::Base::String& packageId, const Tizen::Base::String& executableName, const Tizen::Base::String *pCondition) const ;
+ bool CanHandleType(const Tizen::Base::String& type ) const;
+
+ void Dump(void) const;
+
+private:
+ _AppLaunchCondition* FindItemBySectionName(const Tizen::Base::String& sectionName) const;
+ virtual void OnAppLaunchConditionMet(const _AppLaunchCondition& operation);
+ result LoadPlugin(void);
+ _ConditionHandler(const _ConditionHandler& value);
+ _ConditionHandler& operator =(const _ConditionHandler& source);
+
+private:
+ Tizen::Base::String __typesString;
+ Tizen::Base::String __pluginFileName;
+ _AppLaunchConditionHandlerBase* __pPluginInstance;
+ _AppLaunchConditions __conditionalOperations;
+ _StringComparerT __strComparer;
+ _StringHashMapProviderT __strHashMapProvider;
+
+ Tizen::Base::Runtime::Library* __pLib;
+ destroy_plugin __pfDestroyPlugin;
+}; //_ConditionHandler
+
+
+/**
+ * @class _ConditionRegistryHelper
+ * @brief
+ * @since 2.1
+ */
+
+class _ConditionRegistryHelper
+{
+public:
+ static result AddToRegistry(const Tizen::Base::String& sectionName, const Tizen::Base::String& packageId, const Tizen::Base::String& executableName, const Tizen::Base::String& condition, const Tizen::Base::Collection::IList *pArgs);
+ static result RemoveFromRegistry(const Tizen::Base::String& sectionName);
+ static result GetAllParamsN(const Tizen::Base::Collection::IMap& map, Tizen::Base::String& packageId, Tizen::Base::String& executableName, Tizen::Base::String& condition, Tizen::Base::Collection::ArrayList*& pArgs);
+}; //_ConditionRegistryHelper
+
+
+}} //Tizen::App
+#endif // _FAPP_INTERNAL_CONDITION_HANDLER_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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 FApp_ConditionManagerService.h
+ * @brief This is the header file of the _ConditionManagerService class.
+ *
+ * This header file contains the declarations of the _ConditionManagerService class.
+ */
+
+#ifndef _FAPP_INTERNAL_CONDITION_MANAGER_SERVICE_H_
+#define _FAPP_INTERNAL_CONDITION_MANAGER_SERVICE_H_
+
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FAppTypes.h>
+
+#include "FApp_ConditionHandler.h"
+
+namespace Tizen { namespace Base { namespace Collection { class IList; }}}
+namespace Tizen { namespace App {
+
+
+class _ConditionHandler;
+
+/**
+ * @class _ConditionManagerService
+ * @brief This class contains implementaion of conditional app launch feature.
+ * @since 2.1
+ * @see AppManager, _ConditionManagerProxy
+ */
+class _ConditionManagerService
+ : public Tizen::Base::Object
+{
+ typedef Tizen::Base::Collection::ArrayListT<_ConditionHandler*> _ConditionHandlers;
+ typedef Tizen::Base::Collection::HashMapT<Tizen::Base::String, _ConditionHandler*> _ConditionHandlerMap;
+
+
+public:
+ _ConditionManagerService(void);
+ virtual ~_ConditionManagerService(void);
+ result Construct(void);
+
+ result RegisterAppLaunch(const Tizen::Base::String& packageId, const Tizen::Base::String& executableName, const Tizen::Base::String& condition, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option = AppManager::LAUNCH_OPTION_DEFAULT, const Tizen::Base::String* pSectionName = null);
+ result UnregisterAppLaunch(const Tizen::Base::String& packageId, const Tizen::Base::String& executableName, const Tizen::Base::String* pCondition);
+ result UnregisterAppLaunch(const Tizen::Base::String& packageId, const Tizen::Base::String* pExecutableName); // internal
+ bool IsAppLaunchRegistered(const Tizen::Base::String& packageId, const Tizen::Base::String& executableName, const Tizen::Base::String* pCondition = null);
+
+private:
+ // internal
+ result InitializePlugins(void);
+ result InitializePluginEntry(Tizen::Base::Collection::IMap& map);
+ result InitializeConditionalOperations(void);
+ result InitializeConditionalOperationEntry(const Tizen::Base::String& sectionName, const Tizen::Base::Collection::IMap& map);
+ _ConditionHandler* GetLaunchConditionHandler(const Tizen::Base::String& pluginName);
+ _ConditionHandler* GetHandlerByCondition(const Tizen::Base::String& condition);
+
+ result ValidateArguments(const Tizen::Base::Collection::IList* pArguments) const;
+
+ static void DumpArguments(const Tizen::Base::Collection::IList* pArguments);
+ void Dump(void) const;
+
+private:
+ _ConditionHandlers __handlers;
+ _ConditionHandlerMap __handlerLookupTable;
+
+ _StringComparerT __strComparer;
+ _StringHashMapProviderT __strHashMapProvider;
+
+ friend class UTs_ConditionManagerServiceP;
+}; //_ConditionManagerService
+
+}} //Tizen::App
+#endif // _FAPP_INTERNAL_CONDITION_MANAGER_SERVICE_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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 FApp_ConditionManagerStub.h
+ * @brief This is the header file of the _ConditionManagerStub class.
+ *
+ * This header file contains the declarations of the _ConditionManagerStub class.
+ */
+
+#ifndef _FAPP_INTERNAL_CONDITION_MANAGER_SERVER_H_
+#define _FAPP_INTERNAL_CONDITION_MANAGER_SERVER_H_
+
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FAppTypes.h>
+
+#include <FIo_IIpcServerEventListener.h>
+
+
+namespace Tizen { namespace App {
+
+class _ConditionManagerService;
+
+
+class _ConditionManagerStub :
+ public Tizen::Base::Object,
+ public Tizen::Io::_IIpcServerEventListener
+{
+
+public:
+ _ConditionManagerStub(void);
+ virtual ~_ConditionManagerStub(void);
+ result Construct(void);
+
+ void OnInstallComplete(const AppId& appId, const Tizen::Base::String& executableName, const Tizen::Base::String& packageName );
+ void OnUninstallComplete(const AppId& appId, const Tizen::Base::String& executableName);
+
+private:
+ // ipc handlers.
+ bool OnRegisterAppLaunch(const AppId& appId, const Tizen::Base::String& executableName, const Tizen::Base::String& cond, const Tizen::Base::Collection::ArrayList& args , int flag, result *pRes);
+ bool OnUnregisterAppLaunch(const AppId& appId, const Tizen::Base::String& executableName, const Tizen::Base::String& cond, result *pRes);
+ bool OnIsAppLaunchRegistered(const AppId& appId, const Tizen::Base::String& executableName, const Tizen::Base::String& cond, bool *pIsAppLaunchRegistered, result *pException);
+ result ExtractDueAndPeriod(const Tizen::Base::String& src, Tizen::Base::String& dueTime, Tizen::Base::String& period);
+
+ // _IIpcServerEventListener
+ virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server);
+ virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server);
+ virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId);
+ virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId);
+ virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
+
+ // internal
+ result StartIpcServer(void);
+
+private:
+ Tizen::Io::_IpcServer *__pIpcServer;
+ _ConditionManagerService* __pConditionManagerService;
+}; //_ConditionManagerStub
+
+}} //Tizen::App
+#endif // _FAPP_INTERNAL_CONDITION_MANAGER_SERVER_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_ContextManager.h
+ * @brief This is the header file of the _ContextManager class.
+ *
+ * This header file contains the declarations of the _ContextManager class.
+ */
+
+#ifndef _FAPP_INTERNAL_CONTEXT_MANAGER_H_
+#define _FAPP_INTERNAL_CONTEXT_MANAGER_H_
+
+#include <map>
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FBaseColArrayListT.h>
+#include <FAppTypes.h>
+#include <FBaseRtIEventListener.h>
+
+#include <FApp_Types.h>
+
+namespace Tizen { namespace Base { namespace Collection { class ArrayList; } } }
+
+namespace Tizen { namespace App {
+
+enum _OomAppType
+{
+ OOM_APP_TYPE_SYSTEM,
+ OOM_APP_TYPE_LAUNCHING,
+ OOM_APP_TYPE_FOREGROUND_HIGH,
+ OOM_APP_TYPE_SERVICE_HIGH,
+ OOM_APP_TYPE_FOREGROUND,
+ OOM_APP_TYPE_SERVICE_MID,
+ OOM_APP_TYPE_BACKGROUND_HIGH,
+ OOM_APP_TYPE_SERVICE_LOW,
+ OOM_APP_TYPE_BACKGROUND
+};
+
+class _AppContext
+{
+public:
+ _AppContext(const AppId& appId,
+ const Tizen::Base::String& executableName,
+ _AppType appType,
+ int pid,
+ int ipcClientId,
+ bool isSystemService
+ );
+
+ ~_AppContext(void)
+ {
+ }
+
+ Tizen::Base::String ToString(void) const;
+
+public:
+ AppId appId;
+ Tizen::Base::String executableName;
+ _AppType appType;
+ int pId;
+ int ipcClientId;
+ AppUiState uiState;
+ bool isRegistered;
+ bool isSystemService;
+}; //_AppContext
+
+class _IContextManagerEventListener
+ : virtual public Tizen::Base::Runtime::IEventListener
+{
+public:
+ virtual void OnApplicationTerminated(const _AppContext& appInfo) = 0;
+};
+
+/**
+ * @class _ContextManager
+ * @brief
+ * @since 2.1
+ *
+ *
+ */
+class _ContextManager
+{
+ typedef std::map<int, _AppContext*> AppContexts;
+
+public:
+ _ContextManager(void);
+ ~_ContextManager(void);
+
+ result Construct(void);
+ result Register(const PackageId& appId, const Tizen::Base::String& executableName, _AppType appType, int pid, int ipcClientId, bool isSystemService);
+ result Unregister(int pid);
+ const _AppContext* Find(const AppId& appId, const Tizen::Base::String& executableName) const;
+ const _AppContext* Find(int pid);
+ result GetAppListN(Tizen::Base::Collection::ArrayList* pArray) const;
+ void SetEventListener(_IContextManagerEventListener& listener);
+
+ void AbonormalAppTerminationHanlder(int pid, const AppId& appId, const Tizen::Base::String& execName);
+ static int OnAppTerminate(int pid, void *data);// app_dead_signal_listener
+ void Dump(void) const;
+
+
+private:
+ _ContextManager(const _ContextManager& rhs);
+ _ContextManager& operator=(const _ContextManager& rhs);
+ _OomAppType GetOomAppType(const AppId& appId, const int pid) const;
+ bool IsErrorProneApp(const AppId& appId) const;
+
+public:
+ /**
+ * This is static helper class
+ */
+ class _Util
+ {
+ public:
+ static Tizen::Base::String QueryFeatureFromPackageManager(const AppId& appId, const Tizen::Base::String& execName, const Tizen::Base::String& feature);
+// static Tizen::Base::String GetExecNameFromPackageName(const Tizen::Base::String& packageName);
+ };
+
+private:
+ const unsigned long __magic;
+ AppContexts __appContexts;
+ _IContextManagerEventListener* __pEventListener;
+ Tizen::Base::Collection::ArrayListT<Tizen::Base::String> __errorProneAppIds;
+}; //_ContextManager
+
+} } // Tizen::App
+
+#endif //_FAPP_INTERNAL_CONTEXT_MANAGER_H_
+
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_ICommunicationRequestListener.h
+ * @brief This is the header file for the %_ICommunicationRequestListener class.
+ *
+ * This header file contains the declarations of the %_ICommunicationRequestListener class.
+ */
+
+#ifndef _FAPP_ICOMMUNICATION_EVENT_LISTENER_H_
+#define _FAPP_ICOMMUNICATION_EVENT_LISTENER_H_
+
+#include <FBaseRtIEventListener.h>
+#include <FBase.h>
+
+
+namespace Tizen { namespace App
+{
+
+class _OSP_EXPORT_ _ICommunicationRequestListener
+ : virtual public Tizen::Base::Runtime::IEventListener
+{
+public:
+ virtual ~_ICommunicationRequestListener(void) {}
+ virtual Tizen::Base::String GetId(void) = 0;
+ virtual void OnRequestOccured(AppId appId, Tizen::Base::Collection::ArrayList* request, Tizen::Base::Collection::ArrayList* response) = 0;
+ virtual void OnApplicationTerminated(const AppId& appId, _AppType type) = 0;
+
+}; // _ICommunicationRequestListener
+
+}} // Tizen::App
+
+#endif // _FAPP_ICOMMUNICATION_EVENT_LISTENER_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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 FApp_NotificationManagerService.h
+ * @brief This is the header file of the _NotificationManagerService class.
+ *
+ * This header file contains the declarations of the _NotificationManagerService class.
+ */
+
+#ifndef _FAPP_INTERNAL_NOTIFICATION_MANAGER_SERVICE_H_
+#define _FAPP_INTERNAL_NOTIFICATION_MANAGER_SERVICE_H_
+
+
+#include <appsvc/appsvc.h>
+#include <bundle.h>
+#include <notification/notification.h>
+#include <appfw/app.h>
+#include <appfw/app_manager.h>
+#include <appfw/app_ui_notification.h>
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FAppTypes.h>
+#include <FShellNotificationRequest.h>
+
+
+namespace Tizen { namespace App {
+
+/**
+ * @class _NotificationManagerService
+ * @brief This class contains implementaion of NotificationManager feature.
+ * @since 2.1
+ * @see AppManager, _ConditionManagerProxy
+ */
+class _NotificationManagerService
+ : public Tizen::Base::Object
+{
+
+public:
+ _NotificationManagerService(void);
+ virtual ~_NotificationManagerService(void);
+ result Construct(void);
+
+ result NotifyMessage(const AppId& appId,const Tizen::Shell::NotificationRequest& notiMessage, bool OnGoing);
+ result RemoveNotification(const AppId& appId, bool Ongoing);
+
+};
+
+}} //Tizen::App
+#endif // _FAPP_INTERNAL_NOTIFICATION_MANAGER_SERVICE_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_NotificationManagerStub.h
+ * @brief This is the header file of the _NotificationManagerStub class.
+ *
+ * This header file contains the declarations of the _NotificationManagerStub class.
+ */
+
+#ifndef _FAPP_INTERNAL_NOTIFICATION_MANAGER_STUB_H_
+#define _FAPP_INTERNAL_NOTIFICATION_MANAGER_STUB_H_
+
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FAppTypes.h>
+#include <FShellNotificationRequest.h>
+
+#include <FIo_IIpcServerEventListener.h>
+
+
+namespace Tizen { namespace App {
+
+class _NotificationManagerService;
+
+class _NotificationManagerStub :
+ public Tizen::Base::Object,
+ public Tizen::Io::_IIpcServerEventListener
+{
+
+public:
+ _NotificationManagerStub(void);
+ virtual ~_NotificationManagerStub(void);
+ result Construct(void);
+
+ // ipc handlers.
+ void OnNotifyMessage(const Tizen::App::AppId& appId, const Tizen::Shell::NotificationRequest& notimessage, bool OnGoing, result* pRes);
+ void OnRemoveNotification(const Tizen::App::AppId& appId, bool Ongoing, result* pRes);
+
+private:
+ _NotificationManagerStub(const _NotificationManagerStub& value);
+ _NotificationManagerStub& operator =(const _NotificationManagerStub& source);
+
+ // _IIpcServerEventListener
+ virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server);
+ virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server);
+ virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId);
+ virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId);
+ virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
+
+ // internal
+ result StartIpcServer(void);
+
+private:
+ Tizen::Io::_IpcServer* __pIpcServer;
+ _NotificationManagerService* __pNotificationManagerService;
+}; //_NotificationManagerStub
+
+}} //Tizen::App
+
+#endif // _FAPP_INTERNAL_NOTIFICATION_MANAGER_STUB_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_PackageManagerStub.h
+ * @brief This is the header file of the _PackageManagerStub class.
+ *
+ * This header file contains the declarations of the _PackageManagerStub class.
+ */
+
+#ifndef _FAPP_INTERNAL_PACKAGE_MANAGER_STUB_H_
+#define _FAPP_INTERNAL_PACKAGE_MANAGER_STUB_H_
+
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FAppTypes.h>
+
+#include <FIo_IIpcServerEventListener.h>
+
+
+namespace Tizen { namespace App { namespace Package {
+class _PackageManagerImpl;
+}}}
+
+namespace Tizen { namespace App {
+
+class _PackageManagerStub :
+ public Tizen::Base::Object,
+ public Tizen::Io::_IIpcServerEventListener
+{
+
+public:
+ _PackageManagerStub(void);
+ virtual ~_PackageManagerStub(void);
+ result Construct(void);
+
+ // ipc handlers.
+ void OnInstallPackage(const PackageId& packageId, const Tizen::Base::String& packagePath, int listener, result* pRes);
+ void OnUninstallPackage(const PackageId& packageId, int listener, result* pRes);
+
+private:
+ _PackageManagerStub(const _PackageManagerStub& value);
+ _PackageManagerStub& operator =(const _PackageManagerStub& source);
+
+ // _IIpcServerEventListener
+ virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server);
+ virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server);
+ virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId);
+ virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId);
+ virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
+
+ // internal
+ result StartIpcServer(void);
+
+private:
+ Tizen::Io::_IpcServer* __pIpcServer;
+ Tizen::App::Package::_PackageManagerImpl* __pPackageManagerImpl;
+}; //_PackageManagerStub
+
+}} //Tizen::App
+
+#endif // _FAPP_INTERNAL_PACKAGE_MANAGER_STUB_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_StringKeyHashMapUtil.h
+ *
+ * This header file contains the implementation of the _StringComparerT, _StringHashMapProviderT class.
+ */
+
+
+#ifndef FAPP_INTERNAL_STRINGKEY_HASHMAP_UTIL_H_
+#define FAPP_INTERNAL_STRINGKEY_HASHMAP_UTIL_H_
+
+class _StringComparerT
+ : public Tizen::Base::Collection::IComparerT <Tizen::Base::String>
+ , public Tizen::Base::Object
+{
+public:
+ _StringComparerT(void){}
+ virtual ~_StringComparerT(void){}
+
+ virtual result Compare(const Tizen::Base::String& obj1, const Tizen::Base::String& obj2, int& cmp) const
+ {
+ cmp = obj1.CompareTo(obj2);
+ return E_SUCCESS;
+ }
+}; //_StringComparerT
+
+
+class _StringHashMapProviderT
+ : public Tizen::Base::Collection::IHashCodeProviderT <Tizen::Base::String>
+ , public Tizen::Base::Object
+{
+public:
+ _StringHashMapProviderT(void) {}
+ virtual ~_StringHashMapProviderT(void) {}
+ virtual int GetHashCode(const Tizen::Base::String& obj) const
+ {
+ return obj.GetHashCode();
+ }
+}; //__StringHashMapProviderT
+
+
+
+
+#endif // FAPP_INTERNAL_STRINGKEY_HASHMAP_UTIL_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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 FIo_MmcStorageManagerService.h
+ * @brief This is the header file of the _MmcStorageManagerService class.
+ *
+ * This header file contains the declarations of the _MmcStorageManagerService class.
+ */
+
+#ifndef _FIO_INTERNAL_MMC_STORAGE_MANAGER_SERVICE_H_
+#define _FIO_INTERNAL_MMC_STORAGE_MANAGER_SERVICE_H_
+
+#include <string>
+#include <map>
+
+#include <appsvc/appsvc.h>
+#include <bundle.h>
+#include <vconf.h>
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FAppTypes.h>
+
+#include <FApp_ContextManager.h>
+
+namespace Tizen { namespace Io {
+
+class _IMmcStorageServiceEventListener;
+
+/**
+ * @class _MmcStorageManagerService
+ * @brief This class contains implementaion of MmcStorageManager feature.
+ * @since 2.1
+ * @see
+ */
+class _MmcStorageManagerService
+ : public Tizen::Base::Object
+{
+ typedef std::map< std::string, Tizen::Base::String* > _AppList;
+ typedef std::pair< std::string, Tizen::Base::String* > _AppListPair;
+
+public:
+ result Construct(_IMmcStorageServiceEventListener* pStub);
+
+ result Mount(void);
+
+ result Unmount(void);
+
+ result Format(void);
+
+ static _MmcStorageManagerService* GetInstance(void);
+
+ static result ConvertNativeErrorToResult(int errNo);
+
+private:
+ _MmcStorageManagerService(void);
+
+ virtual ~_MmcStorageManagerService(void);
+
+ static void MmcEventVconfCallback(keynode_t* node, void* userData);
+
+ static result CreateFlag(const Tizen::Base::String& path);
+
+ static result CreateExternalDirectories(const Tizen::Base::String& appRoot, const Tizen::App::PackageId& pkgId);
+
+ static _MmcStorageManagerService* __pMmcStorageManagerService;
+ _IMmcStorageServiceEventListener* __pStub;
+ _AppList __appList;
+ friend class Tizen::App::_ContextManager;
+};
+
+}} // Tizen::Io
+
+#endif // _FIO_INTERNAL_MMC_STORAGE_MANAGER_SERVICE_H_
+
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FIo_MmcStorageManagerStub.h
+ * @brief This is the header file of the _MmcStorageManagerStub class.
+ *
+ * This header file contains the declarations of the _MmcStorageManagerStub class.
+ */
+
+#ifndef _FIO_INTERNAL_MMC_STORAGE_MANAGER_STUB_H_
+#define _FIO_INTERNAL_MMC_STORAGE_MANAGER_STUB_H_
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+
+#include <FIo_IIpcServerEventListener.h>
+#include <FIo_IMmcStorageServiceEventListener.h>
+
+
+namespace Tizen { namespace Io {
+
+class _MmcStorageManagerService;
+
+class _MmcStorageManagerStub :
+ public Tizen::Base::Object,
+ public Tizen::Io::_IIpcServerEventListener,
+ public Tizen::Io::_IMmcStorageServiceEventListener
+{
+
+public:
+ _MmcStorageManagerStub(void);
+ virtual ~_MmcStorageManagerStub(void);
+ result Construct(void);
+
+ // ipc handlers.
+ void OnMount(result* pRes);
+ void OnUnmount(result* pRes);
+ void OnFormat(result* pRes);
+
+ // Server to Client messages
+ virtual result OnMmcMountResponseReceived(result response);
+ virtual result OnMmcUnmountResponseReceived(result response);
+ virtual result OnMmcFormatResponseReceived(result response);
+
+private:
+ _MmcStorageManagerStub(const _MmcStorageManagerStub& value);
+ _MmcStorageManagerStub& operator =(const _MmcStorageManagerStub& source);
+
+ // _IIpcServerEventListener
+ virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server);
+ virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server);
+ virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId);
+ virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId);
+ virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
+
+ // internal
+ result StartIpcServer(void);
+
+private:
+ Tizen::Io::_IpcServer* __pIpcServer;
+ _MmcStorageManagerService* __pMmcStorageManagerService;
+ bool __operationInProgress;
+ int __clientId;
+}; //_MmcStorageManagerStub
+
+}} //Tizen::App
+
+#endif // _FIO_INTERNAL_MMC_STORAGE_MANAGER_STUB_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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 FSys_AccessoryManagerService.h
+ * @brief This is the header file of the _AccessoryManagerService class.
+ *
+ * This header file contains the declarations of the _AccessoryManagerService class.
+ */
+#include <FApp.h>
+#include <FBase.h>
+#include "FApp_CommunicationDispatcher.h"
+#include "FApp_ICommunicationRequestListener.h"
+
+#ifndef _FSYS_INTERNAL_ACCESSORY_MANAGER_SERVICE_H_
+#define _FSYS_INTERNAL_ACCESSORY_MANAGER_SERVICE_H_
+
+namespace Tizen { namespace Base { namespace Runtime {
+class Library;
+}}}
+namespace Tizen { namespace System {
+
+typedef void (*OnRequestOccuredFunction)(Tizen::App::AppId appId, Tizen::Base::Collection::ArrayList* request, Tizen::Base::Collection::ArrayList* response);
+typedef void (*RemoveOwnerApplicationFunction)(const Tizen::App::AppId appId, const Tizen::Base::String& executableName);
+
+/**
+ * @class _AccessoryManagerService
+ * @brief This class contains implementaion of device control.
+ * @since 2.1
+ */
+class _AccessoryManagerService
+ : public Tizen::App::_ICommunicationRequestListener
+{
+private:
+ _AccessoryManagerService(void);
+ virtual ~_AccessoryManagerService(void);
+
+public:
+ virtual Tizen::Base::String GetId(void);
+ virtual void OnRequestOccured(Tizen::App::AppId appId, Tizen::Base::Collection::ArrayList* request, Tizen::Base::Collection::ArrayList* response);
+ virtual void OnApplicationTerminated(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
+ result SendData(Tizen::App::AppId appId, Tizen::Base::Collection::ArrayList* data);
+ static _AccessoryManagerService* GetInstance(void);
+
+private:
+ _AccessoryManagerService(const _AccessoryManagerService& value);
+ _AccessoryManagerService& operator =(const _AccessoryManagerService& value);
+ Tizen::Base::Runtime::Library* __pLib;
+ Tizen::App::_CommunicationDispatcher* __pCommunicationDispatcher;
+ OnRequestOccuredFunction __pOnRequestOccuredFunction;
+ RemoveOwnerApplicationFunction __pRemoveOwnerApplicationFunction;
+}; //_AccessoryManagerService
+
+}} //Tizen::System
+#endif /* _FSYS_INTERNAL_ACCESSORY_MANAGER_SERVICE_H_ */
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FSys_AlarmService.h
+ * @brief This is the header file of the _AlarmService class.
+ *
+ * This header file contains the declarations of the _AlarmService class.
+ */
+
+#include <FApp.h>
+#include <FBase.h>
+#include <FBaseColMultiHashMap.h>
+
+#include "FApp_ICommunicationRequestListener.h"
+
+
+#ifndef _FSYS_INTERNAL_ALARM_SERVICE_H_
+#define _FSYS_INTERNAL_ALARM_SERVICE_H_
+
+namespace Tizen { namespace System {
+
+/**
+ * @class _AlarmService
+ * @brief This class contains implementaion of Alarm control.
+ * @since 3.0
+ */
+class _AlarmService
+ : public Tizen::Base::Object
+ , public Tizen::App::_ICommunicationRequestListener
+{
+private:
+ _AlarmService(void);
+ virtual ~_AlarmService(void);
+public:
+ virtual Tizen::Base::String GetId(void);
+ virtual void OnRequestOccured(Tizen::App::AppId appId, Tizen::Base::Collection::ArrayList* request, Tizen::Base::Collection::ArrayList* response);
+ virtual void OnApplicationTerminated(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
+
+ void OnAlarmExpired(int alarmId);
+ static _AlarmService* GetInstance(void);
+private:
+ int ReserveAlarm(Tizen::Base::DateTime startTime, int period);
+ result AddAlarmList(int alarmId, int period, Tizen::Base::String appId, Tizen::Base::DateTime* endTime);
+ result RemoveAlarmList(int alarmId);
+ result RemoveAlarmList(Tizen::Base::String appId);
+private:
+ Tizen::App::_CommunicationDispatcher* __pCommunicationDispatcher;
+ static _AlarmService* __pAlarmService;
+ Tizen::Base::Collection::MultiHashMap* __pAlarmHashMap;
+ Tizen::Base::DateTime __endTime;
+
+
+
+}; //_AlarmService
+
+}} //Osp::System
+#endif /* _FSYS_INTERNAL_ALARM_SERVICE_H_ */
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FSys_DeviceManagerService.h
+ * @brief This is the header file of the _DeviceManagerService class.
+ *
+ * This header file contains the declarations of the _DeviceManagerService class.
+ */
+#include <FApp.h>
+#include <FBase.h>
+#include <FSys_IDeviceManagerEventListener.h>
+#include "FApp_ICommunicationRequestListener.h"
+
+#ifndef _FSYS_INTERNAL_DEVICE_MANAGER_SERVICE_H_
+#define _FSYS_INTERNAL_DEVICE_MANAGER_SERVICE_H_
+
+namespace Tizen { namespace System {
+
+/**
+ * @class _DeviceManagerService
+ * @brief This class contains implementaion of device control.
+ * @since 2.1
+ */
+class _DeviceManagerService
+ : public Tizen::App::_ICommunicationRequestListener
+ , public Tizen::System::_IDeviceManagerEventListener
+{
+private:
+ _DeviceManagerService(void);
+ virtual ~_DeviceManagerService(void);
+public:
+ virtual Tizen::Base::String GetId(void);
+ virtual void OnRequestOccured(Tizen::App::AppId appId, Tizen::Base::Collection::ArrayList* request, Tizen::Base::Collection::ArrayList* response);
+ virtual void OnApplicationTerminated(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
+ virtual void OnBluetoothEventOccured(int code);
+ void SendEvent(Tizen::Base::String event);
+ void SetBluetoothStatus(bool status);
+ bool GetBluetoothStatus(void);
+ static _DeviceManagerService* GetInstance(void);
+
+private:
+ void AddInterestedApp(Tizen::App::AppId appId);
+ void RemoveInterestedApp(Tizen::App::AppId appId);
+ Tizen::Base::Collection::ArrayList __interestedAppList;
+ Tizen::App::_CommunicationDispatcher* __pCommunicationDispatcher;
+ bool isBluetoothHeadSetConnected;
+ static _DeviceManagerService* __pDeviceManagerService;
+
+}; //_DeviceManagerService
+
+}} //Tizen::System
+#endif /* _FSYS_INTERNAL_DEVICE_MANAGER_SERVICE_H_ */
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FSys_SystemService.h
+ * @brief This is the header file of the _SystemService class.
+ *
+ * This header file contains the declarations of the _SystemService class.
+ */
+#include <FApp.h>
+#include <FBase.h>
+#include "FApp_ICommunicationRequestListener.h"
+
+#ifndef _FSYS_INTERNAL_SYSTEM_SERVICE_H_
+#define _FSYS_INTERNAL_SYSTEM_SERVICE_H_
+
+namespace Tizen { namespace System {
+
+/**
+ * @class _SystemService
+ * @brief This class contains implementaion of device control.
+ * @since 2.1
+ */
+class _SystemService
+ : public Tizen::App::_ICommunicationRequestListener
+ , public Tizen::App::IActiveAppEventListener
+{
+private:
+ _SystemService(void);
+ virtual ~_SystemService(void);
+public:
+ virtual Tizen::Base::String GetId(void);
+ virtual void OnRequestOccured(Tizen::App::AppId appId, Tizen::Base::Collection::ArrayList* request, Tizen::Base::Collection::ArrayList* response);
+ virtual void OnApplicationTerminated(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
+ static _SystemService* GetInstance(void);
+ void RestoreBrightness(void);
+ virtual void OnActiveAppChanged(const Tizen::App::AppId& appId);
+
+private:
+ Tizen::App::_CommunicationDispatcher* __pCommunicationDispatcher;
+ Tizen::Base::Collection::HashMap __appBrightnessList;
+ Tizen::App::AppId __activeAppId;
+ static _SystemService* __pSystemService;
+
+}; //_SystemService
+
+}} //Tizen::System
+#endif /* _FSYS_INTERNAL_SYSTEM_SERVICE_H_ */
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<Manifest xmlns="http://schemas.tizen.org/2012/06/manifest">
+ <Id>aospd00043</Id>
+ <Version>1.0.0</Version>
+ <Type>C++App</Type>
+ <Vendors>
+ <Vendor Locale="eng-GB">Samsung Electronics</Vendor>
+ </Vendors>
+ <Descriptions/>
+ <Url/>
+ <Requirements/>
+ <Apps>
+ <ApiVersion>2.1</ApiVersion>
+ <Secret>9C645DDBA19C71BAD1204DA4DAA7A0B9</Secret>
+ <Privileges>
+ <Privilege>http://tizen.org/privilege/application.launch</Privilege>
+ <Privilege>http://tizen.org/privilege/appmanager.launch</Privilege>
+ <Privilege>http://tizen.org/privilege/alarm</Privilege>
+ <Privilege>http://tizen.org/privilege/packageinfo</Privilege>
+ </Privileges>
+ <ServiceApp AutoRestart="False" Default="True" ExecutableName="osp-app-service" LaunchOnBoot="False">
+ <Names>
+ <Name Locale="eng-GB">osp-app-service</Name>
+ </Names>
+ <Icons/>
+ <AppControls/>
+ <DataControls/>
+ <LaunchConditions/>
+ <Notifications/>
+ </ServiceApp>
+ </Apps>
+</Manifest>
--- /dev/null
+<manifest>
+ <define>
+ <domain name="osp-app-service"/>
+ </define>
+ <request>
+ <domain name="osp-app-service"/>
+ </request>
+ <assign>
+ <filesystem path="/usr/apps/aospd00043/bin/osp-app-service.exe" label="osp-app-service" exec_label="osp-app-service"/>
+ <filesystem path="/etc/rc.d/init.d/boot-osp.sh" label="_" exec_label="none"/>
+ <filesystem path="/etc/rc.d/rc3.d/S44boot-osp" label="_" exec_label="none"/>
+ <filesystem path="/usr/share/license/osp-app-service" label="_"/>
+ </assign>
+</manifest>
--- /dev/null
+[Unit]
+Description=OSP app service
+After=xorg.target
+Requires=xorg.target
+Before=e17.service
+
+[Service]
+Type=simple
+ExecStart=/opt/apps/aospd00043/bin/osp-app-service
+ExecStartPost=-/usr/bin/aul_test update_list aospd00043.osp-app-service /opt/apps/aospd00043/bin/osp-app-service $MAINPID
+
+[Install]
+WantedBy=core-efl.target
--- /dev/null
+Name: osp-app-service
+Summary: osp application service
+Version: 1.2.0.0
+Release: 1
+Group: System/Libraries
+License: Apache License, Version 2.0 or Flora
+Source0: %{name}-%{version}.tar.gz
+Source1: osp-app-service.service
+BuildRequires: cmake
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(chromium)
+BuildRequires: pkgconfig(capi-system-media-key)
+BuildRequires: pkgconfig(capi-network-bluetooth)
+BuildRequires: pkgconfig(capi-appfw-application)
+BuildRequires: pkgconfig(capi-appfw-app-manager)
+BuildRequires: pkgconfig(capi-appfw-package-manager)
+BuildRequires: pkgconfig(capi-system-device)
+BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(capi-messaging-messages)
+BuildRequires: pkgconfig(notification)
+BuildRequires: pkgconfig(appsvc)
+BuildRequires: pkgconfig(pkgmgr)
+BuildRequires: pkgconfig(osp-appfw)
+BuildRequires: pkgconfig(osp-shell)
+BuildRequires: pkgconfig(sysman)
+BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(calendar-service2)
+BuildRequires: osp-appfw-internal-devel
+BuildRequires: osp-shell-internal-devel
+
+# runtime requires
+Requires: osp-appfw
+Requires: osp-installer
+Requires: osp-shell
+Requires: capi-system-device
+Requires: capi-system-info
+Requires: sysman
+Requires: capi-system-device
+Requires(post): coreutils
+Requires(post): /usr/bin/vconftool
+
+Requires(post): coreutils
+
+%description
+osp application service
+
+%prep
+%setup -q
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+%ifarch %{ix86}
+CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ -D_OSP_EMUL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+%else
+CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+%endif
+
+# Call make instruction with smp support
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+mkdir -p %{buildroot}/usr/share/license
+cp %{_builddir}/%{name}-%{version}/LICENSE.APLv2 %{buildroot}/usr/share/license/%{name}
+
+%make_install
+
+mkdir -p %{buildroot}%{_libdir}/systemd/user/core-efl.target.wants
+install -m 0644 %{SOURCE1} %{buildroot}%{_libdir}/systemd/user/osp-app-service.service
+ln -s ../osp-app-service.service %{buildroot}%{_libdir}/systemd/user/core-efl.target.wants/osp-app-service.service
+
+mkdir -p %{buildroot}/etc/rc.d/rc3.d/
+ln -s ../init.d/boot-osp.sh %{buildroot}/etc/rc.d/rc3.d/S44boot-osp
+
+%post
+#/bin/rm -f /etc/ld.so.cache
+#/sbin/ldconfig
+
+/bin/rm -f /etc/rc.d/rc3.d/S43osp-app-service
+/bin/rm -f /etc/rc.d/rc3.d/S44osp-app-service
+/bin/rm -f /etc/rc.d/rc3.d/S99osp-app-service
+/bin/rm -fr /opt/apps/aospd00043
+mkdir -p /usr/apps/aospd00043/lib
+
+/usr/etc/package-manager/backend/tpk -i /usr/apps/aospd00043
+cp -f %{_libdir}/osp/osp-system-service-loader /usr/apps/aospd00043/bin/osp-app-service
+chmod +x /etc/rc.d/init.d/boot-osp.sh
+
+vconftool set -t int memory/appservice/status -1 -i -u 5000
+
+if [ ! -f /var/run/memory/appservice/mmc ]
+then
+ vconftool set -t int memory/appservice/mmc -1 -i -u 5000
+fi
+
+if [ -f /usr/lib/rpm-plugins/msm.so ]
+then
+ chsmack -a osp-app-service /usr/apps/aospd00043/lib
+ chsmack -a osp-app-service /usr/apps/aospd00043/bin/osp-app-service
+ chsmack -e osp-app-service /usr/apps/aospd00043/bin/osp-app-service
+fi
+
+%files
+%manifest osp-app-service.manifest
+/usr/share/license/%{name}
+/usr/apps/*
+/etc/rc.d/*
+%{_libdir}/systemd/user/osp-app-service.service
+%{_libdir}/systemd/user/core-efl.target.wants/osp-app-service.service
--- /dev/null
+#Set Project name
+PROJECT(plugins)
+
+SET(PLUGIN_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
+
+ADD_SUBDIRECTORY(alarm-condition-handler)
+ADD_SUBDIRECTORY(nfc-condition-handler)
+ADD_SUBDIRECTORY(accessory-condition-handler)
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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://floralicense.org/license/
+//
+// 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 AccessoryConditionHandler.cpp
+ * @brief This is the implementation file of the AccessoryConditionHandler class.
+ *
+ */
+
+#include <unique_ptr.h>
+#include <new>
+#include <string.h>
+
+#include <FApp_AppManagerImpl.h>
+#include <FApp_AppLaunchConditionHandlerBase.h>
+#include <FBase_StringConverter.h>
+#include "AccessoryConditionHandler.h"
+#include "AccessoryMonitor.h"
+
+using namespace std;
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+const static char TIZEN_REQUEST[] = {"tizen.request"};
+const static char TIZEN_RESPONSE[] = {"tizen.response"};
+const static char TIZEN_LAUNCH_BY_CONDITION[] = {"tizen.launch_by_condition"};
+const static char TIZEN_INITIALIZE[] = {"tizen.initialize"};
+const static char TIZEN_SUCCESS[] = {"tizen.success"};
+const static char TIZEN_FAILURE[] = {"tizen.failure"};
+const static char TIZEN_PING[] = {"tizen.ping"};
+
+const static char ACCESSORY_SERIAL_COMMAND_MESSAGE[] = {"Osp:Msg"};
+const static char ACCESSORY_SERIAL_COMMAND_REQUEST[] = {"Osp:Req"};
+const static char ACCESSORY_SERIAL_COMMAND_RESPONSE[] = {"Osp:Res"};
+const static char ACCESSORY_SERIAL_COMMAND_HELLO[] = {"Hello"};
+const static char ACCESSORY_SERIAL_COMMAND_OK[] = {"OK"};
+const static char ACCESSORY_SERIAL_COMMAND_SUCCESS[] = {"Susccess"};
+const static char ACCESSORY_SERIAL_COMMAND_FAIL[] = {"Fail"};
+
+AccessoryConditionHandler::AccessoryConditionHandler()
+ :__pAccessoryMonitor(null)
+{
+ result r = E_SUCCESS;
+ SysLog(NID_SYS, "AccessoryConditionHandler is initialized");
+
+ __pAccessoryMonitor = AccessoryMonitor::GetInstance();
+ r = __pAccessoryMonitor->Construct(this);
+
+ if (IsFailed(r))
+ {
+ SysLogException(NID_SYS, r, "Failed to initialize AccessoryMonitor");
+ return;
+ }
+
+ r = __appConditionList.Construct();
+
+ if (IsFailed(r))
+ {
+ SysLogException(NID_SYS, r, "Failed to initialize Condition List");
+ }
+}
+
+AccessoryConditionHandler::~AccessoryConditionHandler()
+{
+ if (__pAccessoryMonitor != null)
+ {
+ __pAccessoryMonitor->ReleaseInstance();
+ }
+}
+
+result
+AccessoryConditionHandler::Register(_AppLaunchCondition& operation)
+{
+ String condition = operation.GetConditionString();
+ SysLog(NID_SYS, "Request to register accessory process, [%S][%S]", operation.GetAppId().GetPointer(), operation.GetConditionString().GetPointer());
+
+ SysTryReturnResult(NID_SYS, condition.StartsWith(L"Serial='", 0) == true, E_INVALID_FORMAT, "It is not compatible format.");
+ SysTryReturnResult(NID_SYS, condition.EndsWith(L"'") == true, E_INVALID_FORMAT, "It is not compatible format.");
+
+ condition.SubString(8, condition.GetLength() - 9, condition);
+ SysLog(NID_SYS, "Requested String is %ls", condition.GetPointer());
+
+ unique_ptr<IEnumerator> pEnum (__appConditionList.GetEnumeratorN());
+ SysTryReturnResult(NID_SYS, pEnum != null, E_SYSTEM, "Enumerator is not created.");
+
+ while(pEnum->MoveNext() == E_SUCCESS)
+ {
+ _AppLaunchCondition* pCondition = static_cast<_AppLaunchCondition*> (pEnum->GetCurrent());
+ if(pCondition->GetAppId() == operation.GetAppId())
+ {
+ SysTryReturnResult(NID_SYS, pCondition->GetConditionString() != condition, E_OBJ_ALREADY_EXIST, "The specified condition(%ls) is already registered.", condition.GetPointer());
+ }
+ }
+ __appConditionList.Add(operation);
+
+ return E_SUCCESS;
+}
+
+result
+AccessoryConditionHandler::Unregister(_AppLaunchCondition& operation)
+{
+ SysLog(NID_SYS, "Request to unregister accessory process");
+
+ unique_ptr<IEnumerator> pEnum (__appConditionList.GetEnumeratorN());
+ SysTryReturnResult(NID_SYS, pEnum != null, E_SYSTEM, "Enumerator is not created.");
+
+ while(pEnum->MoveNext() == E_SUCCESS)
+ {
+ _AppLaunchCondition* pCondition = static_cast<_AppLaunchCondition*> (pEnum->GetCurrent());
+ if(pCondition->GetAppId() == operation.GetAppId())
+ {
+ if(pCondition->GetConditionString() == operation.GetConditionString())
+ {
+ __appConditionList.Remove(*pCondition);
+ return E_SUCCESS;
+ }
+ }
+ }
+ return E_OBJ_NOT_FOUND;
+}
+
+char*
+AccessoryConditionHandler::GetValueFromCommandN(const char* command, int length)
+{
+ if (command == null || length <= 0)
+ return null;
+
+ int valueLength = 0;
+ char* value = null;
+
+ char* indexStart = strstr(const_cast < char* > (command), "'");
+
+ if (indexStart == null)
+ return null;
+
+ indexStart ++;
+
+ char* indexEnd = strstr(indexStart, "'");
+
+ if (indexEnd == null)
+ return null;
+
+ valueLength = indexEnd - indexStart;
+
+ value = new (std::nothrow) char[valueLength + 1];
+ memset(value, 0, valueLength + 1);
+
+ strncpy(value, indexStart, valueLength);
+
+ return value;
+}
+
+bool
+AccessoryConditionHandler::MessageCommandHandle(const char* command, int length)
+{
+ result r = E_SUCCESS;
+ bool resultValue = true;
+ char* commandValue = GetValueFromCommandN(command, length);
+ char* response = null;
+
+ SysTryCatch(NID_IO, commandValue != null, resultValue = false, E_SYSTEM, "[E_SYSTEM] there is no message command");
+
+ SysLog(NID_IO, "Message command is [%s]", commandValue);
+
+ if (strcmp(commandValue, ACCESSORY_SERIAL_COMMAND_HELLO) == 0)
+ {
+ SysLog(NID_IO, "This is hello request");
+
+ int responseLength = strlen(ACCESSORY_SERIAL_COMMAND_MESSAGE) + strlen(ACCESSORY_SERIAL_COMMAND_OK) + 5;
+ response = new (std::nothrow) char[responseLength];
+ memset(response, 0, responseLength);
+
+ response = strcat(response, ACCESSORY_SERIAL_COMMAND_MESSAGE);
+ response = strcat(response, "='");
+ response = strcat(response, ACCESSORY_SERIAL_COMMAND_OK);
+ response = strcat(response, "'\r\n");
+
+ r = __pAccessoryMonitor->SendData(response, strlen(response));
+
+ SysTryCatch(NID_IO, r == E_SUCCESS, resultValue = true, E_SYSTEM, "[%s] Fail to send data");
+ }
+ else
+ {
+ SysLog(NID_IO, "[%s] is not supported command", commandValue);
+ }
+
+CATCH:
+ delete [] commandValue;
+ delete [] response;
+
+ return resultValue;
+}
+
+bool
+AccessoryConditionHandler::TizenRequestCommand(const char* command, int length)
+{
+ int ret = 0;
+ char request[16] = {0,};
+ char value[32] = {0, };
+ char condition[512] = {0, };
+ char* response = null;
+ char* responseMessage = null;
+ result r = E_SUCCESS;
+
+ SysTryCatch(NID_SYS, command != null && length > 0, ,E_SYSTEM, "Condition is not available.");
+
+ ret = sscanf(command, "%13s='%s %s'", request, value, condition);
+
+ if(ret == 2)
+ {
+ value[strlen(value) -1 ] = 0;
+ }
+ else if(ret == 3)
+ {
+ condition[strlen(condition) -1 ] = 0;
+ }
+ else
+ {
+ responseMessage = const_cast <char*> (TIZEN_FAILURE);
+ }
+
+ SysLog(NID_SYS, "Request: %s, %s, %s, %d", request, value, condition, ret);
+
+ if(strcmp(request, TIZEN_REQUEST) == 0 && (ret == 2 || ret ==3))
+ {
+ SysLog(NID_SYS, "Command is request.");
+ if(strcmp(value, TIZEN_LAUNCH_BY_CONDITION) == 0)
+ {
+ SysLog(NID_SYS, "Command is launch request.");
+
+ unique_ptr<IEnumerator> pEnum (__appConditionList.GetEnumeratorN());
+ SysTryCatch(NID_IO, pEnum != null, , E_SYSTEM, "Enumerator is not created.");
+
+ while(pEnum->MoveNext() == E_SUCCESS)
+ {
+ _AppLaunchCondition* pCondition = static_cast<_AppLaunchCondition*>(pEnum->GetCurrent());
+ SysTryCatch(NID_SYS, pCondition != null, ,E_SYSTEM, "Condition is not available.");
+ String registered = pCondition->GetConditionString();
+ String requested(condition);
+
+ registered.SubString(8, registered.GetLength() - 9, registered);
+ if(registered == requested)
+ {
+ SysLog(NID_SYS, "Application[%ls] launch is required.", pCondition->GetAppId().GetPointer());
+ Fire(*pCondition);
+ responseMessage = const_cast <char*> (TIZEN_SUCCESS);
+ break;
+ }
+ }
+ }
+ else if(strcmp(value, TIZEN_PING) == 0)
+ {
+ SysLog(NID_SYS, "Command is launch request.");
+ responseMessage = const_cast <char*> (TIZEN_PING);
+ }
+ else if(strcmp(value, TIZEN_INITIALIZE) == 0)
+ {
+ SysLog(NID_SYS, "Command is initialize.");
+ responseMessage = const_cast <char*> (TIZEN_SUCCESS);
+ }
+ }
+
+CATCH:
+ if(responseMessage == null)
+ {
+ responseMessage = const_cast <char*> (TIZEN_FAILURE);
+ }
+
+ int responseLength = strlen(TIZEN_RESPONSE) + strlen(responseMessage) + 6;
+ response = new (std::nothrow) char[responseLength];
+ if(response == null)
+ {
+ SysLogException(NID_SYS, E_OUT_OF_MEMORY, "It is failed to allocate memory");
+ return false;
+ }
+
+ memset(response, 0, responseLength);
+ response = strcat(response, TIZEN_RESPONSE);
+ response = strcat(response, "='");
+ response = strcat(response, responseMessage);
+ response = strcat(response, "'\r\n");
+
+ r = __pAccessoryMonitor->SendData(response, strlen(response)+1);
+ delete [] response;
+
+ if(r != E_SUCCESS)
+ {
+ return false;
+ }
+
+ return true;
+}
+bool
+AccessoryConditionHandler::RequestCommandHandle(const char* command, int length)
+{
+ int ret = 0;
+ result r = E_SUCCESS;
+ char* response = null;
+ char* resultValue = null;
+ char condition[512] = {0, };
+ int responseLength = 0;
+
+ SysTryCatch(NID_SYS, command != null && length > 0, ,E_SYSTEM, "Condition is not available.");
+
+ ret = sscanf(command, "Osp:Req='%s'", condition);
+ SysTryCatch(NID_SYS, ret == 1, ,E_SYSTEM, "Condition is not available.(%d, %s/%s)", ret, condition, command);
+
+ condition[strlen(condition) -1 ] = 0;
+
+ if(ret == 1)
+ {
+ unique_ptr<IEnumerator> pEnum (__appConditionList.GetEnumeratorN());
+ SysTryCatch(NID_IO, pEnum != null, , E_SYSTEM, "Enumerator is not created.");
+
+ while(pEnum->MoveNext() == E_SUCCESS)
+ {
+ _AppLaunchCondition* pCondition = static_cast<_AppLaunchCondition*>(pEnum->GetCurrent());
+ SysTryCatch(NID_SYS, pCondition != null, ,E_SYSTEM, "Condition is not available.");
+ String registered = pCondition->GetConditionString();
+ String requested(condition);
+
+ registered.SubString(8, registered.GetLength() - 9, registered);
+ if(registered == requested)
+ {
+ SysLog(NID_SYS, "Application[%ls] launch is required.", pCondition->GetAppId().GetPointer());
+ Fire(*pCondition);
+ resultValue = const_cast<char*>(ACCESSORY_SERIAL_COMMAND_SUCCESS);
+ break;
+ }
+ }
+ }
+
+CATCH:
+ if(resultValue == null)
+ {
+ resultValue = const_cast<char*>(ACCESSORY_SERIAL_COMMAND_FAIL);
+ }
+
+ responseLength = strlen(ACCESSORY_SERIAL_COMMAND_RESPONSE) + strlen(resultValue) + 6;
+ response = new (std::nothrow) char[responseLength];
+ if(response == null)
+ {
+ SysLogException(NID_SYS, E_OUT_OF_MEMORY, "It is failed to allocate memory");
+ return false;
+ }
+
+ memset(response, 0, responseLength);
+ response = strcat(response, ACCESSORY_SERIAL_COMMAND_RESPONSE);
+ response = strcat(response, "='");
+ response = strcat(response, resultValue);
+ response = strcat(response, "'\r\n");
+
+ r = __pAccessoryMonitor->SendData(response, strlen(response)+1);
+ delete [] response;
+
+ if(r != E_SUCCESS)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+bool
+AccessoryConditionHandler::ProcessPrimitiveCommand(const char* command, int length)
+{
+ bool resultValue = false;
+
+ SysLog(NID_IO, "serial data is forwarded to ProcessPrimitiveCommand [%s]", command);
+ SysTryCatch(NID_IO, command != null && length > 0, resultValue = false, E_INVALID_ARG, "[E_INVALID_ARG] There is no available data");
+
+ if (strncmp(command, ACCESSORY_SERIAL_COMMAND_MESSAGE, strlen(ACCESSORY_SERIAL_COMMAND_MESSAGE)) == 0)
+ {
+ resultValue = MessageCommandHandle(command, length);
+ SysLog(NID_SYS, "Message result: %d", resultValue);
+ }
+ else if (strncmp(command, ACCESSORY_SERIAL_COMMAND_REQUEST, strlen(ACCESSORY_SERIAL_COMMAND_REQUEST)) == 0)
+ {
+ resultValue = RequestCommandHandle(command, length);
+ SysLog(NID_SYS, "Request result: %d", resultValue);
+ }
+ else if (strncmp(command, TIZEN_REQUEST, strlen(TIZEN_REQUEST)) == 0
+ || strncmp(command, TIZEN_PING, strlen(TIZEN_PING)) == 0)
+ {
+ resultValue = TizenRequestCommand(command, length);
+ SysLog(NID_SYS, "Request result: %d", resultValue);
+ }
+
+CATCH:
+ SysLog(NID_SYS, "result: %d", resultValue);
+ return resultValue;
+
+}
+
+/////////////////////////////////////////////////////////////////////////
+// All plugins must provide both a creation and a destruction function
+/////////////////////////////////////////////////////////////////////////
+extern "C"
+{
+_OSP_EXPORT_ _AppLaunchConditionHandlerBase*
+CreatePlugin(void)
+{
+ SysLog(NID_IO, "CreatePlugin is called");
+ return new (std::nothrow) AccessoryConditionHandler;
+}
+
+_OSP_EXPORT_ void
+DestroyPlugin(_AppLaunchConditionHandlerBase* p)
+{
+ delete p;
+}
+}//extern "C"
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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://floralicense.org/license/
+//
+// 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 AccessoryConditionHandler.h
+ * @brief This is the declaration file of the AccessoryConditionHandler class.
+ */
+
+#ifndef _ACCESSORY_CONDITION_HANDLER_H_
+#define _ACCESSORY_CONDITION_HANDLER_H_
+
+#include <FApp_AppLaunchConditionHandlerBase.h>
+#include <FBase.h>
+
+
+class AccessoryMonitor;
+
+class AccessoryConditionHandler
+ :public Tizen::App::_AppLaunchConditionHandlerBase
+{
+public:
+ AccessoryConditionHandler();
+ ~AccessoryConditionHandler();
+ bool ProcessPrimitiveCommand(const char* command, int length);
+
+ virtual result Register(Tizen::App::_AppLaunchCondition& operation);
+ virtual result Unregister(Tizen::App::_AppLaunchCondition& operation);
+private:
+ char* GetValueFromCommandN(const char* command, int length);
+ bool MessageCommandHandle(const char* command, int length);
+ bool RequestCommandHandle(const char* command, int length);
+ bool TizenRequestCommand(const char* command, int length);
+ AccessoryMonitor* __pAccessoryMonitor;
+ Tizen::Base::Collection::ArrayList __appConditionList;
+};
+
+#endif //_ACCESSORY_CONDITION_HANDLER_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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://floralicense.org/license/
+//
+// 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 AccessoryMonitor.cpp
+ * @brief This is the implementation file of the AccessoryMonitor class.
+ *
+ */
+
+#include "AccessoryMonitor.h"
+#include "AccessoryConditionHandler.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Io;
+
+namespace{
+ const String SERIAL_COMMAND_OPEN(L"Open");
+ const String SERIAL_COMMAND_CLOSE(L"Close");
+ const String SERIAL_COMMAND_WRITE(L"Write");
+ const String SERIAL_COMMAND_DATA(L"Data");
+ const String SERIAL_COMMAND_ERROR(L"Error");
+ const String SERIAL_COMMAND_OK(L"OK");
+ const String SERIAL_SERVICE_ID(L"osp.accessory.serial.service");
+ const String ACCESSORY_COMPONENT_ID(L"osp.accessorymanager.service");
+
+ const int SERIAL_DATA_HEAD = 1;
+ const int SERIAL_DATA_BODY = 2;
+}
+
+
+typedef result (*SendDataFunction)(AppId appId, ArrayList* data);
+SendDataFunction sendFunction = null;
+static AccessoryMonitor* gpAccessoryMonitor = null;
+static int gReferenceCount = 0;
+
+AccessoryMonitor::AccessoryMonitor()
+: __pAccessoryConditionHandler(null)
+, __pDataRouter(null)
+{
+}
+
+AccessoryMonitor::~AccessoryMonitor()
+{
+}
+
+AppId
+AccessoryMonitor::GetClientId(void) const
+{
+ return __clientAppId;
+}
+
+void
+AccessoryMonitor::SetClientId(AppId appId)
+{
+ __clientAppId = appId;
+}
+
+void
+AccessoryMonitor::RemoveClientId(AppId appId)
+{
+ StringComparer strComparer;
+ int cmp = 0;
+ strComparer.Compare(appId, __clientAppId, cmp);
+ if(cmp == 0)
+ {
+ __clientAppId = "";
+ }
+}
+
+_DataRouter*
+AccessoryMonitor::GetDataRouter(void) const
+{
+ return __pDataRouter;
+}
+
+result
+AccessoryMonitor::Construct(AccessoryConditionHandler* pConditionHandler)
+{
+ result r = E_SUCCESS;
+ SysTryReturnResult(NID_APP, pConditionHandler != null, E_INVALID_ARG, "pConditionHandler is empty");
+
+ __pAccessoryConditionHandler = pConditionHandler;
+ SysTryReturnResult(NID_APP, __pDataRouter == null, E_INVALID_STATE, "AccessoryMonitor is already constructed.");
+
+ __clientAppId = "";
+ __pDataRouter = _DataRouter::GetInstance();
+ r = __pDataRouter->Construct(*this);
+ SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "DataRouter is not constructed.");
+
+ return E_SUCCESS;
+}
+
+AccessoryMonitor*
+AccessoryMonitor::GetInstance(void)
+{
+ if(gpAccessoryMonitor == null)
+ gpAccessoryMonitor = new (std::nothrow) AccessoryMonitor();
+
+ gReferenceCount ++;
+ return gpAccessoryMonitor;
+}
+
+void
+AccessoryMonitor::ReleaseInstance(void)
+{
+ if(gReferenceCount == 0)
+ return;
+
+ gReferenceCount --;
+ if(gReferenceCount == 0)
+ {
+ delete gpAccessoryMonitor;
+ gpAccessoryMonitor = null;
+ }
+}
+
+void
+AccessoryMonitor::OnDataRouterDataReceivedN(const char* buffer, int length)
+{
+ SysLog(NID_IO, "serial data is forwarded to AccessoryMonitor class");
+ SysTryReturnVoidResult(NID_APP, buffer != null, E_INVALID_ARG, "[E_INVALID_ARG] buffer should not be null.");
+
+ bool primitiveCommand = false;
+ if(__pAccessoryConditionHandler != null)
+ {
+ primitiveCommand = __pAccessoryConditionHandler->ProcessPrimitiveCommand(buffer, length);
+ }
+
+ if(primitiveCommand == false)
+ {
+ SysLog(NID_IO, "Requested data is not command. it will be forwarded to current application");
+ if(__clientAppId.GetLength() > 0)
+ {
+ ArrayList* pDataList = new (std::nothrow) ArrayList();
+ ByteBuffer* pByteBuffer = new (std::nothrow) ByteBuffer();
+
+ String* pCommand = new (std::nothrow) String(SERIAL_COMMAND_DATA);
+ String* pComponentId= new (std::nothrow) String(ACCESSORY_COMPONENT_ID);
+ char* pIterator = const_cast<char*>(buffer);
+
+ pByteBuffer->Construct(length);
+
+ for(int i = 0; i < length; i++)
+ {
+ pByteBuffer->SetByte((byte)(*pIterator));
+ pIterator++;
+ }
+
+ pDataList->Construct();
+ pDataList->Add(*pComponentId);
+ pDataList->Add(*pCommand);
+ pDataList->Add(*pByteBuffer);
+
+ if(sendFunction!=null)
+ {
+ SysLog(NID_IO, "Data is forwarded to [%ls]", __clientAppId.GetPointer());
+ sendFunction(__clientAppId, pDataList);
+ }
+
+ pDataList->RemoveAll(true);
+ delete(pDataList);
+ }
+ }
+}
+
+result
+AccessoryMonitor::SendData(char* buffer, int length)
+{
+ SysTryReturnResult(NID_APP, __pDataRouter != null, E_INVALID_STATE, "[E_INVALID_STATE] AccessoryMonitor is not constructed.");
+ return __pDataRouter->Write(buffer, length);
+}
+void
+AccessoryMonitor::OnDataRouterStateChanged(_DataRouterState state)
+{
+ SysLog(NID_IO, "STATE is changed %d", (int)state);
+}
+
+
+/////////////////////////////////////////////////////////////////////////
+// Exported functions for _CommunicationDispatcher
+/////////////////////////////////////////////////////////////////////////
+extern "C"
+{
+
+_OSP_EXPORT_ void
+RegisterSendData(SendDataFunction function)
+{
+ sendFunction = function;
+}
+
+_OSP_EXPORT_ void
+RemoveOwnerApplication(const AppId appId, const String& executableName)
+{
+ if(gpAccessoryMonitor != null)
+ {
+ SysLog(NID_IO, "Accessory Owner is removed [%ls, %ls]", appId.GetPointer(), executableName.GetPointer());
+ gpAccessoryMonitor->RemoveClientId(appId);
+ }
+}
+
+_OSP_EXPORT_ bool
+OnRequestOccured(AppId appId, ArrayList* pRequest, ArrayList* pResponse)
+{
+ String* pCommand = null;
+
+ result r = E_SUCCESS;
+ SysTryCatch(NID_APP, pRequest != null, r = E_SYSTEM, E_SYSTEM, "There is no pRequest");
+ SysTryCatch(NID_APP, pResponse != null, r = E_SYSTEM, E_SYSTEM, "There is no pResponse");
+ SysTryCatch(NID_APP, gpAccessoryMonitor != null, r = E_SYSTEM, E_SYSTEM, "AccessoryMonitor is not ready");
+
+ pCommand = static_cast< String* > (pRequest->GetAt(SERIAL_DATA_HEAD));
+
+ SysTryCatch(NID_APP, pCommand != null, , E_SYSTEM, "There is no command");
+
+ SysLog(NID_IO, "Request: %ls", pCommand->GetPointer());
+
+ if(pCommand->Equals(SERIAL_COMMAND_OPEN, true))
+ {
+ SysLog(NID_IO, "Serial open is required");
+ SysTryCatch(NID_APP, gpAccessoryMonitor->GetClientId().GetLength() == 0, , E_SYSTEM, "Serial port is already used by [%ls]", gpAccessoryMonitor->GetClientId().GetPointer());
+ gpAccessoryMonitor->SetClientId(appId);
+ String* pResult = new (std::nothrow) String(SERIAL_COMMAND_OK);
+
+ pResponse->Add(*pResult);
+ }
+ else
+ {
+ SysTryCatch(NID_APP, gpAccessoryMonitor->GetClientId().GetLength() > 0, , E_SYSTEM, "Serial port is not created");
+ if(pCommand->Equals(SERIAL_COMMAND_WRITE, true))
+ {
+ SysLog(NID_IO, "Serial write is required");
+ char* buffer = null;
+ char* pIterator = null;
+ int length = 0;
+
+ ByteBuffer* pByteBuffer = null;
+ pByteBuffer = static_cast < ByteBuffer* > (pRequest->GetAt(SERIAL_DATA_BODY));
+
+ buffer = new (std::nothrow) char[pByteBuffer->GetCapacity()];
+ memset(buffer, 0, pByteBuffer->GetCapacity());
+
+ pIterator = buffer;
+
+ pByteBuffer->SetPosition(0);
+ for(int i = 0; i<pByteBuffer->GetCapacity(); i++)
+ {
+ r = pByteBuffer->GetByte(*(byte*)pIterator);
+ if (!IsFailed(r))
+ {
+ pIterator++;
+ length++;
+ }
+ }
+ gpAccessoryMonitor->GetDataRouter()->Write(buffer, length);
+
+ delete [] buffer;
+ }
+ else if(pCommand->Equals(SERIAL_COMMAND_CLOSE, true))
+ {
+ SysLog(NID_IO, "Serial close is required");
+ gpAccessoryMonitor->RemoveClientId(appId);
+ }
+ else
+ {
+ SysLogException(NID_APP, E_SYSTEM, "Undefined command is pRequested by [%ls]", gpAccessoryMonitor->GetClientId().GetPointer());
+ }
+ }
+CATCH:
+ SetLastResult(r);
+
+ if(r == E_SUCCESS)
+ return true;
+ else
+ return false;
+}
+}//extern "C"
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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://floralicense.org/license/
+//
+// 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 AccessoryManager.h
+ * @brief This is the declaration file of the AccessoryManager class.
+ */
+
+#ifndef _ACCESSORY_MONITOR_
+#define _ACCESSORY_MONITOR_
+
+#include <FApp.h>
+#include <FBase.h>
+#include <FIo.h>
+#include <FIo_IDataRouterEventListener.h>
+#include <FIo_DataRouter.h>
+
+class AccessoryConditionHandler;
+
+class AccessoryMonitor
+ : public Tizen::Base::Object
+ , public Tizen::Io::_IDataRouterEventListener
+{
+private:
+ AccessoryMonitor();
+ ~AccessoryMonitor();
+
+public:
+ result Construct(AccessoryConditionHandler* pConditionHandler);
+ result SendData(char* buffer, int length);
+ Tizen::App::AppId GetClientId(void) const;
+ void SetClientId(Tizen::App::AppId appId);
+ void RemoveClientId(Tizen::App::AppId appId);
+ Tizen::Io::_DataRouter* GetDataRouter(void) const;
+ virtual void OnDataRouterDataReceivedN(const char* buffer, int length);
+ virtual void OnDataRouterStateChanged(Tizen::Io::_DataRouterState state);
+
+ static AccessoryMonitor* GetInstance(void);
+ static void ReleaseInstance(void);
+
+private:
+ AccessoryConditionHandler* __pAccessoryConditionHandler;
+ Tizen::Io::_DataRouter* __pDataRouter;
+ Tizen::App::AppId __clientAppId;
+};
+
+#endif //AccessoryMonitor
--- /dev/null
+SET (this_target osp-cond-accessory)
+
+INCLUDE_DIRECTORIES (
+ /usr/include/osp
+ /usr/include/osp/app
+ /usr/include/osp/base
+ /usr/include/osp/io
+ ../../inc
+ ./
+ )
+
+SET (${this_target}_SOURCE_FILES
+ AccessoryMonitor.cpp
+ AccessoryConditionHandler.cpp
+ )
+
+## SET EXTRA COMPILER FLAGS
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC -Wall" )
+
+## SET C COMPILER FLAGS
+SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## SET CPP COMPILER FLAGS
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## Create Library
+ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES})
+
+SET_TARGET_PROPERTIES(${this_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PLUGIN_INSTALL_DIR}/lib")
+
+TARGET_LINK_LIBRARIES(${this_target} -L/usr/lib/osp -losp-appfw -Wl,--no-undefined -Wl,--as-needed)
+
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 alarm_condition_candler.cpp
+ * @brief This is the declaration file of the _AlarmConditionHandler class.
+ *
+ */
+
+#include <new>
+#include <unique_ptr.h>
+
+#include <appfw/app.h>
+
+#include <FBaseInteger.h>
+#include <FSysSystemTime.h>
+#include <FBaseUtilRegularExpression.h>
+
+#include <FBase_StringConverter.h>
+#include <FSys_AlarmImpl.h>
+
+#include "AlarmConditionHandler.h"
+
+using namespace std;
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::System;
+
+namespace {
+ static const long _ADJUST_MONTH_FOR_TM = 1;
+ static const long _ADJUST_YEAR_FOR_TM = 1900;
+ static const long _SECOND_OF_MINUTE = 60;
+
+ static const int ALARM_CONDITION_FIELD = 1;
+ static const int ALARM_CONDITION_VALUE = 1;
+}
+_AlarmConditionHandler* pAlarmConditionHandler = null;
+int RefAlarmConditionHandler = 0;
+_AlarmConditionHandler*
+_AlarmConditionHandler::GetInstance()
+{
+ if(pAlarmConditionHandler == null)
+ {
+ pAlarmConditionHandler = new (std::nothrow) _AlarmConditionHandler;
+ }
+ RefAlarmConditionHandler ++;
+ return pAlarmConditionHandler;
+}
+
+void
+_AlarmConditionHandler::ReleaseInstance()
+{
+ if(RefAlarmConditionHandler == 0)
+ {
+ return;
+ }
+
+ RefAlarmConditionHandler --;
+ if(RefAlarmConditionHandler == 0)
+ {
+ delete pAlarmConditionHandler;
+ pAlarmConditionHandler = null;
+ }
+}
+
+_AlarmConditionHandler::_AlarmConditionHandler()
+{
+ conditionList.Construct();
+}
+
+_AlarmConditionHandler::~_AlarmConditionHandler()
+{
+}
+
+result
+_AlarmConditionHandler::Convert(_AppLaunchCondition& appLaunchCondition, struct tm* pConvertedTime, int& period)
+{
+ int ret = 0;
+ char garbage[128] = {0};
+ SysTryReturnResult(NID_SYS, pConvertedTime != null, E_INVALID_ARG, "pConvertedTime is null");
+
+ String buf(appLaunchCondition.GetConditionString());
+ SysLog(NID_SYS, "%ls", buf.GetPointer());
+ unique_ptr<char[]> convertedString(_StringConverter::CopyToCharArrayN(buf));
+ SysTryReturnResult(NID_SYS, convertedString.get() != null, E_OUT_OF_MEMORY, "Memory allocation failure.");
+
+ if(buf.StartsWith(L"DueTime", 0) == true)
+ {
+
+ ret = sscanf(convertedString.get(), "DueTime='%d/%d/%d %d:%d:%d' LaunchPeriod='%d'%s", &(pConvertedTime->tm_mon), &(pConvertedTime->tm_mday), &(pConvertedTime->tm_year), &(pConvertedTime->tm_hour), &(pConvertedTime->tm_min), &(pConvertedTime->tm_sec), &period, &garbage);
+
+ SysTryReturnResult(NID_SYS, ret == 7, E_INVALID_FORMAT, "The specified condition format is not compatible.");
+ }
+ else if(buf.StartsWith(L"DateTime", 0) == true)
+ {
+ ret = sscanf(convertedString.get(), "DateTime='%d/%d/%d %d:%d:%d'%s", &(pConvertedTime->tm_mon), &(pConvertedTime->tm_mday), &(pConvertedTime->tm_year), &(pConvertedTime->tm_hour), &(pConvertedTime->tm_min), &(pConvertedTime->tm_sec), &garbage);
+ SysTryReturnResult(NID_SYS, ret == 6, E_INVALID_FORMAT, "The specified condition format is not compatible.");
+ }
+ else
+ {
+ SysLog(NID_SYS, "wrong alarm condition");
+ return E_INVALID_FORMAT;
+ }
+ return E_SUCCESS;
+}
+
+result
+_AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
+{
+ //For condition parsing.
+ int ret = 0;
+
+ //For alarm reserve.
+ struct tm expireTime = {0,};
+ int period = 0;
+ int reservedAlarmId = -1;
+ service_h service = null;
+ char* packageName = null;
+ result r = E_SUCCESS;
+ _AppLaunchCondition* pReservedCondition = null;
+
+ r = Convert(appLaunchCondition, &expireTime, period);
+ SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_INVALID_FORMAT, "It is not valid date time format.");
+
+ DateTime validationCheck;
+ r = validationCheck.SetValue(expireTime.tm_year, expireTime.tm_mon, expireTime.tm_mday, expireTime.tm_hour, expireTime.tm_min, expireTime.tm_sec);
+ SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_INVALID_CONDITION, "It is not valid date time.");
+
+ DateTime currentTime;
+ SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
+
+ TimeSpan validateTs(validationCheck.GetTime());
+ TimeSpan currentTs(currentTime.GetTime());
+
+ if(appLaunchCondition.GetConditionString().StartsWith(L"DueTime", 0) == true)
+ {
+ SysTryReturnResult(NID_SYS, period >= 60 && period <= 525600, E_INVALID_CONDITION, "Required period is not valid. (%d)", period);
+ }
+
+ SysTryReturnResult(NID_SYS, (validateTs.GetTicks() - currentTs.GetTicks()) > 0 , E_INVALID_CONDITION, "Required time does not greater thancurrent time. (%lld)", validateTs.GetTicks() - currentTs.GetTicks());
+
+ unique_ptr<IMapEnumerator>pMapEnum(conditionList.GetMapEnumeratorN());
+
+ while(pMapEnum->MoveNext() == E_SUCCESS)
+ {
+ struct tm reservedTime = {0,};
+ int reservedPeriod = 0;
+ pReservedCondition = static_cast<_AppLaunchCondition*>(pMapEnum->GetValue());
+ r = Convert(*pReservedCondition, &reservedTime, reservedPeriod);
+ SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "Reserved condition has wrong format.");
+
+ if(reservedPeriod == period && expireTime.tm_year == reservedTime.tm_year
+ && expireTime.tm_mon == reservedTime.tm_mon && expireTime.tm_mday == reservedTime.tm_mday
+ && expireTime.tm_hour == reservedTime.tm_hour && expireTime.tm_min == reservedTime.tm_min
+ && expireTime.tm_sec == reservedTime.tm_sec)
+ {
+ SysLogException(NID_SYS, E_OBJ_ALREADY_EXIST, "The specified condition is already registered.");
+ return E_OBJ_ALREADY_EXIST;
+ }
+ }
+
+ expireTime.tm_year -= _ADJUST_YEAR_FOR_TM;
+ expireTime.tm_mon -= _ADJUST_MONTH_FOR_TM;
+
+ ret = service_create(&service);
+ SysTryCatch(NID_SYS, ret == SERVICE_ERROR_NONE, r = E_SYSTEM, r, "It is failed to create service");
+
+ ret = app_get_package(&packageName);
+ SysTryCatch(NID_SYS, ret == APP_ERROR_NONE, r = E_SYSTEM, r, "It is failed to get package name");
+
+ ret = service_set_operation(service, "osp.appsvc.operation.ALARM");
+ SysTryCatch(NID_SYS, ret == SERVICE_ERROR_NONE, r = E_SYSTEM, r, "It is failed to set operation");
+
+ ret = service_set_package(service, packageName);
+ SysTryCatch(NID_SYS, ret == SERVICE_ERROR_NONE, r = E_SYSTEM, r, "It is failed to create service for %s", packageName);
+
+ ret = alarm_schedule_at_date(service, &expireTime, period * _SECOND_OF_MINUTE, &reservedAlarmId);
+ SysTryCatch(NID_SYS, ret == ALARM_ERROR_NONE, r = E_SYSTEM, r, "It is failed to set the Alarm time for %s", packageName);
+
+ r = conditionList.Add(new Integer(reservedAlarmId), &appLaunchCondition);
+
+ if(r == E_OBJ_ALREADY_EXIST)
+ {
+ SysLogException(NID_SYS, E_OBJ_ALREADY_EXIST, "The sspecified condition is already registered.");
+ r = E_OBJ_ALREADY_EXIST;
+ }
+ else if(r != E_SUCCESS)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register requested condition.");
+ r = E_SYSTEM;
+ }
+
+CATCH:
+ if (packageName != null)
+ {
+ free (packageName);
+ }
+
+ if (service != null)
+ {
+ service_destroy(service);
+ }
+
+ return r;
+}
+
+
+result
+_AlarmConditionHandler::Unregister( _AppLaunchCondition& appLaunchCondition)
+{
+ unique_ptr<IMapEnumerator> pMapEnum(conditionList.GetMapEnumeratorN());
+ Integer* pKey = null;
+ _AppLaunchCondition* pAppLaunchCondition = null;
+ result r = E_SYSTEM;
+
+ SysTryReturnResult(NID_SYS, pMapEnum != null, E_SYSTEM, "Reserved condition list is empty");
+
+ while(pMapEnum->MoveNext() == E_SUCCESS)
+ {
+ pKey = static_cast<Integer *>(pMapEnum->GetKey());
+ pAppLaunchCondition = static_cast<_AppLaunchCondition *>(pMapEnum->GetValue());
+
+ if(appLaunchCondition.GetConditionString() == "")
+ {
+ if(appLaunchCondition.GetAppId() == pAppLaunchCondition->GetAppId())
+ {
+ alarm_cancel(pKey->ToInt());
+ conditionList.Remove(*pKey);
+ delete pKey;
+ r = E_SUCCESS;
+ }
+ }
+ else
+ {
+ if(appLaunchCondition.GetAppId() == pAppLaunchCondition->GetAppId()
+ && appLaunchCondition.GetConditionString() == pAppLaunchCondition->GetConditionString())
+ {
+ alarm_cancel(pKey->ToInt());
+ conditionList.Remove(*pKey);
+ delete pKey;
+ r = E_SUCCESS;
+ }
+ }
+
+ }
+ return r;
+}
+
+_AppLaunchCondition*
+_AlarmConditionHandler::GetAppLaunchCondition(int alarmId)
+{
+ SysLog(NID_SYS, "Try to find condition");
+ unique_ptr<IMapEnumerator> pMapEnum(conditionList.GetMapEnumeratorN());
+ Integer* pKey = null;
+ _AppLaunchCondition* pAppLaunchCondition = null;
+ _AppLaunchCondition* pReservedCondition = null;
+
+ if(pMapEnum == null)
+ {
+ SysLog(NID_SYS, "Reserved condition list is empty");
+ return null;
+ }
+
+ while(pMapEnum->MoveNext() == E_SUCCESS)
+ {
+ pKey = static_cast<Integer *>(pMapEnum->GetKey());
+ pAppLaunchCondition = static_cast<_AppLaunchCondition *>(pMapEnum->GetValue());
+ if(pKey->ToInt() == alarmId)
+ {
+ pReservedCondition = pAppLaunchCondition;
+ break;
+ }
+ }
+ return pReservedCondition;
+}
+
+result
+_AlarmConditionHandler::Launch(const Tizen::App::_AppLaunchCondition& condition)
+{
+ return Fire(condition);
+}
+
+//////////////////////////////////////////////////////////////
+// All plugins must provide both a creation and a destruction function
+/////////////////////////////////////////////////////////////
+extern "C"
+{
+_OSP_EXPORT_ _AppLaunchConditionHandlerBase*
+CreatePlugin(void)
+{
+ return _AlarmConditionHandler::GetInstance();
+}
+
+_OSP_EXPORT_ void
+DestroyPlugin(_AppLaunchConditionHandlerBase* p)
+{
+ _AlarmConditionHandler::ReleaseInstance();
+}
+
+_OSP_EXPORT_ void
+OnAlarmForLaunch(int alarmId)
+{
+ SysLog(NID_SYS, "Alarm request %d", alarmId);
+ _AppLaunchCondition* pAppLaunchCondition = null;
+ _AlarmConditionHandler* pAlarmConditionHandler = _AlarmConditionHandler::GetInstance();
+ pAppLaunchCondition = pAlarmConditionHandler->GetAppLaunchCondition(alarmId);
+ if(pAppLaunchCondition != null)
+ {
+ SysLog(NID_SYS, "Launch Request");
+ pAlarmConditionHandler->Launch(*pAppLaunchCondition);
+ }
+ _AlarmConditionHandler::ReleaseInstance();
+}
+
+}//extern "C"
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 alarm_condition_candler.h
+ * @brief This is the implementation file of the _AlarmConditionHandler class.
+ *
+ */
+
+#include <FSysAlarm.h>
+#include <FBaseColHashMap.h>
+
+#include "FApp_AppLaunchConditionHandlerBase.h"
+
+/**
+ * @class _AlarmConditionHandler
+ * @brief This class implements conditional app launch for alarm condition. (DateTime, DueTime)
+ * @final This class is not intended for extension.
+ */
+class _AlarmConditionHandler:
+ public Tizen::App::_AppLaunchConditionHandlerBase
+{
+
+public:
+ static _AlarmConditionHandler* GetInstance(void);
+ static void ReleaseInstance(void);
+
+ Tizen::App::_AppLaunchCondition* GetAppLaunchCondition(int alarmId);
+
+ virtual result Register( Tizen::App::_AppLaunchCondition& appLaunchCondition);
+ virtual result Unregister( Tizen::App::_AppLaunchCondition& appLaunchCondition);
+ result Launch(const Tizen::App::_AppLaunchCondition& condition);
+ result Convert(Tizen::App::_AppLaunchCondition& appLaunchCondition, struct tm* pConvertedTime, int& period);
+
+private:
+ _AlarmConditionHandler(void);
+ virtual ~_AlarmConditionHandler(void);
+
+private:
+ Tizen::Base::Collection::HashMap conditionList;
+};
--- /dev/null
+SET (this_target osp-cond-alarm)
+
+INCLUDE_DIRECTORIES (
+ /usr/include/osp
+ /usr/include/osp/app
+ /usr/include/osp/base
+ /usr/include/osp/io
+ /usr/include/osp/system
+ /usr/include/appfw
+ ../../inc
+ )
+
+SET (${this_target}_SOURCE_FILES
+ AlarmConditionHandler.cpp
+ )
+
+## SET EXTRA COMPILER FLAGS
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC -Wall" )
+
+## SET C COMPILER FLAGS
+SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## SET CPP COMPILER FLAGS
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## Create Library
+ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES})
+
+ADD_DEPENDENCIES(${this_target} osp-appfw)
+
+SET_TARGET_PROPERTIES(${this_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PLUGIN_INSTALL_DIR}/lib")
+TARGET_LINK_LIBRARIES(${this_target} -L/usr/lib/osp -losp-appfw -Wl,--no-undefined -Wl,--as-needed)
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-appfw-application")
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-appfw-app-manager")
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-appfw-package-manager")
+
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?>
+
+<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+ <storageModule moduleId="org.eclipse.cdt.core.settings">
+ <cconfiguration id="0.337419437">
+ <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.337419437" moduleId="org.eclipse.cdt.core.settings" name="Default">
+ <externalSettings/>
+ <extensions>
+ <extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ </extensions>
+ </storageModule>
+ <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+ <configuration buildProperties="" description="" id="0.337419437" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
+ <folderInfo id="0.337419437." name="/" resourcePath="">
+ <toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.888259403" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
+ <targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.888259403.2003055277" name=""/>
+ <builder id="org.eclipse.cdt.build.core.settings.default.builder.2118925050" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.libs.275589824" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.1680722508" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1675042069" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.24576648" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1310280949" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.88316723" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.894902357" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ </toolChain>
+ </folderInfo>
+ </configuration>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+ </cconfiguration>
+ </storageModule>
+ <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+ <project id="nfc-condition-handler.null.1864129499" name="nfc-condition-handler"/>
+ </storageModule>
+ <storageModule moduleId="scannerConfiguration">
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+ <scannerConfigBuildInfo instanceId="0.337419437">
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+ </scannerConfigBuildInfo>
+ </storageModule>
+</cproject>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>nfc-condition-handler</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+ <triggers>clean,full,incremental,</triggers>
+ <arguments>
+ <dictionary>
+ <key>?name?</key>
+ <value></value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.append_environment</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.autoBuildTarget</key>
+ <value>all</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.buildArguments</key>
+ <value></value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.buildCommand</key>
+ <value>make</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
+ <value>clean</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.contents</key>
+ <value>org.eclipse.cdt.make.core.activeConfigSettings</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.enableAutoBuild</key>
+ <value>false</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.enableCleanBuild</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.enableFullBuild</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.fullBuildTarget</key>
+ <value>all</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.stopOnError</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
+ <value>true</value>
+ </dictionary>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+ <triggers>full,incremental,</triggers>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.cdt.core.cnature</nature>
+ <nature>org.eclipse.cdt.core.ccnature</nature>
+ <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+ <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+SET (this_target osp-cond-nfc)
+
+INCLUDE_DIRECTORIES (
+ /usr/include/osp
+ /usr/include/osp/app
+ /usr/include/osp/base
+ ../../inc
+ )
+
+SET (${this_target}_SOURCE_FILES
+ NfcConditionHandler.cpp
+ )
+
+## SET EXTRA COMPILER FLAGS
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC -Wall" )
+
+## SET C COMPILER FLAGS
+SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## SET CPP COMPILER FLAGS
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## Create Library
+ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES})
+
+ADD_DEPENDENCIES(${this_target} osp-appfw)
+
+SET_TARGET_PROPERTIES(${this_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PLUGIN_INSTALL_DIR}/lib")
+TARGET_LINK_LIBRARIES(${this_target} -L/usr/lib/osp -losp-appfw -Wl,--no-undefined -Wl,--as-needed)
+
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 nfc_condition_candler.cpp
+ * @brief This is the implementation file of the _AlarmConditionHandler class.
+ *
+ */
+
+
+#include <new>
+
+#include <FBaseColHashMap.h>
+#include <FBaseUtilRegularExpression.h>
+#include <FBaseUtilUrlEncoder.h>
+
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include <FApp_Aul.h>
+#include <FApp_AppLaunchConditionHandlerBase.h>
+
+
+#ifdef _NfcSysTryLogReturn
+#undef _NfcSysTryLogReturn
+#endif
+
+#define _NfcSysTryLogReturn(condition, returnValue, ...) \
+ if (!(condition)) { \
+ SetLastResult(E_INVALID_FORMAT); \
+ SysLog(NID_APP, __VA_ARGS__); \
+ return returnValue; \
+ } \
+ else {;}
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::System;
+
+
+/**
+ * @class _NfcConditionHandler
+ * @brief This class implements conditional app launch for alarm condition. (NFC)
+ * @final
+ */
+class _NfcConditionHandler:
+ public _AppLaunchConditionHandlerBase
+{
+public:
+ _NfcConditionHandler(void) :
+ uriSchemeMap()
+ {
+ // Makes the URI scheme table which is consist of well-known URI schemes the underlying NFC system supports
+ uriSchemeMap.Construct();
+ uriSchemeMap.Add(*(new String(L"http")), *(new String(L"http")));
+ uriSchemeMap.Add(*(new String(L"https")), *(new String(L"https")));
+ uriSchemeMap.Add(*(new String(L"ftp")), *(new String(L"ftp")));
+ uriSchemeMap.Add(*(new String(L"sftp")), *(new String(L"sftp")));
+ uriSchemeMap.Add(*(new String(L"smb")), *(new String(L"smb")));
+ uriSchemeMap.Add(*(new String(L"nfs")), *(new String(L"nfs")));
+ uriSchemeMap.Add(*(new String(L"telnet")), *(new String(L"telnet")));
+ uriSchemeMap.Add(*(new String(L"file")), *(new String(L"file")));
+ uriSchemeMap.Add(*(new String(L"ssh")), *(new String(L"ssh")));
+ uriSchemeMap.Add(*(new String(L"tel")), *(new String(L"tel")));
+ uriSchemeMap.Add(*(new String(L"mailto")), *(new String(L"mailto")));
+ uriSchemeMap.Add(*(new String(L"news")), *(new String(L"news")));
+ uriSchemeMap.Add(*(new String(L"sip")), *(new String(L"sip")));
+ uriSchemeMap.Add(*(new String(L"sips")), *(new String(L"sips")));
+ uriSchemeMap.Add(*(new String(L"tftp")), *(new String(L"tftp")));
+ uriSchemeMap.Add(*(new String(L"imap")), *(new String(L"imap")));
+ uriSchemeMap.Add(*(new String(L"pop")), *(new String(L"pop")));
+ uriSchemeMap.Add(*(new String(L"market")), *(new String(L"market")));
+ uriSchemeMap.Add(*(new String(L"rtsp")), *(new String(L"rtsp")));
+ }
+
+ virtual ~_NfcConditionHandler(void)
+ {
+ uriSchemeMap.RemoveAll(true);
+ }
+
+ virtual result Register(_AppLaunchCondition& operation)
+ {
+ // TODO: The following pattern is temporary.
+ // It should be changed to cover all NFC conditions according to the NDEF specifications.
+ String pattern(L"([A-Za-z]*)='([0-9A-Za-z&=_\\-\\.\\:\\/\\\\]*)'");
+ String buf(operation.GetConditionString());
+ String field;
+ String value;
+ ArrayList list;
+ Utility::RegularExpression regex;
+ char* pOriginalCondition = null;
+ char* pTranslatedCondition = null;
+ result r = E_SUCCESS;
+ bool ret = true;
+
+ list.Construct();
+
+ r = regex.Construct(pattern);
+ SysTryReturn(NID_APP, !IsFailed(r), E_SYSTEM, E_SYSTEM, "[%s] Failed to regex.Construct(%ls).", GetErrorMessage(r), pattern.GetPointer());
+
+ ret = regex.Consume(buf, &list);
+ r = GetLastResult();
+ SysTryReturn(NID_APP, ret == true, E_INVALID_FORMAT, E_INVALID_FORMAT, "[%s] Failed to parse the condition (%ls).", GetErrorMessage(r),
+ buf.GetPointer());
+
+ field = *(String*)list.GetAt(1);
+ value = *(String*)list.GetAt(2);
+ list.RemoveAll(true);
+
+ if (field == "NFC")
+ {
+ pOriginalCondition = _StringConverter::CopyToCharArrayN(value);
+ SysTryReturnResult(NID_APP, pOriginalCondition != null, E_SYSTEM, "Failed to parse the condition.");
+
+ // Translates OSP condition to SLP service condition
+ pTranslatedCondition = GetNfcAulConditionN(pOriginalCondition);
+ delete[] pOriginalCondition;
+
+ SysTryReturnResult(NID_APP, pTranslatedCondition != null, E_SYSTEM, "Failed to translate the condition.");
+
+ r = _Aul::_DesktopFile::UpdateService(operation.GetAppId(), pTranslatedCondition);
+
+ operation.SetUserData(new String(pTranslatedCondition));
+
+ delete[] pTranslatedCondition;
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+
+ return r;
+ }
+
+ virtual result Unregister(_AppLaunchCondition& operation)
+ {
+ String* pHandle = null;
+// char* pOriginalCondition = null;
+ char* pTranslatedCondition = null;
+ result r = E_SUCCESS;
+
+ pHandle = dynamic_cast<String*>(operation.GetUserData());
+ SysTryReturnResult(NID_APP, pHandle != null, E_INVALID_ARG, "Invalid conditional operation.");
+
+ pTranslatedCondition = _StringConverter::CopyToCharArrayN(*pHandle);
+ SysTryReturnResult(NID_APP, pTranslatedCondition != null, E_SYSTEM, "Failed to parse the condition.");
+
+ // Translates OSP condition to SLP service condition
+// pTranslatedCondition = GetNfcAulConditionN(pOriginalCondition);
+// delete[] pOriginalCondition;
+// SysTryReturnResult(NID_APP, pTranslatedCondition != null, E_SYSTEM, "Failed to translate the condition.");
+
+ r = _Aul::_DesktopFile::RemoveService(operation.GetAppId(), pTranslatedCondition); // only operation name is required to remove service.
+
+ delete[] pTranslatedCondition;
+
+ return r;
+ }
+
+private:
+ char* GetNfcAulConditionN(char* pConditionValue)
+ {
+ //-------------------------------------------------------------------------
+ // The BNF format of the OSP NFC condition is as follows:
+ // <condition> ::= <tnf_field>"&"<type_field>["&"<code_field>]
+ // <tnf_field> ::= "tnf="<tnf_value>
+ // <tnf_value> ::= "rtd"|"mime"|"uri"|"ext"
+ // <type_field> ::= "type="<type_string>
+ // <type_string> ::= <String of US_ASCII characters>
+ // <code_field> ::= "code="<uri_code>
+ // <uri_code> ::= "0x"<hexa_digit><hexa_digit>
+ // <hexa_digit> ::= "0".."9"|"A".."F"
+ //
+ // AUL translation rules according to <tnf_field> are as follows:
+ // "tnf=rtd" --> "NFC_SERVICE_WELL_KNOWN_TYPE:NULL:"<type_string>"/"{<uri_code>|"*"}
+ // "tnf=ext" --> "NFC_SERVICE_EXTERNAL_TYPE:NULL:"<uri_scheme>"/"<type_string>
+ // "tnf=uri" --> "NFC_SERVICE_URI_TYPE:NULL:"<uri_scheme>"/"<type_string>
+ // "tnf=mime" --> "NFC_SERVICE_MIME_TYPE:NULL:"<type_string>
+ // <uri_scheme> is the head part of <type_string> and delimited by colon(:) and one of the wellknown types
+ // <type_string> of "tnf=ext" and "tnf=mime" must be decapitalized for case-insensitive matching
+ // <type_string> of "tnf=ext" and "tnf=uri" must be percent-encoded
+ //
+ // Examples
+ // Source(OSP):
+ // tnf=rtd&type=Sp
+ // tnf=rtd&type=U&code=0x05
+ // tnf=ext&type=Bordeaux_Wine:1996
+ // tnf=uri&type=http://www.tizen.org
+ // tnf=mime&type=text/x-vcard
+ // Target(AUL):
+ // NFC_SERVICE_WELL_KNOWN_TYPE:NULL:Sp/*
+ // NFC_SERVICE_WELL_KNOWN_TYPE:NULL:U/0x05
+ // NFC_SERVICE_EXTERNAL_TYPE:NULL:unknown/bordeauxwine%3A1996
+ // NFC_SERVICE_URI_TYPE:http/http%3A%2F%2Fwww.tizen.org
+ // NFC_SERVICE_MIME_TYPE:NULL:text/x-vcard
+ //-------------------------------------------------------------------------
+
+ String tnfValue; // <tnf_value>
+ String typeString; // <type_string>
+ String uriCode(L'*'); // <uri_code>
+ int delimiterIndex = -1;
+
+ String originalCondition(pConditionValue);
+ String aulFormatCondition;
+ char* pTranslatedCondition = null;
+
+ result r = E_SUCCESS;
+ bool isOk = true;
+
+
+ // Check whether the condition includes the tnf field.
+ isOk = originalCondition.StartsWith(L"tnf=", 0);
+ _NfcSysTryLogReturn(isOk == true, null, "Illegal format (%ls) - No tnf field.", originalCondition.GetPointer() );
+
+ // Search the index of the type field.
+ r = originalCondition.IndexOf(L'&', 0, delimiterIndex);
+ _NfcSysTryLogReturn(r == E_SUCCESS, null, "Illegal format (%ls)- No type field.", originalCondition.GetPointer() );
+
+ // Read <tnf_value>.
+ // The length of <tnf_value> is (delimiterIndex - 4).
+ r = originalCondition.SubString(4, delimiterIndex - 4, tnfValue);
+ _NfcSysTryLogReturn(r == E_SUCCESS, null, "Parsing error. (%ls)", originalCondition.GetPointer() );
+
+ // Check whether the condition includes the type field.
+ isOk = originalCondition.StartsWith(L"type=", delimiterIndex + 1);
+ _NfcSysTryLogReturn(isOk == true, null, "Illegal format (%ls)- No type field.", originalCondition.GetPointer() );
+
+ // Read <type_string>.
+ r = originalCondition.SubString(delimiterIndex + 6, typeString);
+ _NfcSysTryLogReturn(r == E_SUCCESS, null, "Parsing error. (%ls)", originalCondition.GetPointer() );
+
+ if (tnfValue.CompareTo(L"rtd") == 0)
+ {
+ // Search the index of the code field.
+ // The code field is optional.
+ r = typeString.IndexOf(L'&', 0, delimiterIndex);
+ if (!IsFailed(r))
+ {
+ String fullTypeString(typeString);
+
+ r = fullTypeString.SubString(0, delimiterIndex, typeString);
+ _NfcSysTryLogReturn(r == E_SUCCESS, null, "Parsing error. (%ls)", originalCondition.GetPointer() );
+
+ if (typeString.CompareTo(L"U") == 0)
+ {
+ // Check whether the condition includes the type field.
+ isOk = fullTypeString.StartsWith(L"code=", delimiterIndex + 1);
+ _NfcSysTryLogReturn(isOk == true, null, "Illegal format (%ls)- No code field after the second '&'.", originalCondition.GetPointer() );
+
+ // Read <uri_code>.
+ r = fullTypeString.SubString(delimiterIndex + 6, uriCode);
+ _NfcSysTryLogReturn(r == E_SUCCESS, null, "Parsing error. (%ls)", originalCondition.GetPointer() );
+ }
+ }
+
+ aulFormatCondition = L"NFC_SERVICE_WELL_KNOWN_TYPE:NULL:";
+ aulFormatCondition.Append(typeString);
+ aulFormatCondition.Append(L'/');
+ aulFormatCondition.Append(uriCode); // The default value of 'uriCode' is '*'
+ }
+ else if ((tnfValue.CompareTo(L"ext") == 0) || (tnfValue.CompareTo(L"uri") == 0))
+ {
+ if (tnfValue.CompareTo(L"ext") == 0)
+ {
+ aulFormatCondition = L"NFC_SERVICE_EXTERNAL_TYPE:NULL:";
+ // Convert all the letters to lower case.
+ typeString.ToLowerCase();
+ }
+ else
+ {
+ aulFormatCondition = L"NFC_SERVICE_URI_TYPE:NULL:";
+ }
+
+ r = typeString.IndexOf(L':', 0, delimiterIndex);
+ if (!IsFailed(r))
+ {
+ String uriScheme;
+
+ // Extract the URI scheme from <type_string>.
+ r = typeString.SubString(0, delimiterIndex, uriScheme);
+ _NfcSysTryLogReturn(r == E_SUCCESS, null, "Parsing error.");
+
+ // if the URI scheme is one of the registered keywords
+ (void) uriSchemeMap.GetValue(uriScheme);
+ r = GetLastResult();
+ if (!IsFailed(r))
+ {
+ aulFormatCondition.Append(uriScheme);
+ }
+ else
+ {
+ aulFormatCondition.Append(L"unknown");
+ }
+ }
+ else
+ {
+ aulFormatCondition.Append(L"unknown");
+ }
+
+ String encodedTypeString;
+
+ // Encode <type_string> using UTF-8 encoding scheme.
+ r = UrlEncoder::Encode(typeString, L"UTF-8", encodedTypeString);
+ _NfcSysTryLogReturn(r == E_SUCCESS, null, "Failed to UTF-8 Encoding.");
+
+ aulFormatCondition.Append(L'/');
+ aulFormatCondition.Append(encodedTypeString);
+ }
+ else if (tnfValue.CompareTo(L"mime") == 0)
+ {
+ typeString.ToLowerCase();
+
+ aulFormatCondition = L"NFC_SERVICE_MIME_TYPE:NULL:";
+ aulFormatCondition.Append(typeString);
+ }
+ else
+ {
+ SysLog(NID_APP, "Illegal format (%ls) - Invalid TNF value", originalCondition.GetPointer() );
+ return null;
+ }
+
+ pTranslatedCondition = _StringConverter::CopyToCharArrayN(aulFormatCondition);
+ _NfcSysTryLogReturn(pTranslatedCondition != null, null, "String conversion error.");
+
+ return pTranslatedCondition;
+ }
+
+private:
+ HashMap uriSchemeMap;
+}; //_NfcConditionHandler
+
+
+/////////////////////////////////////////////////////////////////////////
+// All plugins must provide both a creation and a destruction function
+/////////////////////////////////////////////////////////////////////////
+extern "C"
+{
+_OSP_EXPORT_ _AppLaunchConditionHandlerBase*
+CreatePlugin(void)
+{
+ return new (std::nothrow) _NfcConditionHandler;
+}
+
+_OSP_EXPORT_ void
+DestroyPlugin(_AppLaunchConditionHandlerBase* p)
+{
+ delete p;
+}
+}//extern "C"
--- /dev/null
+#libosp-cond-alarm.so
+Key=DateTime,LaunchPeriod,DueTime
+Filename=libosp-cond-alarm.so
+
+#libosp-cond-nfc.so
+Key=NFC
+Filename=libosp-cond-nfc.so
+
+#libosp-cond-accessory.so
+Key=ACCESSORY,Serial
+Filename=libosp-cond-accessory.so
--- /dev/null
+#osp-channel-service
+Priority=High
+AppId=cp7ipabg4k.osp-channel-service
+#osp-security-service
+Priority=High
+q7097a278m.osp-security-service
+#osp-connectivity-service
+AppId=57r43275q7.osp-connectivity-service
+#osp-location-service
+AppId=800ij447xl.osp-location-service
\ No newline at end of file
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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/prctl.h>
+#include <signal.h>
+#include <unique_ptr.h>
+
+#include <vconf.h>
+#include <calendar_service.h>
+#include <calendar_types2.h>
+
+#include <FIoFile.h>
+#include <FBaseSysLog.h>
+
+#include <FApp_Aul.h>
+#include <FIo_RegistryImpl.h>
+#include <FSys_EnvironmentImpl.h>
+#include <FBase_StringConverter.h>
+#include <FBaseRt_Process.h>
+
+#include "FApp_AppInfo.h"
+#include "FApp_AppManagerImpl.h"
+#include "FApp_AppControlManager.h"
+#include "FApp_CommunicationDispatcher.h"
+#include "FApp_ContextManager.h"
+#include "FApp_AppManagerStub.h"
+#include "FApp_ConditionManagerStub.h"
+#include "FSys_DeviceManagerService.h"
+#include "FSys_SystemService.h"
+#include "FSys_AlarmService.h"
+#include "FSys_AccessoryManagerService.h"
+#include "FApp_PackageManagerStub.h"
+#include "FApp_NotificationManagerStub.h"
+#include "FAppPkg_PackageManagerImpl.h"
+#include "FIo_MmcStorageManagerStub.h"
+#include "AppService.h"
+
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Io;
+using namespace Tizen::System;
+using namespace Tizen::App;
+
+namespace
+{
+static const RequestId HANDLER_REQUEST_INSTALL_COMPLETE = 0;
+static const RequestId HANDLER_REQUEST_UNINSTALL_COMPLETE = 1;
+static const RequestId HANDLER_REQUEST_ID = 2;
+static const RequestId HANDLER_REQUEST_ALARMID = 2;
+
+const char _APP_PATH_FORMAT[] = "/opt/apps/0000000000/bin/%ls";
+const char _HEARTBEAT_PATH[] = "/tmp/osp-initialized";
+#ifndef VCONFKEY_APPSERVICE_STATUS
+#define VCONFKEY_APPSERVICE_STATUS "memory/appservice/status"
+#endif
+
+}
+
+
+AppService::AppService()
+: __pCommunicationDispatcher(null)
+, __pContextMgr(null)
+, __pAppManagerStub(null)
+, __pConditionManagerStub(null)
+, __handlerThread(*this)
+, __pDeviceManagerService(null)
+, __pSystemService(null)
+, __pAccessoryManagerService(null)
+, __pAlarmService(null)
+, __pPackageManagerStub(null)
+, __pNotificationManagerStub(null)
+, __pMmcStorageManagerStub(null)
+{
+ SysLog(NID_APP, "Enter.");
+
+ int pid = getpid();
+ setpgid(pid, pid);
+
+ InitializeIpc();
+
+ SysLog(NID_APP, "Exit.");
+}
+
+AppService::~AppService()
+{
+ SysLog(NID_APP, "Enter.");
+
+ vconf_set_int(VCONFKEY_APPSERVICE_STATUS, -1);
+
+ Tizen::App::Package::_PackageManagerImpl::GetInstance()->RemoveEventListener(this);
+
+ delete __pAppManagerStub;
+ delete __pConditionManagerStub;
+ delete __pPackageManagerStub;
+ delete __pNotificationManagerStub;
+ delete __pMmcStorageManagerStub;
+
+ delete __pContextMgr;
+
+ SysLog(NID_APP, "Exit.");
+}
+
+Service*
+AppService::CreateInstance(void)
+{
+ static AppService* pAppService = new (std::nothrow) AppService();
+
+ return pAppService;
+}
+
+bool
+AppService::OnAppInitializing(AppRegistry& appRegistry)
+{
+ SysLog(NID_APP, "Enter.");
+
+ result r = __handlerThread.Construct(THREAD_TYPE_EVENT_DRIVEN);
+ SysTryReturn(NID_APP, IsFailed(r) == false, false, r, "[%s] Event thread creation failure.", GetErrorMessage(r));
+
+ r = __handlerThread.Start();
+ SysTryReturn(NID_APP, IsFailed(r) == false, false, r, "[%s] Event thread Start failure.", GetErrorMessage(r));
+
+ SysLog(NID_APP, "Exit.");
+ return true;
+}
+
+bool
+AppService::OnAppInitialized(void)
+{
+ SysLog(NID_APP, "Enter.");
+
+ _Aul::SetPowerOffNotiListener(OnPowerOffNotiReceived, this);
+
+ result r = _AppManagerImpl::GetInstance()->AddEventListener(*this);
+ SysAssertf(!IsFailed(r), "[%s] Failed to add event listener.", GetErrorMessage(r));
+
+ LaunchSecurityService();
+ LaunchChannelService();
+// LaunchSystemServices();
+// LaunchUserServices();
+//
+
+ InitializeServices();
+
+ const String tmpPath = _HEARTBEAT_PATH;
+ File file;
+ (void) file.Construct(tmpPath, "w");
+
+ vconf_set_int(VCONFKEY_APPSERVICE_STATUS, 1);
+ SysLog(NID_APP, "Exit.");
+ return true;
+}
+
+void
+AppService::OnPowerOffNotiReceived(void* pData)
+{
+ SysLog(NID_APP, "'power_off_start' noti received from system-server with 0x%x.", pData);
+
+ AppService* pAppService = static_cast<AppService*>(pData);
+ if (pAppService)
+ {
+ SysLog(NID_APP, "osp-app-service is terminating now.");
+ pAppService->Terminate();
+ }
+}
+
+
+bool
+AppService::InitializeIpc(void)
+{
+ SysLog(NID_APP, "Enter.");
+ result r = E_SUCCESS;
+
+ __pContextMgr = new (std::nothrow) _ContextManager();
+ SysAssert(__pContextMgr != null);
+ SysTryCatch(NID_APP, __pContextMgr != null,, E_OUT_OF_MEMORY, "failed to _ContextManager creation.");
+
+ r = __pContextMgr->Construct();
+ SysAssert(!IsFailed(r));
+ SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
+
+ __pAppManagerStub = new (std::nothrow) _AppManagerStub();
+ SysAssert(__pAppManagerStub != null);
+ SysTryCatch(NID_APP, __pAppManagerStub != null,, E_OUT_OF_MEMORY, "failed to _AppManagerStub creation.");
+
+ r = __pAppManagerStub->Construct(__pContextMgr);
+ SysAssert(!IsFailed(r));
+ SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
+
+ __pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
+ SysAssert(__pCommunicationDispatcher != null);
+ SysTryCatch(NID_APP, __pCommunicationDispatcher != null,, E_OUT_OF_MEMORY, "failed to _CommunicationDispatcher creation.");
+
+ SysLog(NID_APP, "Exit.");
+ return true;
+
+CATCH:
+ SysLog(NID_APP, "Catch.");
+
+ delete __pAppManagerStub;
+ __pAppManagerStub = null;
+
+ delete __pContextMgr;
+ __pContextMgr = null;
+
+ SysAssertf(false, "IPC services initializing is failed.");
+ return false;
+}
+
+bool
+AppService::InitializeServices(void)
+{
+ SysLog(NID_APP, "Enter.");
+ result r = E_SUCCESS;
+
+ __pConditionManagerStub = new (std::nothrow) _ConditionManagerStub();
+ SysAssert(__pConditionManagerStub != null);
+ SysTryCatch(NID_APP, __pConditionManagerStub != null,, E_OUT_OF_MEMORY, "failed to _ConditionManagerStub creation.");
+
+ r = __pConditionManagerStub->Construct();
+ SysAssert(!IsFailed(r));
+ SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
+
+ __pDeviceManagerService = _DeviceManagerService::GetInstance();
+ SysAssert( __pDeviceManagerService != null);
+ SysTryCatch(NID_APP, __pDeviceManagerService != null,, E_OUT_OF_MEMORY, "failed to _DeviceManagerService creation.");
+
+ __pSystemService = _SystemService::GetInstance();
+ SysAssert( __pSystemService != null);
+ SysTryCatch(NID_APP, __pSystemService != null,, E_OUT_OF_MEMORY, "failed to _SystemService creation.");
+
+ __pAlarmService = _AlarmService::GetInstance();
+ SysAssert( __pAlarmService != null);
+ SysTryCatch(NID_APP, __pAlarmService != null,, E_OUT_OF_MEMORY, "failed to _pAlarmService creation.");
+
+ __pAccessoryManagerService = _AccessoryManagerService::GetInstance();
+ SysAssert( __pAccessoryManagerService != null);
+ SysTryCatch(NID_APP, __pAccessoryManagerService != null,, E_OUT_OF_MEMORY, "failed to _AccessoryManagerService creation.");
+
+ __pPackageManagerStub = new (std::nothrow) _PackageManagerStub();
+ SysAssert(__pPackageManagerStub != null);
+ SysTryCatch(NID_APP, __pPackageManagerStub != null,, E_OUT_OF_MEMORY, "failed to _PackageManagerStub creation.");
+
+ r = __pPackageManagerStub->Construct();
+ SysAssert(!IsFailed(r));
+ SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
+
+ __pNotificationManagerStub = new (std::nothrow) _NotificationManagerStub();
+ SysAssert(__pNotificationManagerStub != null);
+ SysTryCatch(NID_APP, __pNotificationManagerStub != null,, E_OUT_OF_MEMORY, "failed to _pNotificationManagerStub creation.");
+
+ r = __pNotificationManagerStub->Construct();
+ SysAssert(!IsFailed(r));
+ SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
+
+ __pMmcStorageManagerStub = new (std::nothrow) _MmcStorageManagerStub();
+ SysAssert(__pMmcStorageManagerStub != null);
+ SysTryCatch(NID_APP, __pMmcStorageManagerStub != null,, E_OUT_OF_MEMORY, "failed to __pMmcStorageManagerStub creation.");
+
+ r = __pMmcStorageManagerStub->Construct();
+ SysAssert(!IsFailed(r));
+ SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
+
+ SysLog(NID_APP, "Exit.");
+ return true;
+
+CATCH:
+ SysLog(NID_APP, "Catch.");
+
+ delete __pConditionManagerStub;
+ __pConditionManagerStub = null;
+
+ delete __pPackageManagerStub;
+ __pPackageManagerStub = null;
+
+ delete __pNotificationManagerStub;
+ __pNotificationManagerStub = null;
+
+ delete __pMmcStorageManagerStub;
+ __pNotificationManagerStub = null;
+
+ SysAssertf(false, "System services initializing is failed.");
+ return false;
+}
+
+result
+AppService::SetOomAdj(int pid, int adj)
+{
+ // set oom_adj to -17 for system service
+ result r = E_SUCCESS;
+ char buf[FILENAME_MAX];
+ FILE *fP = NULL;
+
+ snprintf(buf, FILENAME_MAX, "/proc/%d/oom_adj", pid);
+ fP = fopen(buf, "w");
+ SysTryReturnResult(NID_APP, fP != NULL, E_SYSTEM, "oom_adj change failed with %s.", strerror(errno));
+
+ fprintf(fP, "%d", adj);
+ fclose(fP);
+
+ return r;
+}
+
+int
+AppService::CreateProcess(const String& appId)
+{
+ SysTryReturn(NID_APP, appId.GetLength() > 10 && appId[10] == L'.', -1, E_INVALID_ARG, "[E_INVALID_ARG] Wrong appId %ls.", appId.GetPointer());
+ int pid = fork();
+
+ if (pid == -1)
+ {
+ return -1;
+ }
+ else if (pid == 0)
+ {
+ char path[FILENAME_MAX];
+ memset(path, '\0', FILENAME_MAX);
+
+ snprintf(path, FILENAME_MAX, _APP_PATH_FORMAT, appId.GetPointer() + 11);
+
+ int ret = wcstombs(path + strlen("/opt/apps/"), appId.GetPointer(), 10);
+ if (ret == -1)
+ {
+ SysLogException(NID_APP, E_SYSTEM, "Launching service (%ls)(%s) failed with [%s].", appId.GetPointer(), path, strerror(errno));
+ _Process::Exit(1);
+ }
+
+ SysLog(NID_APP, "Launching %s.", path);
+
+ int currentPid = getpid();
+
+ SetOomAdj(currentPid, -17); // set oom_adj to -17 for system service
+
+ prctl(PR_SET_PDEATHSIG, SIGTERM);
+
+ setpgid(currentPid, currentPid);
+
+ ret = execl(path, path, static_cast<char*>(NULL));
+ if (ret < 0)
+ {
+ SysLogException(NID_APP, E_SYSTEM, "Launching service (%ls)(%s) failed with [%s].", appId.GetPointer(), path, strerror(errno));
+ _Process::Exit(1);
+ }
+ }
+
+ return pid;
+}
+
+bool
+AppService::LaunchSystemServices(void)
+{
+ const wchar_t systemServiceRegPath[] = L"res/system-services.ini";
+ const String regKeyAppId = L"AppId";
+ const String regKeyPriority = L"Priority";
+
+ SysLog(NID_APP, "Enter.");
+ _RegistryImpl reg;
+ const String& systemListPath = _AppInfo::GetAppRootPath() + systemServiceRegPath;
+
+ result r = reg.Construct(systemListPath, REG_OPEN_READ_ONLY, null);
+ // SysTryReturn(NID_APP, !IsFailed(r), r, r, "");
+ if (IsFailed(r))
+ {
+ SysLog(NID_APP, "failed to open registry '%ls'", systemListPath.GetPointer());
+ return true;
+ }
+
+ IList *pSections = null;
+ reg.GetSectionListN(&pSections);
+ SysTryReturn(NID_APP, pSections != null, false, E_SYSTEM, "[E_SYSTEM] GetSectionListN fails (%ls) ", systemListPath.GetPointer() );
+
+ String* pSecName = null;
+ String appIdValue;
+ String priorityValue;
+ std::unique_ptr<IEnumerator> pEnum(pSections->GetEnumeratorN());
+ SysTryCatch(NID_APP, pEnum != null, , E_SYSTEM, "[E_SYSTEM] pSections->GetEnumeratorN fails (%ls)", systemListPath.GetPointer() );
+
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ pSecName = static_cast<String*>(pEnum->GetCurrent());
+ if ( pSecName != null)
+ {
+ priorityValue = L"";
+ r = reg.GetValue(*pSecName, regKeyPriority, priorityValue);
+ if (!IsFailed(r) && priorityValue == L"High")
+ {
+ // channel and security service are launched by code already.
+ continue;
+ }
+
+ reg.GetValue(*pSecName, regKeyAppId, appIdValue);
+
+ int pid = CreateProcess(appIdValue);
+ if (pid != -1)
+ {
+ SysLog(NID_APP, "System service(%ls) is launched as pid(%d).", appIdValue.GetPointer(), pid);
+// __pContextMgr->Register(appIdValue, executableNameValue, pid, pid, true);
+ }
+ else
+ {
+ SysLog(NID_APP, "Failed to launch System service(%ls).", appIdValue.GetPointer());
+ }
+ }
+ }
+
+
+ pSections->RemoveAll(true);
+ delete pSections;
+
+ SysLog(NID_APP, "Exit.");
+ return true;
+
+CATCH:
+ pSections->RemoveAll(true);
+ delete pSections;
+ return false;
+}
+
+bool
+AppService::LaunchChannelService(void)
+{
+ SysLog(NID_APP, "Launching channel service...");
+ return CreateProcess(L"cp7ipabg4k.osp-channel-service" ) == E_SUCCESS;
+}
+
+bool
+AppService::LaunchSecurityService(void)
+{
+ SysLog(NID_APP, "Launching security service...");
+ return CreateProcess(L"q7097a278m.osp-security-service" ) == E_SUCCESS;
+}
+
+bool
+AppService::LaunchUserServices(void)
+{
+ SysLog(NID_APP, "Enter.");
+
+ IList* pAppIdList_ForLaunchOnBoot = Tizen::App::Package::_PackageManagerImpl::GetInstance()->GetFilteredAppIdListN(L"LaunchOnBoot", L"True");
+ if (pAppIdList_ForLaunchOnBoot == null)
+ {
+ SysLog(NID_APP, "No launch-on-boot entry.");
+ return true;
+ }
+
+ result r = E_SUCCESS;
+ String* pPackageNameStr = null;
+ char* pPackageName = null;
+
+ for (int i = 0; i < pAppIdList_ForLaunchOnBoot->GetCount(); i++)
+ {
+ pPackageNameStr = dynamic_cast<String*>(pAppIdList_ForLaunchOnBoot->GetAt(i));
+ if (pPackageNameStr != null)
+ {
+ pPackageName = _StringConverter::CopyToCharArrayN(*pPackageNameStr);
+
+ SysLog(NID_APP, "'%ls'", pPackageNameStr->GetPointer()) ;
+ r = _AppControlManager::GetInstance()->LaunchPkg(pPackageName, null, null, null, null, null);
+ delete[] pPackageName;
+
+ if (!IsFailed(r))
+ {
+ SysLog(NID_APP, "'%ls'is launched", pPackageNameStr->GetPointer()) ;
+ }
+ else
+ {
+ SysLog(NID_APP, "%s", GetErrorMessage(r) );
+ }
+ }
+ }
+
+ pAppIdList_ForLaunchOnBoot->RemoveAll(true);
+ delete pAppIdList_ForLaunchOnBoot;
+
+ SysLog(NID_APP, "Exit.");
+ return !IsFailed(r);
+}
+
+bool
+AppService::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
+{
+ const String tmpPath = _HEARTBEAT_PATH;
+ File::Remove(tmpPath);
+ return true;
+}
+
+void
+AppService::OnLowMemory(void)
+{
+
+}
+
+void
+AppService::OnBatteryLevelChanged(BatteryLevel batteryLevel)
+{
+
+}
+
+void
+AppService::OnUserEventReceivedN(RequestId requestId, IList *pArgs)
+{
+ if ( pArgs == null)
+ {
+ return;
+ }
+
+ SysLog(NID_APP, "OnUserEventReceivedN() is called. RequestId = %d \n", requestId);
+
+ if (requestId == HANDLER_REQUEST_ALARMID)
+ {
+ String* pArg = null;
+ for (int i = 0; (pArg = static_cast<String*>(pArgs->GetAt(i))) != null; i++)
+ {
+ int alarmId = -1;
+ Integer::Parse(*pArg, alarmId);
+ SysLog(NID_APP, "Alarm event is expired alarm Id is %d", alarmId);
+ if (__pAlarmService != NULL)
+ {
+ __pAlarmService->OnAlarmExpired(alarmId);
+ }
+ else
+ {
+ SysLog(NID_APP, "Alarm Service is not available. Alarm Event could not be announced.");
+ }
+ }
+ }
+
+ pArgs->RemoveAll(true);
+}
+
+ArrayList*
+AppService::GetPackageEventArgsN(const AppId& appId)
+{
+ ArrayList* pArray = new (std::nothrow) ArrayList;
+ SysTryReturn(NID_APP, pArray != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Array allocation failure.");
+
+ pArray->Construct();
+
+
+ String tmpExecName = Tizen::App::Package::_PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
+ String tmpPackageName = appId + "." + tmpExecName;
+
+ String* pPackageName;
+ String* pAppId;
+ String* pExecName;
+
+ pPackageName = new (std::nothrow) String(tmpPackageName);
+ SysTryCatch(NID_APP, pPackageName != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] packageName allocation failure.");
+ pArray->Add(*pPackageName);
+
+ pAppId = new (std::nothrow) String(appId);
+ SysTryCatch(NID_APP, pAppId != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppId %ls allocation failure.", appId.GetPointer());
+ pArray->Add(*pAppId);
+
+// pExecName = new (std::nothrow) String(_ContextManager::_Util::GetExecNameFromPackageName(packageName));
+ pExecName = new (std::nothrow) String(tmpExecName);
+ SysTryCatch(NID_APP, pExecName != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
+ pArray->Add(*pExecName);
+
+ return pArray;
+
+CATCH:
+ pArray->RemoveAll(true);
+ delete pArray;
+
+ return null;
+}
+
+void
+AppService::OnPackageInstallationCompleted(const PackageId& packageId, Tizen::App::Package::PackageInstallationResult installationResult)
+{
+ SysLog(NID_APP, "Enter. packageId(%ls), installationResult(%d)", packageId.GetPointer(), installationResult);
+
+ if (installationResult == Tizen::App::Package::PACKAGE_INSTALLATION_RESULT_SUCCESS)
+ {
+ ArrayList* pArray = GetPackageEventArgsN(packageId);
+ SysTryReturnVoidResult(NID_APP, pArray != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetPackageEventArgsN failure.");
+
+ result r = __handlerThread.SendUserEvent(HANDLER_REQUEST_INSTALL_COMPLETE, pArray);
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] Propagated.", GetErrorMessage(r));
+ }
+
+ SysLog(NID_APP, "Exit.");
+}
+
+void
+AppService::OnPackageUninstallationCompleted(const PackageId& packageId, bool uninstallationResult)
+{
+ SysLog(NID_APP, "Enter. packageId(%ls), uninstallationResult(%d)", packageId.GetPointer(), uninstallationResult);
+
+ if (uninstallationResult == true)
+ {
+ ArrayList* pArray = GetPackageEventArgsN(packageId);
+ SysTryReturnVoidResult(NID_APP, pArray != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetPackageEventArgsN failure.");
+
+ result r = __handlerThread.SendUserEvent(HANDLER_REQUEST_UNINSTALL_COMPLETE, pArray);
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] Propagated.", GetErrorMessage(r));
+ }
+
+ SysLog(NID_APP, "Exit.");
+}
+
+void
+AppService::OnPackageInstallationInProgress(const PackageId& packageId, int progress)
+{
+}
+
+bool
+ConfirmCalendarService(void)
+{
+ int count = 0;
+ long interval = 100;
+ int ret = CALENDAR_ERROR_NONE;
+ int WAIT_COUNT = 40;
+
+ while (true)
+ {
+ int ret = calendar_connect();
+ if (ret == CALENDAR_ERROR_NONE)
+ {
+ calendar_disconnect();
+ SysLog(NID_APP, "Found calendar service on %dth trial.", count);
+ return true;
+ }
+
+ SysLog(NID_APP, "Waiting for calendar service %dth time(%d msec).", count, interval);
+
+ if (count >= WAIT_COUNT)
+ {
+ SysLog(NID_APP, "Count overflow.");
+ return false;
+ }
+
+ count++;
+ Thread::Sleep(interval);
+ interval += 150 * count;
+ }
+
+ return false;
+}
+
+void
+AppService::OnApplicationLaunched(const AppId& appId, Tizen::App::_AppType type)
+{
+ static bool channelServiceLaunched = false;
+ static bool securityServiceLaunched = false;
+
+ const String CHANNEL_SERVICE_APPID = L"cp7ipabg4k";
+ const String SECURITY_SERVICE_APPID = L"q7097a278m";
+
+ if (appId == CHANNEL_SERVICE_APPID)
+ {
+ channelServiceLaunched = true;
+ }
+ else if (appId == SECURITY_SERVICE_APPID)
+ {
+ securityServiceLaunched = true;
+ }
+
+
+ if (securityServiceLaunched && channelServiceLaunched)
+ {
+ _AppManagerImpl::GetInstance()->RemoveEventListener(*this);
+ LaunchSystemServices();
+
+ Tizen::App::Package::_PackageManagerImpl::GetInstance()->AddEventListener(this, 0);
+
+ ConfirmCalendarService();
+ vconf_set_int(VCONFKEY_APPSERVICE_STATUS, 2);
+
+ LaunchUserServices();
+ }
+}
+
+void
+AppService::OnApplicationTerminated(const AppId& appId, Tizen::App::_AppType type)
+{
+ SysLog(NID_APP, "Do nothing.");
+}
+
+
+/*
+ * AppService::_TaskHandlerThread
+ */
+
+AppService::_TaskHandlerThread::_TaskHandlerThread(AppService& mgr)
+ : __mgr(mgr)
+{
+}
+
+AppService::_TaskHandlerThread::~_TaskHandlerThread(void)
+{
+}
+
+bool
+AppService::_TaskHandlerThread::OnStart(void)
+{
+ return true;
+}
+
+void
+AppService::_TaskHandlerThread::OnStop(void)
+{
+}
+
+void
+AppService::_TaskHandlerThread::OnUserEventReceivedN(RequestId reqId, IList* pArgs)
+{
+ SysLog(NID_APP, "Enter.");
+ SysTryReturnVoidResult(NID_APP, pArgs != null && pArgs->GetCount() == 3, E_INVALID_STATE, "Wrong argument delivered for install complete event.");
+
+ String* pPackageName= dynamic_cast<String*>( pArgs->GetAt(0) );
+ SysTryReturnVoidResult(NID_APP, pPackageName != null, E_INVALID_STATE, "Invalid packageName for install complete event.");
+
+ String* pAppId = dynamic_cast<String*>( pArgs->GetAt(1) );
+ SysTryReturnVoidResult(NID_APP, pAppId != null, E_INVALID_STATE, "Invalid appId for install complete event.");
+
+ String* pExecName= dynamic_cast<String*>( pArgs->GetAt(2) );
+ SysTryReturnVoidResult(NID_APP, pExecName != null, E_INVALID_STATE, "Invalid execName for install complete event.");
+
+ switch (reqId)
+ {
+ case HANDLER_REQUEST_INSTALL_COMPLETE:
+ {
+ String isLaunchOnBoot = _ContextManager::_Util::QueryFeatureFromPackageManager(*pAppId, *pExecName, L"LaunchOnBoot" );
+ if ( isLaunchOnBoot == L"True")
+ {
+ String realId = *pAppId + '.' + *pExecName;
+ result r = _AppManagerImpl::GetInstance()->LaunchApplication(realId, null, AppManager::LAUNCH_OPTION_DEFAULT);
+ SysTryLog(NID_APP, !IsFailed(r), "%s", GetErrorMessage(r) );
+ SysLog(NID_APP, "'%ls'is launched", pExecName->GetPointer()) ;
+ }
+
+ SysTryReturnVoidResult(NID_APP, __mgr.__pConditionManagerStub != null, E_INVALID_STATE, "Invalid condition manager stub for install complete event.");
+ __mgr.__pConditionManagerStub->OnInstallComplete(*pAppId, *pExecName, *pPackageName);
+ }
+ break;
+
+ case HANDLER_REQUEST_UNINSTALL_COMPLETE:
+ {
+ SysTryReturnVoidResult(NID_APP, __mgr.__pConditionManagerStub != null, E_INVALID_STATE, "Invalid condition manager stub for install complete event.");
+ __mgr.__pConditionManagerStub->OnUninstallComplete(*pAppId, *pExecName );
+ }
+ break;
+
+ default:
+ SysLog(NID_APP, "Wrong request Id for handler thread : 0x%x", reqId);
+ break;
+ }
+
+ pArgs->RemoveAll(true);
+ delete pArgs;
+
+ SysLog(NID_APP, "Exit.");
+}
+
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 <new>
+
+#include <FOspConfig.h>
+#include <FApp.h>
+#include "AppService.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif // __cplusplus
+
+_OSP_EXPORT_ int OspMain(int argc, char*pArgv[]);
+
+int
+OspMain(int argc, char* pArgv[])
+{
+ result r = E_SUCCESS;
+
+ AppLog("Application started.");
+ ArrayList* pArgs = new (std::nothrow) ArrayList();
+ pArgs->Construct();
+ for (int i = 0; i < argc; i++)
+ {
+ pArgs->Add(*(new (std::nothrow) String(pArgv[i])));
+ }
+
+ r = Tizen::App::Service::Execute(AppService::CreateInstance, pArgs);
+ if (IsFailed(r))
+ {
+ AppLogException("Application execution failed - [%s].", GetErrorMessage(r));
+ r &= 0x0000FFFF;
+ }
+
+ pArgs->RemoveAll(true);
+ delete pArgs;
+ AppLog("Application finished.");
+
+ return static_cast<int>(r);
+}
+#ifdef __cplusplus
+}
+#endif // __cplusplus
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_AppManagerService.cpp
+ * @brief This is the implementation for the _AppManagerService class.
+ */
+
+#include <FBaseSysLog.h>
+#include <FApp_AppInfo.h>
+#include <FApp_Aul.h>
+#include <FApp_AppManagerEventArg.h>
+#include <FApp_IAppManagerServiceEventListener.h>
+
+#include "FAppPkg_PackageManagerImpl.h"
+#include "FApp_ContextManager.h"
+#include "FApp_AppManagerService.h"
+
+
+using namespace Tizen::Base;
+using namespace Tizen::Io;
+using namespace Tizen::Text;
+
+
+namespace Tizen { namespace App {
+
+
+_AppManagerService::_AppManagerService(void)
+: __pContextMgr(null)
+, __pStub(null)
+, __pProxy(null)
+{
+ SysLog(NID_APP, "");
+}
+
+_AppManagerService::~_AppManagerService(void)
+{
+ SysLog(NID_APP, "");
+}
+
+result
+_AppManagerService::Construct(_ContextManager *pContextMgr, _IAppManagerServiceEventListener* pStub)
+{
+ SysTryReturnResult(NID_APP, pContextMgr != null, E_INVALID_ARG, "pContextMgr should not be null!");
+
+ SysLog(NID_APP, "Enter\n");
+ __pContextMgr = pContextMgr;
+ __pContextMgr->SetEventListener(*this);
+ __pStub = pStub;
+ __eventListeners.Construct();
+ SysLog(NID_APP, "Exit\n");
+
+ return E_SUCCESS;
+}
+
+
+///////////////////////////////////////////
+// stub implementations
+///////////////////////////////////////////
+
+result
+_AppManagerService::LaunchApplication(const AppId& appId, const String& executableName, int req)
+{
+ SysLog(NID_APP, "(appId:%ls, serviceId:%ls)", appId.GetPointer(), executableName.GetPointer());
+ return E_SUCCESS;
+}
+
+result
+_AppManagerService::TerminateApplication(const AppId& appId, const String& executableName)
+{
+ SysTryReturnResult(NID_APP, __pContextMgr != null, E_INVALID_STATE, "pContextMgr should not be null!");
+ SysTryReturnResult(NID_APP, __pStub != null, E_INVALID_STATE, "__pStub should not be null!");
+
+ SysTryReturnResult(NID_APP, appId.IsEmpty() == false, E_INVALID_ARG, "The appId is empty.")
+ SysTryReturnResult(NID_APP, appId.GetLength() < WIDGET_APP_MAX_APPID_LENGTH, E_MAX_EXCEEDED, "The appId is too long (Maximum %d bytes).", WIDGET_APP_MAX_APPID_LENGTH)
+ SysTryReturnResult(NID_APP, appId != _AppInfo::GetAppId(), E_INVALID_ARG, "This service can't be terminated.")
+ //SysTryReturnResult(NID_APP, _Aul::IsInstalled(appId) == true, E_OBJ_NOT_FOUND, "The application(%ls) is not installed.", appId.GetPointer());
+
+ const _AppContext* pAppContext = __pContextMgr->Find(appId, executableName);
+ SysTryReturnResult(NID_APP, pAppContext != null, E_OBJ_NOT_FOUND, "can't find appId(%ls, %ls).", appId.GetPointer(), executableName.GetPointer());
+
+ SysLog(NID_APP, "trying aul_terminate_pid(appId:%ls, exec:%ls, pid:%d).", appId.GetPointer(), executableName.GetPointer(), pAppContext->pId );
+
+ return _Aul::TerminateApplicationByPid( pAppContext->pId );
+// return __pStub->OnTerminateApplicationRequested(pAppContext->ipcClientId);
+}
+
+bool
+_AppManagerService::IsRunning(const AppId& appId, const String& executableName)
+{
+ SysTryReturnResult(NID_APP, appId.IsEmpty()==false, E_INVALID_ARG, "The appId is empty.")
+ SysTryReturnResult(NID_APP, appId.GetLength() < WIDGET_APP_MAX_APPID_LENGTH, E_INVALID_ARG, "The appId is too long (Maximum %d bytes).", WIDGET_APP_MAX_APPID_LENGTH)
+
+ return _Aul::IsRunning(appId, executableName);
+}
+
+result
+_AppManagerService::GetRunningAppList(Tizen::Base::Collection::ArrayList* pArray)
+{
+ SysTryReturnResult(NID_APP, __pContextMgr != null, E_INVALID_STATE, "pContextMgr should not be null!");
+
+ return __pContextMgr->GetAppListN(pArray);
+}
+
+result
+_AppManagerService::RegisterApplication(const AppId& appId, const String& executableName, _AppType appType, int pid)
+{
+ return RegisterApplication(appId, executableName, appType, pid, -1);
+}
+
+result
+_AppManagerService::RegisterApplication(const AppId& appId, const String& executableName, _AppType appType, int pid, int clientId)
+{
+ if (_AppInfo::GetProcessId() == pid)
+ {
+ SysLog(NID_APP, "Service itself is registered.");
+ }
+ else
+ {
+ SysLog(NID_APP, "Sending event for %ls(%d).", appId.GetPointer(), pid);
+
+ _AppManagerEventArg arg(appId, appType, _AppManagerEvent::_APP_MANAGER_EVENT_LAUNCHED);
+ SendEventToAllListeners(arg);
+ }
+
+ SysTryReturnResult(NID_APP, __pContextMgr != null, E_INVALID_STATE, "pContextMgr should not be null!");
+ return __pContextMgr->Register(appId, executableName, appType, pid, clientId, true);
+}
+
+result
+_AppManagerService::UnregisterApplication(int pid)
+{
+ SysTryReturnResult(NID_APP, __pContextMgr != null, E_INVALID_STATE, "pContextMgr should not be null!");
+ return __pContextMgr->Unregister(pid);
+}
+
+
+//const _AppContext*
+//_AppManagerService::GetAppInfoSimple(const AppId& appId, const String* pExecutableName) const
+//{
+// SysTryReturn(NID_APP, __pContextMgr != null, null, E_INVALID_STATE, "pContextMgr should not be null!");
+//
+// return __pContextMgr->Find(appId, pExecutableName);
+//}
+
+result
+_AppManagerService::InitEventListener( _IAppManagerServiceEventListener* pListener)
+{
+ __pProxy = pListener;
+ return E_SUCCESS;
+}
+
+
+result
+_AppManagerService::AddEventListener(int clientId)
+{
+ return __eventListeners.Add(clientId, null);
+}
+
+result
+_AppManagerService::RemoveEventListener(int clientId)
+{
+ return __eventListeners.Remove(clientId);
+}
+
+void
+_AppManagerService::OnApplicationTerminated(const _AppContext& appInfo)
+{
+ SysLog(NID_APP, "Enter");
+ if ( appInfo.pId == _AppInfo::GetProcessId() )
+ {
+ SysLog(NID_APP, "Service itself is terminated.");
+ return;
+ }
+
+ RemoveEventListener(appInfo.ipcClientId);
+
+ _AppManagerEventArg arg(appInfo.appId, appInfo.appType, _AppManagerEvent::_APP_MANAGER_EVENT_TERMINATED);
+ SendEventToAllListeners(arg);
+}
+
+result
+_AppManagerService::SendEventToAllListeners(const _AppManagerEventArg& arg)
+{
+ _AppManagerServiceEventListenerEnum* pEnum = __eventListeners.GetMapEnumeratorN();
+
+ result r = GetLastResult();
+ SysTryReturn(NID_APP, pEnum != null, r, r, "[%s] Propagated.", GetErrorMessage(r));
+
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ int clientId = -1;
+ r = pEnum->GetKey(clientId);
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
+
+ _IAppManagerServiceEventListener* pListener = (clientId == -1) ? __pProxy : __pStub;
+
+ if ( pListener != null )
+ {
+ SysLog(NID_APP, "Trying to SendResponse(%d)", clientId);
+ r = pListener->OnServiceEventReceived(clientId, arg);
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] OnServiceEventReceived fails.", GetErrorMessage(r));
+// SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
+ }
+ }
+
+ delete pEnum;
+ return E_SUCCESS;
+
+CATCH:
+ delete pEnum;
+ return r;
+}
+
+void
+_AppManagerService::Dump(void)
+{
+ __pContextMgr->Dump();
+}
+
+
+}}//namespace Tizen { namespace App {
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_AppManagerStub.cpp
+ * @brief This is the implementation for the _AppManagerStub class.
+ */
+
+#include <FBaseSysLog.h>
+#include <FIo_IpcServer.h>
+#include <FSec_AccessController.h>
+
+#include <FApp_AppManagerProxy.h>
+#include <FApp_AppManagerIpcMessage.h>
+
+#include "FApp_AppManagerService.h"
+#include "FApp_AppManagerStub.h"
+#include "FApp_ContextManager.h"
+
+
+using namespace Tizen::Base;
+using namespace Tizen::Io;
+using namespace Tizen::Text;
+using namespace Tizen::Security;
+
+
+namespace Tizen { namespace App {
+
+
+_AppManagerStub::_AppManagerStub(void)
+:__pIpcServer(null),
+ __pAppManagerService(null)
+{
+ SysLog(NID_APP, "Enter\n");
+
+ SysLog(NID_APP, "Exit\n");
+}
+
+_AppManagerStub::~_AppManagerStub(void)
+{
+ SysLog(NID_APP, "Enter\n");
+
+ if ( __pIpcServer != null)
+ {
+ __pIpcServer->Stop();
+ delete __pIpcServer;
+ }
+
+ delete __pAppManagerService;
+
+ SysLog(NID_APP, "Exit\n");
+}
+
+result
+_AppManagerStub::Construct(_ContextManager *pContextMgr)
+{
+ SysTryReturnResult(NID_APP, pContextMgr != null, E_INVALID_ARG, "pContextMgr is null.");
+
+ SysLog(NID_APP, "Enter\n");
+
+ result r = E_SUCCESS;
+
+ __pAppManagerService = new (std::nothrow) _AppManagerService();
+ SysTryReturnResult(NID_APP, __pAppManagerService != null, E_OUT_OF_MEMORY, "Not enough memory.");
+
+ r = __pAppManagerService->Construct(pContextMgr, this);
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __pAppManagerService->Construct. (%s)", GetErrorMessage(r) );
+
+ _AppManagerProxy::SetService(__pAppManagerService);
+
+ r = StartIpcServer();
+
+ SysLog(NID_APP, "Exit\n");
+
+ return r;
+}
+
+result
+_AppManagerStub::StartIpcServer(void)
+{
+ __pIpcServer = new (std::nothrow) _IpcServer();
+ SysTryReturn(NID_APP, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
+
+ result r = __pIpcServer->Construct( "osp.app.ipcserver.appmanager", *this);
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.appmanager");
+
+ return E_SUCCESS;
+
+CATCH:
+ delete __pIpcServer;
+ __pIpcServer = null;
+ return r;
+}
+
+
+// server to client message
+result
+_AppManagerStub::OnServiceEventReceived(const int clientId, const _AppManagerEventArg& arg)
+{
+// SysLog(NID_APP, "appId:%ls, executableName:%ls, appType:%d", arg.GetAppId().GetPointer(), arg.GetName().GetPointer(), arg.GetAppType());
+ SysTryReturnResult(NID_APP, __pIpcServer != null, E_INVALID_STATE, "__pIpcServer is null.");
+
+ result r = __pIpcServer->SendResponse(clientId, new AppManager_OnEventReceived(arg));
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
+
+ return E_SUCCESS;
+}
+
+result
+_AppManagerStub::OnTerminateApplicationRequested(int clientId)
+{
+ SysTryReturnResult(NID_APP, __pIpcServer != null, E_INVALID_STATE, "__pIpcServer is null.");
+
+ result r = __pIpcServer->SendResponse(clientId, new AppManager_OnTerminateApplicationRequested());
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
+
+ return E_SUCCESS;
+}
+
+
+/////////////////////////////////////////////
+// handlers
+/////////////////////////////////////////////
+
+bool
+_AppManagerStub::OnLaunchApplication(const AppId& appId, const String& execName, int req)
+{
+ SysTryCatch(NID_APP, __pAppManagerService != null, , E_INVALID_STATE, "__pAppManagerService is null!");
+
+ SysLog(NID_APP, "(appId:%ls)", appId.GetPointer());
+
+ __pAppManagerService->LaunchApplication(appId, execName, req);
+
+CATCH:
+ return true;
+}
+
+bool
+_AppManagerStub::OnTerminateApplication(const AppId& appId, const String& execName, result *pRes)
+{
+ SysTryCatch(NID_APP, __pAppManagerService != null, *pRes = E_INVALID_STATE, E_INVALID_STATE, "__pAppManagerService is null!");
+
+ SysLog(NID_APP, "(appId:%ls, %ls)", appId.GetPointer(), execName.GetPointer());
+
+ // APPLICATION_MANAGER
+ *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_APPLICATION_KILL);
+
+ if (IsFailed(*pRes))
+ {
+ SysLog(NID_APP, "[E_PRIVILEGE_DENIED]The application does not have the privilege to call this method.");
+ *pRes = E_PRIVILEGE_DENIED;
+ return true;
+ }
+
+ *pRes = __pAppManagerService->TerminateApplication(appId, execName);
+
+CATCH:
+ return true;
+}
+
+bool
+_AppManagerStub::OnIsRunning(const AppId& appId, const String& execName, bool *pRes)
+{
+ SysTryCatch(NID_APP, __pAppManagerService != null, *pRes = false, E_INVALID_STATE, "__pAppManagerService is null!");
+
+ SysLog(NID_APP, "_AppManagerStub::IsRunning(%ls, %ls)", appId.GetPointer(), execName.GetPointer());
+ *pRes = __pAppManagerService->IsRunning(appId, execName);
+
+CATCH:
+ return true;
+}
+
+bool
+_AppManagerStub::OnGetRunningAppList(Tizen::Base::Collection::ArrayList* pArray, result *pRes)
+{
+ SysTryReturn(NID_APP, pArray != null, E_INVALID_ARG, E_INVALID_ARG, "pArray shoud not be null!");
+ SysTryCatch(NID_APP, __pAppManagerService != null, *pRes = E_INVALID_STATE, E_INVALID_STATE, "__pAppManagerService is null!");
+ SysLog(NID_APP, "");
+
+ *pRes = __pAppManagerService->GetRunningAppList(pArray);
+
+CATCH:
+ return true;
+}
+
+bool
+_AppManagerStub::OnRegisterApplication(const AppId& appId, const String& executableName, int appType, int pid)
+{
+ SysTryCatch(NID_APP, __pAppManagerService != null, , E_INVALID_STATE, "__pAppManagerService is null!");
+ SysLog(NID_APP, "_AppManagerStub::RegisterApplication(appId:%ls, pid:%d)\n", appId.GetPointer(), pid);
+
+ __pAppManagerService->RegisterApplication(appId, executableName, static_cast<_AppType>(appType), pid, __pIpcServer->GetClientId());
+
+CATCH:
+ return true;
+}
+
+bool
+_AppManagerStub::OnUnregisterApplication(int pid)
+{
+ SysTryCatch(NID_APP, __pAppManagerService != null, , E_INVALID_STATE, "__pAppManagerService is null!");
+ SysLog(NID_APP, "_AppManagerStub::UnregisterApplication(pid:%d)\n", pid);
+ __pAppManagerService->UnregisterApplication(pid);
+
+CATCH:
+ return true;
+}
+
+bool
+_AppManagerStub::OnAddEventListener(int pid)
+{
+ SysTryReturn(NID_APP, __pIpcServer != null, true, E_INVALID_STATE, "__pIpcServer should not be null!");
+
+ __pAppManagerService->AddEventListener(__pIpcServer->GetClientId());//, this);
+ return true;
+}
+
+bool
+_AppManagerStub::OnRemoveEventListener(int pid)
+{
+ SysTryReturn(NID_APP, __pIpcServer != null, true, E_INVALID_STATE, "__pIpcServer should not be null!");
+
+ __pAppManagerService->RemoveEventListener(__pIpcServer->GetClientId());//, this);
+ return true;
+}
+
+
+void
+_AppManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
+{
+ SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
+
+ IPC_BEGIN_MESSAGE_MAP(_AppManagerStub, message)
+ IPC_MESSAGE_HANDLER_EX(AppManager_LaunchApplication, &server, OnLaunchApplication)
+ IPC_MESSAGE_HANDLER_EX(AppManager_TerminateApplication, &server, OnTerminateApplication)
+ IPC_MESSAGE_HANDLER_EX(AppManager_IsRunning, &server, OnIsRunning)
+ IPC_MESSAGE_HANDLER_EX(AppManager_GetRunningAppList, &server, OnGetRunningAppList)
+ IPC_MESSAGE_HANDLER_EX(AppManager_RegisterApplication, &server, OnRegisterApplication)
+ IPC_MESSAGE_HANDLER_EX(AppManager_UnregisterApplication, &server, OnUnregisterApplication)
+ IPC_MESSAGE_HANDLER_EX(AppManager_AddEventListener, &server, OnAddEventListener)
+ IPC_MESSAGE_HANDLER_EX(AppManager_RemoveEventListener, &server, OnRemoveEventListener)
+ IPC_END_MESSAGE_MAP()
+}
+
+void
+_AppManagerStub::OnIpcServerStarted(const _IpcServer& server)
+{
+// SysLog(NID_APP, "\n");
+}
+
+void
+_AppManagerStub::OnIpcServerStopped(const _IpcServer& server)
+{
+// SysLog(NID_APP, "\n");
+}
+
+void
+_AppManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
+{
+// SysLog(NID_APP, "(clientId:%d)\n", clientId);
+}
+
+void
+_AppManagerStub::OnIpcClientDisconnected(const _IpcServer& server, int clientId)
+{
+// SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), clientId);
+}
+
+
+}}//namespace Tizen { namespace App {
--- /dev/null
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_CommunicationDispatcher.cpp
+ * @brief This is the implementation file for _CommunicationDispatcher class.
+ *
+ */
+
+#include <new>
+#include <FApp_AppManagerImpl.h>
+#include <FIo_IpcServer.h>
+#include <FIo_AppServiceIpcMessages.h>
+#include "FApp_CommunicationDispatcher.h"
+
+using namespace Tizen::Io;
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+namespace
+{
+ const String COMMUNICATION_DISPATCHER_IPC_ID = L"osp.app.ipcserver.communicationdispatcher";
+ const String COMMUNICATION_MUTEX_ID = L"osp.app.ipcserver.communicationdispatcher";
+}
+
+typedef struct communicationListener
+{
+ _ICommunicationRequestListener* requestListener;
+ struct communicationListener* prev;
+ struct communicationListener* next;
+}listener;
+
+communicationListener* gp_CommunicationListener = null;
+_CommunicationDispatcher* gp_CommunicationDispatcher = null;
+
+void
+ReleaseCommunicationListener(void)
+{
+ communicationListener* pIter = gp_CommunicationListener;
+ communicationListener* pTemp = null;
+
+ while (pIter != null)
+ {
+ pTemp = pIter;
+ pIter = pIter->next;
+ free(pTemp);
+ }
+ gp_CommunicationListener = null;
+}
+
+communicationListener*
+GetCommunicationListener(String key)
+{
+ communicationListener* pIter = gp_CommunicationListener;
+ if (pIter == null)
+ {
+ return null;
+ }
+
+ while (pIter != null)
+ {
+ if (pIter->requestListener != null)
+ {
+ StringComparer strComparer;
+ int cmp = 0;
+ strComparer.Compare(pIter->requestListener->GetId(), key, cmp);
+ if (cmp == 0)
+ {
+ return pIter;
+ }
+ }
+ pIter = pIter->next;
+ }
+ return null;
+}
+
+bool
+AddCommunicationListener(_ICommunicationRequestListener* pListener)
+{
+ if (pListener == null)
+ {
+ return false;
+ }
+
+ if (GetCommunicationListener(pListener->GetId()) == null)
+ {
+ communicationListener* pTemp = (communicationListener*)malloc(sizeof(communicationListener));
+ SysTryReturn(NID_APP, pTemp != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
+
+ memset(pTemp, 0, sizeof(communicationListener));
+ pTemp->requestListener = pListener;
+
+ if (gp_CommunicationListener == null)
+ {
+ gp_CommunicationListener = pTemp;
+ }
+ else
+ {
+ communicationListener* pIter = gp_CommunicationListener;
+
+ while (pIter->next != null)
+ {
+ pIter = pIter->next;
+ }
+ pIter->next = pTemp;
+ pTemp->prev = pIter;
+ }
+ return true;
+ }
+ return false;
+}
+
+bool
+RemoveCommunicationListener(_ICommunicationRequestListener* pListener)
+{
+ if (pListener == null)
+ {
+ return false;
+ }
+ communicationListener* pIter = GetCommunicationListener(pListener->GetId());
+
+ if (pIter == null)
+ {
+ return false;
+ }
+
+ if (pIter == gp_CommunicationListener)
+ {
+ gp_CommunicationListener = pIter->next;
+ free(pIter);
+ }
+ else
+ {
+ pIter->prev->next = pIter->next;
+ pIter->next->prev = pIter->prev;
+ }
+ return true;
+}
+
+_CommunicationDispatcher::_CommunicationDispatcher()
+: __pIpcServer(null)
+, __pRegisteredAppList(null)
+, __pAppManagerImpl(null)
+{
+ result r = E_SUCCESS;
+
+ __currentAppId= "";
+ __currentClientId.value = 0;
+
+ __pIpcServer = new (std::nothrow) _IpcServer();
+ r = __pIpcServer->Construct(COMMUNICATION_DISPATCHER_IPC_ID, *this);
+ SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to IPC server initialize. [%s] Propaged.", r);
+
+ r = __pIpcServer->Start();
+ SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to start IPC server. [%s] Propaged.", r);
+
+ __pRegisteredAppList = new (std::nothrow) ArrayList();
+ r =__pRegisteredAppList->Construct();
+ SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to create registered app list. [%s] Propaged.", r);
+
+ r = __Mutex.Create(COMMUNICATION_MUTEX_ID);
+ SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to create mutex. [%s] Propaged.", r);
+
+ __pAppManagerImpl = _AppManagerImpl::GetInstance();
+ SysTryCatch(NID_APP, __pAppManagerImpl != null, r = E_SYSTEM, r, "Failed to get _AppManagerImpl instance");
+
+ r = __pAppManagerImpl->AddEventListener(*this);
+ SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to add event listener. [%s] Propaged.", r);
+
+CATCH:
+ SetLastResult(r);
+}
+
+_CommunicationDispatcher::~_CommunicationDispatcher()
+{
+ result r = E_SUCCESS;
+ r = __pIpcServer->Stop();
+ SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to stop IPC server. [%s] Propaged.", r);
+
+ r = __Mutex.Release();
+ SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to release mutex. [%s] Propaged.", r);
+
+ r = __pAppManagerImpl->RemoveEventListener(*this);
+ SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to remove event listener. [%s] Propaged.", r);
+
+ ReleaseCommunicationListener();
+
+CATCH:
+ delete __pIpcServer;
+
+ __pRegisteredAppList->RemoveAll(true);
+ delete __pRegisteredAppList;
+
+ SetLastResult(r);
+}
+
+_CommunicationDispatcher*
+_CommunicationDispatcher::GetInstance()
+{
+ if (gp_CommunicationDispatcher == null)
+ {
+ gp_CommunicationDispatcher = new (std::nothrow) _CommunicationDispatcher();
+ }
+
+ return gp_CommunicationDispatcher;
+}
+
+Integer*
+_CommunicationDispatcher::GetClientId(const AppId& appId, const String& componentId) const
+{
+ int index = 0;
+ int numOfAppList = 0;
+ SysLog(NID_APP, "AppId: %ls, ComponentId %ls", appId.GetPointer(), componentId.GetPointer());
+ SysTryCatch(NID_APP, __pRegisteredAppList != null, , E_SYSTEM, "Registered app list is not ready");
+ numOfAppList = __pRegisteredAppList->GetCount();
+
+ while (index < numOfAppList)
+ {
+ AppId* currentAppId = null;
+ currentAppId = (AppId*)__pRegisteredAppList->GetAt(index);
+ if (currentAppId != null)
+ {
+ StringComparer strComparer;
+ int cmp = 0;
+
+ strComparer.Compare(appId, *currentAppId, cmp);
+ if (cmp == 0)
+ {
+ String* currentComponentId = (String*)__pRegisteredAppList->GetAt(index+1);
+ if (currentComponentId != null)
+ {
+ strComparer.Compare(componentId, *currentComponentId, cmp);
+ if (cmp == 0)
+ {
+ SysLog(NID_APP, "Registered information is found.");
+
+ Integer* pClientId = (Integer*)__pRegisteredAppList->GetAt(index+2);
+ if (pClientId != null)
+ {
+ return pClientId;
+ }
+ }
+ }
+ }
+
+ }
+ index += 3;
+ }
+ SysLog(NID_APP, "There is no registered information.");
+CATCH:
+ return null;
+}
+
+result
+_CommunicationDispatcher::RemoveClientId(AppId appId)
+{
+ int index = 0;
+ int numOfAppList = 0;
+ SysTryCatch(NID_APP, __pRegisteredAppList != null, , E_SYSTEM, "Registered app list is not ready");
+ numOfAppList = __pRegisteredAppList->GetCount();
+
+ while (index < numOfAppList)
+ {
+ AppId* currentAppId = null;
+
+ currentAppId = (AppId*)__pRegisteredAppList->GetAt(index);
+ if (currentAppId != null)
+ {
+ StringComparer strComparer;
+ int cmp = 0;
+
+ strComparer.Compare(appId, *currentAppId, cmp);
+ if (cmp == 0)
+ {
+ SysLog(NID_APP, "Registered information is found.");
+ __pRegisteredAppList->RemoveAt(index+2, true);
+ __pRegisteredAppList->RemoveAt(index+1, true);
+ __pRegisteredAppList->RemoveAt(index, true);
+ index -= 3;
+ numOfAppList -= 3;
+ }
+
+ }
+ index += 3;
+ }
+ SysLog(NID_APP, "There is no registered information.");
+CATCH:
+ return null;
+}
+
+result
+_CommunicationDispatcher::RemoveClientId(AppId appId, String componentId)
+{
+ int index = 0;
+ int numOfAppList = 0;
+ SysTryCatch(NID_APP, __pRegisteredAppList != null, , E_SYSTEM, "Registered app list is not ready");
+ numOfAppList = __pRegisteredAppList->GetCount();
+
+ while (index < numOfAppList)
+ {
+ AppId* currentAppId = null;
+ currentAppId = (AppId*)__pRegisteredAppList->GetAt(index);
+ if (currentAppId != null)
+ {
+ StringComparer strComparer;
+ int cmp = 0;
+
+ strComparer.Compare(appId, *currentAppId, cmp);
+ if (cmp == 0)
+ {
+ String* currentComponentId = (String*)__pRegisteredAppList->GetAt(index+1);
+ if (currentComponentId != null)
+ {
+ strComparer.Compare(componentId, *currentComponentId, cmp);
+ if (cmp == 0)
+ {
+ SysLog(NID_APP, "Registered information is found.");
+ __pRegisteredAppList->RemoveAt(index+2, true);
+ __pRegisteredAppList->RemoveAt(index+1, true);
+ __pRegisteredAppList->RemoveAt(index, true);
+ }
+ }
+ }
+
+ }
+ index += 3;
+ }
+ SysLog(NID_APP, "There is no registered information.");
+CATCH:
+ return null;
+}
+
+result
+_CommunicationDispatcher::RemoveClientId(AppId appId, String componentId, Integer clientId)
+{
+ int index = 0;
+ int numOfAppList = 0;
+ SysTryCatch(NID_APP, __pRegisteredAppList != null, , E_SYSTEM, "Registered app list is not ready");
+ numOfAppList = __pRegisteredAppList->GetCount();
+
+ while (index < numOfAppList)
+ {
+ AppId* currentAppId = null;
+ currentAppId = (AppId*)__pRegisteredAppList->GetAt(index);
+ if (currentAppId != null)
+ {
+ StringComparer strComparer;
+ int cmp = 0;
+
+ strComparer.Compare(appId, *currentAppId, cmp);
+ if (cmp == 0)
+ {
+ String* currentComponentId = (String*)__pRegisteredAppList->GetAt(index+1);
+ if (currentComponentId != null)
+ {
+ strComparer.Compare(componentId, *currentComponentId, cmp);
+ if (cmp == 0)
+ {
+ SysLog(NID_APP, "Registered information is found.");
+ Integer* pClientId = (Integer*)__pRegisteredAppList->GetAt(index+2);
+ if (pClientId != null)
+ {
+ if (pClientId->value == clientId.value)
+ {
+ __pRegisteredAppList->RemoveAt(index+2, true);
+ __pRegisteredAppList->RemoveAt(index+1, true);
+ __pRegisteredAppList->RemoveAt(index, true);
+ }
+ }
+ }
+ }
+ }
+
+ }
+ index += 3;
+ }
+ SysLog(NID_APP, "There is no registered information.");
+CATCH:
+ return null;
+}
+
+result
+_CommunicationDispatcher::AddClientId(AppId appId, String componentId, Integer clientId)
+{
+ Integer* currentClientId = null;
+
+ SysTryReturnResult(NID_APP, __pRegisteredAppList != null, E_SYSTEM, "Registered app list is not ready");
+
+ currentClientId = GetClientId(appId, componentId);
+ SysTryReturnResult(NID_APP, currentClientId == null, E_KEY_ALREADY_EXIST, "This is already registered. AppId: %ls, ComponentId: %ls, ClientId: %d", appId.GetPointer(), componentId.GetPointer(), clientId.value);
+
+ SysLog(NID_SYS, "AppId: %ls, ComponentId: %ls, ClientId: %d", appId.GetPointer(), componentId.GetPointer(), clientId.value);
+
+ AppId* pAppId = new (std::nothrow) AppId(appId);
+ String* pComponentId = new (std::nothrow) String(componentId);
+ Integer* pClientId = new (std::nothrow) Integer();
+ pClientId->value = clientId.value;
+
+ __pRegisteredAppList->Add(*pAppId);
+ __pRegisteredAppList->Add(*pComponentId);
+ __pRegisteredAppList->Add(*pClientId);
+
+ return E_SUCCESS;
+}
+
+result
+_CommunicationDispatcher::SendData(const Tizen::App::AppId appId, ArrayList& data)
+{
+ Integer* clientId = null;
+ result r = E_SUCCESS;
+ String* communicationId = null;
+
+ SysTryReturnResult(NID_APP, __pRegisteredAppList != null, E_SYSTEM, "_CommunicationDispatcher is not ready");
+
+ communicationId = (String*)data.GetAt(0);
+ SysTryReturnResult(NID_APP, communicationId != null, E_SYSTEM, "There is no communicationId");
+
+ clientId = GetClientId(appId, *communicationId);
+
+ if (clientId!=null)
+ {
+ SysLog(NID_APP, "ClientId: %d", clientId->ToInt());
+
+ int client = clientId->ToInt();
+ //IpcServer Send
+ r = __pIpcServer->SendResponse(client, new (std::nothrow) IoService_Data(data));
+
+ if (r != E_SUCCESS)
+ {
+ SysLog(NID_APP, "Send Result %s.", GetErrorMessage(r));
+ return r;
+ }
+ return E_SUCCESS;
+ }
+ return E_OBJ_NOT_FOUND;
+}
+
+void
+_CommunicationDispatcher::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
+{
+ __Mutex.Acquire();
+ SysLog(NID_APP, "Start");
+ SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
+
+ __currentAppId = server.GetClientAppId();
+ __currentClientId.value = server.GetClientId();
+
+ IPC_BEGIN_MESSAGE_MAP(_CommunicationDispatcher, message)
+ IPC_MESSAGE_HANDLER_EX(IoService_Request, &server, OnRequestOccured)
+ IPC_END_MESSAGE_MAP_EX()
+ SysLog(NID_APP, "End");
+ __Mutex.Release();
+}
+
+bool
+_CommunicationDispatcher::OnRequestOccured(const Tizen::Base::Collection::ArrayList& request, Tizen::Base::Collection::ArrayList* response)
+{
+ SysLog(NID_APP, "Application is requested by IPC, currentAppId is %ls", __currentAppId.GetPointer());
+
+ String* componentId = (String*)request.GetAt(0);
+ _ICommunicationRequestListener* plistener = null;
+
+ if (componentId == null)
+ {
+ SysLog(NID_APP, "there is no componentId");
+ }
+
+ if (componentId != null)
+ {
+ AddClientId(__currentAppId, *componentId, __currentClientId);
+ SysLog(NID_APP, "Requested componentId is %ls", componentId->GetPointer());
+
+ communicationListener* pTemp = GetCommunicationListener(*componentId);
+
+ if (pTemp != null)
+ {
+ plistener = pTemp->requestListener;
+
+ if (plistener!=null)
+ {
+ plistener->OnRequestOccured(__currentAppId, const_cast <ArrayList*> (&request), response);
+ }
+ }
+ else
+ {
+ SysLog(NID_APP, "Requested module is not exist.");
+ }
+ }
+
+ return true;
+}
+
+result
+_CommunicationDispatcher::AddCommunicationEventListener(_ICommunicationRequestListener& listener)
+{
+ bool added = false;
+ added = AddCommunicationListener(&listener);
+ SysLog(NID_APP, "%ls", listener.GetId().GetPointer());
+ SysTryReturnResult(NID_APP, added == true, E_KEY_ALREADY_EXIST, "listner is already registed for key [%ld]", listener.GetId().GetPointer());
+
+ return E_SUCCESS;
+}
+
+result
+_CommunicationDispatcher::RemoveCommunicationEventListener(_ICommunicationRequestListener& listener)
+{
+ bool removed = false;
+ removed = RemoveCommunicationListener(&listener);
+ SysTryReturnResult(NID_APP, removed == true, E_KEY_NOT_FOUND, "listner is already registed for key [%ld]", listener.GetId().GetPointer());
+
+ return E_SUCCESS;
+}
+
+void
+_CommunicationDispatcher::OnApplicationLaunched(const AppId& appId, _AppType type)
+{
+}
+
+void
+_CommunicationDispatcher::OnApplicationTerminated(const AppId& appId, _AppType type)
+{
+ SysLog(NID_APP, "App[%ls] terminate event is forwarded", appId.GetPointer());
+
+ __Mutex.Acquire();
+ communicationListener* pIter = gp_CommunicationListener;
+ SysLog(NID_APP, "App[%ls] terminate event is forwarded", appId.GetPointer());
+
+ RemoveClientId(appId);
+
+ while (pIter != null)
+ {
+ if (pIter->requestListener != null)
+ {
+ SysLog(NID_APP, "listener is [%ls]", pIter->requestListener->GetId().GetPointer());
+ pIter->requestListener->OnApplicationTerminated(appId, type);
+ }
+ pIter = pIter->next;
+ }
+ __Mutex.Release();
+}
+
+
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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 FApp_ConditionHandler.cpp
+ * @brief This is the implementation for the _ConditionHandler class.
+ */
+
+#include <unistd.h>
+#include <cstdio>
+
+#include <FBaseRtLibrary.h>
+#include <FAppApp.h>
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include <FIo_DirectoryImpl.h>
+#include <FApp_AppManagerImpl.h>
+#include <FApp_AppControlManager.h>
+
+#include "FApp_ConditionHandler.h"
+
+namespace Tizen { namespace App {
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Io;
+
+_ConditionHandler::_ConditionHandler(const String& fileName, const String& types)
+: __typesString(types)
+, __pluginFileName(fileName)
+, __pPluginInstance(null)
+, __pLib(null)
+, __pfDestroyPlugin(null)
+{
+ SysLog(NID_APP, "%ls, %ls", fileName.GetPointer(), types.GetPointer() );
+}
+
+_ConditionHandler::~_ConditionHandler()
+{
+ SysLog(NID_APP, "Enter");
+ if (__pfDestroyPlugin != null && __pPluginInstance != null)
+ {
+ __pfDestroyPlugin(__pPluginInstance);
+ __pfDestroyPlugin = null;
+ __pPluginInstance = null;
+ }
+
+ delete __pLib;
+
+ SysLog(NID_APP, "Exit");
+}
+//#define FILENAME_MAX 2048
+
+result
+_ConditionHandler::Construct()
+{
+ SysLog(NID_APP, "Enter");
+
+ result r = LoadPlugin();
+ __conditionalOperations.Construct( 16, 0.75f, __strHashMapProvider, __strComparer);
+
+ SysLog(NID_APP, "Exit");
+ return r;
+}
+
+result
+_ConditionHandler::LoadPlugin(void)
+{
+ char filePath[FILENAME_MAX];
+ char* pFileName = _StringConverter::CopyToCharArrayN(__pluginFileName);
+ create_plugin pfCreatePlugin = null;
+ result r = E_SUCCESS;
+
+ String dataPath = App::GetInstance()->GetAppRootPath() + L"lib";
+ snprintf(filePath, FILENAME_MAX, "%ls/%s", dataPath.GetPointer(), pFileName);
+ delete[] pFileName;
+
+ if (access(filePath, F_OK) != 0) // for uts-app
+ {
+ dataPath.Clear();
+ pFileName = _StringConverter::CopyToCharArrayN(__pluginFileName);
+ r = _AppManagerImpl::GetAppRootPath(L"aospd00043", dataPath);
+ snprintf(filePath, FILENAME_MAX, "%ls/%s", dataPath.GetPointer(), pFileName);
+ delete[] pFileName;
+ SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM,
+ "[E_SYSTEM] osp-app-service should be installed.");
+
+ dataPath.Append(L"data");
+ }
+
+ __pLib = new (std::nothrow) Runtime::Library();
+ r = __pLib->Construct(filePath);
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "dlopen fails (%s)", GetErrorMessage(r) );
+
+ pfCreatePlugin = (create_plugin)__pLib->GetProcAddress(L"CreatePlugin");
+ __pfDestroyPlugin = (destroy_plugin)__pLib->GetProcAddress(L"DestroyPlugin");
+ SysTryCatch(NID_APP, pfCreatePlugin != null && __pfDestroyPlugin != null, r = E_FAILURE, E_FAILURE, "failed to get symbols," );
+
+ __pPluginInstance = pfCreatePlugin();
+ SysTryCatch(NID_APP, __pPluginInstance != null, r = E_FAILURE, E_FAILURE, "pfCreatePlugin fails" );
+
+ __pPluginInstance->SetEventListener(*this);
+
+ return E_SUCCESS;
+
+CATCH:
+ SysLog(NID_APP, "CATCH:");
+ delete __pLib;
+ __pLib = null;
+ __pfDestroyPlugin = null;
+ return r;
+}
+
+result
+_ConditionHandler::CreateUniqueId(String& uniqueId)
+{
+ int index = 0;//TODO: improve algorithm
+ String candidateSectionName(__pluginFileName);
+ while( index < Integer::VALUE_MAX)
+ {
+ candidateSectionName.Format(1024, L"%ls_%d",__pluginFileName.GetPointer(), index );
+ if (FindItemBySectionName(candidateSectionName) == null)
+ {
+ uniqueId.Clear();
+ uniqueId.Append(candidateSectionName);
+ return E_SUCCESS;
+ }
+ index++;
+ }
+
+ return E_OVERFLOW;
+}
+
+result
+_ConditionHandler::AddCondition( _AppLaunchCondition& operation)
+{
+ SysTryReturnResult(NID_APP, __pPluginInstance != null, E_INVALID_STATE, "" );
+
+ //TODO
+ String condition = operation.GetConditionString();
+ if (HasCondition(operation.GetAppId(), operation.GetExecutableName(), &condition))
+ return E_OBJ_ALREADY_EXIST;
+
+ result r = __pPluginInstance->Register(operation);
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] failed to register", GetErrorMessage(r) );
+
+ String uniqueId;
+ if (operation.__regSectionName.IsEmpty())
+ {
+ CreateUniqueId(uniqueId);
+ operation.__regSectionName = uniqueId;
+ _ConditionRegistryHelper::AddToRegistry(uniqueId, operation.GetAppId(), operation.GetExecutableName(), operation.GetConditionString(), operation.__pArguments );
+ }
+ else
+ {
+ // from registry conditional-operations.ini
+ uniqueId = operation.__regSectionName;
+ }
+
+ __conditionalOperations.Add(operation.GetConditionString(), &operation);
+ SysLog(NID_APP, "AppLaunchCondition item count (%d)", __conditionalOperations.GetCount());
+
+ return E_SUCCESS;
+}
+
+result
+_ConditionHandler::RemoveCondition(const AppId& appId, const String* pExecutableName, const String* pCondition)
+{
+ SysLog(NID_APP,"Trying to unregister appId(%ls)", appId.GetPointer() );
+ SysTryReturnResult(NID_APP, __pPluginInstance != null, E_INVALID_STATE, "" );
+
+ bool found = false;
+
+ IListT<_AppLaunchCondition*>* pValues = __conditionalOperations.GetValuesN();
+ SysTryReturn(NID_APP, pValues != null, GetLastResult(), GetLastResult(), "[%s] Propagated.", GetErrorMessage(GetLastResult()));
+
+ result r = E_SUCCESS;
+ for (int i = 0; i< pValues->GetCount(); i++)
+ {
+ String uniqueId;
+
+ _AppLaunchCondition *pOperation = null;
+ r = pValues->GetAt(i, pOperation);
+ SysTryCatch(NID_APP, pOperation != null, , r, "[%s] Propagated.", GetErrorMessage(r) );
+ SysLog(NID_APP,"Trying to unregister appId(%ls), pExecutableName(%ls), condition(%ls)", appId.GetPointer(), pOperation->GetExecutableName().GetPointer(), pOperation->GetConditionString().GetPointer() );
+
+ if ( pOperation->GetAppId() == appId
+ && ( pExecutableName == null || pOperation->GetExecutableName() == *pExecutableName )
+ && ( pCondition == null || pOperation->GetConditionString() == *pCondition ) )
+ {
+ r = __pPluginInstance->Unregister(*pOperation);
+ SysTryCatch(NID_APP, !IsFailed(r), delete pOperation, r, "[%s] failed to Unregister(%ls, %ls)", GetErrorMessage(r), appId.GetPointer(), pOperation->GetConditionString().GetPointer() );//TBC
+ _ConditionRegistryHelper::RemoveFromRegistry(pOperation->__regSectionName);
+
+ r = __conditionalOperations.Remove(pOperation->GetConditionString(), pOperation);
+ SysTryLog(NID_APP, !IsFailed(r), "[%s]", GetErrorMessage(r));
+
+ SysLog(NID_APP,"Unregistered appId(%ls), pExecutableName(%ls), condition(%ls)", appId.GetPointer(), pOperation->GetExecutableName().GetPointer(), pOperation->GetConditionString().GetPointer() );
+
+ delete pOperation;
+ if ( pCondition != null)
+ {
+ pValues->RemoveAll();
+ delete pValues;
+ return E_SUCCESS;
+ }
+ else
+ {
+ found = true;
+ // loop next
+ }
+ }
+ }
+
+ return (found) ? E_SUCCESS : E_OBJ_NOT_FOUND;
+
+CATCH:
+ pValues->RemoveAll();
+ delete pValues;
+ return r;
+}
+
+
+//TODO: argument?
+bool
+_ConditionHandler::HasCondition(const AppId& appId, const String& executableName, const String *pCondition) const
+{
+ IListT<_AppLaunchCondition*>* pList = __conditionalOperations.GetValuesN();
+ SysTryReturn(NID_APP, pList != null, false, GetLastResult(), "[%s] Propagated. ", GetLastResult());
+
+ result r = E_SUCCESS;
+ for (int i = 0; i < pList->GetCount(); i++)
+ {
+ _AppLaunchCondition *pOperation = null;
+ r = pList->GetAt(i, pOperation);
+ SysTryCatch(NID_APP, pOperation != null, , r, "[%s] Propagated.", GetErrorMessage(r));
+
+ if (pOperation->GetAppId() == appId && pOperation->GetExecutableName() == executableName
+ && ( pCondition == null || pOperation->GetConditionString() == *pCondition) )
+ {
+ return true;
+ }
+ }
+
+CATCH:
+ delete pList;
+ return false;
+}
+
+bool
+_ConditionHandler::CanHandleType(const String& type ) const
+{
+ return __typesString.Contains(type);
+}
+
+_AppLaunchCondition*
+_ConditionHandler::FindItemBySectionName(const String& sectionName) const
+{
+ IListT<_AppLaunchCondition*>* pValues = __conditionalOperations.GetValuesN();
+ SysTryReturn(NID_APP, pValues != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(GetLastResult()));
+
+ result r = E_SUCCESS;
+ for (int i = 0; i< pValues->GetCount(); i++)
+ {
+ _AppLaunchCondition *pOperation = null;
+ r = pValues->GetAt(i, pOperation);
+ if ( !IsFailed(r) && pOperation->__regSectionName == sectionName)
+ {
+ return pOperation;
+ }
+ }
+ return null;
+}
+
+void
+_ConditionHandler::OnAppLaunchConditionMet(const _AppLaunchCondition& operation)
+{
+ SysLog(NID_APP, "Enter");
+
+ result r = _AppControlManager::GetInstance()->LaunchAppWithCondition(operation.GetAppId(), operation.GetExecutableName(), operation.GetConditionString(), operation.__pArguments );
+ SysTryLog(NID_APP, !IsFailed(r), "[%ls] LaunchApplication failed.", GetErrorMessage(r));
+
+ SysLog(NID_APP, "Exit");
+}
+
+void
+_ConditionHandler::Dump(void) const
+{
+ SysLog(NID_APP, "[%ls]", this->__pluginFileName.GetPointer() );
+
+// result r = E_SUCCESS;
+// _AppLaunchConditionEnumerator* pEnum =__conditionalOperations.GetMapEnumeratorN();
+// SysTryReturnVoidResult(NID_APP, pEnum != null, GetLastResult(), "[%s]", GetErrorMessage(GetLastResult()));
+//
+// while( pEnum->MoveNext() == E_SUCCESS )
+// {
+// _AppLaunchCondition *pOperation = null;
+// r = pEnum->GetValue(pOperation);
+// SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
+// SysTryCatch(NID_APP, pOperation != null, , r, "[%s] Propagated.", GetErrorMessage(r));
+//
+// SysLog(NID_APP, "appId:%ls, condition:%ls, uniqueId:%ls", pOperation->__appId.GetPointer(), pOperation->GetConditionString().GetPointer(), pOperation->__regSectionName.GetPointer() );
+// }
+//
+//CATCH:
+// delete pEnum;
+}
+
+
+}} // Tizen::App
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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 FApp_ConditionManagerService.cpp
+ * @brief This is the implementation for the _ConditionManagerService class.
+ */
+#include <cstdio>
+
+#include <FIoDirectory.h>
+#include <FIoRegistry.h>
+#include <FAppApp.h>
+
+#include <FBaseSysLog.h>
+#include <FIo_RegistryImpl.h>
+
+#include "FApp_Types.h"
+#include "FAppPkg_PackageManagerImpl.h"
+#include "FApp_ConditionHandler.h"
+#include "FApp_ConditionManagerService.h"
+#include "FApp_Aul.h"
+
+
+namespace Tizen { namespace App {
+
+using namespace Package;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Io;
+
+namespace
+{
+ const String REGISTRY_FILE_PLUGIN = L"res/app-launch-condition-handlers.ini";
+ const String REG_KEY_KEY = L"Key";
+ const String REG_KEY_FILENAME = L"Filename";
+
+ const String REGISTRY_FILE_OPERATIONS = L"data/app-launch-conditions.ini";
+ const String REG_KEY_APPID = L"PackageId";
+ const String REG_KEY_EXENAME = L"ExecutableName";
+ const String REG_KEY_CONDTION = L"Condition";
+ const String REG_KEY_LAUNCH_TYPE = L"LaunchType";
+ const String REG_KEY_ARG_COUNT = L"ArgCount";
+ const String REG_KEY_ARG = L"Arg";
+
+ const int MAX_LEN_ARG = 1024;
+ const int MAX_LEN_CONDITION = 400;
+}
+
+
+_ConditionManagerService::_ConditionManagerService()
+{
+ SysLog(NID_APP, "Enter");
+ SysLog(NID_APP, "Exit");
+}
+
+_ConditionManagerService::~_ConditionManagerService()
+{
+ SysLog(NID_APP, "Enter");
+ result r = E_SUCCESS;
+
+ _ConditionHandler* pHandler = null;
+ for (int i =0; i < __handlers.GetCount(); i ++)
+ {
+ pHandler = null;
+ r = __handlers.GetAt(i, pHandler);
+ delete pHandler;
+ }
+ __handlers.RemoveAll();
+
+ SysLog(NID_APP, "Exit");
+}
+
+result
+_ConditionManagerService::Construct(void)
+{
+ SysLog(NID_APP,"Enter.");
+
+ result r = E_SUCCESS;
+
+ r = __handlers.Construct();
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __handlers.Construct.(%s)", GetErrorMessage(r) );
+
+ r = __handlerLookupTable.Construct( 16, 0.75f, __strHashMapProvider, __strComparer);
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __handlerLookupTable.Construct.(%s)", GetErrorMessage(r) );
+
+ r = InitializePlugins();
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to InitializePlugins.(%s)", GetErrorMessage(r) );
+
+ r = InitializeConditionalOperations();
+ SysTryLog(NID_APP, !IsFailed(r), "failed to InitializeLaunchConditions.(%s)", GetErrorMessage(r) );
+
+ SysLog(NID_APP,"Exit.");
+ return E_SUCCESS;
+}
+
+result
+_ConditionManagerService::InitializePlugins(void)
+{
+ SysLog(NID_APP,"Enter.");
+ _RegistryImpl reg;
+ const String& homePath = App::GetInstance()->GetAppRootPath();
+
+ result r = reg.Construct(homePath + REGISTRY_FILE_PLUGIN, REG_OPEN_READ_ONLY , null);
+ if (IsFailed(r))
+ {
+ SysLog(NID_APP, "failed to open registry '%ls' (%s)", (homePath + REGISTRY_FILE_PLUGIN).GetPointer(), GetErrorMessage(r) );
+ return E_SUCCESS;
+ }
+
+ IList *pSections = null;
+ r = reg.GetSectionListN(&pSections);
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to GetSectionListN. (%s)", GetErrorMessage(r) );
+
+ IEnumerator* pEnum = pSections->GetEnumeratorN();
+ String* pSecName = null;
+
+ IMap* pMap = null;
+
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ pSecName = static_cast<String*>(pEnum->GetCurrent());
+ pSecName->Trim();
+
+ pMap = reg.GetAllEntriesN(*pSecName);
+ SysTryCatch(NID_APP, pMap != null, , E_SYSTEM, "");// try next
+
+ r = InitializePluginEntry(*pMap);
+ if ( r == E_OBJ_NOT_FOUND)
+ {
+ // empty statement
+ }
+ else
+ {
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "");
+ }
+
+ pMap->RemoveAll(true);
+ delete pMap;
+ }
+
+ pSections->RemoveAll(true);
+
+ SysLog(NID_APP,"Exit.");
+ return E_SUCCESS;
+
+CATCH:
+ SysLog(NID_APP,"Catch.");
+ pSections->RemoveAll(true);
+
+ return r;
+}
+
+result
+_ConditionManagerService::InitializePluginEntry(IMap& map)
+{
+ result r = E_SUCCESS;
+
+ const String* pTypes = static_cast<const String*>(map.GetValue(REG_KEY_KEY));
+ const String* pFilename = static_cast<const String*>(map.GetValue(REG_KEY_FILENAME));
+ _ConditionHandler * pHandler = null;
+
+ SysTryReturn(NID_APP, pTypes != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "registry value is invalid. pTypes is null");
+ SysTryReturn(NID_APP, pFilename != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "registry value is invalid. pFilename is null");
+
+ Utility::StringTokenizer strTok(*pTypes, L',');
+ String type;
+
+ pHandler = new (std::nothrow) _ConditionHandler(*pFilename, *pTypes);
+ SysTryReturn(NID_APP, pHandler != null, E_FAILURE, E_FAILURE, "failed to new _ConditionHandler(%ls, %ls).", pFilename->GetPointer(), pTypes->GetPointer() );
+
+ r = pHandler->Construct();
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "failed to pHandler->Construct. (%s)", GetErrorMessage(r) );
+
+ __handlers.Add(pHandler);
+
+
+ if ( strTok.GetTokenCount() == 0)
+ {
+ __handlerLookupTable.Add(*pTypes, pHandler);
+ }
+ else
+ {
+ while ( strTok.GetNextToken(type) == E_SUCCESS)
+ {
+ type.Trim();
+ __handlerLookupTable.Add(type, pHandler);
+ }
+ }
+
+ SysLog(NID_APP, "%ls is loaded.", pFilename->GetPointer() );
+
+ return E_SUCCESS;
+
+CATCH:
+ SysLog(NID_APP, "CATCH:");
+ delete pHandler;
+ return r;
+}
+
+// condinfo.ini
+result
+_ConditionManagerService::InitializeConditionalOperations(void)
+{
+ SysLog(NID_APP,"Enter.");
+ _RegistryImpl reg;
+ String homePath = App::GetInstance()->GetAppRootPath();
+
+ result r = reg.Construct(homePath + REGISTRY_FILE_OPERATIONS, REG_OPEN_READ_ONLY, null);
+// SysTryReturn(NID_APP, !IsFailed(r), r, r, "");
+ if ( IsFailed(r))
+ {
+ SysLog(NID_APP, "failed to open registry '%ls'", (homePath + REGISTRY_FILE_OPERATIONS).GetPointer());
+ return E_SUCCESS;
+ }
+
+ IList *pSections = null;
+ reg.GetSectionListN(&pSections );
+
+ IEnumerator* pEnum = pSections->GetEnumeratorN();
+ String* pSecName = null;
+
+ IMap* pMap = null;
+
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ pSecName = static_cast<String*>(pEnum->GetCurrent());
+ pSecName->Trim();
+
+ pMap = reg.GetAllEntriesN(*pSecName);
+ SysTryCatch(NID_APP, pMap != null, r = E_INVALID_FORMAT, E_INVALID_FORMAT, "failed to GetAllEntryNamesN(%ls)", pSecName->GetPointer() );
+
+ r = InitializeConditionalOperationEntry(*pSecName, *pMap);
+ SysTryLog(NID_APP, !IsFailed(r), "failed to InitializeConditionalOperationEntry(%ls), but ignored.", pSecName->GetPointer() );
+
+ pMap->RemoveAll(true);
+ delete pMap;
+
+ pMap = null;
+ }
+
+ r = E_SUCCESS;
+
+CATCH:
+ delete pEnum;
+
+ pSections->RemoveAll(true);
+ delete pSections;
+
+ SysLog(NID_APP,"Exit.");
+ return r;
+}
+
+result
+_ConditionManagerService::InitializeConditionalOperationEntry(const String& sectionName, const IMap& map)
+{
+ String packageId;
+ String executableName;
+ String condition;
+ ArrayList* pArgs = null;
+
+ result r = _ConditionRegistryHelper::GetAllParamsN(map, packageId, executableName, condition, pArgs);
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] packageId(%ls), condition(%ls) is failed to register.", GetErrorMessage(r), packageId.GetPointer(), condition.GetPointer() );
+
+ r = RegisterAppLaunch( packageId, executableName, condition, pArgs, AppManager::LAUNCH_OPTION_DEFAULT, §ionName);
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] packageId(%ls), condition(%ls) is failed to register.", GetErrorMessage(r), packageId.GetPointer(), condition.GetPointer() );
+
+ if (pArgs != null)
+ {
+ pArgs->RemoveAll(true);
+ delete pArgs;
+ }
+ return r;
+
+//CATCH:
+// // remove invalid conditions.
+// _ConditionRegistryHelper::RemoveFromRegistry(sectionName);
+// return r;
+}
+
+_ConditionHandler*
+_ConditionManagerService::GetHandlerByCondition(const String& condition)
+{
+ Tizen::Base::Utility::StringTokenizer strTok(condition, L"=");
+ SysTryReturn(NID_APP, strTok.GetTokenCount() > 0, null, E_INVALID_ARG, "Condition string is invalid.(%ls)", condition.GetPointer() );
+
+ String key;
+ result r = strTok.GetNextToken(key);
+ SysTryReturn(NID_APP, !IsFailed(r), null, E_INVALID_ARG, "[%s](%ls)", GetErrorMessage(r), condition.GetPointer() );
+
+ _ConditionHandler* pHandler = null;
+ r = __handlerLookupTable.GetValue(key, pHandler);
+ SysTryReturn(NID_APP, !IsFailed(r), null, E_INVALID_ARG, "[%s](%ls)", GetErrorMessage(r), key.GetPointer() );
+
+ return pHandler;
+}
+
+///////////////////////////////////////////
+// stub implementations
+///////////////////////////////////////////
+
+void
+_ConditionManagerService::DumpArguments(const IList* pArguments)
+{
+ if (pArguments != null)
+ {
+ const String* pArg = null;
+ for(int i = 0; i < pArguments->GetCount(); i ++)
+ {
+ pArg = dynamic_cast<const String*>(pArguments->GetAt(i));
+ if (pArg != null)
+ {
+ SysLog(NID_APP, "argument%d : %ls", i, pArg->GetPointer());
+ }
+ }
+ }
+}
+
+result
+_ConditionManagerService::RegisterAppLaunch(const Tizen::Base::String& packageId, const String& executableName, const Tizen::Base::String& condition, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option, const String* pRegSectionName)
+{
+ SysTryReturnResult(NID_APP, packageId.IsEmpty()==false, E_INVALID_ARG, "The packageId is empty.");
+
+ const String& exeName = (executableName.IsEmpty()) ? Tizen::App::Package::_PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId) : executableName;
+
+ result r = E_SUCCESS;
+ SysTryReturnResult(NID_APP, exeName.IsEmpty()==false, E_INVALID_ARG, "The name is empty.");
+ SysTryReturnResult(NID_APP, condition.IsEmpty()==false, E_INVALID_ARG, "The launch condition is empty or too long (Maximum %d bytes).", MAX_LEN_CONDITION);
+ SysTryReturnResult(NID_APP, condition.GetLength() < MAX_LEN_CONDITION, E_INVALID_ARG, "The launch condition is empty or too long (Maximum %d bytes).", MAX_LEN_CONDITION);
+ //SysTryReturnResult(NID_APP, _PackageManagerImpl::GetInstance()->IsPackageInstalled(packageId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer()); // Moved to client side due to negative test.
+ SysTryReturn(NID_APP, pArguments == null || (r = ValidateArguments(pArguments)) == E_SUCCESS, r, r, "[%s]", GetErrorMessage(r));
+
+ SysTryReturnResult(NID_APP, (packageId.GetLength() + executableName.GetLength()) < WIDGET_APP_MAX_APPID_LENGTH, E_INVALID_ARG, "The appId is too long (Maximum %d bytes).", WIDGET_APP_MAX_APPID_LENGTH);
+
+ SysLog(NID_APP,"packageId(%ls), executableName(%ls), condition(%ls)", packageId.GetPointer(), executableName.GetPointer(), condition.GetPointer() );
+ if (pArguments != null)
+ {
+ DumpArguments(pArguments);
+ }
+
+ _ConditionHandler* pHandler = this->GetHandlerByCondition(condition);
+ SysTryReturnResult(NID_APP, pHandler != null, E_INVALID_ARG, "failed to GetHandlerByCondition(%ls)", condition.GetPointer() );
+
+ _AppLaunchCondition* pAppLaunchCondition = new (std::nothrow) _AppLaunchCondition();
+ SysTryReturnResult(NID_APP, pAppLaunchCondition != null, E_OUT_OF_MEMORY, "failed to create pAppLaunchCondition");
+
+ r = pAppLaunchCondition->Construct(packageId, exeName, condition, pArguments, option, pRegSectionName );
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "failed to pAppLaunchCondition->Constructor");
+
+ r = pHandler->AddCondition(*pAppLaunchCondition);
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s]", GetErrorMessage(r));
+
+ SysLog(NID_APP, "SUCCESSED.");
+ return E_SUCCESS;
+
+CATCH:
+ delete pAppLaunchCondition;
+ return r;
+}
+
+result
+_ConditionManagerService::ValidateArguments(const IList* pArguments) const
+{
+ int totalArgumentsLen = 0;
+ for (int i = 0; i< pArguments->GetCount(); i ++)
+ {
+ const String* pArg = dynamic_cast<const String*>(pArguments->GetAt(i));
+ SysTryReturnResult(NID_APP, pArg != null, E_SYSTEM , "A system error has occurred.");
+
+ totalArgumentsLen += pArg->GetLength();
+ }
+ SysTryReturnResult(NID_APP, totalArgumentsLen < MAX_LEN_ARG, E_MAX_EXCEEDED, "The size of pArguments(%d) has exceeded the maximum limit(%d).", totalArgumentsLen, MAX_LEN_ARG);
+ return E_SUCCESS;
+}
+
+
+result
+_ConditionManagerService::UnregisterAppLaunch(const Tizen::Base::String& packageId, const String& executableName, const Tizen::Base::String* pCondition)
+{
+ SysTryReturnResult(NID_APP, _PackageManagerImpl::GetInstance()->IsPackageInstalled(packageId) == true, E_APP_NOT_INSTALLED, "The packageId(%ls) is not installed.", packageId.GetPointer());
+ String exeName = ( executableName.IsEmpty())? Tizen::App::Package::_PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId) : executableName;
+
+ SysLog(NID_APP,"packageId(%ls), executableName(%ls), condition(%ls)", packageId.GetPointer(), exeName.GetPointer(), (pCondition) ? pCondition->GetPointer() : L"" );
+
+ if ( pCondition == null)
+ {
+ return UnregisterAppLaunch(packageId, &exeName);
+ }
+ else
+ {
+ _ConditionHandler* pHandler = GetHandlerByCondition(*pCondition);
+ SysTryReturnResult(NID_APP, pHandler != null, E_OBJ_NOT_FOUND, "");
+
+ return pHandler->RemoveCondition(packageId, &exeName, pCondition);
+ }
+
+ SysLog(NID_APP, "FAILED.");
+ return E_FAILURE;// NEVER_GET_HERE
+}
+
+result
+_ConditionManagerService::UnregisterAppLaunch(const Tizen::Base::String& packageId, const String* pExecutableName)
+{
+ result r = E_SUCCESS;
+ _ConditionHandler* pHandler = null;
+ for (int i =0; i < __handlers.GetCount(); i ++)
+ {
+ pHandler = null;
+ r = __handlers.GetAt(i, pHandler);
+ SysTryReturn(NID_APP, pHandler != null, r, r, "[%s]", GetErrorMessage(r) );
+ pHandler->RemoveCondition(packageId, pExecutableName, null);
+ }
+
+ return E_SUCCESS;
+}
+bool
+_ConditionManagerService::IsAppLaunchRegistered(const Tizen::Base::String& packageId, const String& executableName, const Tizen::Base::String* pCondition)
+{
+ //SysTryReturnResult(NID_APP, _Aul::IsInstalled(appId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
+ SysTryReturnResult(NID_APP, _PackageManagerImpl::GetInstance()->IsPackageInstalled(packageId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", packageId.GetPointer());
+
+ ClearLastResult();
+ String exeName = ( executableName.IsEmpty())? Tizen::App::Package::_PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId) : executableName;
+
+ if (pCondition == null)
+ {
+ result r = E_SUCCESS;
+ _ConditionHandler* pHandler = null;
+ for (int i =0; i < __handlers.GetCount(); i ++)
+ {
+ pHandler = null;
+ r = __handlers.GetAt(i, pHandler);
+ SysTryReturn(NID_APP, pHandler != null, r, r, "[%s]", GetErrorMessage(r) );
+ if ( pHandler->HasCondition(packageId, exeName, null) == true)
+ {
+ return true;
+ }
+ }
+ }
+ else
+ {
+ _ConditionHandler* pHandler = GetHandlerByCondition(*pCondition);
+ SysTryReturn(NID_APP, pHandler != null, false, E_INVALID_ARG, "[E_INVALID_ARG]");
+
+ return pHandler->HasCondition(packageId, exeName, pCondition);
+ }
+
+ return false;
+}
+
+
+///////////////////////////////////////////
+// internal helper
+///////////////////////////////////////////
+//TODO: save arguments
+result
+_ConditionRegistryHelper::AddToRegistry(const String& sectionName, const Tizen::Base::String& packageId, const String& executableName, const String& condition, const IList *pArg)
+{
+ _RegistryImpl reg;
+
+ result r = reg.Construct(App::GetInstance()->GetAppRootPath() + REGISTRY_FILE_OPERATIONS, REG_OPEN_READ_WRITE | REG_OPEN_CREATE, null);
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "%s", GetErrorMessage(r) );
+
+// String name = String(packageId) + String(condition);
+ r = reg.AddSection(sectionName);
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] sectionName : %ls", GetErrorMessage(r), sectionName.GetPointer() );
+
+ r = reg.AddValue(sectionName, REG_KEY_APPID, packageId);
+ r = reg.AddValue(sectionName, REG_KEY_EXENAME, executableName);
+ r = reg.AddValue(sectionName, REG_KEY_CONDTION, condition);
+ r = reg.AddValue(sectionName, REG_KEY_LAUNCH_TYPE, L"");
+
+ if (pArg != null)
+ {
+ String value = Integer::ToString(pArg->GetCount());
+ r = reg.AddValue(sectionName, REG_KEY_ARG_COUNT, value );
+
+ const String* pCurArg = null;
+ String key;
+ for( int i = 0; i< pArg->GetCount(); i ++)
+ {
+ pCurArg = dynamic_cast<const String*>(pArg->GetAt(i));
+ if (pCurArg != null)
+ {
+ key = REG_KEY_ARG + Integer::ToString(i);
+ r = reg.AddValue(sectionName, key, *pCurArg);
+ }
+ }
+ }
+
+ r = reg.Flush();
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "%s", GetErrorMessage(r) );
+
+ SysLog(NID_APP, "ConditionInfo is added to registry. [%ls] packageId=%ls, condition=%ls, lunchType=none", sectionName.GetPointer(), packageId.GetPointer(), condition.GetPointer() );
+
+ return E_SUCCESS;
+
+CATCH:
+ return r;
+}
+
+result
+_ConditionRegistryHelper::RemoveFromRegistry(const String §ion)
+{
+ _RegistryImpl reg;
+ result r = reg.Construct(App::GetInstance()->GetAppRootPath() + REGISTRY_FILE_OPERATIONS, REG_OPEN_READ_WRITE, null);
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "%s", GetErrorMessage(r) );
+
+ r = reg.RemoveSection(section);
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "%s", GetErrorMessage(r) );
+
+ r = reg.Flush();
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "%s", GetErrorMessage(r) );
+
+ SysLog(NID_APP, "Removed. [%ls]", section.GetPointer() );
+ return E_SUCCESS;
+
+CATCH:
+ return r;
+}
+
+result
+_ConditionRegistryHelper::GetAllParamsN(const IMap& map, String& packageId, String& executableName, String& condition, ArrayList*& pArgs)
+{
+ const String* pPackageId = static_cast<const String*>(map.GetValue(REG_KEY_APPID));
+ const String* pExeName = static_cast<const String*>(map.GetValue(REG_KEY_EXENAME));
+ const String* pCondition = static_cast<const String*>(map.GetValue(REG_KEY_CONDTION));
+ // const String* pLaunchMode = static_cast<const String*>(map.GetValue(REG_KEY_LAUNCH_TYPE));
+ SysTryReturn(NID_APP, pPackageId != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "registry value is invalid. pPackageId is null");
+ SysTryReturn(NID_APP, pCondition != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "registry value is invalid. pCondition is null");
+
+ const String* pArgCount = static_cast<const String*>(map.GetValue(REG_KEY_ARG_COUNT));
+ if (pArgCount != null)
+ {
+ int argCount;
+ Integer::Parse(*pArgCount, argCount);
+ if (argCount > 0)
+ {
+ String key;
+ const String* pValue = null;
+ pArgs = new ArrayList();
+ pArgs->Construct();
+ for (int i = 0; i< argCount; i++)
+ {
+ key = REG_KEY_ARG + Integer::ToString(i);
+ pValue = dynamic_cast<const String*>(map.GetValue(key));
+ SysTryCatch(NID_APP, pValue != null, , GetLastResult(), "failed to get '%ls'.", key.GetPointer() );
+ pArgs->Add(*new String(*pValue));
+ }
+ }
+ }
+
+ packageId = *pPackageId;
+ condition = *pCondition;
+ if (pExeName)
+ {
+ executableName = *pExeName;
+ }
+ return E_SUCCESS;
+
+CATCH:
+ if (pArgs != null)
+ {
+ pArgs->RemoveAll(true);
+ }
+ delete pArgs;
+ pArgs = null;
+
+ return E_FAILURE;
+}
+
+
+//bool
+//_ConditionRegistryHelper::ContainsSectionName(const String& sectionName)
+//{
+// _RegistryImpl reg;
+//
+// result r = reg.Construct(REGISTRY_FILE_OPERATIONS, REG_OPEN_READ_ONLY, false, 0);
+// SysTryReturn(NID_APP, !IsFailed(r), r, r, "%s", GetErrorMessage(r) );
+// return ( reg.GetSectionIndex(sectionName) >= 0);
+//}
+
+void
+_ConditionManagerService::Dump(void) const
+{
+// result r = E_SUCCESS;
+// _ConditionHandler* pHandler = null;
+// for (int i =0; i < __handlers.GetCount(); i ++)
+// {
+// pHandler = null;
+// r = __handlers.GetAt(i, pHandler);
+// SysTryReturnVoidResult(NID_APP, pHandler != null, r, "[%s]", GetErrorMessage(r) );
+// pHandler->Dump();
+// }
+}
+
+
+}} //namespace Tizen { namespace App {
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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 FApp_ConditionManagerStub.cpp
+ * @brief This is the implementation for the _ConditionManagerStub class.
+ */
+#include <cstdio>
+#include <dlfcn.h>
+
+#include <FSec_AccessController.h>
+
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include <FIo_IpcServer.h>
+#include <FAppPkg_PackageManagerImpl.h>
+#include <FApp_ConditionManagerIpcMessages.h>
+#include "FApp_ConditionManagerService.h"
+#include "FApp_ConditionManagerStub.h"
+
+
+namespace Tizen { namespace App {
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Io;
+using namespace Tizen::Security;
+
+
+///////////////////////////////////////////
+// _ConditionManagerStub
+///////////////////////////////////////////
+
+_ConditionManagerStub::_ConditionManagerStub()
+ :__pIpcServer(null)
+ ,__pConditionManagerService(null)
+{
+ SysLog(NID_APP, "Enter\n");
+ SysLog(NID_APP, "Exit\n");
+}
+
+_ConditionManagerStub::~_ConditionManagerStub()
+{
+ SysLog(NID_APP, "Enter\n");
+
+ if ( __pIpcServer != null)
+ {
+ __pIpcServer->Stop();
+ delete __pIpcServer;
+ }
+
+ SysLog(NID_APP, "Exit\n");
+}
+
+result
+_ConditionManagerStub::Construct(void)
+{
+ SysLog(NID_APP, "Enter.");
+
+ __pConditionManagerService = new (std::nothrow) _ConditionManagerService();
+
+ result r = E_SUCCESS;
+ r = __pConditionManagerService->Construct();
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __pConditionManagerService->Construct.(%s)", GetErrorMessage(r) );
+
+ r = StartIpcServer();
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to StartIpcServer.(%s)", GetErrorMessage(r) );
+
+ SysLog(NID_APP, "Exit.");
+ return E_SUCCESS;
+}
+
+result
+_ConditionManagerStub::StartIpcServer(void)
+{
+ __pIpcServer = new (std::nothrow) _IpcServer();
+ SysTryReturn(NID_APP, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
+
+ result r = __pIpcServer->Construct( "osp.app.ipcserver.conditionmanager", *this);
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.appmanager");
+
+ return E_SUCCESS;
+
+CATCH:
+ delete __pIpcServer;
+ __pIpcServer = null;
+ return r;
+}
+
+//
+// from XML : <Condition Name="DueTime">07/24/2012 22:52:33 60m</Condition>
+// from API : "DueTime='12/31/2020 21:24:59' LaunchPeriod='60'"
+//
+result
+_ConditionManagerStub::ExtractDueAndPeriod(const String& src, String& dueTime, String& period)
+{
+ DateTime tmpDate;
+ const int dateTimeLen = 19;
+
+ result r = src.SubString(0, dateTimeLen, dueTime);
+ SysTryReturn(NID_APP, IsFailed(r) == false, E_INVALID_FORMAT, E_INVALID_FORMAT, "invalid DueTime value.(%ls)", src.GetPointer());
+
+ r = DateTime::Parse(dueTime, tmpDate);
+ SysTryReturn(NID_APP, IsFailed(r) == false, E_INVALID_FORMAT, E_INVALID_FORMAT, "invalid DueTime value.(%ls)", dueTime.GetPointer());
+
+ r = src.SubString(dateTimeLen + 1, src.GetLength() -(dateTimeLen + 1) -1, period);//60
+ SysTryReturn(NID_APP, IsFailed(r) == false, E_INVALID_FORMAT, E_INVALID_FORMAT, "invalid DueTime value.(%ls)", dueTime.GetPointer());
+
+ return E_SUCCESS;
+}
+
+void
+_ConditionManagerStub::OnInstallComplete(const AppId& appId, const String& executableName, const String& packageName )
+{
+ SysTryReturnVoidResult(NID_APP, __pConditionManagerService != null, E_INVALID_STATE, "Invalid condition manager service state.");
+ SysLog(NID_APP, "Enter");
+
+ ArrayList* pArray = Tizen::App::Package::_PackageManagerImpl::GetInstance()->GetAppLaunchConditionListN(packageName);
+ SysTryReturnVoidResult(NID_APP, pArray != null, E_INVALID_STATE, "failed to GetAppLaunchConditionListN(%ls)", packageName.GetPointer());
+
+ Tizen::App::Package::_LaunchConditionInfoImpl* pCondition = null;
+ String condition;
+ String name;
+ String value;
+ result r = E_SUCCESS;
+
+ for ( int i = 0; i < pArray->GetCount(); i++)
+ {
+ pCondition = dynamic_cast<Tizen::App::Package::_LaunchConditionInfoImpl*>(pArray->GetAt(i));
+ if ( pCondition == null)
+ {
+ continue;
+ }
+
+ name = pCondition->GetName();
+ value = pCondition->GetValue();
+
+ if ( name == L"DueTime")
+ {
+ String dueTime;
+ String period;
+
+ r = ExtractDueAndPeriod(value, dueTime, period);
+ if( IsFailed(r))
+ {
+ continue;
+ }
+
+ condition.Format( 1024, L"DueTime='%ls' LaunchPeriod='%ls'", dueTime.GetPointer(), period.GetPointer());
+ }
+ else
+ {
+ condition = name + "='" + value + "'";
+ }
+
+ SysLog(NID_APP, "condition(%ls)", condition.GetPointer());
+ __pConditionManagerService->RegisterAppLaunch(appId, executableName, condition, null, AppManager::LAUNCH_OPTION_DEFAULT, null);
+ }
+ SysLog(NID_APP, "Exit");
+}
+
+void
+_ConditionManagerStub::OnUninstallComplete(const AppId& appId, const String& executableName)
+{
+ SysTryReturnVoidResult(NID_APP, __pConditionManagerService != null, E_INVALID_STATE, "Invalid condition manager service state.");
+
+ __pConditionManagerService->UnregisterAppLaunch(appId, null);
+}
+
+///////////////////////////////////////////
+// ipc handlers
+///////////////////////////////////////////
+
+bool
+_ConditionManagerStub::OnRegisterAppLaunch(const AppId& appId, const String& executableName, const String& cond, const Tizen::Base::Collection::ArrayList& args , int flag, result *pRes)
+{
+ SysLog(NID_APP, "(appId:%ls, executableName:%ls, cond:%ls, flag:%x)\n", appId.GetPointer(), executableName.GetPointer(), cond.GetPointer(), flag);
+// SysTryCatch(NID_APP, __pConditionManagerService != null, *pRes = E_INVALID_STATE, E_INVALID_STATE, "__pConditionManagerService is null!");
+ if ( __pConditionManagerService == null )
+ {
+ SysLog(NID_APP, "__pConditionManagerService is null!");
+ *pRes = E_INVALID_STATE;
+ return true;
+ }
+
+ String targetAppId;
+ if ( appId.IsEmpty() == true )
+ {
+ // APPLICATION_SERVICE
+ targetAppId = __pIpcServer->GetClientAppId();
+ }
+ else
+ {
+ // APPLICATION_MANAGER
+ *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_APPMANAGER_LAUNCH);
+
+ if (IsFailed(*pRes))
+ {
+ SysLog(NID_APP, "[E_PRIVILEGE_DENIED]The application does not have the privilege to call this method.");
+ *pRes = E_PRIVILEGE_DENIED;
+ return true;
+ }
+
+ targetAppId = appId;
+ }
+
+ *pRes = __pConditionManagerService->RegisterAppLaunch(targetAppId, executableName, cond, (args.GetCount()>0)? &args : null, AppManager::LAUNCH_OPTION_DEFAULT);
+
+//CATCH:
+ return true;
+}
+
+bool
+_ConditionManagerStub::OnUnregisterAppLaunch(const AppId& appId, const String& executableName, const String& cond, result *pRes)
+{
+ SysLog(NID_APP, "(appId:%ls, executableName:%ls, cond:%ls)\n", appId.GetPointer(), executableName.GetPointer(), cond.GetPointer());
+// SysTryCatch(NID_APP, __pConditionManagerService != null, *pRes = E_INVALID_STATE, E_INVALID_STATE, "__pConditionManagerService is null!");
+ if ( __pConditionManagerService == null )
+ {
+ SysLog(NID_APP, "__pConditionManagerService is null!");
+ *pRes = E_INVALID_STATE;
+ return true;
+ }
+
+ String targetAppId;
+ if ( appId.IsEmpty() == true )
+ {
+ // APPLICATION_SERVICE
+ targetAppId = __pIpcServer->GetClientAppId();
+ }
+ else
+ {
+ // APPLICATION_MANAGER
+ *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_APPMANAGER_LAUNCH);
+
+ if (IsFailed(*pRes))
+ {
+ SysLog(NID_APP, "[E_PRIVILEGE_DENIED]The application does not have the privilege to call this method.");
+ *pRes = E_PRIVILEGE_DENIED;
+ return true;
+ }
+
+ targetAppId = appId;
+ }
+
+ *pRes = __pConditionManagerService->UnregisterAppLaunch(targetAppId, executableName, (cond.IsEmpty() == true) ? null : (String*)&cond);
+
+//CATCH:
+ return true;
+}
+
+bool
+_ConditionManagerStub::OnIsAppLaunchRegistered(const AppId& appId, const String& executableName, const String& cond, bool *pIsAppLaunchRegistered, result *pException)
+{
+ if ( __pConditionManagerService == null )
+ {
+ SysLog(NID_APP, "__pConditionManagerService is null!");
+ *pException = E_SYSTEM;
+ return true;
+ }
+
+ String targetAppId;
+ if ( appId.IsEmpty() == true )
+ {
+ // NP
+ targetAppId = __pIpcServer->GetClientAppId();
+ }
+ else
+ {
+ // APPLICATION_MANAGER
+ result r = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_APPMANAGER_LAUNCH);
+ if(IsFailed(r))
+ {
+ *pException = E_PRIVILEGE_DENIED;
+ SysTryReturn(NID_APP, !IsFailed(r), true, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+ }
+
+ targetAppId = appId;
+ }
+
+ *pIsAppLaunchRegistered = __pConditionManagerService->IsAppLaunchRegistered( targetAppId, executableName, (cond.IsEmpty() == true) ? null : &cond);
+ *pException = GetLastResult();
+ SysLog(NID_APP, "(appId:%s, executableName:%ls, cond:%s) is registered = (%s)\n", appId.GetPointer(), executableName.GetPointer(), cond.GetPointer(), (*pIsAppLaunchRegistered)? "true":"false");
+
+ return true;
+}
+
+void
+_ConditionManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
+{
+ SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
+
+ IPC_BEGIN_MESSAGE_MAP(_ConditionManagerStub, message)
+ IPC_MESSAGE_HANDLER_EX(ConditionManager_RegisterAppLaunch, &server, OnRegisterAppLaunch)
+ IPC_MESSAGE_HANDLER_EX(ConditionManager_UnregisterAppLaunch, &server, OnUnregisterAppLaunch)
+ IPC_MESSAGE_HANDLER_EX(ConditionManager_IsAppLaunchRegistered, &server, OnIsAppLaunchRegistered)
+ IPC_END_MESSAGE_MAP()
+}
+
+void
+_ConditionManagerStub::OnIpcServerStarted(const _IpcServer& server)
+{
+ SysLog(NID_APP, "\n");
+}
+
+void
+_ConditionManagerStub::OnIpcServerStopped(const _IpcServer& server)
+{
+ SysLog(NID_APP, "\n");
+}
+
+void
+_ConditionManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
+{
+ SysLog(NID_APP, "(clientId:%d)\n", clientId);
+}
+
+void
+_ConditionManagerStub::OnIpcClientDisconnected(const _IpcServer& server, int clientId)
+{
+ SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), clientId);
+}
+
+}} //namespace Tizen { namespace App {
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_ContextManager.cpp
+ * @brief This is the implementation for the _ContextManager.cpp class.
+ */
+
+#include <cstdio>
+#include <cerrno>
+#include <dlfcn.h>
+#include <string>
+
+#include <FBaseColArrayList.h>
+#include <FBaseSysLog.h>
+#include <FIoFile.h>
+
+#include <FBase_StringConverter.h>
+#include <FApp_Aul.h>
+#include <FApp_AppManagerImpl.h>
+#include <FAppPkg_PackageManagerImpl.h>
+
+#include "FApp_ContextManager.h"
+#include "FIo_MmcStorageManagerService.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Io;
+
+namespace Tizen { namespace App {
+
+const unsigned long CONTEXT_MANAGER_MAGIC = 0x585443; // 'C' 'T' 'X'
+
+///////////////////////////////////////////////////
+// _AppContext
+///////////////////////////////////////////////////
+_AppContext::_AppContext(const String& appId, const String& executableName, _AppType appType, int pid, int ipcClientId, bool isSystemService)
+: appId(appId)
+, executableName(executableName)
+, appType(appType)
+, pId(pid)
+, ipcClientId(ipcClientId)
+, uiState(APP_UI_STATE_BACKGROUND)
+, isRegistered(true)
+, isSystemService(isSystemService)
+{
+}
+
+String
+_AppContext::ToString(void) const
+{
+ Tizen::Base::String ret;
+ ret.Format(1024, L"%ls.%ls(pid:%d)", appId.GetPointer(), executableName.GetPointer(), pId);
+ return ret;
+}
+
+
+///////////////////////////////////////////////////
+// _ContextManager
+///////////////////////////////////////////////////
+_ContextManager::_ContextManager()
+ : __magic(CONTEXT_MANAGER_MAGIC)
+ , __pEventListener(null)
+{
+ //
+}
+
+_ContextManager::~_ContextManager()
+{
+}
+
+result
+_ContextManager::Construct(void)
+{
+ result r = E_SUCCESS;
+ __errorProneAppIds.Construct();
+ _Aul::SetOnAppTerminatedCb(OnAppTerminate, this);
+
+ return r;
+}
+
+void
+_ContextManager::SetEventListener(_IContextManagerEventListener& listener)
+{
+ __pEventListener = &listener;
+}
+
+result
+_ContextManager::Register(const PackageId& pkgId, const String& executableName, _AppType appType, int pid, int ipcClientId, bool isSystemService )
+{
+ if( __appContexts[pid] != null)
+ {
+ SysAssertf( isSystemService == true, "The application (appid:%ls, pid:%d) is registered twice.", pkgId.GetPointer(), pid);
+ return E_SUCCESS;
+ }
+
+ _AppContext* pAppContext = new (std::nothrow) _AppContext(pkgId, executableName, appType, pid, ipcClientId, isSystemService);
+
+ __appContexts[pid] = pAppContext;
+
+ String appRoot(L"/opt/usr/apps/");
+ appRoot.Append(pkgId);
+ String compatFile(appRoot);
+ compatFile.Append(L"/info/compat.info");
+
+ bool ospCompat = File::IsFileExist(compatFile);
+ if (GetLastResult() == E_SUCCESS && ospCompat == true)
+ {
+ _MmcStorageManagerService* pMmcMgr = _MmcStorageManagerService::GetInstance();
+ String* pAppRoot = new (std::nothrow) String(appRoot);
+
+ int index = 0;
+ result r = appRoot.LastIndexOf(L'/', appRoot.GetLength() - 1, index);
+ SysTryLog(NID_IO, !IsFailed(r), "[E_SYSTEM] The method cannot proceed due to a severe system error.");
+
+ String pkgId;
+ r = appRoot.SubString(++index, pkgId);
+ SysTryLog(NID_IO, !IsFailed(r), "[E_SYSTEM] The method cannot proceed due to a severe system error.");
+
+ //pMmcMgr->__appList[pid] = pAppRoot;
+ char* pKey = _StringConverter::CopyToCharArrayN(pkgId);
+ std::string key(pKey);
+ delete[] pKey;
+ pMmcMgr->__appList.insert(_MmcStorageManagerService::_AppListPair(key, pAppRoot));
+ SysLog(NID_APP, "OSP compatible application (%ls) is registered.", pkgId.GetPointer());
+ }
+
+ // ==== set oom policy for ServiceApp
+ result r = E_SUCCESS;
+ switch (GetOomAppType(pkgId, pid))
+ {
+ case OOM_APP_TYPE_SYSTEM:
+ break;
+ case OOM_APP_TYPE_LAUNCHING:
+ break;
+ case OOM_APP_TYPE_FOREGROUND_HIGH:
+ break;
+ case OOM_APP_TYPE_SERVICE_HIGH:
+ break;
+ case OOM_APP_TYPE_FOREGROUND:
+ break;
+ case OOM_APP_TYPE_SERVICE_MID:
+ r = _Aul::SetOomAdj(pid, -7);
+ break;
+ case OOM_APP_TYPE_BACKGROUND_HIGH:
+ break;
+ case OOM_APP_TYPE_SERVICE_LOW:
+ r = _Aul::SetOomAdj(pid, -3);
+ break;
+ case OOM_APP_TYPE_BACKGROUND:
+ break;
+ }
+ SysLog(NID_APP, "Set OOM : result is %s", GetErrorMessage(r));
+
+ SysLog(NID_APP, "The %s (appid:%ls, pid:%d) Registered.", isSystemService ? "application":"system service", pkgId.GetPointer(), pid);
+ Dump();
+ return E_SUCCESS;
+}
+
+// see also OnAppTerminate
+result
+_ContextManager::Unregister(int pid)
+{
+ _AppContext* pAppContext = __appContexts[pid];
+ SysTryReturn(NID_APP, pAppContext != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "Unknown pid(%d).", pid);
+
+ pAppContext->isRegistered = false;
+ SysLog(NID_APP, "(appid:%ls, pid:%d) Unregistered.", pAppContext->appId.GetPointer(), pid);
+
+#if 0
+ _MmcStorageManagerService* pMmcMgr = _MmcStorageManagerService::GetInstance();
+ String* pAppRoot = pMmcMgr->__appList[pid];
+ if (pAppRoot != null)
+ {
+ pMmcMgr->__appList.erase(pid);
+ SysLog(NID_APP, "OSP 2.0 application is unregistered.");
+ }
+#endif
+
+ return E_SUCCESS;
+}
+
+// event handler for _Aul::SetOnAppTerminatedCb
+int
+_ContextManager::OnAppTerminate(int pid, void *pData)
+{
+ SysTryReturn(NID_APP, pData != null, -1, E_INVALID_STATE, "");
+
+ _ContextManager* pContextMgr = static_cast<_ContextManager*>(pData);
+ SysTryReturn(NID_APP, pContextMgr->__magic == CONTEXT_MANAGER_MAGIC, -1, E_INVALID_STATE, "Wrong magic number %x(%x)", pContextMgr->__magic, CONTEXT_MANAGER_MAGIC);
+
+ _AppContext* pAppContext = pContextMgr->__appContexts[pid];
+
+ if ( pAppContext == null)
+ {
+// SysLog(NID_APP, "Not registered pid(%d), It means this process isn't osp app.", pid);
+ return 0;
+ }
+
+ if (pAppContext->isRegistered)
+ {
+ SysLog(NID_APP, "This app is terminated abnormally.");
+ pContextMgr->AbonormalAppTerminationHanlder( pAppContext->pId, pAppContext->appId, pAppContext->executableName );
+ }
+
+ if (pContextMgr->__pEventListener != null )
+ {
+ pContextMgr->__pEventListener->OnApplicationTerminated(*pAppContext);
+ }
+
+ int res = pContextMgr->__appContexts.erase(pid);
+ SysTryCatch(NID_APP, res == 1, , E_INVALID_STATE, "[E_INVALID_STATE] __appContexts.erase(%d) returns (%d). It seems to be invalid.", pid, res);
+
+ SysLog(NID_APP, "app info is removed (%ls, %d)", pAppContext->executableName.GetPointer(), pid);
+
+ pContextMgr->Dump();
+
+CATCH:
+ delete pAppContext;
+ return 0;
+}
+
+void
+_ContextManager::AbonormalAppTerminationHanlder(int pid, const AppId& appId, const String& execName)
+{
+ this->Unregister(pid);
+
+ const String& needToAutoRestartOnFailure = _Util::QueryFeatureFromPackageManager(appId, execName, L"AutoRestart");
+ if (needToAutoRestartOnFailure == "True")
+ {
+ if(!IsErrorProneApp(appId))// prevent error prone app being restarted over and over again..
+ {
+ SysLog(NID_APP, "The app is configured as AutoRestart, so It will be restarted.");
+
+ __errorProneAppIds.Add(appId);
+
+ String realId = appId + L'.' + execName;
+ _AppManagerImpl::GetInstance()->LaunchApplication(realId, null, AppManager::LAUNCH_OPTION_DEFAULT);
+
+ }
+ else
+ {
+ SysLog(NID_APP, "The app is configured as AutoRestart, but It won't be restarted. because it was already restarted, and terminated unexpectedly again. ");
+ }
+ }
+}
+
+bool
+_ContextManager::IsErrorProneApp(const AppId& appId) const
+{
+ const int count = __errorProneAppIds.GetCount();
+ String errorProneAppId;
+
+ for (int i = 0; i < count; i ++)
+ {
+ __errorProneAppIds.GetAt(i, errorProneAppId);
+ if(errorProneAppId == appId)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+const _AppContext*
+_ContextManager::Find(const AppId& appId, const Tizen::Base::String& executableName) const
+{
+ AppContexts::const_iterator it;
+
+ for (it = __appContexts.begin(); it != __appContexts.end(); it++)
+ {
+ const _AppContext* const pAppContext = (*it).second;
+
+ if (pAppContext != null && pAppContext->appId == appId && pAppContext->executableName == executableName)
+ {
+ return pAppContext;
+ }
+ }
+
+ return null;
+}
+
+const _AppContext*
+_ContextManager::Find(int pid)
+{
+ return __appContexts[pid];
+}
+
+result
+_ContextManager::GetAppListN(Tizen::Base::Collection::ArrayList* pArray) const
+{
+ AppContexts::const_iterator it;
+ String logText;
+
+ for (it = __appContexts.begin(); it != __appContexts.end(); it++)
+ {
+ const _AppContext* const pAppContext = (*it).second;
+
+ if (pAppContext != null)
+ {
+ if ( pArray != null)
+ {
+ pArray->Add(pAppContext->appId);
+ }
+
+ logText.Append(pAppContext->appId);
+ logText.Append(L", ");
+ }
+ }
+ SysLog(NID_APP, "Total %d apps : %ls", __appContexts.size(), logText.GetPointer() );
+
+ return E_SUCCESS;
+}
+
+_OomAppType
+_ContextManager::GetOomAppType(const AppId& appId, const int pid) const
+{
+ _OomAppType appType = OOM_APP_TYPE_FOREGROUND;
+
+ // FIX_ME : will be implemented for type checking
+
+ return appType;
+}
+
+void
+_ContextManager::Dump(void) const
+{
+ AppContexts::const_iterator it;
+
+ SysLog(NID_APP, "registered app count : %d", __appContexts.size());
+
+ for (it = __appContexts.begin(); it != __appContexts.end(); it++)
+ {
+ const _AppContext* const pAppContext = (*it).second;
+ if (pAppContext != null)
+ {
+ SysLog(NID_APP, "%ls", pAppContext->ToString().GetPointer());
+ }
+ }
+}
+
+
+
+/*
+ * _ContextManager::Util
+ */
+
+/*String
+_ContextManager::_Util::GetExecNameFromPackageName(const String& packageName)
+{
+ String execName;
+ const String prefix(L"org.tizen.1234567890");
+ const int prefixLen = prefix.GetLength();
+ packageName.SubString(prefixLen, execName);
+
+ return execName;
+}*/
+
+String
+_ContextManager::_Util::QueryFeatureFromPackageManager(const String& appId, const String& execName, const String& feature)
+{
+ ArrayList* pFeatureList = Tizen::App::Package::_PackageManagerImpl::GetInstance()->GetPackageAppFeatureListN(appId, execName);
+ SysTryReturn(NID_APP, pFeatureList != null, L"", E_SYSTEM, "Cannot acquire feature list.");
+
+ String ret = L"";
+
+ for (int i = 0; i < pFeatureList->GetCount(); i++)
+ {
+ const Tizen::App::Package::_AppFeatureInfoImpl* pInfo = static_cast<const Tizen::App::Package::_AppFeatureInfoImpl*>(pFeatureList->GetAt(i));
+ SysLog(NID_APP, "%ls, %ls", pInfo->GetName().GetPointer(), pInfo->GetValue().GetPointer());
+ if (pInfo != null && pInfo->GetName() == feature)
+ {
+ ret = pInfo->GetValue();
+ break;
+ }
+ }
+
+ pFeatureList->RemoveAll(true);
+ delete pFeatureList;
+
+ return ret;
+}
+
+} } // Tizen::App
+
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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 FApp_NotificationManagerService.cpp
+ * @brief This is the implementation for the _NotificationManagerService class.
+ */
+
+#include <unique_ptr.h>
+
+#include <FShellNotificationManager.h>
+#include <FShellNotificationRequest.h>
+
+#include <FBaseSysLog.h>
+#include <FBaseInternalTypes.h>
+#include <FBase_StringConverter.h>
+#include <FApp_AppArg.h>
+#include "FApp_AppInfo.h"
+#include "FApp_Aul.h"
+#include "FApp_NotificationManagerService.h"
+#include "FAppPkg_PackageManagerImpl.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Io;
+using namespace Tizen::Shell;
+
+extern "C" int service_create_request(bundle *data, service_h *service);
+extern "C" int service_to_bundle(service_h service, bundle** data);
+
+namespace
+{
+
+result
+ConvertNotificationResult(int error)
+{
+ switch (error)
+ {
+ case NOTIFICATION_ERROR_NONE:
+ return E_SUCCESS;
+ case NOTIFICATION_ERROR_INVALID_DATA:
+ return E_INVALID_ARG;
+ case NOTIFICATION_ERROR_NO_MEMORY:
+ return E_OUT_OF_MEMORY;
+ case NOTIFICATION_ERROR_FROM_DB:
+ return E_DATABASE;
+ case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
+ return E_SYSTEM;
+ case NOTIFICATION_ERROR_NOT_EXIST_ID:
+ return E_SYSTEM;
+ default:
+ return E_SYSTEM;
+ }
+}
+
+static int
+GetMessageLength()
+{
+ static int length = (_AppInfo::GetApiVersion() < _API_VERSION_2_1) ? 127 : MAX_NOTIFICATION_MESSAGE_LENGTH;
+
+ return length;
+}
+
+}
+
+namespace Tizen { namespace App {
+
+_NotificationManagerService::_NotificationManagerService()
+
+{
+}
+
+_NotificationManagerService::~_NotificationManagerService()
+{
+}
+
+result
+_NotificationManagerService::Construct(void)
+{
+ return E_SUCCESS;
+}
+
+result
+_NotificationManagerService::NotifyMessage(const AppId& appId,const NotificationRequest& notiMessage, bool isOngoing)
+{
+ result r = E_SUCCESS;
+ int progress = -1;
+ char* pMsg = null;
+ notification_h core = NULL;
+ char* pTitleText = NULL;
+ char* pIconPath = NULL;
+ char* pSoundPath = NULL;
+ bundle* kb = NULL;
+ bundle* service_data = NULL;
+ service_h svc = NULL;
+ _AppArg arg;
+
+
+ const String& messageText = notiMessage.GetAlertText();
+ const String& launchArguments = notiMessage.GetAppMessage();
+ const String& titleText = notiMessage.GetTitleText();
+ const String& iconPath = notiMessage.GetIconFilePath();
+ const String& soundPath = notiMessage.GetSoundFilePath();
+
+ bool isAppInstalled = _Aul::IsInstalled(appId);
+ SysTryReturnResult(NID_APP, isAppInstalled == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
+
+ std::unique_ptr<char[]> buffer(_StringConverter::CopyToCharArrayN(appId));
+
+ if (isOngoing || !messageText.IsEmpty())
+ {
+ SysTryReturnResult(NID_APP,
+ messageText.GetLength() <= GetMessageLength(), E_INVALID_ARG,
+ "MessageText is greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
+
+ if (isOngoing)
+ {
+ core = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
+ SysTryReturnResult(NID_APP, core!= NULL , E_SYSTEM, "Notification creation failed ");
+ }
+ else
+ {
+ core = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
+ SysTryReturnResult(NID_APP, core!= NULL , E_SYSTEM, "Notification creation failed ");
+ }
+
+ pMsg = _StringConverter::CopyToCharArrayN(messageText);
+ notification_set_text(core, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+
+ if (!titleText.IsEmpty())
+ {
+ pTitleText = _StringConverter::CopyToCharArrayN(titleText);
+ r = ConvertNotificationResult(notification_set_text(core, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
+ }
+ else
+ {
+ app_manager_get_app_name(buffer.get(), &pTitleText);
+ r = ConvertNotificationResult(notification_set_text(core, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
+ }
+ if (!iconPath.IsEmpty())
+ {
+ pIconPath = _StringConverter::CopyToCharArrayN(iconPath);
+ r = ConvertNotificationResult(notification_set_image(core, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath));
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
+ }
+ else
+ {
+ app_manager_get_app_icon_path(buffer.get(), &pIconPath);
+ r = ConvertNotificationResult(notification_set_image(core, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath));
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
+ }
+ if (!soundPath.IsEmpty())
+ {
+ pSoundPath = _StringConverter::CopyToCharArrayN(soundPath);
+ r = ConvertNotificationResult(notification_set_sound(core, NOTIFICATION_SOUND_TYPE_USER_DATA, pSoundPath));
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set sound failed.", GetErrorMessage(r));
+ }
+
+ r = arg.Construct(launchArguments);
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
+
+ kb = arg.GetBundle();
+ service_create_request(kb, &svc);
+ service_set_app_id(svc, buffer.get());
+
+ if (service_to_bundle(svc, &service_data) == SERVICE_ERROR_NONE)
+ {
+ notification_set_property(core, 0);
+ notification_set_execute_option(core, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
+ SysLog(NID_APP, "Sending notification[%ls] for package %s.", messageText.GetPointer(), buffer.get());
+ }
+
+ if (isOngoing)
+ {
+ OngoingActivityType activityType = notiMessage.GetOngoingActivityType();
+ progress = notiMessage.GetOngoingActivityProgress();
+
+ switch (activityType)
+ {
+ case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
+ r = ConvertNotificationResult(notification_insert(core,NULL));
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
+
+ r = ConvertNotificationResult(notification_update_progress(core, NOTIFICATION_PRIV_ID_NONE, progress/100.));
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
+ break;
+ case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
+ notification_insert(core,NULL);
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
+
+ r = ConvertNotificationResult(notification_update_size(core,NOTIFICATION_PRIV_ID_NONE, progress));
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
+ break;
+ case ONGOING_ACTIVITY_TYPE_TEXT:
+ r = ConvertNotificationResult(notification_insert(core,NULL));
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
+ break;
+ default:
+ r = E_OPERATION_FAILED;
+ //ui_notification_set_content() is done already
+ break;
+ }
+ }
+ else
+ {
+ r = ConvertNotificationResult(notification_insert(core,NULL));
+ SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
+ }
+
+ }
+ else
+ {
+ SysTryReturnResult(NID_APP, 0, E_INVALID_ARG, "MessageText is Empty");
+ }
+
+ if (notiMessage.GetBadgeNumber() >= 0)
+ {
+ notification_set_badge(NULL, NOTIFICATION_GROUP_ID_NONE, notiMessage.GetBadgeNumber());
+ }
+
+CATCH:
+ delete[] pMsg;
+ delete[] pIconPath;
+ delete[] pTitleText;
+ delete[] pSoundPath;
+
+ if (core)
+ {
+ notification_free(core);
+ }
+ service_destroy(svc);
+ return r;
+}
+
+result
+_NotificationManagerService::RemoveNotification(const AppId& appId, bool isOngoing)
+{
+ int retCode = 0;
+ bool b = _Aul::IsInstalled(appId);
+ SysTryReturnResult(NID_APP, b == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
+
+ std::unique_ptr<char[]> pAppid(_StringConverter::CopyToCharArrayN(appId));
+
+ if (isOngoing)
+ {
+ retCode = notification_delete_all_by_type(pAppid.get(), NOTIFICATION_TYPE_ONGOING);
+ }
+ else
+ {
+ retCode = notification_delete_all_by_type(pAppid.get(), NOTIFICATION_TYPE_NOTI);
+ }
+
+ result r = E_SUCCESS;
+
+ switch (retCode)
+ {
+ case NOTIFICATION_ERROR_NONE:
+ r = E_SUCCESS;
+ break;
+
+ case NOTIFICATION_ERROR_INVALID_DATA:
+ r = E_INVALID_ARG;
+ break;
+
+ default:
+ r = E_SYSTEM;
+ break;
+ }
+
+ SysLog(NID_APP, "[%s] Finished.", GetErrorMessage(r));
+ return r;
+}
+}} //namespace Tizen { namespace App {
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_NotificationManagerStub.cpp
+ * @brief This is the implementation for the _NotificationManagerStub class.
+ */
+#include <cstdio>
+#include <dlfcn.h>
+
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include <FIo_IpcServer.h>
+#include <FSec_AccessController.h>
+#include <FShell_NotificationManagerIpcMessages.h>
+
+#include "FApp_NotificationManagerService.h"
+#include "FApp_NotificationManagerStub.h"
+
+
+namespace Tizen { namespace App {
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Io;
+using namespace Tizen::Security;
+using namespace Tizen::Shell;
+
+
+///////////////////////////////////////////
+// _NotificationManagerStub
+///////////////////////////////////////////
+
+_NotificationManagerStub::_NotificationManagerStub()
+ :__pIpcServer(null)
+ ,__pNotificationManagerService(null)
+{
+ SysLog(NID_APP, "_NotificationManagerStub - Enter\n");
+}
+
+_NotificationManagerStub::~_NotificationManagerStub()
+{
+ if ( __pIpcServer != null)
+ {
+ __pIpcServer->Stop();
+ delete __pIpcServer;
+ }
+
+ SysLog(NID_APP, "_NotificationManagerStub - Exit\n");
+}
+
+result
+_NotificationManagerStub::Construct(void)
+{
+ SysLog(NID_APP, "Enter.");
+
+ __pNotificationManagerService = new (std::nothrow) _NotificationManagerService();
+ SysTryReturnResult(NID_APP, __pNotificationManagerService != null, E_OUT_OF_MEMORY, "Not enough memory.");
+
+ result r = E_SUCCESS;
+ r = __pNotificationManagerService->Construct();
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __pNotificationManagerService->Construct.(%s)", GetErrorMessage(r) );
+
+ r = StartIpcServer();
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to StartIpcServer.(%s)", GetErrorMessage(r) );
+
+ SysLog(NID_APP, "Exit.");
+ return E_SUCCESS;
+}
+
+result
+_NotificationManagerStub::StartIpcServer(void)
+{
+ SysLog(NID_APP, "_NotificationManagerStub - StartIpcServer");
+
+ __pIpcServer = new (std::nothrow) _IpcServer();
+ SysTryReturnResult(NID_APP, __pIpcServer != null, E_OUT_OF_MEMORY, "Not enough memory.");
+
+ result r = __pIpcServer->Construct( "osp.app.ipcserver.notificationmanager", *this);
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.notificationmanager");
+
+ r = __pIpcServer->Start();
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to Start IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.notificationmanager");
+
+ return E_SUCCESS;
+
+CATCH:
+ delete __pIpcServer;
+ __pIpcServer = null;
+ return r;
+}
+
+void
+_NotificationManagerStub::OnNotifyMessage(const AppId& appId, const NotificationRequest& notiMessage,bool Ongoing, result* pRes)
+{
+ SysTryReturnVoidResult(NID_APP, __pNotificationManagerService != null, E_INVALID_STATE, "Invalid Notification manager state.");
+
+ *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_NOTIFICATIONMANAGER);
+ SysTryReturnVoidResult(NID_APP, !IsFailed(*pRes), *pRes = E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+ *pRes = __pNotificationManagerService->NotifyMessage(appId, notiMessage,Ongoing);
+}
+
+void
+_NotificationManagerStub::OnRemoveNotification(const AppId& appId, bool Ongoing, result* pRes)
+{
+ SysTryReturnVoidResult(NID_APP, __pNotificationManagerService != null, E_INVALID_STATE, "Invalid Notification manager state.");
+
+ *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_NOTIFICATIONMANAGER);
+ SysTryReturnVoidResult(NID_APP, !IsFailed(*pRes), *pRes = E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+ *pRes = __pNotificationManagerService->RemoveNotification(appId, Ongoing);
+}
+
+///////////////////////////////////////////
+// ipc handlers
+///////////////////////////////////////////
+void
+_NotificationManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
+{
+ SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
+
+ IPC_BEGIN_MESSAGE_MAP(_NotificationManagerStub, message)
+ IPC_MESSAGE_HANDLER_EX(NotificationManager_NotifyMessage, &server, OnNotifyMessage)
+ IPC_MESSAGE_HANDLER_EX(NotificationManager_RemoveNotification, &server, OnRemoveNotification)
+ IPC_END_MESSAGE_MAP()
+}
+
+void
+_NotificationManagerStub::OnIpcServerStarted(const _IpcServer& server)
+{
+ SysLog(NID_APP, "_NotificationManagerStub::OnIpcServerStarted \n");
+}
+
+void
+_NotificationManagerStub::OnIpcServerStopped(const _IpcServer& server)
+{
+ SysLog(NID_APP, "_NotificationManagerStub::OnIpcServerStopped \n");
+}
+
+void
+_NotificationManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
+{
+ SysLog(NID_APP, "_NotificationManagerStub::OnIpcClientConnected (clientId:%d)\n", clientId);
+}
+
+void
+_NotificationManagerStub::OnIpcClientDisconnected(const _IpcServer&server, int clientId)
+{
+ SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), clientId);
+}
+
+}} //namespace Tizen { namespace App {
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FApp_PackageManagerStub.cpp
+ * @brief This is the implementation for the _PackageManagerStub class.
+ */
+#include <cstdio>
+#include <dlfcn.h>
+
+#include <FAppPkgIPackageInstallationResponseListener.h>
+#include <FAppPkgIPackageUninstallationResponseListener.h>
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include <FIo_IpcServer.h>
+#include <FSec_AccessController.h>
+#include <FApp_PackageManagerIpcMessages.h>
+
+#include "FAppPkg_PackageManagerImpl.h"
+#include "FApp_PackageManagerStub.h"
+
+
+namespace Tizen { namespace App {
+
+using namespace Tizen::App::Package;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Io;
+using namespace Tizen::Security;
+
+
+///////////////////////////////////////////
+// _PackageManagerStub
+///////////////////////////////////////////
+
+_PackageManagerStub::_PackageManagerStub()
+ :__pIpcServer(null)
+ ,__pPackageManagerImpl(null)
+{
+ SysLog(NID_APP, "_PackageManagerStub - Enter\n");
+}
+
+_PackageManagerStub::~_PackageManagerStub()
+{
+ if ( __pIpcServer != null)
+ {
+ __pIpcServer->Stop();
+ delete __pIpcServer;
+ }
+
+ SysLog(NID_APP, "_PackageManagerStub - Exit\n");
+}
+
+result
+_PackageManagerStub::Construct(void)
+{
+ SysLog(NID_APP, "_PackageManagerStub - Construct.");
+
+ __pPackageManagerImpl = Tizen::App::Package::_PackageManagerImpl::GetInstance();
+
+ result r = E_SUCCESS;
+ r = StartIpcServer();
+ SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to StartIpcServer.(%s)", GetErrorMessage(r));
+
+ return E_SUCCESS;
+}
+
+result
+_PackageManagerStub::StartIpcServer(void)
+{
+ SysLog(NID_APP, "_PackageManagerStub - StartIpcServer");
+
+ __pIpcServer = new (std::nothrow) _IpcServer();
+ SysTryReturn(NID_APP, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
+
+ result r = __pIpcServer->Construct( "osp.app.ipcserver.packagemanager", *this);
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.packagemanager");
+
+ r = __pIpcServer->Start();
+ SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to Start IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.packagemanager");
+
+ return E_SUCCESS;
+
+CATCH:
+ delete __pIpcServer;
+ __pIpcServer = null;
+ return r;
+}
+
+void
+_PackageManagerStub::OnInstallPackage(const PackageId& packageId, const String& packagePath, int listener, result* pRes)
+{
+ SysTryReturnVoidResult(NID_APP, __pPackageManagerImpl != null, E_INVALID_STATE, "Invalid package manager state.");
+
+ *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_PACKAGEMANAGER_INSTALL);
+ SysTryReturnVoidResult(NID_APP, !IsFailed(*pRes), *pRes = E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+ //String appId;
+ //*pRes = __pPackageManagerImpl->InstallPackage(packageId, packagePath, (IPackageInstallationResponseListener*)listener);
+}
+
+void
+_PackageManagerStub::OnUninstallPackage(const PackageId& packageId, int listener, result* pRes)
+{
+ SysTryReturnVoidResult(NID_APP, __pPackageManagerImpl != null, E_INVALID_STATE, "Invalid package manager state.");
+
+ *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_PACKAGEMANAGER_INSTALL);
+ SysTryReturnVoidResult(NID_APP, !IsFailed(*pRes), *pRes = E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+ //*pRes = __pPackageManagerImpl->UninstallPackage(packageId, (IPackageUninstallationResponseListener*)listener);
+}
+
+///////////////////////////////////////////
+// ipc handlers
+///////////////////////////////////////////
+void
+_PackageManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
+{
+ SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
+
+ IPC_BEGIN_MESSAGE_MAP(_PackageManagerStub, message)
+ IPC_MESSAGE_HANDLER_EX(PackageManager_InstallPackage, &server, OnInstallPackage)
+ IPC_MESSAGE_HANDLER_EX(PackageManager_UninstallPackage, &server, OnUninstallPackage)
+ IPC_END_MESSAGE_MAP()
+}
+
+void
+_PackageManagerStub::OnIpcServerStarted(const _IpcServer& server)
+{
+ SysLog(NID_APP, "_PackageManagerStub::OnIpcServerStarted \n");
+}
+
+void
+_PackageManagerStub::OnIpcServerStopped(const _IpcServer& server)
+{
+ SysLog(NID_APP, "_PackageManagerStub::OnIpcServerStopped \n");
+}
+
+void
+_PackageManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
+{
+ SysLog(NID_APP, "_PackageManagerStub::OnIpcClientConnected (clientId:%d)\n", clientId);
+}
+
+void
+_PackageManagerStub::OnIpcClientDisconnected(const _IpcServer&server, int clientId)
+{
+ SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), clientId);
+}
+
+}} //namespace Tizen { namespace App {
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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 FIo_MmcStorageManagerService.cpp
+ * @brief This is the implementation for the _MmcStorageManagerService class.
+ */
+
+#include <unistd.h>
+#include <sys/mount.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unique_ptr.h>
+#include <sysman_managed.h>
+#include <vconf.h>
+
+#include <FIoFile.h>
+#include <FIoDirectory.h>
+#include <FIoMmcStorageManager.h>
+#include <FBaseSysLog.h>
+#include <FBaseInternalTypes.h>
+#include <FBase_StringConverter.h>
+#include <FAppTypes.h>
+#include "FIo_MmcStorageManagerService.h"
+#include "FIo_MmcStorageManagerStub.h"
+
+#define VCONFKEY_APPSERVICE_MMC_STATUS "memory/appservice/mmc"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Io;
+using namespace Tizen::App;
+
+struct mmc_contents mmcContents;
+
+namespace Tizen { namespace Io {
+
+_MmcStorageManagerService* _MmcStorageManagerService::__pMmcStorageManagerService = null;
+static const char _EXTERNAL_MOUNT_FLAG[] = "/tmp/osp-compat/mount/external";
+static const int _MAX_PATH_LENGTH = 256;
+
+result
+_MmcStorageManagerService::ConvertNativeErrorToResult(int errNo)
+{
+ SysLog(NID_IO, "ConvertNativeErrorToResult received : %d\n", errNo);
+ result r = E_SUCCESS;
+ //Covert the SLP response to Osp response
+ switch(errNo)
+ {
+ case 0:
+ r = E_SUCCESS;
+ break;
+
+ case EINVAL:
+ // fall through
+ case ENOENT:
+ r = E_IO;
+ break;
+
+ case ENOMEM:
+ r = E_OUT_OF_MEMORY;
+ break;
+
+ default:
+ r = E_SYSTEM;
+ }
+ return r;
+}
+
+//Callbacks from SLP. Its a C function.
+static void
+MmcMountCb(int response, void* data)
+{
+ SysLog(NID_IO, "MmcMountCb Called: %d\n", response);
+ result ospResult = E_SUCCESS;
+
+ ospResult = _MmcStorageManagerService::ConvertNativeErrorToResult(response);
+ SysTryLog(NID_IO, !IsFailed(ospResult), "[%s] Failed to mount MMC, errno: %d (%s)", GetErrorMessage(ospResult), response, strerror(response));
+ result r = ((_IMmcStorageServiceEventListener*)data)->OnMmcMountResponseReceived(ospResult);
+ SysTryReturnVoidResult(NID_IO, !IsFailed(r), r, "[%s] OnMmcMountResponseReceived failed.", GetErrorMessage(r));
+}
+
+static void
+MmcUnmountCb(int response, void* data)
+{
+ SysLog(NID_IO, "MmcUnmountCb Called: %d\n", response);
+ result ospResult = E_SUCCESS;
+
+ ospResult = _MmcStorageManagerService::ConvertNativeErrorToResult(response);
+ SysTryLog(NID_IO, !IsFailed(ospResult), "[%s] Failed to unmount MMC, errno: %d (%s)", GetErrorMessage(ospResult), response, strerror(response));
+ result r = ((_IMmcStorageServiceEventListener*)data)->OnMmcUnmountResponseReceived(ospResult);
+ SysTryReturnVoidResult(NID_IO, !IsFailed(r), r, "[%s] OnMmcUnmountResponseReceived failed.", GetErrorMessage(r));
+}
+
+static void
+MmcFormatCb(int response, void* data)
+{
+ SysLog(NID_IO, "MmcFormatCb Called: %d\n", response);
+ result ospResult = E_SUCCESS;
+
+ ospResult = _MmcStorageManagerService::ConvertNativeErrorToResult(response);
+ SysTryLog(NID_IO, !IsFailed(ospResult), "[%s] Failed to format MMC, errno: %d (%s)", GetErrorMessage(ospResult), response, strerror(response));
+ result r = ((_IMmcStorageServiceEventListener*)data)->OnMmcFormatResponseReceived(ospResult);
+ SysTryReturnVoidResult(NID_IO, !IsFailed(r), r, "[%s] OnMmcFormatResponseReceived failed.", GetErrorMessage(r));
+}
+
+_MmcStorageManagerService::_MmcStorageManagerService(void)
+ : __pStub(null)
+{
+}
+
+_MmcStorageManagerService::~_MmcStorageManagerService(void)
+{
+ int ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, MmcEventVconfCallback);
+}
+
+_MmcStorageManagerService*
+_MmcStorageManagerService::GetInstance(void)
+{
+ if (__pMmcStorageManagerService == null)
+ {
+ __pMmcStorageManagerService = new (std::nothrow) _MmcStorageManagerService();
+ }
+ return __pMmcStorageManagerService;
+}
+
+result
+_MmcStorageManagerService::Construct(_IMmcStorageServiceEventListener* pStub)
+{
+ __pStub = pStub;
+
+ int ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, MmcEventVconfCallback, this);
+ SysTryReturnResult(NID_IO, ret == 0, E_SYSTEM, "Failed to register MMC event vconf callback.");
+
+ return E_SUCCESS;
+}
+
+result
+_MmcStorageManagerService::Mount(void)
+{
+ int slpResult = 0;
+
+ mmcContents.mmc_cb = MmcMountCb;
+ mmcContents.user_data = __pStub;
+
+ slpResult = sysman_request_mount_mmc(&mmcContents);
+ SysTryReturnResult(NID_IO, slpResult == 0, E_SYSTEM, "Mount Failed. Slp sync return value: %d", slpResult);
+
+ return E_SUCCESS;
+}
+
+result
+_MmcStorageManagerService::Unmount(void)
+{
+ int slpResult = 0;
+
+ mmcContents.mmc_cb = MmcUnmountCb;
+ mmcContents.user_data = __pStub;
+
+ slpResult = sysman_request_unmount_mmc(&mmcContents, 1);
+ SysTryReturnResult(NID_IO, slpResult == 0, E_SYSTEM, "Unmount Failed. Slp sync return value: %d", slpResult);
+
+ return E_SUCCESS;
+}
+
+result
+_MmcStorageManagerService::Format(void)
+{
+ int slpResult = 0;
+
+ mmcContents.mmc_cb = MmcFormatCb;
+ mmcContents.user_data = __pStub;
+
+ slpResult = sysman_request_format_mmc(&mmcContents);
+ SysTryReturnResult(NID_IO, slpResult == 0, E_SYSTEM, "Format Failed. Slp sync return value: %d", slpResult);
+
+ return E_SUCCESS;
+}
+
+void
+_MmcStorageManagerService::MmcEventVconfCallback(keynode_t* node, void* userData)
+{
+ static char mountList[][_MAX_PATH_LENGTH] =
+ {
+ "/opt/storage/sdcard",
+ "/Storagecard/Media"
+ };
+ char mountPoint[_MAX_PATH_LENGTH] = { 0, };
+
+ if (strcmp(VCONFKEY_SYSMAN_MMC_STATUS, vconf_keynode_get_name(node)) == 0)
+ {
+ int value = 0;
+ int res = vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &value);
+ result r = E_SUCCESS;
+
+ _MmcStorageManagerService* pMmcMgr = static_cast< _MmcStorageManagerService* >(userData);
+ _AppList::const_iterator iter;
+ for (iter = pMmcMgr->__appList.begin(); iter != pMmcMgr->__appList.end(); ++iter)
+ {
+ const String* pAppRoot = iter->second;
+ if (pAppRoot != null)
+ {
+ std::unique_ptr< char[] > pAppRootPath(_StringConverter::CopyToCharArrayN(*pAppRoot));
+ SysTryReturnVoidResult(NID_IO, pAppRootPath != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+ char* pPkgId = strrchr(pAppRootPath.get(), '/');
+ char mountFlag[_MAX_PATH_LENGTH] = { 0, };
+ sprintf(mountFlag, "%s/%s", _EXTERNAL_MOUNT_FLAG, ++pPkgId);
+
+ if (value == 1)
+ {
+ SysLog(NID_IO, "MMC mount event for OSP compatible application.");
+
+ res = access(mountFlag, F_OK);
+ if (res == -1 && errno == ENOENT)
+ {
+ r = _MmcStorageManagerService::CreateFlag(mountFlag);
+ SysTryReturnVoidResult(NID_IO, !IsFailed(r), E_SYSTEM, "[%s] Failed to create mount flag (%s)",
+ GetErrorMessage(r), mountFlag);
+
+ if (access(pAppRootPath.get(), F_OK) == 0)
+ {
+ for (int i = 0; i < sizeof(mountList)/_MAX_PATH_LENGTH; ++i)
+ {
+ memset(mountPoint, 0, _MAX_PATH_LENGTH);
+ sprintf(mountPoint, "%ls%s", pAppRoot->GetPointer(), mountList[i]);
+#ifdef _OSP_EMUL_
+ res = mount("/dev/emul_mmcblk0", mountPoint, "ext3", 0, "");
+#else
+ res = mount("/dev/mmcblk1p1", mountPoint, "vfat", 0,
+ "uid=0,gid=0,dmask=0000,fmask=0111,iocharset=iso8859-1,utf8,shortname=mixed,smackfsroot=*,smackfsdef=*");
+#endif
+ if (res == -1)
+ {
+ SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] Failed to mount (%s), errno: %d (%s)",
+ mountPoint, errno, strerror(errno));
+
+ res = unlink(mountFlag);
+ SysTryReturnVoidResult(NID_IO, res == 0, E_SYSTEM, "[E_SYSTEM] Failed to remove mount flag (%s), errno: %d (%s)",
+ mountFlag, errno, strerror(errno));
+ }
+ }
+
+ r = _MmcStorageManagerService::CreateExternalDirectories(*pAppRoot, String(pPkgId));
+ SysTryReturnVoidResult(NID_IO, !IsFailed(r), E_SYSTEM, "[%s] Failed to create external directories.",
+ GetErrorMessage(r));
+
+ char mountSrc[_MAX_PATH_LENGTH] = { 0, };
+ char mountDest[_MAX_PATH_LENGTH] = { 0, };
+ sprintf(mountSrc, "/opt/storage/sdcard/osp/apps/%s", pPkgId);
+ sprintf(mountDest, "%ls/HomeExt", pAppRoot->GetPointer());
+ res = mount(mountSrc, mountDest, null, MS_BIND, null);
+ if (res == -1)
+ {
+ SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] Failed to mount (%s), errno: %d (%s)",
+ mountDest, errno, strerror(errno));
+
+ res = unlink(mountFlag);
+ SysTryReturnVoidResult(NID_IO, res == 0, E_SYSTEM, "[E_SYSTEM] Failed to remove mount flag (%s), errno: %d (%s)",
+ mountFlag, errno, strerror(errno));
+ }
+
+ SysLog(NID_IO, "mount() succeeded, mount flag: %s", mountFlag);
+ }
+ }
+ else if (res == -1)
+ {
+ SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] Failed to access mount flag (%s), errno: %d (%s)",
+ mountFlag, errno, strerror(errno));
+ return;
+ }
+ else
+ {
+ SysLog(NID_IO, "mount() was already done.");
+ }
+ }
+ else
+ {
+ SysLog(NID_IO, "MMC unmount event for OSP compatible application.");
+
+ for (int i = 0; i < sizeof(mountList)/_MAX_PATH_LENGTH; ++i)
+ {
+ memset(mountPoint, 0, _MAX_PATH_LENGTH);
+ sprintf(mountPoint, "%ls%s", pAppRoot->GetPointer(), mountList[i]);
+
+ res = umount2(mountPoint, MNT_DETACH);
+ SysTryLog(NID_IO, res == 0 || errno == ENOENT, "[E_SYSTEM] Failed to unmount (%s), errno: %d (%s)",
+ mountPoint, errno, strerror(errno));
+ }
+
+ char mountDest[_MAX_PATH_LENGTH] = { 0, };
+ sprintf(mountDest, "%ls/HomeExt", pAppRoot->GetPointer());
+ res = umount2(mountDest, MNT_DETACH);
+ SysTryLog(NID_IO, res == 0 || errno == ENOENT, "[E_SYSTEM] Failed to unmount (%s), errno: %d (%s)",
+ mountDest, errno, strerror(errno));
+
+ if (access(mountFlag, F_OK) == 0)
+ {
+ res = unlink(mountFlag);
+ SysTryReturnVoidResult(NID_IO, res == 0, E_SYSTEM, "[E_SYSTEM] Failed to remove mount flag (%s), errno: %d (%s)",
+ mountFlag, errno, strerror(errno));
+ }
+
+ if (access(pAppRootPath.get(), F_OK) != 0 && errno == ENOENT)
+ {
+ std::string key(pPkgId);
+ String* pAppRoot = pMmcMgr->__appList[key];
+ if (pAppRoot != null)
+ {
+ pMmcMgr->__appList.erase(key);
+ SysLog(NID_IO, "OSP compatible application is unregistered.");
+ }
+ }
+ SysLog(NID_IO, "unmount() succeeded, mount flag: %s", mountFlag);
+ }
+ }
+ }
+ res = vconf_set_int(VCONFKEY_APPSERVICE_MMC_STATUS, value);
+ }
+}
+
+result
+_MmcStorageManagerService::CreateFlag(const String& path)
+{
+ int index = 0;
+ result r = path.LastIndexOf(L'/', path.GetLength() - 1, index);
+ SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "The method cannot proceed due to a severe system error.");
+
+ String dirPath;
+ r = path.SubString(0, index, dirPath);
+ SysTryReturnResult(NID_IO, !IsFailed(r), E_SYSTEM, "The method cannot proceed due to a severe system error.");
+
+ if (!File::IsFileExist(dirPath) && GetLastResult() == E_SUCCESS)
+ {
+ r = Directory::Create(dirPath, true);
+ SysTryReturnResult(NID_IO, !IsFailed(r), r, "Failed to create parent directory.");
+ }
+
+ File file;
+ r = file.Construct(path, "w");
+ SysTryReturnResult(NID_IO, !IsFailed(r), r, "Failed to create mount flag.");
+
+ return E_SUCCESS;
+}
+
+result
+_MmcStorageManagerService::CreateExternalDirectories(const String& appRoot, const PackageId& pkgId)
+{
+ String appHomeExt(appRoot);
+ appHomeExt.Append("/HomeExt");
+ if (!File::IsFileExist(appHomeExt) && GetLastResult() == E_SUCCESS)
+ {
+ result r = Directory::Create(appHomeExt, false);
+ SysTryReturnResult(NID_IO, !IsFailed(r), r, "Failed to create application HomeExt directory.");
+ }
+
+ String mmcHomeExt(L"/opt/storage/sdcard/osp/apps/");
+ mmcHomeExt.Append(pkgId);
+ if (!File::IsFileExist(mmcHomeExt) && GetLastResult() == E_SUCCESS)
+ {
+ result r = Directory::Create(mmcHomeExt, true);
+ SysTryReturnResult(NID_IO, !IsFailed(r), r, "Failed to create MMC HomeExt directory.");
+ }
+
+ return E_SUCCESS;
+}
+
+}} // Tizen::Io
+
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FIo_MmcStorageManagerStub.cpp
+ * @brief This is the implementation for the _MmcStorageManagerStub class.
+ */
+
+#include <cstdio>
+#include <dlfcn.h>
+
+#include <FBaseSysLog.h>
+#include <FSystem.h>
+
+#include <FBase_StringConverter.h>
+#include <FIo_IpcServer.h>
+#include <FSec_AccessController.h>
+
+#include "FIo_MmcStorageManagerIpcMessages.h"
+#include "FIo_MmcStorageManagerService.h"
+#include "FIo_MmcStorageManagerStub.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Security;
+using namespace Tizen::System;
+
+namespace Tizen { namespace Io {
+
+///////////////////////////////////////////
+// _MmcStorageManagerStub
+///////////////////////////////////////////
+
+_MmcStorageManagerStub::_MmcStorageManagerStub()
+ : __pIpcServer(null)
+ , __pMmcStorageManagerService(null)
+ , __operationInProgress(false)
+{
+ SysLog(NID_IO, "_MmcStorageManagerStub - Enter\n");
+}
+
+_MmcStorageManagerStub::~_MmcStorageManagerStub()
+{
+ if ( __pIpcServer != null)
+ {
+ __pIpcServer->Stop();
+ delete __pIpcServer;
+ }
+
+ SysLog(NID_IO, "_MmcStorageManagerStub - Exit\n");
+}
+
+result
+_MmcStorageManagerStub::Construct(void)
+{
+ __pMmcStorageManagerService = _MmcStorageManagerService::GetInstance();
+ SysTryReturnResult(NID_IO, __pMmcStorageManagerService != null, E_OUT_OF_MEMORY, "Not enough memory.");
+
+ result r = E_SUCCESS;
+ r = __pMmcStorageManagerService->Construct(this);
+ SysTryReturn(NID_IO, !IsFailed(r), r, r, "failed to __pMmcStorageManagerService->Construct.(%s)", GetErrorMessage(r) );
+
+ r = StartIpcServer();
+ SysTryReturn(NID_IO, !IsFailed(r), r, r, "failed to StartIpcServer.(%s)", GetErrorMessage(r) );
+
+ return E_SUCCESS;
+}
+
+result
+_MmcStorageManagerStub::StartIpcServer(void)
+{
+ __pIpcServer = new (std::nothrow) _IpcServer();
+ SysTryReturnResult(NID_IO, __pIpcServer != null, E_OUT_OF_MEMORY, "Not enough memory.");
+
+ result r = __pIpcServer->Construct( "osp.io.ipcserver.mmcstoragemanager", *this);
+ SysTryCatch(NID_IO, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.io.ipcserver.mmcstoragemanager");
+
+ r = __pIpcServer->Start();
+ SysTryCatch(NID_IO, !IsFailed(r), , r, "[%s] Failed to Start IPC server(%s)", GetErrorMessage(r), "osp.io.ipcserver.mmcstoragemanager");
+
+ return E_SUCCESS;
+
+CATCH:
+ delete __pIpcServer;
+ __pIpcServer = null;
+ return r;
+}
+
+void
+_MmcStorageManagerStub::OnMount(result* pRes)
+{
+ SysTryReturnVoidResult(NID_IO, __pMmcStorageManagerService != null, E_INVALID_STATE, "Invalid Mmc storage manager state.");
+
+ *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_SYSTEMSETTING_READ);
+ SysTryReturnVoidResult(NID_IO, !IsFailed(*pRes), *pRes = E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+ if (__operationInProgress == true)
+ {
+ SysLog(NID_IO, "Operation is in-progress.\n");
+ *pRes = E_SERVICE_BUSY;
+ return;
+ }
+
+ String state;
+
+ result r = DeviceManager::GetState(DEVICE_TYPE_STORAGE_CARD, state);
+ SysTryReturnVoidResult(NID_IO, !IsFailed(r), r, "[%s] Propagated.", GetErrorMessage(r));
+
+ if (state == String(L"Mounted"))
+ {
+ SysLog(NID_IO, "Already Mounted.\n");
+ *pRes = E_INVALID_OPERATION;
+ return;
+ }
+ __operationInProgress = true;
+
+ *pRes = __pMmcStorageManagerService->Mount();
+}
+
+void
+_MmcStorageManagerStub::OnUnmount(result* pRes)
+{
+ SysTryReturnVoidResult(NID_IO, __pMmcStorageManagerService != null, E_INVALID_STATE, "Invalid Mmc storage manager state.");
+
+ *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_SYSTEMSETTING_READ);
+ SysTryReturnVoidResult(NID_IO, !IsFailed(*pRes), *pRes = E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+ if (__operationInProgress == true)
+ {
+ SysLog(NID_IO, "Operation is in-progress.\n");
+ *pRes = E_SERVICE_BUSY;
+ return;
+ }
+
+ String state;
+
+ result r = DeviceManager::GetState(DEVICE_TYPE_STORAGE_CARD, state);
+ SysTryReturnVoidResult(NID_IO, !IsFailed(r), *pRes = r, "[%s] Propagated.", GetErrorMessage(r));
+
+ if (state != String(L"Mounted"))
+ {
+ SysLog(NID_IO, "Already Unmounted.\n");
+ *pRes = E_INVALID_OPERATION;
+ return;
+ }
+ __operationInProgress = true;
+
+ *pRes = __pMmcStorageManagerService->Unmount();
+}
+
+void
+_MmcStorageManagerStub::OnFormat(result* pRes)
+{
+ SysTryReturnVoidResult(NID_IO, __pMmcStorageManagerService != null, E_INVALID_STATE, "Invalid Mmc storage manager state.");
+
+ *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_SYSTEMSETTING_READ);
+ SysTryReturnVoidResult(NID_IO, !IsFailed(*pRes), *pRes = E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+ if (__operationInProgress == true)
+ {
+ SysLog(NID_IO, "Operation is in-progress.\n");
+ *pRes = E_SERVICE_BUSY;
+ return;
+ }
+
+ String state;
+
+ result r = DeviceManager::GetState(DEVICE_TYPE_STORAGE_CARD, state);
+ SysTryReturnVoidResult(NID_IO, !IsFailed(r), *pRes = r, "[%s] Propagated.", GetErrorMessage(r));
+
+ if (state != String(L"Unmounted"))
+ {
+ SysLog(NID_IO, "MMC is not Unmounted. Unmount it first.");
+ *pRes = E_INVALID_OPERATION;
+ return;
+ }
+ __operationInProgress = true;
+
+ *pRes = __pMmcStorageManagerService->Format();
+}
+
+///////////////////////////////////////////
+// ipc handlers
+///////////////////////////////////////////
+void
+_MmcStorageManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
+{
+ SysLog(NID_IO, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
+
+ IPC_BEGIN_MESSAGE_MAP(_MmcStorageManagerStub, message)
+ IPC_MESSAGE_HANDLER_EX(MmcStorageManager_Mount, &server, OnMount)
+ IPC_MESSAGE_HANDLER_EX(MmcStorageManager_Unmount, &server, OnUnmount)
+ IPC_MESSAGE_HANDLER_EX(MmcStorageManager_Format, &server, OnFormat)
+ IPC_END_MESSAGE_MAP()
+}
+
+void
+_MmcStorageManagerStub::OnIpcServerStarted(const _IpcServer& server)
+{
+ SysLog(NID_IO, "_MmcStorageManagerStub::OnIpcServerStarted \n");
+}
+
+void
+_MmcStorageManagerStub::OnIpcServerStopped(const _IpcServer& server)
+{
+ SysLog(NID_IO, "_MmcStorageManagerStub::OnIpcServerStopped \n");
+}
+
+void
+_MmcStorageManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
+{
+ __clientId = clientId;
+ SysLog(NID_IO, "_MmcStorageManagerStub::OnIpcClientConnected (clientId:%d)\n", clientId);
+}
+
+void
+_MmcStorageManagerStub::OnIpcClientDisconnected(const _IpcServer&server, int clientId)
+{
+ SysLog(NID_IO, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), clientId);
+}
+
+//Server to Client message
+result
+_MmcStorageManagerStub::OnMmcMountResponseReceived(result response)
+{
+ SysLog(NID_IO, "Response msg is : [%s]\n", GetErrorMessage(response));
+
+ __operationInProgress = false;
+
+ SysTryReturnResult(NID_IO, __pIpcServer != null, E_INVALID_STATE, "__pIpcServer is null.");
+
+ result r = __pIpcServer->SendResponse(__clientId, new MmcStorageManager_MountReceived(response));
+ SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
+
+ return r;
+}
+
+result
+_MmcStorageManagerStub::OnMmcUnmountResponseReceived(result response)
+{
+ SysLog(NID_IO, "Response msg is : [%s]\n", GetErrorMessage(response));
+
+ __operationInProgress = false;
+
+ SysTryReturnResult(NID_IO, __pIpcServer != null, E_INVALID_STATE, "__pIpcServer is null.");
+
+ result r = __pIpcServer->SendResponse(__clientId, new MmcStorageManager_UnmountReceived(response));
+ SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
+
+ return r;
+}
+
+result
+_MmcStorageManagerStub::OnMmcFormatResponseReceived(result response)
+{
+ SysLog(NID_IO, "Response msg is : [%s]\n", GetErrorMessage(response));
+
+ __operationInProgress = false;
+
+ SysTryReturnResult(NID_IO, __pIpcServer != null, E_INVALID_STATE, "__pIpcServer is null.");
+
+ result r = __pIpcServer->SendResponse(__clientId, new MmcStorageManager_FormatReceived(response));
+ SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
+
+ return r;
+}
+
+}} //namespace Tizen { namespace Io {
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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://floralicense.org/license/
+//
+// 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 FSys_AccessoryManagerService.cpp
+ * @brief This is the implementation file for _AccessoryManagerService class.
+ */
+
+#include <new>
+#include <FBaseSysLog.h>
+#include <FBaseRtLibrary.h>
+
+#include "FSys_AccessoryManagerService.h"
+#include "FApp_CommunicationDispatcher.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Io;
+using namespace Tizen::System;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Runtime;
+
+namespace {
+ const String ACCESSORY_MANAGER_SERVICE_ID = L"osp.accessorymanager.service";
+ const String ACCESSORY_PLUGIN_LIBRARY_PATH = L"/opt/apps/aospd00043/lib/libosp-cond-accessory.so";
+}
+
+typedef result (*SendDataFunction)(Tizen::App::AppId appId, Tizen::Base::Collection::ArrayList* data);
+typedef void (*RegisterSendDataFunction)(SendDataFunction function);
+
+_AccessoryManagerService* gpAccessoryManagerService = null;
+
+result
+SendDataFunc(AppId appId, ArrayList* data)
+{
+ SysLog(NID_SYS, "Request to send data");
+ SysTryReturnResult(NID_SYS, gpAccessoryManagerService != null, E_SYSTEM, "AccessoryManagerService is not ready");
+ return gpAccessoryManagerService->SendData(appId, data);
+}
+
+_AccessoryManagerService*
+_AccessoryManagerService::GetInstance()
+{
+ if(gpAccessoryManagerService == null)
+ {
+ gpAccessoryManagerService = new (std::nothrow) _AccessoryManagerService();
+ }
+ return gpAccessoryManagerService;
+}
+
+_AccessoryManagerService::_AccessoryManagerService()
+ : _ICommunicationRequestListener()
+ , __pLib(null)
+ , __pCommunicationDispatcher(null)
+ , __pOnRequestOccuredFunction(null)
+ , __pRemoveOwnerApplicationFunction(null)
+{
+ result r = E_SUCCESS;
+ RegisterSendDataFunction pRegisterSendDataFunction;
+
+ __pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
+ SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "Failed to get _CommunicationDispatcher");
+
+ r = __pCommunicationDispatcher->AddCommunicationEventListener(*this);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to add event listener on _CommunicationDispatcher");
+
+ __pLib = new Library();
+ r = __pLib->Construct(ACCESSORY_PLUGIN_LIBRARY_PATH);
+ SysTryCatch(NID_APP, !IsFailed(r),, r, "dlopen fails (%s)", GetErrorMessage(r));
+
+ pRegisterSendDataFunction = (RegisterSendDataFunction)__pLib->GetProcAddress(L"RegisterSendData");
+ SysTryCatch(NID_APP, pRegisterSendDataFunction != null, r = E_SYSTEM, E_SYSTEM, "Failed to find RegisterSendDataFunction");
+
+ __pOnRequestOccuredFunction = (OnRequestOccuredFunction)__pLib->GetProcAddress(L"OnRequestOccured");
+ SysTryCatch(NID_APP, __pOnRequestOccuredFunction != null, r = E_SYSTEM, E_SYSTEM, "Failed to find OnRequestOccuredFunction");
+
+ __pRemoveOwnerApplicationFunction = (RemoveOwnerApplicationFunction)__pLib->GetProcAddress(L"RemoveOwnerApplication");
+ SysTryCatch(NID_APP, __pRemoveOwnerApplicationFunction != null, r = E_SYSTEM, E_SYSTEM, "Failed to find OnRequestOccuredFunction");
+
+ pRegisterSendDataFunction(SendDataFunc);
+
+CATCH:
+ SetLastResult(r);
+}
+
+_AccessoryManagerService::~_AccessoryManagerService()
+{
+ result r = E_SUCCESS;
+
+ SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher is not initiated.");
+
+ r = __pCommunicationDispatcher->RemoveCommunicationEventListener(*this);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to remove event listener on _CommunicationDispatcher");
+
+CATCH:
+ SetLastResult(r);
+
+}
+
+result
+_AccessoryManagerService::SendData(AppId appId, ArrayList* data)
+{
+ SysTryReturnResult(NID_SYS, __pCommunicationDispatcher != null, E_SYSTEM, "_CommunicationDispatcher is not initiated.");
+
+ return __pCommunicationDispatcher->SendData(appId, *data);
+}
+
+String
+_AccessoryManagerService::GetId(void)
+{
+ return ACCESSORY_MANAGER_SERVICE_ID;
+}
+
+void
+_AccessoryManagerService::OnRequestOccured(AppId appId, ArrayList* request, ArrayList* response)
+{
+ result r = E_SUCCESS;
+ SysTryCatch(NID_SYS, __pOnRequestOccuredFunction != null, r = E_SYSTEM, E_SYSTEM, "There is no OnRequestOccuredFunction");
+
+ SysLog(NID_SYS, "AppId is [%ls]", appId.GetPointer());
+ __pOnRequestOccuredFunction(appId, request, response);
+
+CATCH:
+ SetLastResult(r);
+}
+
+void
+_AccessoryManagerService::OnApplicationTerminated(const AppId& appId, _AppType type)
+{
+ result r = E_SUCCESS;
+ SysTryCatch(NID_SYS, __pRemoveOwnerApplicationFunction != null, r = E_SYSTEM, E_SYSTEM, "There is no RemoveOwnerApplicationFunction");
+
+ __pRemoveOwnerApplicationFunction(appId, L"");
+CATCH:
+ SetLastResult(r);
+}
+
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FSys_AlarmService.cpp
+ * @brief This is the implementation file for _AlarmService class.
+ */
+
+#include <unique_ptr.h>
+#include <new>
+#include <appfw/app.h>
+
+#include <FBaseRtLibrary.h>
+#include <FBaseSysLog.h>
+
+#include <FSec_AccessController.h>
+#include <FSys_SystemTimeImpl.h>
+#include <FAppPkg_PackageManagerImpl.h>
+#include "FApp_CommunicationDispatcher.h"
+#include "FSys_AlarmService.h"
+
+using namespace std;
+
+using namespace Tizen::App;
+using namespace Tizen::App::Package;
+using namespace Tizen::Io;
+using namespace Tizen::System;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Security;
+
+namespace {
+ const String _ALARM_ALARM_SERVICE_ID = L"osp.alarm.service";
+ const String _ALARM_SET_SINGLEALARM = L"osp.alarm.set.singlealarm";
+ const String _ALARM_SET_REPEATEDALARM = L"osp.alarm.set.repeatedalarm";
+ const String _ALARM_CANCEL = L"osp.alarm.cancel";
+ const String _ALARM_NONE = L"osp.alarm.none";
+ const String _ALARM_EXPIRY_EVENT = L"osp.alarm.expired.callback";
+ const String _ALARM_RESULT_OK = L"osp.alarm.result.ok";
+ const String _ALARM_RESULT_ERROR = L"osp.alarm.result.error";
+
+ static const long _SECOND_OF_MINUTE = 60;
+ static const long _ADJUST_MONTH_FOR_TM = 1;
+ static const long _ADJUST_YEAR_FOR_TM = 1900;
+ static const int _ALARM_SERVICE_ID = 0;
+ static const int _ALARM_COMMAND_ID = 1;
+ static const int _ALARM_CANCEL_ID = 2;
+ static const int _ALARM_START_TIME = 2;
+ static const int _ALARM_PERIOD = 3;
+ static const int _ALARM_END_TIME = 4;
+
+ static const wchar_t* ALARM_PLUGIN_LIBRARY_PATH = L"/opt/apps/aospd00043/lib/libosp-cond-alarm.so";
+}
+
+Tizen::System::_AlarmService* Tizen::System::_AlarmService::__pAlarmService = null;
+typedef void (*OnAlarmForLaunch)(int alarmId);
+
+_AlarmService::_AlarmService()
+ : _ICommunicationRequestListener()
+ , __pCommunicationDispatcher(null)
+ , __pAlarmHashMap(null)
+ , __endTime()
+{
+ result r = E_SUCCESS;
+
+ __pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
+ SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher initiate is failed");
+
+ r = __pCommunicationDispatcher->AddCommunicationEventListener(*this);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "fail to add event listener");
+
+ if (!__pAlarmHashMap)
+ {
+ __pAlarmHashMap = new (std::nothrow) MultiHashMap();
+ SysTryCatch(NID_SYS, __pAlarmHashMap != null, r = E_SYSTEM, E_SYSTEM, "__pAlarmHashMap should not be null");
+
+ r = __pAlarmHashMap->Construct();
+ SysTryCatch(NID_SYS, !IsFailed(r), r= E_SYSTEM, E_SYSTEM, "[%s] Propagated.", GetErrorMessage(r));
+ }
+
+ //Checks for any alarm existence
+ alarm_cancel_all();
+
+CATCH:
+ SetLastResult(r);
+}
+
+_AlarmService::~_AlarmService()
+{
+ result r = E_SUCCESS;
+
+ SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher is not ready");
+
+ r = __pCommunicationDispatcher->RemoveCommunicationEventListener(*this);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "fail to remove event listener");
+
+ SysLog(NID_SYS, "Alarm Service destruct to cancel all alarms.");
+
+ //Cancel all the alarms before exiting
+ alarm_cancel_all();
+
+ delete __pAlarmHashMap;
+ __pAlarmHashMap = null;
+
+CATCH:
+ SetLastResult(r);
+}
+
+_AlarmService*
+_AlarmService::GetInstance(void)
+{
+ if(__pAlarmService == null)
+ {
+ __pAlarmService = new (std::nothrow) _AlarmService();
+ }
+ return __pAlarmService;
+}
+
+String
+_AlarmService::GetId(void)
+{
+ return _ALARM_ALARM_SERVICE_ID;
+}
+
+int
+_AlarmService::ReserveAlarm(Tizen::Base::DateTime startTime, int period)
+{
+ int reservedAlarmId = -1;
+ struct tm expireTime = {0,};
+ result r = E_SUCCESS;
+
+ int ret = 0;
+ char* packageName = null;
+ service_h service;
+
+ SysLog(NID_SYS, "Reserve time is %d/%d/%d %d:%d:%d", startTime.GetYear(), startTime.GetMonth(), startTime.GetDay(), startTime.GetHour(), startTime.GetMinute(), startTime.GetSecond());
+
+ expireTime.tm_year = startTime.GetYear() - _ADJUST_YEAR_FOR_TM;
+ expireTime.tm_mon = startTime.GetMonth() - _ADJUST_MONTH_FOR_TM;
+ expireTime.tm_mday = startTime.GetDay();
+ expireTime.tm_hour = startTime.GetHour();
+ expireTime.tm_min = startTime.GetMinute();
+ expireTime.tm_sec = startTime.GetSecond();
+
+ ret = service_create(&service);
+ SysTryCatch(NID_SYS, ret == SERVICE_ERROR_NONE, r = E_SYSTEM, r, "Failed to create service");
+
+ ret = app_get_package(&packageName);
+ SysTryCatch(NID_SYS, ret == APP_ERROR_NONE, r = E_SYSTEM, r, "Failed to get package name");
+
+ ret = service_set_operation(service, "osp.appsvc.operation.ALARM");
+ SysTryCatch(NID_SYS, ret == SERVICE_ERROR_NONE, r = E_SYSTEM, r, "Failed to set operation");
+
+ ret = service_set_package(service, packageName);
+ SysTryCatch(NID_SYS, ret == SERVICE_ERROR_NONE, r = E_SYSTEM, r, "Failed to create service for %s", packageName);
+
+ ret = alarm_schedule_at_date(service, &expireTime, period * _SECOND_OF_MINUTE, &reservedAlarmId);
+ SysTryCatch(NID_SYS, ret == ALARM_ERROR_NONE, r = E_SYSTEM, r, "Failed to set the Alarm time for %s", packageName);
+
+ SysLog(NID_SYS, "Alarm is reserved for %s. AlarmId is %d.", packageName, reservedAlarmId);
+
+CATCH:
+ if(r == E_SYSTEM)
+ {
+ if(packageName != null)
+ {
+ SysLog(NID_SYS, "Fail to reserve Alarm for %s", packageName);
+ }
+ reservedAlarmId = -1;
+ }
+
+ if(packageName != null)
+ {
+ free (packageName);
+ }
+
+ if(service != null)
+ {
+ service_destroy(service);
+ }
+
+ return reservedAlarmId;
+}
+
+result
+_AlarmService::AddAlarmList(int alarmId, int period, String appId, DateTime* endTime)
+{
+ result r = E_SUCCESS;
+
+ SysTryReturnResult(NID_SYS, __pAlarmHashMap != null, E_SYSTEM, "Alarm list does not initialized");
+ SysLog(NID_SYS, "New Alarm Id is added (%d, %d, %ls)", alarmId, period, appId.GetPointer());
+
+ Integer* reservedAlarmId = null;
+ Integer* alarmPeriod = null;
+ String* alarmAppId = null;
+
+ Integer* reverseAlarmId = null;
+ String* reverseAppId = null;
+
+ reservedAlarmId = new (std::nothrow) Integer(alarmId);
+ SysTryCatch(NID_SYS, reservedAlarmId != null, r = E_SYSTEM, E_SYSTEM, "reservedAlarmId should not be null");
+
+ alarmPeriod = new (std::nothrow) Integer(period);
+ SysTryCatch(NID_SYS, alarmPeriod != null, r = E_SYSTEM, E_SYSTEM, "alarmPeriod should not be null");
+
+ alarmAppId = new (std::nothrow) String(appId);
+ SysTryCatch(NID_SYS, alarmAppId != null, r = E_SYSTEM, E_SYSTEM, "alarmAppId should not be null");
+
+ //Forward
+ r = __pAlarmHashMap->Add(*reservedAlarmId, *alarmAppId);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r, r, "Fail to add new alarm app id on the alarm list");
+
+ r = __pAlarmHashMap->Add(*reservedAlarmId, *alarmPeriod);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r, r, "Fail to add new alarm period on the alarm list");
+
+ if(endTime != null)
+ {
+ DateTime* alarmEndTime = new DateTime(*endTime);
+
+ SysLog(NID_SYS, "Endtime is exist %d:%d:%d", alarmEndTime->GetHour(), alarmEndTime->GetMinute(), alarmEndTime->GetSecond());
+ r = __pAlarmHashMap->Add(*reservedAlarmId, *alarmEndTime);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r, r, "Fail to add new alarm endtime on the alarm list");
+ }
+
+ //Reverse
+ reverseAlarmId = new (std::nothrow) Integer(alarmId);
+ SysTryCatch(NID_SYS, reverseAlarmId != null, r = E_SYSTEM, E_SYSTEM, "reverseAlarmId should not be null");
+
+ reverseAppId = new (std::nothrow) String(appId);
+ SysTryCatch(NID_SYS, reverseAppId != null, r = E_SYSTEM, E_SYSTEM, "reverseAppId should not be null");
+
+ r = __pAlarmHashMap->Add(*reverseAppId, *reverseAlarmId);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r, r, "Fail to add new alarm on the alarm list");
+CATCH:
+ if(r != E_SUCCESS)
+ {
+ if(reservedAlarmId != null)
+ {
+ __pAlarmHashMap->Remove(*reservedAlarmId, false);
+ delete reservedAlarmId;
+ }
+
+ if(alarmPeriod != null)
+ {
+ delete alarmPeriod;
+ }
+
+ if(alarmAppId != null)
+ {
+ delete alarmAppId;
+ }
+
+ if(reverseAppId != null)
+ {
+ __pAlarmHashMap->Remove(*reverseAppId, false);
+ delete reverseAppId;
+ }
+
+ if(reverseAlarmId != null)
+ {
+ delete reverseAlarmId;
+ }
+ }
+ return r;
+}
+
+result
+_AlarmService::RemoveAlarmList(int alarmId)
+{
+ result r = E_SUCCESS;
+ Integer requiredAlarmId(alarmId);
+ unique_ptr<IEnumerator>pValueEnum(null);
+
+ SysTryReturnResult(NID_SYS, __pAlarmHashMap != null, E_SYSTEM, "Alarm list does not initialized");
+
+ alarm_cancel(alarmId);
+ SysLog(NID_SYS, "AlarmId %d disarms the timer.", alarmId);
+
+ pValueEnum.reset(__pAlarmHashMap->GetValuesN(requiredAlarmId));
+
+ if(pValueEnum != null)
+ {
+ SysLog(NID_SYS, "Reserved Alarms are exist");
+ String* alarmAppId = null;
+ r = pValueEnum->MoveNext();
+ SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "Reserved Alarm List is not valid.");
+ alarmAppId = static_cast< String* >(pValueEnum->GetCurrent());
+
+ if(alarmAppId != null)
+ {
+ SysLog(NID_SYS, "Alarm AppId is %S", alarmAppId->GetPointer());
+ unique_ptr<IEnumerator>pAlarmEnum(__pAlarmHashMap->GetValuesN(*alarmAppId));
+ if(pAlarmEnum != null)
+ {
+ while(pAlarmEnum->MoveNext() == E_SUCCESS)
+ {
+ Integer* reverseAlarmId = static_cast< Integer* >(pAlarmEnum->GetCurrent());
+ if(reverseAlarmId != null)
+ {
+ SysLog(NID_SYS, "Reserved Alarm is %d", reverseAlarmId->ToInt());
+ if(reverseAlarmId->ToInt() == alarmId)
+ {
+ SysLog(NID_SYS, "Remove reservedAlarmId for reverse look-up");
+ __pAlarmHashMap->Remove(*alarmAppId, *reverseAlarmId);
+ delete reverseAlarmId;
+ break;
+ }
+ }
+ }
+ }
+
+ int count = 0;
+ __pAlarmHashMap->GetCount(*alarmAppId, count);
+ if(count == 0)
+ {
+ SysLog(NID_SYS, "There is no reserved alarm for AppId:%S", alarmAppId->GetPointer());
+ __pAlarmHashMap->Remove(*alarmAppId, true);
+ }
+ }
+ }
+ r = __pAlarmHashMap->Remove(requiredAlarmId, true);
+ return r;
+}
+
+result
+_AlarmService::RemoveAlarmList(String appId)
+{
+ result r = E_SUCCESS;
+ Integer requiredAlarmId;
+ IEnumerator *pValueEnum = null;
+
+ SysTryReturnResult(NID_SYS, __pAlarmHashMap != null, E_SYSTEM, "Alarm list does not initialized");
+ pValueEnum = __pAlarmHashMap->GetValuesN(appId);
+
+ if(pValueEnum != null)
+ {
+ SysLog(NID_SYS, "Reserved Alarms are exist for AppId:%S", appId.GetPointer());
+ while(pValueEnum->MoveNext() == E_SUCCESS)
+ {
+ Integer* reverseAlarmId = static_cast< Integer* >(pValueEnum->GetCurrent());
+ if(reverseAlarmId != null)
+ {
+ SysLog(NID_SYS, "Reserved AlarmId is %d", reverseAlarmId->ToInt());
+ alarm_cancel(reverseAlarmId->ToInt());
+ __pAlarmHashMap->Remove(*reverseAlarmId, true);
+ }
+ }
+ delete pValueEnum;
+ }
+ r = __pAlarmHashMap->Remove(appId, true);
+
+ return r;
+}
+
+void
+_AlarmService::OnRequestOccured(AppId appId, ArrayList* request, ArrayList* response)
+{
+ result r = E_SUCCESS;
+
+ String* serviceId = null;
+ String* commandId = null;
+ String* result = null;
+ int reservedAlarmId = 0;
+
+ SysTryReturnVoidResult(NID_SYS, request != null && response != null, E_INVALID_ARG, "This is critical issue. Parameters are null");
+
+ serviceId = new (std::nothrow) String(_ALARM_ALARM_SERVICE_ID);
+ SysTryReturnVoidResult(NID_SYS, serviceId != null, E_SYSTEM, "This is critical issue. serviceId should not be null");
+
+ String* alarmCommand = null;
+
+ alarmCommand = (String*)request->GetAt(_ALARM_COMMAND_ID);
+ SysTryCatch(NID_SYS, alarmCommand != null, r = E_INVALID_ARG, E_INVALID_ARG, "Parameters has no command %x", alarmCommand);
+
+ if(*alarmCommand == _ALARM_SET_SINGLEALARM || *alarmCommand == _ALARM_SET_REPEATEDALARM)
+ {
+ SysLog(NID_SYS, "Alarm setting request");
+ int period = 0;
+
+ if(*alarmCommand == _ALARM_SET_SINGLEALARM)
+ {
+ SysLog(NID_SYS, "Single Alarm setting request");
+ commandId = new (std::nothrow) String(_ALARM_SET_SINGLEALARM);
+ SysTryCatch(NID_SYS, commandId != null, r = E_SYSTEM, E_SYSTEM, "commandId should not be null");
+ }
+ else
+ {
+ SysLog(NID_SYS, "Repeated Alarm setting request");
+ commandId = new (std::nothrow) String(_ALARM_SET_REPEATEDALARM);
+ SysTryCatch(NID_SYS, commandId != null, r = E_SYSTEM, E_SYSTEM, "commandId should not be null");
+
+ String* periodArg = (String*)request->GetAt(_ALARM_PERIOD);
+ SysTryCatch(NID_SYS, commandId != null, r = E_SYSTEM, E_SYSTEM, "Period should not be null");
+ Integer::Parse(*periodArg, period);
+ SysLog(NID_SYS, "period value parse done");
+ }
+
+ DateTime startTime;
+ DateTime currentTime;
+ DateTime endTime;
+
+ String* startTimeArg = (String*)request->GetAt(_ALARM_START_TIME);
+ SysLog(NID_SYS, "Alarm requested start time is %S", startTimeArg->GetPointer());
+
+ DateTime::Parse(*startTimeArg, startTime);
+ SysLog(NID_SYS, "Starttime Parse result: %d-%d-%d %d:%d:%d", startTime.GetYear(), startTime.GetMonth(), startTime.GetDay(), startTime.GetHour(), startTime.GetMinute(), startTime.GetSecond());
+
+ String* endTimeArg = (String*)request->GetAt(_ALARM_END_TIME);
+
+ if(endTimeArg != null)
+ {
+ DateTime::Parse(*endTimeArg, endTime);
+ SysLog(NID_SYS, "Endtime Parse result: %d-%d-%d %d:%d:%d", startTime.GetYear(), startTime.GetMonth(), startTime.GetDay(), startTime.GetHour(), startTime.GetMinute(), startTime.GetSecond());
+ }
+
+ r = _SystemTimeImpl::GetCurrentTime(WALL_TIME, currentTime);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "Failed to get current Time.");
+
+ SysTryCatch(NID_SYS, startTime.CompareTo(currentTime) > 0, r = E_SYSTEM, E_SYSTEM, "Requested time has to be greater then current time: %d-%d-%d %d:%d:%d", currentTime.GetYear(), currentTime.GetMonth(), currentTime.GetDay(), currentTime.GetHour(), currentTime.GetMinute(), currentTime.GetSecond());
+
+ reservedAlarmId = ReserveAlarm(startTime, period);
+
+ SysLog(NID_SYS, "Reserved AppId %S", appId.GetPointer());
+ if(reservedAlarmId != -1)
+ {
+ if(endTimeArg == null)
+ {
+ r = AddAlarmList(reservedAlarmId, period, appId, null);
+ }
+ else
+ {
+ r = AddAlarmList(reservedAlarmId, period, appId, &endTime);
+ }
+ }
+ else
+ {
+ r = E_SYSTEM;
+ }
+
+ }
+ else if(*alarmCommand == _ALARM_CANCEL)
+ {
+ SysLog(NID_SYS, "Alarm Cancel request");
+
+ int alarmId = 0;
+
+ commandId = new (std::nothrow) String(_ALARM_CANCEL);
+ SysTryCatch(NID_SYS, commandId != null, r = E_SYSTEM, E_SYSTEM, "commandId should not be null");
+
+ String* removableAlarmId = (String*)request->GetAt(_ALARM_CANCEL_ID);
+
+ r = Integer::Parse(*removableAlarmId, alarmId);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "Failed to parse alarm id");
+
+ r = RemoveAlarmList(alarmId);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r, r, "Failed to parse alarm id");
+
+ }
+ else
+ {
+ commandId = new (std::nothrow) String(_ALARM_NONE);
+ SysTryCatch(NID_SYS, commandId != null, r = E_SYSTEM, E_SYSTEM, "commandId should not be null");
+ r = E_SYSTEM;
+ }
+
+CATCH:
+ response->Add(*serviceId);
+
+ if(r == E_SUCCESS)
+ {
+ result = new (std::nothrow) String(_ALARM_RESULT_OK);
+ response->Add(*commandId);
+ response->Add(*result);
+ if(reservedAlarmId != -1)
+ {
+ String* tempAlarmId = new (std::nothrow) String();
+ tempAlarmId->Append(reservedAlarmId);
+ response->Add(tempAlarmId);
+ }
+ }
+ else if(r == E_SYSTEM)
+ {
+ result = new (std::nothrow) String(_ALARM_RESULT_ERROR);
+ response->Add(*commandId);
+ response->Add(*result);
+ }
+ else if(r == E_OBJ_NOT_FOUND)
+ {
+ result = new (std::nothrow) String(_ALARM_RESULT_ERROR);
+ response->Add(*commandId);
+ response->Add(*result);
+ }
+ else
+ {
+ result = new (std::nothrow) String(_ALARM_RESULT_ERROR);
+ if(commandId == null)
+ {
+ commandId = new (std::nothrow) String(_ALARM_NONE);
+ }
+ response->Add(*commandId);
+ response->Add(*result);
+ }
+
+ SetLastResult(r);
+}
+
+void
+_AlarmService::OnAlarmExpired(int alarmId)
+{
+ result r = E_SUCCESS;
+ String* pAppId = null;
+ Integer* pPeriod = null;
+ unique_ptr<IEnumerator> pValueEnum(null);
+ Integer requiredAlarmId(alarmId);
+ DateTime* endTime = null;
+
+ SysTryReturnVoidResult(NID_SYS, __pAlarmHashMap != null, E_SYSTEM, "Alarm list does not initialized");
+
+ pValueEnum.reset(__pAlarmHashMap->GetValuesN(requiredAlarmId));
+
+ if(pValueEnum != null)
+ {
+ String alarmAppId;
+ SysLog(NID_SYS, "Matching Alarm Id is %d \n", alarmId);
+ r = pValueEnum->MoveNext();
+ SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "Alarm enum value is not valid.");
+ pAppId = static_cast< String* >(pValueEnum->GetCurrent());
+ alarmAppId.Append(*pAppId);
+ r = pValueEnum->MoveNext();
+ pPeriod = static_cast< Integer* >(pValueEnum->GetCurrent());
+ SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "Alarm enum value is not valid.");
+
+ if(pValueEnum->MoveNext() == E_SUCCESS)
+ {
+ endTime = static_cast< DateTime* >(pValueEnum->GetCurrent());
+ }
+
+ SysLog(NID_SYS, "Reserved Alarm AppId:%ls, Period:%d\n", pAppId->GetPointer(), pPeriod->ToInt());
+
+ if (pPeriod->ToInt() > 0)
+ {
+ if(endTime != null)
+ {
+ DateTime currentTime;
+ _SystemTimeImpl::GetCurrentTime(WALL_TIME, currentTime);
+ SysLog(NID_SYS, "Current time: %d:%d:%d", currentTime.GetHour(), currentTime.GetMinute(), currentTime.GetSecond());
+ currentTime.AddMinutes(pPeriod->ToInt());
+ SysLog(NID_SYS, "Next time: %d:%d:%d", currentTime.GetHour(), currentTime.GetMinute(), currentTime.GetSecond());
+ SysLog(NID_SYS, "Endtime is exist %d:%d:%d", endTime->GetHour(), endTime->GetMinute(), endTime->GetSecond());
+
+ if (currentTime.CompareTo(*endTime) >= 0)
+ {
+ SysLog(NID_SYS, "Next time is greater then end time.");
+ RemoveAlarmList(alarmId);
+ pValueEnum->Reset();
+ }
+ }
+ }
+ else if (pPeriod->ToInt() == 0)
+ {
+ RemoveAlarmList(alarmId);
+ }
+ else
+ {
+ pValueEnum->Reset();
+ return;
+ }
+
+ SysLog(NID_SYS, "Alarm Id match and need to call IPC callback. (%S)", alarmAppId.GetPointer());
+ ArrayList data;
+ String serviceId(_ALARM_ALARM_SERVICE_ID);
+ String commandId(_ALARM_EXPIRY_EVENT);
+ String expiredAlarmId(requiredAlarmId.ToString());
+ data.Add(serviceId);
+ data.Add(commandId);
+ data.Add(expiredAlarmId);
+
+ r = __pCommunicationDispatcher->SendData(alarmAppId, data);
+ SysLog(NID_SYS, "Alarm expire event is delivered to %S with %S, Result: %s",alarmAppId.GetPointer(), expiredAlarmId.GetPointer(), GetErrorMessage(r));
+ }
+ else
+ {
+ SysLog(NID_SYS, "AlarmObj2 entry for alarm id not found: %d", alarmId);
+
+ //For conditional launch
+ SysLog(NID_SYS, "Start to load external lib");
+ Library lib;
+ OnAlarmForLaunch pOnAlarmForLaunch = null;
+ r = lib.Construct(ALARM_PLUGIN_LIBRARY_PATH);
+
+ if(r == E_SUCCESS)
+ {
+ SysLog(NID_SYS, "Open alarm condition library");
+ pOnAlarmForLaunch = (OnAlarmForLaunch)lib.GetProcAddress(L"OnAlarmForLaunch");
+ if(pOnAlarmForLaunch != null)
+ {
+ SysLog(NID_SYS, "Function is found");
+ pOnAlarmForLaunch(alarmId);
+ SysLog(NID_SYS, "Requested to check current alarm id to AlarmConditionHandler %d", alarmId);
+ }
+ else
+ {
+ SysLog(NID_SYS, "Fail to find alarm function");
+ }
+ }
+ else
+ {
+ SysLog(NID_SYS, "Fail to open alarm condition library");
+ }
+ }
+}
+
+void
+_AlarmService::OnApplicationTerminated(const AppId& appId, _AppType type)
+{
+ SysLog(NID_SYS, "Terminated AppId %S", appId.GetPointer());
+ RemoveAlarmList(appId);
+}
+
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FSys_DeviceManagerService.cpp
+ * @brief This is the implementation file for _DeviceManagerService class.
+ */
+
+#include <new>
+#include <system/media_key.h>
+#include <bluetooth.h>
+
+#include <FBaseSysLog.h>
+#include <FSys_DeviceManagerEventProvider.h>
+
+#include "FApp_CommunicationDispatcher.h"
+#include "FSys_DeviceManagerService.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Io;
+using namespace Tizen::System;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+namespace {
+ const String DEVICE_MANAGER_SERVICE_ID = L"osp.devicemanager.service";
+ const String DEVICE_MANAGER_COMMAND_OPEN = L"osp.devicemanager.command.open";
+ const String DEVICE_MANAGER_COMMAND_CLOSE = L"osp.devicemanager.command.close";
+ const String DEVICE_MANAGER_COMMAND_STATUS= L"osp.devicemanager.command.status";
+ const String DEVICE_MANAGER_COMMAND_EVENT = L"osp.devicemanager.command.event";
+ const String DEVICE_MANAGER_BLUETOOTH = L"osp.devicemanager.bluetooth";
+
+ const String BLUETOOTH_A2DP_CONNECTED = L"Connected";
+ const String BLUETOOTH_A2DP_DISCONNECTED = L"Disconnected";
+ const String BLUETOOTH_A2DP_PLAY = L"Play";
+ const String BLUETOOTH_A2DP_STOP = L"Stop";
+ const String BLUETOOTH_A2DP_PAUSE = L"Pause";
+ const String BLUETOOTH_A2DP_RESUME = L"Resume";
+ const String BLUETOOTH_A2DP_FORWARD = L"Forward";
+ const String BLUETOOTH_A2DP_FASTFORWARD = L"FastForward";
+ const String BLUETOOTH_A2DP_BACKWARD = L"Backward";
+ const String BLUETOOTH_A2DP_REWIND = L"Rewind";
+}
+
+Tizen::System::_DeviceManagerService* Tizen::System::_DeviceManagerService::__pDeviceManagerService = null;
+
+void bluetooth_connection_state_changed(int result, bool connected, const char* remote_address, bt_audio_profile_type_e type, void* user_data)
+{
+ SysLog(NID_SYS, "Bluetooth headset connection event, %s,%d", remote_address, connected);
+ String bt_event;
+ _DeviceManagerService* pDeviceManagerService = _DeviceManagerService::GetInstance();
+
+ if(pDeviceManagerService != null)
+ {
+ if(pDeviceManagerService->GetBluetoothStatus() != connected)
+ {
+ if(connected == true)
+ {
+ bt_event = BLUETOOTH_A2DP_CONNECTED;
+ }
+ else
+ {
+ bt_event = BLUETOOTH_A2DP_DISCONNECTED;
+ }
+ pDeviceManagerService->SendEvent(bt_event);
+ }
+ pDeviceManagerService->SetBluetoothStatus(connected);
+ }
+}
+
+void app_media_key_handler(media_key_e key, media_key_event_e status, void* pUserData)
+{
+ String event;
+ SysLog(NID_SYS, "Bluetooth headset event is occured %d, %d", (int)key, (int)status);
+ _DeviceManagerService* pDeviceManagerService = _DeviceManagerService::GetInstance();
+ if(pDeviceManagerService != null)
+ {
+ if(status == MEDIA_KEY_STATUS_RELEASED)
+ {
+ switch(key)
+ {
+ case MEDIA_KEY_PLAY:
+ event = BLUETOOTH_A2DP_PLAY;
+ break;
+ case MEDIA_KEY_STOP:
+ event = BLUETOOTH_A2DP_STOP;
+ break;
+ case MEDIA_KEY_PAUSE:
+ event = BLUETOOTH_A2DP_PAUSE;
+ break;
+ case MEDIA_KEY_PREVIOUS:
+ event = BLUETOOTH_A2DP_BACKWARD;
+ break;
+ case MEDIA_KEY_NEXT:
+ event = BLUETOOTH_A2DP_FORWARD;
+ break;
+ case MEDIA_KEY_FASTFORWARD:
+ event = BLUETOOTH_A2DP_FASTFORWARD;
+ break;
+ case MEDIA_KEY_REWIND:
+ event = BLUETOOTH_A2DP_REWIND;
+ break;
+ case MEDIA_KEY_UNKNOWN:
+ break;
+ default:
+ SysLog(NID_SYS, "default");
+ }
+ pDeviceManagerService->SendEvent(event);
+ }
+ }
+}
+
+_DeviceManagerService::_DeviceManagerService()
+ : _ICommunicationRequestListener()
+ , __pCommunicationDispatcher(null)
+ , isBluetoothHeadSetConnected(false)
+{
+ result r = E_SUCCESS;
+ int btResult = 0;
+
+ __pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
+ SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher initiate is failed");
+
+ r = __pCommunicationDispatcher->AddCommunicationEventListener(*this);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "fail to add event listener");
+
+ btResult = bt_initialize();
+ SysTryCatch(NID_SYS, btResult == BT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to init bluetooth module");
+
+ btResult = bt_audio_initialize();
+ SysTryCatch(NID_SYS, btResult == BT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to init bluetooth audio module");
+
+ btResult = bt_audio_set_connection_state_changed_cb(bluetooth_connection_state_changed, null);
+ SysTryCatch(NID_SYS, btResult == BT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to register bluetooth audio event");
+
+ r = __interestedAppList.Construct();
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "fail to initiate bluetooth headset application list");
+CATCH:
+ SetLastResult(r);
+}
+
+_DeviceManagerService::~_DeviceManagerService()
+{
+ result r = E_SUCCESS;
+ int btResult = 0;
+
+ SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher is not ready");
+
+ r = __pCommunicationDispatcher->RemoveCommunicationEventListener(*this);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "fail to remove event listener");
+
+ btResult = bt_audio_unset_connection_state_changed_cb();
+ SysTryCatch(NID_SYS, btResult == BT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to unregister bluetooth headset connection event");
+
+ btResult = bt_audio_deinitialize();
+ SysTryCatch(NID_SYS, btResult == BT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to close bluetooth");
+
+ btResult = bt_deinitialize();
+ SysTryCatch(NID_SYS, btResult == BT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to init bluetooth module");
+
+CATCH:
+ SetLastResult(r);
+}
+
+_DeviceManagerService*
+_DeviceManagerService::GetInstance(void)
+{
+ if(__pDeviceManagerService == null)
+ {
+ __pDeviceManagerService = new (std::nothrow) _DeviceManagerService();
+ }
+ return __pDeviceManagerService;
+}
+
+String
+_DeviceManagerService::GetId(void)
+{
+ return DEVICE_MANAGER_SERVICE_ID;
+}
+
+void
+_DeviceManagerService::SendEvent(String event)
+{
+ if(__interestedAppList.GetCount() > 0)
+ {
+ int count = 0;
+ AppId* pAppId = null;
+ ArrayList data;
+ String serviceId(DEVICE_MANAGER_SERVICE_ID);
+ String commandId(DEVICE_MANAGER_COMMAND_EVENT);
+ String deviceId(DEVICE_MANAGER_BLUETOOTH);
+ String eventId(event);
+
+ data.Construct();
+ data.Add(serviceId);
+ data.Add(commandId);
+ data.Add(deviceId);
+ data.Add(eventId);
+
+ for(count = 0 ; count < __interestedAppList.GetCount() ; count++)
+ {
+ pAppId = (AppId*)__interestedAppList.GetAt(count);
+ if(pAppId == null)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "fail to get appid from bluetooth headset app list");
+ return;
+ }
+
+ __pCommunicationDispatcher->SendData(*pAppId, data);
+ SysLog(NID_SYS, "Bluetooth headset event is sended to %ls", pAppId->GetPointer());
+ }
+
+ }
+ else
+ {
+ SysLog(NID_SYS, "Bluetooth Headset Event is not required by any application");
+ }
+}
+
+void
+_DeviceManagerService::OnBluetoothEventOccured(int code)
+{
+ int count = 0;
+ AppId* pAppId = null;
+
+ String command = DEVICE_MANAGER_COMMAND_EVENT;
+ String device = DEVICE_MANAGER_BLUETOOTH;
+ String event = L"event test";
+
+ result r = E_SUCCESS;
+
+ if(__interestedAppList.GetCount() == 0)
+ {
+ SysLog(NID_SYS, "Bluetooth Headset Event is not required by any application");
+ return;
+ }
+
+ ArrayList eventData;
+ r = eventData.Construct();
+ SysTryCatch(NID_SYS, r == E_SUCCESS, , E_SYSTEM, "fail to create eventData, [%s] Propagated.", GetErrorMessage(r));
+
+ eventData.Add(command);
+ eventData.Add(device);
+ eventData.Add(event);
+
+ for(count = 0 ; count < __interestedAppList.GetCount() ; count++)
+ {
+ pAppId = (AppId*)__interestedAppList.GetAt(count);
+ if(pAppId == null)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "fail to get appid from bluetooth headset app list");
+ return;
+ }
+
+ r = __pCommunicationDispatcher->SendData(*pAppId, eventData);
+ if(r != E_SUCCESS)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "fail to send bluetooth event data");
+ }
+ }
+
+CATCH:
+ SetLastResult(r);
+}
+
+void
+_DeviceManagerService::AddInterestedApp(AppId appId)
+{
+ int count = 0;
+ for(count = 0; count < __interestedAppList.GetCount(); count++)
+ {
+ AppId* pAppId = null;
+
+ pAppId = (AppId*)__interestedAppList.GetAt(count);
+ if(*pAppId == appId)
+ {
+ return;
+ }
+ }
+
+ if(__interestedAppList.GetCount() == 0)
+ {
+ SysLog(NID_SYS, "Bluetooth headset event is reserved.");
+ media_key_reserve(app_media_key_handler, null);
+ }
+
+ AppId* pNewAppId = new AppId(appId);
+ __interestedAppList.Add(*pNewAppId);
+
+}
+
+void
+_DeviceManagerService::RemoveInterestedApp(AppId appId)
+{
+ int count = 0;
+ for(count = 0; count < __interestedAppList.GetCount(); count++)
+ {
+ AppId* pAppId = null;
+
+ pAppId = (AppId*)__interestedAppList.GetAt(count);
+ if(*pAppId == appId)
+ {
+ __interestedAppList.RemoveAt(count, true);
+
+ if(__interestedAppList.GetCount() == 0)
+ {
+ SysLog(NID_SYS, "Bluetooth headset event is released.");
+ media_key_release();
+ }
+
+ return;
+ }
+ }
+
+}
+
+void
+_DeviceManagerService::OnRequestOccured(AppId appId, ArrayList* request, ArrayList* response)
+{
+ StringComparer strComparer;
+ int cmp = 0;
+ result r = E_SUCCESS;
+ String* command = null;
+ String* device = null;
+
+ SysLog(NID_APP, "Request is forwarded to _DeviceManagerService");
+ SysTryCatch(NID_SYS, request != null && response != null, r = E_INVALID_ARG, E_INVALID_ARG, "Parameters are null");
+
+ command = (String*)request->GetAt(1);
+ device = (String*)request->GetAt(2);
+ SysTryCatch(NID_SYS, command!= null && device != null, r = E_INVALID_ARG, E_INVALID_ARG, "Parameters has no command %x, %x", command, device);
+
+ SysLog(NID_SYS, "command is %ls, device is %ls", command->GetPointer(), device->GetPointer());
+
+ strComparer.Compare(*command, DEVICE_MANAGER_COMMAND_OPEN, cmp);
+ if(cmp == 0)
+ {
+ strComparer.Compare(*device, DEVICE_MANAGER_BLUETOOTH, cmp);
+ if(cmp == 0)
+ {
+ SysLog(NID_SYS, "Bluetooth headset event is required");
+ AddInterestedApp(appId);
+ }
+ }
+
+ strComparer.Compare(*command, DEVICE_MANAGER_COMMAND_CLOSE, cmp);
+ if(cmp == 0)
+ {
+ strComparer.Compare(*device, DEVICE_MANAGER_BLUETOOTH, cmp);
+ if(cmp == 0)
+ {
+ RemoveInterestedApp(appId);
+ }
+ }
+
+ strComparer.Compare(*command, DEVICE_MANAGER_COMMAND_STATUS, cmp);
+ if(cmp == 0)
+ {
+ strComparer.Compare(*device, DEVICE_MANAGER_BLUETOOTH, cmp);
+ if(cmp == 0)
+ {
+
+ SysLog(NID_SYS, "Bluetooth headset status is %d", isBluetoothHeadSetConnected);
+ if(response != null)
+ {
+ String* serviceId = new (std::nothrow) String(DEVICE_MANAGER_SERVICE_ID);
+ String* commandId = new (std::nothrow) String(DEVICE_MANAGER_COMMAND_STATUS);
+ String* deviceId = new (std::nothrow) String(DEVICE_MANAGER_BLUETOOTH);
+ String* status = null;
+ if(isBluetoothHeadSetConnected == true)
+ {
+ status = new (std::nothrow) String(BLUETOOTH_A2DP_CONNECTED);
+ }
+ else
+ {
+ status = new (std::nothrow) String(BLUETOOTH_A2DP_DISCONNECTED);
+ }
+ response->Add(*serviceId);
+ response->Add(*commandId);
+ response->Add(*deviceId);
+ response->Add(*status);
+ }
+ }
+ }
+
+CATCH:
+ SetLastResult(r);
+}
+
+void
+_DeviceManagerService::OnApplicationTerminated(const AppId& appId, _AppType type)
+{
+ RemoveInterestedApp(appId);
+}
+
+bool
+_DeviceManagerService::GetBluetoothStatus(void)
+{
+ return isBluetoothHeadSetConnected;
+}
+void
+_DeviceManagerService::SetBluetoothStatus(bool status)
+{
+ isBluetoothHeadSetConnected = status;
+}
+
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 FSys_SystemService.cpp
+ * @brief This is the implementation file for _SystemService class.
+ */
+#include <unique_ptr.h>
+#include <new>
+#include <time.h>
+
+#include <device.h>
+#include <system_info.h>
+
+#include <FBaseSysLog.h>
+
+#include <FApp_AppManagerImpl.h>
+#include <FBase_StringConverter.h>
+#include <FSec_AccessController.h>
+
+#include "FApp_CommunicationDispatcher.h"
+#include "FSys_SystemService.h"
+
+using namespace std;
+
+using namespace Tizen::App;
+using namespace Tizen::Io;
+using namespace Tizen::System;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Security;
+
+namespace {
+ static const wchar_t* _SYSTEM_SERVICE_ID = L"osp.system.service";
+ static const wchar_t* _SYSTEM_COMMAND_CHANGE_TIME = L"osp.system.command.change.time";
+ static const wchar_t* _SYSTEM_COMMAND_CHANGE_BRIGHTNESS = L"osp.system.command.change.brightness";
+ static const wchar_t* _SYSTEM_COMMAND_RESTORE_BRIGHTNESS = L"osp.system.command.restore.brightness";
+ static const wchar_t* _SYSTEM_COMMAND_GET_IMEI = L"osp.system.command.get.imei";
+ static const wchar_t* _SYSTEM_RESULT_OK = L"osp.system.result.ok";
+ static const wchar_t* _SYSTEM_RESULT_ERROR = L"osp.system.result.error";
+ static const wchar_t* _SYSTEM_RESULT_INVALID = L"osp.system.result.invalid";
+ static const wchar_t* _SYSTEM_RESULT_PRIVILEGED = L"osp.system.result.privilege";
+ static const int _SYSTEM_COMMAND_ID = 1;
+ static const int _SYSTEM_COMMAND_ARG = 2;
+}
+
+Tizen::System::_SystemService* Tizen::System::_SystemService::__pSystemService = null;
+
+void
+DeviceBatteryCallback(int percent, void* userData)
+{
+ device_battery_warn_e batteryLevel = DEVICE_BATTERY_WARN_EMPTY;
+ int ret = device_battery_get_warning_status(&batteryLevel);
+ if(ret == DEVICE_ERROR_NONE && batteryLevel < DEVICE_BATTERY_WARN_NORMAL)
+ {
+ _SystemService* pSystemService = _SystemService::GetInstance();
+ if(pSystemService != null)
+ {
+ pSystemService->RestoreBrightness();
+ }
+ }
+}
+
+_SystemService::_SystemService()
+ : _ICommunicationRequestListener()
+ , __pCommunicationDispatcher(null)
+{
+ int ret = 0;
+ result r = E_SUCCESS;
+ _AppManagerImpl* pAppManagerImpl = null;
+
+ __pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
+ SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher initiate is failed");
+
+ r = __pCommunicationDispatcher->AddCommunicationEventListener(*this);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "fail to add event listener");
+
+ __appBrightnessList.Construct();
+ pAppManagerImpl = _AppManagerImpl::GetInstance();
+ SysTryCatch(NID_SYS, pAppManagerImpl != null, r = E_SYSTEM, E_SYSTEM, "It is failed to get _AppManagerImpl class.");
+
+ r = pAppManagerImpl->AddActiveAppEventListener(*this);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to add active app event listener");
+
+ ret = device_battery_set_cb(DeviceBatteryCallback, null);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to add battery event listener");
+
+CATCH:
+ SetLastResult(r);
+}
+
+_SystemService::~_SystemService()
+{
+ int ret = 0;
+ result r = E_SUCCESS;
+ _AppManagerImpl* pAppManagerImpl = null;
+ SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher is not ready");
+
+ r = __pCommunicationDispatcher->RemoveCommunicationEventListener(*this);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "fail to remove event listener");
+
+ ret = device_battery_unset_cb();
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to remove battery event listener");
+
+ pAppManagerImpl = _AppManagerImpl::GetInstance();
+ SysTryCatch(NID_SYS, pAppManagerImpl != null, r = E_SYSTEM, E_SYSTEM, "It is failed to get _AppManagerImpl class.");
+
+ r = pAppManagerImpl->RemoveActiveAppEventListener(*this);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, , E_SYSTEM, "It is failed to remove active app listener.");
+
+ __appBrightnessList.RemoveAll(true);
+
+CATCH:
+ SetLastResult(r);
+}
+
+_SystemService*
+_SystemService::GetInstance(void)
+{
+ if(__pSystemService == null)
+ {
+ __pSystemService = new (std::nothrow) _SystemService();
+ }
+ return __pSystemService;
+}
+
+String
+_SystemService::GetId(void)
+{
+ return _SYSTEM_SERVICE_ID;
+}
+
+void
+_SystemService::RestoreBrightness(void)
+{
+ int ret = 0;
+ Integer* pBrightness = null;
+ String convertedActiveAppId;
+ __activeAppId.SubString( 0, 10, convertedActiveAppId);
+
+ SysLog(NID_SYS, "Active App is %ls", __activeAppId.GetPointer());
+
+ pBrightness = (Integer*)(__appBrightnessList.GetValue(convertedActiveAppId));
+
+ if(pBrightness != null)
+ {
+ //Change application's brightness
+ SysLog(NID_SYS, "Application's brightness is %d", pBrightness->ToInt());
+ ret = device_set_brightness(0, pBrightness->ToInt());
+ if(ret != DEVICE_ERROR_NONE)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to change screen brightness");
+ }
+ }
+ else
+ {
+ //Restore system brightness
+ SysLog(NID_SYS, "Restore to System brightness");
+ ret = device_set_brightness_from_settings(0);
+ if(ret != DEVICE_ERROR_NONE)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to restore screen brightness");
+ }
+ }
+
+}
+
+void
+_SystemService::OnActiveAppChanged(const AppId& appId)
+{
+ __activeAppId = appId;
+ RestoreBrightness();
+}
+
+void
+_SystemService::OnRequestOccured(AppId appId, ArrayList* request, ArrayList* response)
+{
+ int ret = 0;
+ result r = E_SUCCESS;
+ StringComparer strComparer;
+ String* resultId = null;
+ String* command = null;
+ String* serviceId = null;
+ String* commandId = null;
+ String* returnValue = null;
+
+ SysLog(NID_APP, "Request is forwarded to SystemService");
+ SysTryCatch(NID_SYS, request != null && response != null, r = E_INVALID_ARG, E_INVALID_ARG, "Parameters are null");
+
+ command = (String*)request->GetAt(_SYSTEM_COMMAND_ID);
+ SysTryCatch(NID_SYS, command!= null, r = E_INVALID_ARG, E_INVALID_ARG, "Parameters has no command %x, %x", command);
+
+ serviceId = new (std::nothrow) String(_SYSTEM_SERVICE_ID);
+ commandId = new (std::nothrow) String(_SYSTEM_COMMAND_CHANGE_TIME);
+
+ if(*command == _SYSTEM_COMMAND_GET_IMEI)
+ {
+ SysLog(NID_SYS, "Get IMEI");
+ if(response != null)
+ {
+ r = _AccessController::CheckSystemPrivilege(appId, _PRV_USERIDENTITY);
+
+ if(r != E_SUCCESS)
+ {
+ SysLogException(NID_SYS, E_PRIVILEGE_DENIED, "Application[%ls] does not have enought privilege.", appId.GetPointer());
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_PRIVILEGED);
+ }
+ else
+ {
+ char* pImei = null;
+ ret = system_info_get_value_string(SYSTEM_INFO_KEY_MOBILE_DEVICE_ID, &pImei);
+ if(ret != SYSTEM_INFO_ERROR_NONE || pImei == null)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to get IMEI.");
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_ERROR);
+ }
+ else
+ {
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_OK);
+ returnValue = new (std::nothrow) String(pImei);
+ }
+ }
+ }
+ }
+ else if(*command == _SYSTEM_COMMAND_CHANGE_BRIGHTNESS)
+ {
+ SysLog(NID_SYS, "Change brightness");
+ int brightness = 0;
+ String* brightnessBuffer = (String*)request->GetAt(_SYSTEM_COMMAND_ARG);
+
+ if(brightnessBuffer == null)
+ {
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_ERROR);
+ }
+ else
+ {
+ Integer::Parse(*brightnessBuffer, brightness);
+ SysLog(NID_SYS, "requested brightness is %d", brightness);
+
+ __appBrightnessList.Remove(appId, true);
+ unique_ptr<Integer> pBrightness(new (std::nothrow) Integer(brightness));
+ unique_ptr<String> pAppId(new (std::nothrow) String(appId));
+
+ SysTryCatch(NID_SYS, pBrightness != null && pAppId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "It is failed to create appId or brightness.");
+
+ r = __appBrightnessList.Add(pAppId.get(), pBrightness.get());
+
+ SysTryCatch(NID_SYS, r == E_SUCCESS, , r, "It is failed to add appid and brightness.");
+
+ pAppId.release();
+ pBrightness.release();
+
+ SysLog(NID_SYS, "Current App is %ls, Active App is %ls", appId.GetPointer(), __activeAppId.GetPointer());
+
+ String convertedActiveAppId;
+ __activeAppId.SubString( 0, 10, convertedActiveAppId);
+
+ if(convertedActiveAppId == appId)
+ {
+ SysLog(NID_SYS, "Current application is active. So brightness is changed.");
+ ret = device_set_brightness(0, brightness);
+ SysTryCatch(NID_SYS, ret == DEVICE_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "It is failed to change brightness [%d].", brightness);
+ }
+
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_OK);
+ }
+ }
+ else if(*command == _SYSTEM_COMMAND_RESTORE_BRIGHTNESS)
+ {
+ SysLog(NID_SYS, "Restore brightness");
+ __appBrightnessList.Remove(appId);
+ String convertedActiveAppId;
+ __activeAppId.SubString( 0, 10, convertedActiveAppId);
+
+ if(convertedActiveAppId == appId)
+ {
+ SysLog(NID_SYS, "Current application is active. So brightness is restored.");
+ ret = device_set_brightness_from_settings(0);
+ SysTryCatch(NID_SYS, ret == DEVICE_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "It is failed to restore system brightness.");
+ }
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_OK);
+ }
+
+ else if(*command == _SYSTEM_COMMAND_CHANGE_TIME)
+ {
+ SysLog(NID_SYS, "Change system time");
+ r = _AccessController::CheckSystemPrivilege(appId, _PRV_SYSTEMSETTING_WRITE);
+ if(r != E_SUCCESS)
+ {
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_PRIVILEGED);
+ }
+ else
+ {
+ struct tm tTime;
+ String* dateTime = (String*)request->GetAt(_SYSTEM_COMMAND_ARG);
+ char* datetime = null;
+
+ datetime = _StringConverter::CopyToCharArrayN(*dateTime);
+ if(datetime != null)
+ {
+ sscanf(datetime, "%3d %2d %2d %2d:%2d:%2d", &(tTime.tm_year), &(tTime.tm_mon), &(tTime.tm_mday), &(tTime.tm_hour), &(tTime.tm_min), &(tTime.tm_sec));
+ time_t _tTime = mktime(&tTime);
+ if(stime(&_tTime) == 0)
+ {
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_OK);
+ }
+ else
+ {
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_ERROR);
+ }
+ delete [] datetime;
+ }
+ else
+ {
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_ERROR);
+ }
+ }
+ }
+ else
+ {
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_INVALID);
+ }
+
+CATCH:
+ if(resultId == null)
+ {
+ resultId = new (std::nothrow) String(_SYSTEM_RESULT_ERROR);
+ }
+
+ response->Add(*serviceId);
+ response->Add(*commandId);
+ response->Add(*resultId);
+
+ if(returnValue != null)
+ {
+ response->Add(*returnValue);
+ }
+ SetLastResult(r);
+}
+
+void
+_SystemService::OnApplicationTerminated(const AppId& appId, _AppType type)
+{
+ SysLog(NID_SYS, "Application (%ls) is terminated.", appId.GetPointer());
+ __appBrightnessList.Remove(appId, true);
+}
+
--- /dev/null
+{
+global:
+ OspMain;
+local:
+ *;
+};