Skip to content
This repository was archived by the owner on Sep 13, 2024. It is now read-only.

Commit 18c8bea

Browse files
Merge pull request #24 from coderbunker/issue#14-secret_touch
Implemented secret touch to open PIN dialog
2 parents b5cbf27 + 6fec81e commit 18c8bea

File tree

5 files changed

+146
-35
lines changed

5 files changed

+146
-35
lines changed
0 Bytes
Binary file not shown.

app/src/main/java/com/coderbunker/kioskapp/KioskActivity.java

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import com.coderbunker.kioskapp.lib.HOTP;
2424
import com.coderbunker.kioskapp.lib.TOTP;
2525

26-
import java.security.InvalidKeyException;
27-
import java.security.NoSuchAlgorithmException;
2826
import java.util.ArrayList;
2927
import java.util.Arrays;
3028
import java.util.List;
@@ -50,7 +48,7 @@ public class KioskActivity extends Activity {
5048
private Button n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
5149
private ArrayList<Button> numbers;
5250

53-
private int cptPwd;
51+
private int cptPwd, clicks = 0;
5452

5553
private Timer timerLock, timerNav;
5654

@@ -82,6 +80,14 @@ protected void onCreate(Bundle savedInstanceState) {
8280
"com.coderbunker.kioskapp", Context.MODE_PRIVATE);
8381

8482
URL = prefs.getString("url", "https://naibaben.github.io/");
83+
String otp = prefs.getString("otp", null);
84+
85+
if (otp == null) {
86+
Intent intent = new Intent(KioskActivity.this, SettingsActivity.class);
87+
Toast.makeText(context, "Please setup first the One-Time-Passwords on your phone before you use the kiosk mode.", Toast.LENGTH_LONG).show();
88+
startActivity(intent);
89+
finish();
90+
}
8591

8692
//Get the webView and load the URL
8793
webView = findViewById(R.id.webview);
@@ -124,23 +130,60 @@ public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError e
124130

125131
Toast.makeText(this, "Loading " + URL, Toast.LENGTH_SHORT).show();
126132

133+
//Touch events for password
134+
webView.setOnClickListener(new View.OnClickListener() {
135+
@Override
136+
public void onClick(View v) {
137+
hideSystemUI();
138+
139+
System.out.println("Touch" + clicks);
140+
141+
if (!dialogPrompted && locked) {
142+
new Timer().schedule(new TimerTask() {
143+
@Override
144+
public void run() {
145+
clicks = 0;
146+
}
147+
}, 500);
148+
clicks++;
149+
System.out.println(clicks);
150+
if (clicks >= 4) {
151+
askPassword();
152+
clicks = 0;
153+
}
154+
} else {
155+
156+
}
157+
}
158+
});
127159
webView.setOnTouchListener(new View.OnTouchListener() {
128160

129161
@Override
130162
public boolean onTouch(View view, MotionEvent motionEvent) {
131163
hideSystemUI();
132164

165+
System.out.println("Touch" + clicks);
166+
133167
if (!dialogPrompted && locked) {
134-
askPassword();
168+
new Timer().schedule(new TimerTask() {
169+
@Override
170+
public void run() {
171+
clicks = 0;
172+
}
173+
}, 500);
174+
clicks++;
175+
System.out.println(clicks);
176+
if (clicks >= 4) {
177+
askPassword();
178+
clicks = 0;
179+
}
135180
return true;
136181
} else
137182
return false;
138-
139-
140183
}
141184
});
142185

143-
numbers = new ArrayList<Button>();
186+
numbers = new ArrayList<>();
144187
}
145188

146189

@@ -185,11 +228,6 @@ public void onWindowFocusChanged(boolean hasFocus) {
185228
}
186229
}
187230

188-
189-
public static void setURL(String newURL) {
190-
URL = newURL;
191-
}
192-
193231
public void enterNumber(String number) {
194232

195233
switch (cptPwd) {
@@ -249,6 +287,7 @@ private void checkPwd() {
249287
prefs.edit().putInt("hotp_counter", hotp_counter).apply();
250288

251289
launchHome();
290+
return;
252291
}
253292
}
254293

app/src/main/java/com/coderbunker/kioskapp/SettingsActivity.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
import android.content.SharedPreferences;
77
import android.graphics.Bitmap;
88
import android.graphics.Color;
9-
import android.support.v7.app.AppCompatActivity;
109
import android.os.Bundle;
11-
import android.view.KeyEvent;
1210
import android.view.MenuItem;
1311
import android.view.View;
1412
import android.webkit.URLUtil;
@@ -24,6 +22,8 @@
2422
import com.google.zxing.common.BitMatrix;
2523
import com.google.zxing.qrcode.QRCodeWriter;
2624

25+
import java.util.UUID;
26+
2727
import static android.widget.Toast.LENGTH_LONG;
2828

2929
public class SettingsActivity extends Activity {
@@ -97,8 +97,15 @@ public void onClick(View v) {
9797
editor.apply();
9898
}
9999

100-
otp_uri = "otpauth://totp/Time%20based?secret=" + otp + "&issuer=Kiosk%20Coderbunker";
101-
hotp_uri = "otpauth://hotp/Hash%20based?secret=" + otp + "&issuer=Kiosk%20Coderbunker&counter=" + (hotp_counter - 1) + "&algorithm=SHA1";
100+
String device = prefs.getString("uuid", null);
101+
102+
if (device == null) {
103+
device = UUID.randomUUID().toString();
104+
prefs.edit().putString("uuid", device).apply();
105+
}
106+
107+
otp_uri = "otpauth://totp/" + device + "%20-%20Time?secret=" + otp + "&issuer=Kiosk%20Coderbunker";
108+
hotp_uri = "otpauth://hotp/" + device + "%20-%20Counter?secret=" + otp + "&issuer=Kiosk%20Coderbunker&counter=" + (hotp_counter - 1) + "&algorithm=SHA1";
102109

103110
generateQRCodeTOTP(otp_uri);
104111
generateQRCodeHOTP(hotp_uri);

app/src/main/res/layout/activity_settings.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
android:id="@+id/root"
66
android:layout_width="match_parent"
77
android:layout_height="match_parent"
8+
android:background="#FFF"
89
android:orientation="vertical"
910
tools:context=".SettingsActivity">
1011

@@ -108,13 +109,17 @@
108109
android:layout_width="match_parent"
109110
android:layout_height="wrap_content"
110111
android:hint="Enter the URL here..."
111-
android:inputType="textUri" />
112+
android:inputType="textUri"
113+
android:textColor="#000" />
112114

113115
<Button
114116
android:id="@+id/btnSave"
115117
android:layout_width="match_parent"
116118
android:layout_height="wrap_content"
117-
android:text="Save" />
119+
android:background="#FFF"
120+
android:elevation="4dp"
121+
android:text="Save"
122+
android:textColor="#000" />
118123

119124

120125
</LinearLayout>

app/src/main/res/layout/password_dialog.xml

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="fill_parent"
4-
android:layout_height="fill_parent">
4+
android:layout_height="fill_parent"
5+
android:background="#FFF">
56

67
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
78
android:id="@+id/layout_root"
@@ -22,42 +23,60 @@
2223
android:layout_width="wrap_content"
2324
android:layout_height="wrap_content"
2425
android:layout_weight="1"
25-
android:clickable="false" />
26+
android:background="#FFF"
27+
android:clickable="false"
28+
android:textColor="#000"
29+
android:textSize="30sp" />
2630

2731
<Button
2832
android:id="@+id/b2"
2933
android:layout_width="wrap_content"
3034
android:layout_height="wrap_content"
3135
android:layout_weight="1"
32-
android:clickable="false" />
36+
android:background="#FFF"
37+
android:clickable="false"
38+
android:textColor="#000"
39+
android:textSize="30sp" />
3340

3441
<Button
3542
android:id="@+id/b3"
3643
android:layout_width="wrap_content"
3744
android:layout_height="wrap_content"
3845
android:layout_weight="1"
39-
android:clickable="false" />
46+
android:background="#FFF"
47+
android:clickable="false"
48+
android:textColor="#000"
49+
android:textSize="30sp" />
4050

4151
<Button
4252
android:id="@+id/b4"
4353
android:layout_width="wrap_content"
4454
android:layout_height="wrap_content"
4555
android:layout_weight="1"
46-
android:clickable="false" />
56+
android:background="#FFF"
57+
android:clickable="false"
58+
android:textColor="#000"
59+
android:textSize="30sp" />
4760

4861
<Button
4962
android:id="@+id/b5"
5063
android:layout_width="wrap_content"
5164
android:layout_height="wrap_content"
5265
android:layout_weight="1"
53-
android:clickable="false" />
66+
android:background="#FFF"
67+
android:clickable="false"
68+
android:textColor="#000"
69+
android:textSize="30sp" />
5470

5571
<Button
5672
android:id="@+id/b6"
5773
android:layout_width="wrap_content"
5874
android:layout_height="wrap_content"
5975
android:layout_weight="1"
60-
android:clickable="false" />
76+
android:background="#FFF"
77+
android:clickable="false"
78+
android:textColor="#000"
79+
android:textSize="30sp" />
6180

6281
</LinearLayout>
6382

@@ -88,67 +107,108 @@
88107
<Button
89108
android:id="@+id/number1"
90109
android:layout_columnWeight="1"
110+
android:layout_margin="3dp"
111+
android:background="#FFF"
112+
android:elevation="4dp"
91113
android:tag="1"
92-
android:text="1" />
114+
android:text="1"
115+
android:textColor="#000" />
93116

94117
<Button
95118
android:id="@+id/number2"
96119
android:layout_columnWeight="1"
120+
android:layout_margin="3dp"
121+
android:background="#FFF"
122+
android:elevation="4dp"
97123
android:tag="2"
98-
android:text="2" />
124+
android:text="2"
125+
android:textColor="#000" />
99126

100127
<Button
101128
android:id="@+id/number3"
102129
android:layout_columnWeight="1"
130+
android:layout_margin="3dp"
131+
android:background="#FFF"
132+
android:elevation="4dp"
103133
android:tag="3"
104-
android:text="3" />
134+
android:text="3"
135+
android:textColor="#000" />
105136

106137
<Button
107138
android:id="@+id/number4"
108139
android:layout_columnWeight="1"
140+
android:layout_margin="3dp"
141+
android:background="#FFF"
142+
android:elevation="4dp"
109143
android:tag="4"
110-
android:text="4" />
144+
android:text="4"
145+
android:textColor="#000" />
111146

112147
<Button
113148
android:id="@+id/number5"
114149
android:layout_columnWeight="1"
150+
android:layout_margin="3dp"
151+
android:background="#FFF"
152+
android:elevation="4dp"
115153
android:tag="5"
116-
android:text="5" />
154+
android:text="5"
155+
android:textColor="#000" />
117156

118157
<Button
119158
android:id="@+id/number6"
120159
android:layout_columnWeight="1"
160+
android:layout_margin="3dp"
161+
android:background="#FFF"
162+
android:elevation="4dp"
121163
android:tag="6"
122-
android:text="6" />
164+
android:text="6"
165+
android:textColor="#000" />
123166

124167
<Button
125168
android:id="@+id/number7"
126169
android:layout_columnWeight="1"
170+
android:layout_margin="3dp"
171+
android:background="#FFF"
172+
android:elevation="4dp"
127173
android:onClick=""
128174
android:tag="7"
129-
android:text="7" />
175+
android:text="7"
176+
android:textColor="#000" />
130177

131178
<Button
132179
android:id="@+id/number8"
133180
android:layout_columnWeight="1"
181+
android:layout_margin="3dp"
182+
android:background="#FFF"
183+
android:elevation="4dp"
134184
android:onClick=""
135185
android:tag="8"
136-
android:text="8" />
186+
android:text="8"
187+
android:textColor="#000" />
137188

138189
<Button
139190
android:id="@+id/number9"
140191
android:layout_columnWeight="1"
192+
android:layout_margin="3dp"
193+
android:background="#FFF"
194+
android:elevation="4dp"
141195
android:onClick=""
142196
android:tag="9"
143-
android:text="9" />
197+
android:text="9"
198+
android:textColor="#000" />
144199

145200
<Button
146201
android:id="@+id/number0"
147202
android:layout_column="1"
148203
android:layout_columnWeight="1"
204+
android:layout_margin="3dp"
205+
android:background="#FFF"
206+
android:elevation="4dp"
149207
android:onClick=""
150208
android:tag="0"
151-
android:text="0" />
209+
android:text="0"
210+
android:textColor="#000" />
211+
152212
</GridLayout>
153213

154214
</RelativeLayout>

0 commit comments

Comments
 (0)