use of io.github.muntashirakon.AppManager.scanner.vt.VtFileReportScanItem in project AppManager by MuntashirAkon.
the class ScannerActivity method onAuthenticated.
@Override
protected void onAuthenticated(Bundle savedInstanceState) {
setContentView(R.layout.activity_scanner);
setSupportActionBar(findViewById(R.id.toolbar));
model = new ViewModelProvider(this).get(ScannerViewModel.class);
mActionBar = getSupportActionBar();
Intent intent = getIntent();
isExternalApk = intent.getBooleanExtra(EXTRA_IS_EXTERNAL, true);
mProgressIndicator = findViewById(R.id.progress_linear);
mProgressIndicator.setVisibilityAfterHide(View.GONE);
showProgress(true);
apkUri = IntentCompat.getDataUri(intent);
if (apkUri == null) {
Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show();
finish();
return;
}
File apkFile = null;
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
if (!FmProvider.AUTHORITY.equals(apkUri.getAuthority())) {
try {
fd = getContentResolver().openFileDescriptor(apkUri, "r");
if (fd == null) {
throw new FileNotFoundException("FileDescription cannot be null");
}
apkFile = FileUtils.getFileFromFd(fd);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
} else {
String path = apkUri.getPath();
if (path != null)
apkFile = new File(path);
}
model.loadSummary(apkFile, apkUri);
model.getApkChecksums().observe(this, checksums -> {
SpannableStringBuilder sb = new SpannableStringBuilder(apkUri.toString()).append("\n");
sb.append(getPrimaryText(this, getString(R.string.checksums)));
for (Pair<String, String> digest : checksums) {
sb.append("\n").append(getPrimaryText(this, digest.first + ": ")).append(getMonospacedText(digest.second));
}
((TextView) findViewById(R.id.apk_title)).setText(R.string.source_dir);
((TextView) findViewById(R.id.apk_description)).setText(sb);
});
File finalApkFile = apkFile;
model.getPackageInfo().observe(this, packageInfo -> {
if (packageInfo != null) {
String archiveFilePath = model.getApkFile().getAbsolutePath();
mPackageName = packageInfo.packageName;
final ApplicationInfo applicationInfo = packageInfo.applicationInfo;
applicationInfo.publicSourceDir = archiveFilePath;
applicationInfo.sourceDir = archiveFilePath;
mAppName = applicationInfo.loadLabel(getPackageManager());
} else {
mAppName = finalApkFile != null ? finalApkFile.getName() : apkUri.getLastPathSegment();
}
if (mActionBar != null) {
mActionBar.setTitle(mAppName);
mActionBar.setSubtitle(R.string.scanner);
}
});
model.getApkVerifierResult().observe(this, result -> {
TextView checksumDescription = findViewById(R.id.checksum_description);
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(PackageUtils.getApkVerifierInfo(result, this));
List<X509Certificate> certificates = result.getSignerCertificates();
if (certificates != null && certificates.size() > 0) {
builder.append(getCertificateInfo(certificates));
}
checksumDescription.setText(builder);
});
model.getAllClasses().observe(this, allClasses -> {
classListAll = allClasses;
((TextView) findViewById(R.id.classes_title)).setText(getResources().getQuantityString(R.plurals.classes, classListAll.size(), classListAll.size()));
findViewById(R.id.classes).setOnClickListener(v -> {
Intent intent1 = new Intent(this, ClassListingActivity.class);
intent1.putExtra(ClassListingActivity.EXTRA_APP_NAME, mAppName);
intent1.putExtra(ClassListingActivity.EXTRA_DEX_VFS_ID, model.getDexVfsId());
startActivity(intent1);
});
// Fetch tracker info
new Thread(() -> {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
try {
setTrackerInfo();
} catch (Exception e) {
e.printStackTrace();
}
}).start();
// Fetch library info
new Thread(() -> {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
try {
setLibraryInfo();
// Progress is dismissed here because this will take the largest time
runOnUiThread(() -> showProgress(false));
} catch (Exception e) {
e.printStackTrace();
}
}).start();
});
// VirusTotal
View vtView = findViewById(R.id.vt);
if (!FeatureController.isInternetEnabled() || AppPref.getVtApiKey() == null) {
vtView.setVisibility(View.GONE);
findViewById(R.id.vt_disclaimer).setVisibility(View.GONE);
}
TextView vtTitle = findViewById(R.id.vt_title);
TextView vtDescription = findViewById(R.id.vt_description);
model.getVtFileScanMeta().observe(this, vtFileScanMeta -> {
if (vtFileScanMeta == null) {
// Uploading
vtTitle.setText(R.string.vt_uploading);
} else {
// Upload completed and queued
vtTitle.setText(R.string.vt_queued);
vtDescription.setText(vtFileScanMeta.getPermalink());
}
});
model.getVtFileReport().observe(this, vtFileReport -> {
if (vtFileReport == null) {
// Failed
vtTitle.setText(R.string.vt_failed);
vtDescription.setText(null);
vtView.setOnClickListener(null);
} else {
// Successful or still queued
int positives = vtFileReport.getPositives() == null ? -1 : vtFileReport.getPositives();
if (positives < 0) {
// Still checking
vtTitle.setText(R.string.vt_queued);
vtDescription.setText(vtFileReport.getPermalink());
return;
}
CharSequence resultSummary = getString(R.string.vt_success, positives, vtFileReport.getTotal());
@ColorRes int color;
if (positives == 0) {
color = R.color.stopped;
} else if (positives <= 5) {
color = R.color.tracker;
} else
color = R.color.electric_red;
DialogTitleBuilder titleBuilder = new DialogTitleBuilder(this).setTitle(getString(R.string.vt_success, positives, vtFileReport.getTotal())).setSubtitle(getString(R.string.vt_scan_date, vtFileReport.getScanDate())).setEndIcon(R.drawable.ic_vt, v -> {
Uri vtPermalink = Uri.parse(vtFileReport.getPermalink());
Intent linkIntent = new Intent(Intent.ACTION_VIEW, vtPermalink);
if (linkIntent.resolveActivity(getPackageManager()) != null) {
startActivity(linkIntent);
}
}).setEndIconContentDescription(R.string.vt_permalink);
Spanned result;
Map<String, VtFileReportScanItem> vtFileReportScanItems = vtFileReport.getScans();
if (vtFileReportScanItems != null) {
@ColorInt int colorRed = ContextCompat.getColor(this, R.color.electric_red);
@ColorInt int colorGreen = ContextCompat.getColor(this, R.color.stopped);
ArrayList<Spannable> detectedList = new ArrayList<>();
ArrayList<Spannable> undetectedList = new ArrayList<>();
for (String avName : vtFileReportScanItems.keySet()) {
VtFileReportScanItem item = Objects.requireNonNull(vtFileReportScanItems.get(avName));
if (item.isDetected()) {
detectedList.add(new SpannableStringBuilder(getColoredText(getPrimaryText(this, avName), colorRed)).append(getSmallerText(" (" + item.getVersion() + ")")).append("\n").append(item.getMalware()));
} else {
undetectedList.add(new SpannableStringBuilder(getColoredText(getPrimaryText(this, avName), colorGreen)).append(getSmallerText(" (" + item.getVersion() + ")")));
}
}
detectedList.addAll(undetectedList);
result = getOrderedList(detectedList);
} else
result = null;
vtTitle.setText(getColoredText(resultSummary, ContextCompat.getColor(this, color)));
if (result != null) {
vtDescription.setText(R.string.tap_to_see_details);
vtView.setOnClickListener(v -> new MaterialAlertDialogBuilder(this).setCustomTitle(titleBuilder.build()).setMessage(result).setPositiveButton(R.string.ok, null).setNeutralButton(R.string.copy, (dialog, which) -> {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(getString(R.string.scan_in_vt), result);
clipboard.setPrimaryClip(clip);
Snackbar.make(vtView, R.string.copied_to_clipboard, Snackbar.LENGTH_SHORT).show();
}).show());
}
}
});
}
Aggregations