Add support of writing DALi cache file for Android.
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / android / android-framework-impl.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/android/android-framework-impl.h>
20
21 namespace Dali
22 {
23
24 namespace Internal
25 {
26
27 namespace Adaptor
28 {
29
30 namespace
31 {
32 AndroidFramework* gAndroidFramework = nullptr; // raw specific pointer to allow AndroidFramework::Get
33 }
34
35 Dali::Integration::AndroidFramework& AndroidFramework::New()
36 {
37   Dali::Integration::AndroidFramework* androidFramework = new Dali::Integration::AndroidFramework;
38   AndroidFramework* impl = new AndroidFramework( androidFramework );
39   androidFramework->mImpl = impl;
40   return *androidFramework;
41 }
42
43 void AndroidFramework::Delete()
44 {
45   DALI_ASSERT_ALWAYS( gAndroidFramework != nullptr && "Cannot delete already deleted AndroidFramework." );
46
47   delete gAndroidFramework->mAndroidFramework;
48   gAndroidFramework = nullptr;
49 }
50
51 void AndroidFramework::SetNativeApplication( android_app* application )
52 {
53   mNativeApplication = application;
54 }
55
56 android_app* AndroidFramework::GetNativeApplication() const
57 {
58   return mNativeApplication;
59 }
60
61 void AndroidFramework::SetJVM( JavaVM* jvm )
62 {
63   mJVM = jvm;
64 }
65
66 JavaVM* AndroidFramework::GetJVM() const
67 {
68   return mJVM;
69 }
70
71 void AndroidFramework::SetApplicationAssets( AAssetManager* assets )
72 {
73   mAssets = assets;
74 }
75
76 AAssetManager* AndroidFramework::GetApplicationAssets() const
77 {
78   return mAssets;
79 }
80
81 void AndroidFramework::SetInternalDataPath( const std::string& path )
82 {
83   mInternalDataPath = path;
84 }
85
86 std::string AndroidFramework::GetInternalDataPath() const
87 {
88   return mInternalDataPath;
89 }
90
91 void AndroidFramework::SetApplicationConfiguration( AConfiguration* configuration )
92 {
93   mConfiguration = configuration;
94 }
95
96 AConfiguration* AndroidFramework::GetApplicationConfiguration() const
97 {
98   return mConfiguration;
99 }
100
101 void AndroidFramework::SetApplicationWindow( ANativeWindow* window )
102 {
103   mWindow = window;
104 }
105
106 ANativeWindow* AndroidFramework::GetApplicationWindow() const
107 {
108   return mWindow;
109 }
110
111 void AndroidFramework::OnTerminate()
112 {
113   mFramework->AppStatusHandler( APP_DESTROYED, nullptr );
114 }
115
116 void AndroidFramework::OnPause()
117 {
118   mFramework->AppStatusHandler( APP_PAUSE, nullptr );
119 }
120
121 void AndroidFramework::OnResume()
122 {
123   mFramework->AppStatusHandler( APP_RESUME, nullptr );
124 }
125
126 void AndroidFramework::OnWindowCreated( ANativeWindow* window )
127 {
128   mFramework->AppStatusHandler( APP_WINDOW_CREATED, window );
129 }
130
131 void AndroidFramework::OnWindowDestroyed( ANativeWindow* window )
132 {
133   mFramework->AppStatusHandler( APP_WINDOW_DESTROYED, window );
134 }
135
136 Dali::Integration::AndroidFramework& AndroidFramework::Get()
137 {
138   DALI_ASSERT_ALWAYS( gAndroidFramework != nullptr && "AndroidFramework not instantiated" );
139
140   return *gAndroidFramework->mAndroidFramework;
141 }
142
143 AndroidFramework::AndroidFramework( Dali::Integration::AndroidFramework* androidFramework )
144  : mAndroidFramework( androidFramework ),
145    mFramework( nullptr ),
146    mNativeApplication( nullptr ),
147    mWindow( nullptr ),
148    mAssets( nullptr ),
149    mConfiguration( nullptr ),
150    mJVM( nullptr )
151 {
152   DALI_ASSERT_ALWAYS( gAndroidFramework == nullptr && "Cannot create more than one AndroidFramework." );
153
154   gAndroidFramework = this;
155 }
156
157 AndroidFramework::~AndroidFramework()
158 {
159   gAndroidFramework = nullptr;
160 }
161
162 } // namespace Adaptor
163
164 } // namespace Internal
165
166 } // namespace Dali