2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef SRC_APPLICATION_APPLICATION_MANAGER_H__
18 #define SRC_APPLICATION_APPLICATION_MANAGER_H__
20 #include <app_event.h>
21 #include <app_manager.h>
23 #include <package-manager.h>
24 #include <pkgmgr-info.h>
29 #if defined(TIZEN_MOBILE)
30 #include <context-service/context_history.h>
31 #elif defined(TIZEN_WEARABLE)
32 #include <context-service/wearable/context_history.h>
35 #include "common/picojson.h"
36 #include "common/platform_result.h"
38 typedef std::function<void(picojson::value*)> JsonCallback;
40 namespace application {
42 class ApplicationInstance;
43 typedef struct LaunchAppControlCallbackDataStruct {
44 ApplicationInstance* instance;
45 std::shared_ptr<picojson::value> response;
46 std::string reply_callback_id;
47 } LaunchAppControlCallbackData;
49 class ApplicationManager {
51 explicit ApplicationManager(ApplicationInstance& instance);
52 ~ApplicationManager();
54 void GetCurrentApplication(const std::string& app_id, picojson::object* out);
55 void Kill(const picojson::value& args);
56 void Launch(const picojson::value& args);
57 void LaunchAppControl(const picojson::value& args);
58 void FindAppControl(const picojson::value& args);
59 void GetAppsContext(const picojson::value& args);
60 void GetAppContext(const picojson::value& args, picojson::object* out);
61 void GetAppsInfo(const picojson::value& args);
62 void GetAppInfo(const std::string& app_id, picojson::object* out);
63 void GetAppCerts(const std::string& app_id, picojson::object* out);
64 void GetAppSharedUri(const std::string& app_id, picojson::object* out);
65 void GetAppMetaData(const std::string& app_id, picojson::object* out);
66 void GetBatteryUsageInfo(const picojson::value& args, picojson::object* out);
67 void GetAppsUsageInfo(const picojson::value& args, picojson::object* out);
68 void StartAppInfoEventListener(picojson::object* out);
69 void StopAppInfoEventListener();
70 void GetApplicationInformationSize(const picojson::value& args, picojson::object* out);
71 void AsyncResponse(const common::PlatformResult& result,
72 std::shared_ptr<picojson::value>* response);
74 void BroadcastEventHelper(const picojson::value& args, picojson::object& out, bool trusted);
75 common::PlatformResult StartEventListener(const std::string& event_name,
76 const JsonCallback& callback);
77 void StopEventListener(const std::string& event_name);
78 common::PlatformResult StartStatusListener(const JsonCallback& callback);
79 common::PlatformResult StopStatusChangeListener();
82 char* GetPackageId(const std::string& app_id);
84 pkgmgr_client* pkgmgr_client_handle_;
85 pkgmgr_client* pkgmgr_client_uninstall_handle_;
86 ApplicationInstance& instance_;
87 app_manager_event_h app_status_handle_;
89 JsonCallback event_callback_;
90 JsonCallback status_callback_;
91 std::map<std::string, event_handler_h> event_handler_map_;
92 std::set<LaunchAppControlCallbackData*> launch_app_control_set;
93 static void OnEvent(const char* event_name, bundle* event_data, void* user_data);
94 static void OnStatusEvent(const char* type, const char* app_id,
95 app_manager_event_type_e event_type,
96 app_manager_event_state_e event_state, app_manager_event_h handle,
99 #if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
100 static common::PlatformResult GetContextHistory(
101 const picojson::value& args, picojson::object* out,
102 common::PlatformResult (*)(const picojson::value&, const context_history_filter_h,
103 context_history_data_e* data_type),
104 common::PlatformResult (*)(const context_history_record_h, picojson::object*));
106 static common::PlatformResult BatteryUsageFilter(const picojson::value&,
107 const context_history_filter_h,
108 context_history_data_e* data_type);
109 static common::PlatformResult BatteryUsageAttributes(const context_history_record_h,
112 static common::PlatformResult AppsUsageFilter(const picojson::value&,
113 const context_history_filter_h,
114 context_history_data_e* data_type);
115 static common::PlatformResult AppsUsageAttributes(const context_history_record_h,
120 } // namespace application
121 } // namespace extension
123 #endif // SRC_APPLICATION_APPLICATION_MANAGER_H__