2 * Copyright (c) 2019 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.
25 #include <app_control_internal.h>
28 #include "rua_private.h"
29 #include "rua_manager.h"
30 #include "rua_context_internal.h"
31 #include "rua_info_internal.h"
33 static int __convert_aul_error(int error)
37 return RUA_ERROR_INVALID_PARAMETER;
39 return RUA_ERROR_PERMISSION_DENIED;
41 return RUA_ERROR_OUT_OF_MEMORY;
43 return RUA_ERROR_IO_ERROR;
47 API int rua_manager_foreach_rua_info(rua_manager_rua_info_cb callback,
50 return rua_info_foreach(callback, user_data);
53 API int rua_manager_delete_rua_info(rua_info_h info)
60 _E("Invalid parameter");
61 return RUA_ERROR_INVALID_PARAMETER;
64 ret = rua_info_get_app_id(info, &app_id);
65 if (ret != RUA_ERROR_NONE)
68 ret = rua_info_get_instance_id(info, &instance_id);
69 if (ret != RUA_ERROR_NONE) {
75 ret = rua_delete_history_with_instance_id(app_id,
78 ret = rua_delete_history_with_pkgname(app_id);
85 _E("Failed to delete RUA history. error(%d)", ret);
86 return __convert_aul_error(ret);
89 return RUA_ERROR_NONE;
92 API int rua_manager_delete_all_rua_info(void)
96 ret = rua_clear_history();
98 _E("Failed to clear RUA history. error(%d)", ret);
99 return __convert_aul_error(ret);
102 return RUA_ERROR_NONE;
105 API int rua_manager_get_app_control_from_rua_info(rua_info_h info,
106 app_control_h *app_control)
108 app_control_h handle;
113 if (!info || !app_control) {
114 _E("Invalid parameter");
115 return RUA_ERROR_INVALID_PARAMETER;
118 ret = rua_info_get_args(info, &args);
119 if (ret != RUA_ERROR_NONE)
122 b = bundle_decode((bundle_raw *)args, strlen(args));
125 _E("Failed to decode bundle");
126 return RUA_ERROR_OUT_OF_MEMORY;
129 ret = app_control_create_request(b, &handle);
131 if (ret != APP_CONTROL_ERROR_NONE) {
132 _E("Failed to create app_control handle");
133 return RUA_ERROR_OUT_OF_MEMORY;
136 *app_control = handle;
138 return RUA_ERROR_NONE;
141 API int rua_manager_get_rua_context_from_rua_info(rua_info_h info,
142 rua_context_h *context)
144 return rua_context_create_from_rua_info(info, context);
147 API int rua_manager_is_running(rua_context_h context, bool *running)
149 return rua_context_is_running(context, running);
152 API int rua_manager_resume(rua_context_h context)
154 return rua_context_resume(context);
157 API int rua_manager_terminate(rua_context_h context)
159 return rua_context_terminate(context);