Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package fuzion24.device.vulnerability.test.ui;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand Down Expand Up @@ -48,6 +52,9 @@ public class MainActivity extends AppCompatActivity {

private static final String TAG = "VULN_TEST";

private static final int CREATE_CHECK_FOR_UPDATES_JOB = 1;
private static final int CHECK_FOR_UPDATES = 2;

private DeviceInfo devInfo;
private ArrayList<VulnerabilityTestResult> testResults;
private TextView emptyView;
Expand Down Expand Up @@ -117,17 +124,16 @@ public void onClick(View v) {
}
});


// Creates the jobs to check for updates.
JobManager.instance().cancelAllForTag(CheckForUpdatesJob.TAG);

new JobRequest.Builder(CheckForUpdatesJob.TAG)
.setPeriodic(TimeUnit.DAYS.toMillis(7))
.setRequirementsEnforced(true)
.setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)
.setPersisted(true)
.build()
.schedule();
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
createCheckForUpdatesJob();
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
CREATE_CHECK_FOR_UPDATES_JOB);
}
}

@Override
Expand Down Expand Up @@ -210,21 +216,22 @@ public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
return true;

case R.id.menu_check_updates:
final MaterialDialog progressDialog = new MaterialDialog.Builder(this)
.title(R.string.loading)
.content(R.string.checking_updates)
.cancelable(false)
.progress(true, 0)
.show();

CheckForUpdatesJob.checkForUpdates(this, progressDialog);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
checkForUpdates();
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
CHECK_FOR_UPDATES);
}

return true;

case R.id.menu_opensource_licences:
Intent mainIntent = new Intent(MainActivity.this, OpenSourceLicencesActivity.class);
startActivity(mainIntent);

return true;

default:
return super.onOptionsItemSelected(item);
}
Expand Down Expand Up @@ -311,6 +318,44 @@ public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
numberOfFailedTests.setText(String.valueOf(numberOfFailed));
}

private void createCheckForUpdatesJob() {
new JobRequest.Builder(CheckForUpdatesJob.TAG)
.setPeriodic(TimeUnit.DAYS.toMillis(7))
.setRequirementsEnforced(true)
.setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)
.setPersisted(true)
.build()
.schedule();
}

private void checkForUpdates() {
final MaterialDialog progressDialog = new MaterialDialog.Builder(this)
.title(R.string.loading)
.content(R.string.checking_updates)
.cancelable(false)
.progress(true, 0)
.show();

CheckForUpdatesJob.checkForUpdates(this, progressDialog);
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case CREATE_CHECK_FOR_UPDATES_JOB:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
createCheckForUpdatesJob();
}
break;

case CHECK_FOR_UPDATES:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
checkForUpdates();
}
break;
}
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Expand Down