Merge "Use existing callback ID for recurring callbacks" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / tizen-wayland / adaptor-impl-tizen.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/adaptor/common/adaptor-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <app_common.h>
23 #include <system_settings.h>
24
25 #ifdef APPCORE_WATCH_AVAILABLE
26 #include <screen_connector_provider.h>
27 #endif
28
29 #ifdef ECORE_WAYLAND2
30 #include <dali/internal/adaptor/tizen-wayland/dali-ecore-wl2.h>
31 #else
32 #include <dali/internal/adaptor/tizen-wayland/dali-ecore-wayland.h>
33 #endif
34
35 #include <aul.h>
36 #include <unistd.h>
37
38 namespace Dali
39 {
40
41 namespace Internal
42 {
43
44 namespace Adaptor
45 {
46
47 namespace
48 {
49
50 static void OnSystemLanguageChanged( system_settings_key_e key, void* data )
51 {
52   char* locale = NULL;
53   if( system_settings_get_value_string( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale ) != SYSTEM_SETTINGS_ERROR_NONE ||
54       locale == NULL )
55   {
56     DALI_LOG_ERROR( "DALI OnSystemLanguageChanged failed " );
57     return;
58   }
59
60   Adaptor* adaptor = static_cast< Adaptor* >( data );
61   if( adaptor != NULL )
62   {
63     adaptor->SetRootLayoutDirection( locale );
64   }
65
66   free( locale );
67 }
68
69 } // namesapce
70
71 std::string Adaptor::GetApplicationPackageName()
72 {
73   char appname[4096] = {0};
74   int pid = getpid();
75   aul_app_get_pkgname_bypid( pid, appname, sizeof( appname ) );
76   return appname;
77 }
78
79 void Adaptor::GetDataStoragePath( std::string& path)
80 {
81 #ifdef USE_APPFW
82   char *pathInt = app_get_data_path();
83   if ( pathInt )
84   {
85     path = pathInt;
86     free( pathInt );
87   }
88   else
89   {
90     path = "";
91   }
92 #endif
93
94 }
95
96 void Adaptor::GetAppId( std::string& appId )
97 {
98 #ifdef USE_APPFW
99   char *id;
100   app_get_id(&id);
101   if ( id )
102   {
103     appId = id;
104     free( id );
105   }
106   else
107   {
108     appId = "";
109   }
110 #endif
111 }
112
113 void Adaptor::SurfaceInitialized()
114 {
115 #ifdef APPCORE_WATCH_AVAILABLE
116   if ( !mUseRemoteSurface )
117   {
118     return;
119   }
120   char *appId;
121   app_get_id(&appId);
122
123   // Use strdup() in app_get_id(), so need to free memory
124   if( appId )
125   {
126 #ifdef ECORE_WAYLAND2
127     Ecore_Wl2_Window* ecoreWlWindow = AnyCast< Ecore_Wl2_Window* >( mWindows.front()->GetNativeHandle() );
128     screen_connector_provider_remote_enable( appId, ecore_wl2_window_surface_get( ecoreWlWindow ) );
129 #else
130     Ecore_Wl_Window* ecoreWlWindow = AnyCast< Ecore_Wl_Window* >( mWindows.front()->GetNativeHandle() );
131     screen_connector_provider_remote_enable( appId, ecore_wl_window_surface_get( ecoreWlWindow ) );
132 #endif
133     free( appId );
134   }
135 #endif
136 }
137
138 void Adaptor::SetupSystemInformation()
139 {
140   if( system_settings_add_changed_cb( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, OnSystemLanguageChanged, this ) != SYSTEM_SETTINGS_ERROR_NONE )
141   {
142     DALI_LOG_ERROR( "DALI system_settings_add_changed_cb failed.\n" );
143     return;
144   }
145
146   char* locale = NULL;
147   if( system_settings_get_value_string( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale ) != SYSTEM_SETTINGS_ERROR_NONE ||
148       locale == NULL )
149   {
150     DALI_LOG_ERROR( "DALI OnSystemLanguageChanged failed " );
151     return;
152   }
153
154   SetRootLayoutDirection( locale );
155
156   free( locale );
157
158 }
159
160 } // namespace Adaptor
161
162 } // namespace Internal
163
164 } // namespace Dali