2 * Copyright (c) 2013-2015 TRUSTONIC LIMITED
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 package com
.trustonic
.tuiservice
;
34 import java
.util
.LinkedList
;
35 import java
.util
.concurrent
.atomic
.AtomicBoolean
;
37 import com
.trustonic
.tuiservice
.TuiActivity
.PerformActionInBackground
;
38 import com
.trustonic
.util
.tLog
;
40 import android
.content
.Context
;
41 import android
.content
.Intent
;
42 import android
.graphics
.Bitmap
;
43 import android
.graphics
.BitmapFactory
;
44 //import android.os.Build;
45 //import android.util.DisplayMetrics;
46 import android
.os
.PowerManager
;
47 //import android.view.Surface;
49 public class TuiTlcWrapper
{
50 private static final String TAG
= TuiTlcWrapper
.class.getSimpleName();
52 // public static final int INIT_SESSION = 1;
53 public static final int CLOSE_SESSION
= 2;
55 private static Context context
= null;
56 private static PerformActionInBackground handler
= null;
57 private static final Object sessionSignal
= new Object();
58 private static final Object startSignal
= new Object();
59 private static final Object finishSignal
= new Object();
60 private static boolean sessionOpened
= false;
61 private static AtomicBoolean isActityAlive
= new AtomicBoolean();
62 private static AtomicBoolean isActivityCreated
= new AtomicBoolean();
64 private static PowerManager pm
;
65 private static PowerManager
.WakeLock wl
;
68 public static boolean isSessionOpened() {
69 synchronized (sessionSignal
) {
73 public static void setSessionOpened(boolean sessionOpened
) {
74 synchronized (sessionSignal
) {
75 TuiTlcWrapper
.sessionOpened
= sessionOpened
;
79 public static Object
getStartSignal() {
82 public static Object
getFinishSignal() {
86 public static PerformActionInBackground
getHandler() {
89 public static void setHandler(PerformActionInBackground handler
) {
90 TuiTlcWrapper
.handler
= handler
;
93 public static void setIsActityAlive(boolean status
) {
94 TuiTlcWrapper
.isActityAlive
.set(status
);
97 public static void setIsActivityCreated(boolean status
) {
98 TuiTlcWrapper
.isActivityCreated
.set(status
);
101 public static boolean startTuiSession(){
104 synchronized (startSignal
) {
105 /* create activities */
106 Intent myIntent
= new Intent(context
, TuiActivity
.class);
107 myIntent
.setFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
108 | Intent
.FLAG_DEBUG_LOG_RESOLUTION
109 | Intent
.FLAG_ACTIVITY_NO_ANIMATION
);
110 context
.startActivity(myIntent
);
111 /* Wait activity created*/
112 startSignal
.wait(5000);
113 if( ! TuiTlcWrapper
.isActityAlive
.get()) {
114 tLog
.d(TAG
, "ERROR ACTIVITY timout");
119 } catch (InterruptedException e
) {
120 // TODO Auto-generated catch block
124 /* Enable cancel events catching */
125 synchronized (sessionSignal
) {
126 TuiTlcWrapper
.sessionOpened
= true;
132 public static void acquireWakeLock() {
133 /* Ensure that CPU is still running */
136 } catch (Exception e1
) {
137 // TODO Auto-generated catch block
138 e1
.printStackTrace();
142 public static void finishTuiSession(){
143 tLog
.d(TAG
, "finishTuiSession!");
144 if(TuiTlcWrapper
.isActivityCreated
.get()) {
145 /* Disable cancel events catching */
146 synchronized (sessionSignal
) {
147 TuiTlcWrapper
.sessionOpened
= false;
151 synchronized (finishSignal
) {
152 /* Send a message to the activity UI thread */
153 handler
.sendMessage(handler
.obtainMessage(CLOSE_SESSION
));
154 /* Wait activity closed */
155 finishSignal
.wait(5000);
156 if(TuiTlcWrapper
.isActivityCreated
.get()) {
157 tLog
.d(TAG
, "ERROR ACTIVITY timout");
160 }catch (Exception e
) {
161 // TODO: handle exception
169 } catch (Exception e2
) {
170 // TODO Auto-generated catch block
171 e2
.printStackTrace();
176 /* Initialize static members */
177 public static void init(Context ctxt
) {
181 pm
= (PowerManager
) ctxt
.getSystemService(Context
.POWER_SERVICE
);
182 wl
= pm
.newWakeLock(PowerManager
.PARTIAL_WAKE_LOCK
, "TuiService");
184 /* Start the TlcTui native thread */
188 /* Native functions */
189 public static native int startTlcTui();
190 public static native boolean notifyEvent(int eventType
);
193 * this is used to load the library on application startup. The
194 * library has already been unpacked to the app specific folder
195 * at installation time by the package manager.
198 System
.loadLibrary("Tui");