Add GetResourceStoragePath
[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::GetResourceStoragePath( std::string& path )
80 {
81 #ifdef USE_APPFW
82   char *pathInt = app_get_resource_path();
83   if ( pathInt )
84   {
85     path = pathInt;
86     free( pathInt );
87   }
88   else
89   {
90     path = "";
91   }
92 #endif
93 }
94
95 void Adaptor::GetDataStoragePath( std::string& path )
96 {
97 #ifdef USE_APPFW
98   char *pathInt = app_get_data_path();
99   if ( pathInt )
100   {
101     path = pathInt;
102     free( pathInt );
103   }
104   else
105   {
106     path = "";
107   }
108 #endif
109
110 }
111
112 void Adaptor::GetAppId( std::string& appId )
113 {
114 #ifdef USE_APPFW
115   char *id;
116   app_get_id(&id);
117   if ( id )
118   {
119     appId = id;
120     free( id );
121   }
122   else
123   {
124     appId = "";
125   }
126 #endif
127 }
128
129 void Adaptor::SurfaceInitialized()
130 {
131 #ifdef APPCORE_WATCH_AVAILABLE
132   if ( !mUseRemoteSurface )
133   {
134     return;
135   }
136   char *appId;
137   app_get_id(&appId);
138
139   // Use strdup() in app_get_id(), so need to free memory
140   if( appId )
141   {
142 #ifdef ECORE_WAYLAND2
143     Ecore_Wl2_Window* ecoreWlWindow = AnyCast< Ecore_Wl2_Window* >( mWindows.front()->GetNativeHandle() );
144     screen_connector_provider_remote_enable( appId, ecore_wl2_window_surface_get( ecoreWlWindow ) );
145 #else
146     Ecore_Wl_Window* ecoreWlWindow = AnyCast< Ecore_Wl_Window* >( mWindows.front()->GetNativeHandle() );
147     screen_connector_provider_remote_enable( appId, ecore_wl_window_surface_get( ecoreWlWindow ) );
148 #endif
149     free( appId );
150   }
151 #endif
152 }
153
154 void Adaptor::SetupSystemInformation()
155 {
156   if( system_settings_add_changed_cb( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, OnSystemLanguageChanged, this ) != SYSTEM_SETTINGS_ERROR_NONE )
157   {
158     DALI_LOG_ERROR( "DALI system_settings_add_changed_cb failed.\n" );
159     return;
160   }
161
162   char* locale = NULL;
163   if( system_settings_get_value_string( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale ) != SYSTEM_SETTINGS_ERROR_NONE ||
164       locale == NULL )
165   {
166     DALI_LOG_ERROR( "DALI OnSystemLanguageChanged failed " );
167     return;
168   }
169
170   SetRootLayoutDirection( locale );
171
172   free( locale );
173
174 }
175
176 } // namespace Adaptor
177
178 } // namespace Internal
179
180 } // namespace Dali