Merge "Fix AndroidFramework::Delete() so it doesn't crash anymore and small cleanup...
[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::SetApplicationConfiguration( AConfiguration* configuration )
82 {
83   mConfiguration = configuration;
84 }
85
86 AConfiguration* AndroidFramework::GetApplicationConfiguration() const
87 {
88   return mConfiguration;
89 }
90
91 void AndroidFramework::SetApplicationWindow( ANativeWindow* window )
92 {
93   mWindow = window;
94 }
95
96 ANativeWindow* AndroidFramework::GetApplicationWindow() const
97 {
98   return mWindow;
99 }
100
101 void AndroidFramework::OnTerminate()
102 {
103   mFramework->AppStatusHandler( APP_DESTROYED, nullptr );
104 }
105
106 void AndroidFramework::OnPause()
107 {
108   mFramework->AppStatusHandler( APP_PAUSE, nullptr );
109 }
110
111 void AndroidFramework::OnResume()
112 {
113   mFramework->AppStatusHandler( APP_RESUME, nullptr );
114 }
115
116 void AndroidFramework::OnWindowCreated( ANativeWindow* window )
117 {
118   mFramework->AppStatusHandler( APP_WINDOW_CREATED, window );
119 }
120
121 void AndroidFramework::OnWindowDestroyed( ANativeWindow* window )
122 {
123   mFramework->AppStatusHandler( APP_WINDOW_DESTROYED, window );
124 }
125
126 Dali::Integration::AndroidFramework& AndroidFramework::Get()
127 {
128   DALI_ASSERT_ALWAYS( gAndroidFramework != nullptr && "AndroidFramework not instantiated" );
129
130   return *gAndroidFramework->mAndroidFramework;
131 }
132
133 AndroidFramework::AndroidFramework( Dali::Integration::AndroidFramework* androidFramework )
134  : mAndroidFramework( androidFramework ),
135    mFramework( nullptr ),
136    mNativeApplication( nullptr ),
137    mWindow( nullptr ),
138    mAssets( nullptr ),
139    mConfiguration( nullptr ),
140    mJVM( nullptr )
141 {
142   DALI_ASSERT_ALWAYS( gAndroidFramework == nullptr && "Cannot create more than one AndroidFramework." );
143
144   gAndroidFramework = this;
145 }
146
147 AndroidFramework::~AndroidFramework()
148 {
149   gAndroidFramework = nullptr;
150 }
151
152 } // namespace Adaptor
153
154 } // namespace Internal
155
156 } // namespace Dali