2 * Copyright © 2020 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #include "ivi-compositor.h"
30 #include <sys/smack.h>
36 * default policy implementation allows every action to be possible
38 * This is an example, that implements the API
40 * For injecting rules back in the compositor one should use ivi_policy_add()
41 * - policy_rule_allow_to_add is required in order to add further policy rules
42 * - policy_rule_try_event will be callback executed when handling the state
46 ivi_policy_default_surface_create(struct ivi_surface *surf, void *user_data)
48 /* verify that the surface should be created */
53 ivi_policy_default_surface_commmited(struct ivi_surface *surf, void *user_data)
55 /* verify that the surface should be committed */
60 ivi_policy_default_surface_activate(struct ivi_surface *surf, void *user_data)
62 /* verify that the surface should be switched to */
67 ivi_policy_default_surface_deactivate(struct ivi_surface *surf, void *user_data)
69 /* verify that the surface should be de-activated to */
74 ivi_policy_default_surface_activate_default(struct ivi_surface *surf, void *user_data)
76 /* verify that the surface should be switched to */
81 ivi_policy_default_surface_advertise_state_change(struct ivi_surface *surf, void *user_data)
83 /* verify that the surface should sent as notification */
87 /* we allow all applications to bind to private extensions. See the deny-all
88 * policy instead for how to retrieve the clients fd and its label to check
91 ivi_policy_default_shell_bind_interface(void *client, void *interface)
97 ivi_policy_default_allow_to_add(void *user_data)
99 /* verify that policy rules can be added with ivi_policy_add() */
104 * Policy rules added by ivi_policy_add() will be handled by this callback, and
105 * should be treated depending on the event. Note this is just an example.
108 ivi_policy_default_try_event(struct ivi_a_policy *a_policy)
110 uint32_t event = a_policy->event;
113 case AGL_SHELL_POLICY_EVENT_SHOW:
114 ivi_layout_activate(a_policy->output, a_policy->app_id);
116 case AGL_SHELL_POLICY_EVENT_HIDE:
117 ivi_layout_deactivate(a_policy->policy->ivi, a_policy->app_id);
123 static const struct ivi_policy_api policy_api = {
124 .struct_size = sizeof(policy_api),
125 .surface_create = ivi_policy_default_surface_create,
126 .surface_commited = ivi_policy_default_surface_commmited,
127 .surface_activate = ivi_policy_default_surface_activate,
128 .surface_deactivate = ivi_policy_default_surface_deactivate,
129 .surface_activate_by_default = ivi_policy_default_surface_activate_default,
130 .surface_advertise_state_change = ivi_policy_default_surface_advertise_state_change,
131 .shell_bind_interface = ivi_policy_default_shell_bind_interface,
132 .policy_rule_allow_to_add = ivi_policy_default_allow_to_add,
133 .policy_rule_try_event = ivi_policy_default_try_event,
137 ivi_policy_init(struct ivi_compositor *ivi)
139 ivi->policy = ivi_policy_create(ivi, &policy_api, ivi);
143 weston_log("Installing 'allow-all' policy engine\n");