Skip to content

Commit 998f11e

Browse files
committed
Add a scan resume dialog
1 parent fa6651c commit 998f11e

File tree

3 files changed

+121
-6
lines changed

3 files changed

+121
-6
lines changed

app/src/main/java/fuzion24/device/vulnerability/test/ui/MainActivity.java

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import android.view.View;
1919
import android.widget.TextView;
2020

21-
import com.nowsecure.android.vts.BuildConfig;
21+
import com.afollestad.materialdialogs.DialogAction;
22+
import com.afollestad.materialdialogs.MaterialDialog;
2223
import com.nowsecure.android.vts.R;
2324

24-
import org.json.JSONArray;
2525
import org.json.JSONException;
2626
import org.json.JSONObject;
2727

@@ -60,7 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {
6060
getSupportActionBar().setTitle(R.string.app_name);
6161

6262
if (savedInstanceState != null && savedInstanceState.containsKey(SERIALIZABLE_RESULTS)) {
63-
testResults = (ArrayList<VulnerabilityTestResult>) savedInstanceState.getSerializable(SERIALIZABLE_RESULTS);
63+
testResults = (ArrayList<VulnerabilityTestResult>) savedInstanceState.getSerializable(SERIALIZABLE_RESULTS);
6464
} else {
6565
testResults = new ArrayList<>();
6666
}
@@ -95,7 +95,7 @@ protected void onCreate(Bundle savedInstanceState) {
9595
tvBuildSDK.setText(devInfo.getBuildSDK());
9696

9797
StringBuilder sb = new StringBuilder();
98-
for(String s : devInfo.getSupportedABIS()){
98+
for (String s : devInfo.getSupportedABIS()) {
9999
sb.append(s);
100100
sb.append(" ");
101101
}
@@ -134,7 +134,7 @@ public void onClick(View v) {
134134
}
135135

136136
}).show();
137-
137+
138138
return true;
139139
}
140140

@@ -146,7 +146,7 @@ public void onClick(View v) {
146146
intent.setType("text/plain");
147147
intent.putExtra(Intent.EXTRA_SUBJECT, "Android VTS Results");
148148
intent.putExtra(Intent.EXTRA_TEXT, json.toString(4));
149-
} else if(itemId == R.id.menu_share_results) {
149+
} else if (itemId == R.id.menu_share_results) {
150150
Uri formUri = new ShareViaGoogleForm(json).buildUri();
151151
intent = new Intent(Intent.ACTION_VIEW, formUri);
152152
}
@@ -177,10 +177,59 @@ public void finished(final List<VulnerabilityTestResult> results) {
177177

178178
emptyView.setVisibility(View.GONE);
179179
recyclerAdapter.updateResults(results);
180+
181+
showScanResume(results);
180182
}
181183
}).execute();
182184
}
183185

186+
private void showScanResume(final List<VulnerabilityTestResult> results) {
187+
int numberOfFailed = 0;
188+
189+
for (VulnerabilityTestResult result : results) {
190+
if (result.getException() != null) {
191+
continue;
192+
}
193+
194+
if (result.isVulnerable()) {
195+
numberOfFailed++;
196+
}
197+
}
198+
199+
MaterialDialog.Builder dialogBuilder = new MaterialDialog.Builder(this)
200+
.title(R.string.scan_details)
201+
.customView(R.layout.dialog_scan_details_layout, true)
202+
.positiveText(R.string.dismiss);
203+
204+
if (numberOfFailed > 0) {
205+
dialogBuilder.negativeText(R.string.my_device_is_vulnerable_info)
206+
.onNegative(new MaterialDialog.SingleButtonCallback() {
207+
@Override
208+
public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
209+
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.nowsecure.com/blog/2015/11/18/my-device-is-vulnerable-now-what/"));
210+
startActivity(browserIntent);
211+
}
212+
});
213+
}
214+
215+
View view = dialogBuilder.show().getCustomView();
216+
217+
TextView state = (TextView) view.findViewById(R.id.scan_details_device_state);
218+
if (numberOfFailed > 0) {
219+
state.setText(R.string.scan_details_vulnerable_message);
220+
state.setTextColor(getResources().getColor(R.color.red));
221+
} else {
222+
state.setText(R.string.scan_details_secure_message);
223+
state.setTextColor(getResources().getColor(R.color.green));
224+
}
225+
226+
TextView numberOfTests = (TextView) view.findViewById(R.id.scan_details_number_tests);
227+
numberOfTests.setText(String.valueOf(results.size()));
228+
229+
TextView numberOfFailedTests = (TextView) view.findViewById(R.id.scan_details_failed_tests);
230+
numberOfFailedTests.setText(String.valueOf(numberOfFailed));
231+
}
232+
184233
@Override
185234
public void onConfigurationChanged(Configuration newConfig) {
186235
super.onConfigurationChanged(newConfig);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:orientation="vertical">
7+
8+
<TextView
9+
android:id="@+id/scan_details_device_state"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:padding="5dp"
13+
android:text="@string/scan_details_secure_message"
14+
android:textSize="18sp"
15+
android:textStyle="bold"/>
16+
17+
<LinearLayout
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content"
20+
android:orientation="horizontal"
21+
android:paddingLeft="5dp"
22+
android:paddingTop="2dp">
23+
24+
<TextView
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content"
27+
android:paddingRight="5dp"
28+
android:text="@string/scan_details_number_tests"/>
29+
30+
<TextView
31+
android:id="@+id/scan_details_number_tests"
32+
android:layout_width="match_parent"
33+
android:layout_height="wrap_content"
34+
android:text="10"/>
35+
36+
</LinearLayout>
37+
38+
39+
<LinearLayout
40+
android:layout_width="wrap_content"
41+
android:layout_height="wrap_content"
42+
android:orientation="horizontal"
43+
android:paddingLeft="5dp"
44+
android:paddingTop="2dp">
45+
46+
<TextView
47+
android:layout_width="match_parent"
48+
android:layout_height="wrap_content"
49+
android:paddingRight="5dp"
50+
android:text="@string/scan_details_number_failed_tests"/>
51+
52+
<TextView
53+
android:id="@+id/scan_details_failed_tests"
54+
android:layout_width="match_parent"
55+
android:layout_height="wrap_content"
56+
android:text="10"/>
57+
58+
</LinearLayout>
59+
60+
</LinearLayout>

app/src/main/res/values/strings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,11 @@
3535
<string name="cvssv2">CVSSV2: </string>
3636
<string name="cve_date">CVE Date: </string>
3737
<string name="notification_new_tests">New tests are available</string>
38+
<string name="scan_details">Scan details</string>
39+
<string name="my_device_is_vulnerable_info">Now What?</string>
40+
<string name="scan_details_number_failed_tests">Number of failed tests:</string>
41+
<string name="scan_details_number_tests">Number of tests:</string>
42+
<string name="scan_details_secure_message">Your device is secure</string>
43+
<string name="scan_details_vulnerable_message">Your device is vulnerable</string>
3844

3945
</resources>

0 commit comments

Comments
 (0)