Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

feat: Add Check environment patch #683

Merged
merged 40 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a1ed41a
feat: Add `Check environment` patch
oSumAtrIX Aug 30, 2024
7b15722
Merge branch 'dev' into feat/check-env
oSumAtrIX Aug 31, 2024
186113e
feat: Add `Check environment` patch
oSumAtrIX Sep 1, 2024
7cc885b
Merge branch 'dev' into feat/check-env
oSumAtrIX Sep 1, 2024
35b1e0f
rename method
oSumAtrIX Sep 1, 2024
3eb2229
use activity context
oSumAtrIX Sep 1, 2024
7b401f6
small changes
oSumAtrIX Sep 1, 2024
bc3faf7
Use last three digits to prevent brute forcing the hashed IP
oSumAtrIX Sep 2, 2024
498aaf5
fix some issues add todos
oSumAtrIX Sep 2, 2024
d7bbf18
refactor: Run all checks off main thread in sequence. Fix dialog but…
LisoUseInAIKyrios Sep 2, 2024
40e6892
fix: Verify patch time is not in the future
LisoUseInAIKyrios Sep 3, 2024
b908366
fix: Check data returned from ip service. Try other services if needed.
LisoUseInAIKyrios Sep 3, 2024
3f18ac7
fix: Remove Check if manager is installed
LisoUseInAIKyrios Sep 3, 2024
5fa21bf
fix: Check device hardware signature first and use that as the only i…
LisoUseInAIKyrios Sep 3, 2024
6a441a4
fix: Remove ip check that sometimes fails due to privacy concerns and…
LisoUseInAIKyrios Sep 3, 2024
e1e70a4
fix: Remove debugging
LisoUseInAIKyrios Sep 3, 2024
92246af
fix: Remove social media links, as the main website is where they sh…
LisoUseInAIKyrios Sep 3, 2024
69e6bf9
fix: Don't show any dialog buttons until after a few seconds
LisoUseInAIKyrios Sep 3, 2024
7d6d1aa
fix: Use empty space for buttons until they are shown
LisoUseInAIKyrios Sep 3, 2024
0af3a71
fix: Wait 10 seconds before showing a dialog button
LisoUseInAIKyrios Sep 3, 2024
2d2c356
refactor: Allow forcing the warning dialog by including `"revanced_ch…
LisoUseInAIKyrios Sep 3, 2024
a16fd62
fix: Close the app if the official website is opened
LisoUseInAIKyrios Sep 3, 2024
9495fae
fix: Do not check install time if installing non root thru adb, to en…
LisoUseInAIKyrios Sep 3, 2024
fab864d
fix: Use info logging since a fresh install will not have debugging e…
LisoUseInAIKyrios Sep 3, 2024
48b48f4
fix: Use a longer delay so the announcement patch is less likely to a…
LisoUseInAIKyrios Sep 3, 2024
9677c7b
fix: Use info logging since a fresh install will not have debugging e…
LisoUseInAIKyrios Sep 3, 2024
f975b84
refactor
LisoUseInAIKyrios Sep 3, 2024
51bf121
fix: Add helper method to force a specific dialog to show on top
LisoUseInAIKyrios Sep 4, 2024
0dac63b
fix: Do not show patch time failure if app data is cleared. Show how…
LisoUseInAIKyrios Sep 4, 2024
b47fab4
fix: Use install time check to pass Termux installs. Do not show war…
LisoUseInAIKyrios Sep 4, 2024
2dc043e
fix: Show which hash failed
LisoUseInAIKyrios Sep 4, 2024
0a5cb8e
fix: Log both device and patch time strings
LisoUseInAIKyrios Sep 4, 2024
c21b1d4
fix: Log both device and patch time strings. Remove `Build.SERIAL` a…
LisoUseInAIKyrios Sep 5, 2024
778ea1d
fix: use UTF8 just in case Board.properties has foreign characters
LisoUseInAIKyrios Sep 5, 2024
9cdc943
fix: Do not hide the dialog buttons if the user changes apps then cha…
LisoUseInAIKyrios Sep 5, 2024
0268869
small refactor
oSumAtrIX Sep 5, 2024
925ee8c
fix wording/deprecation warnings
oSumAtrIX Sep 5, 2024
7ea8c56
fix: Use Android 6.0 sorting
LisoUseInAIKyrios Sep 5, 2024
5a20c02
fix: Use spacing between bullet points and text
LisoUseInAIKyrios Sep 5, 2024
2c4915a
fix: Cleanup of time check and comments
LisoUseInAIKyrios Sep 6, 2024
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
112 changes: 112 additions & 0 deletions app/src/main/java/app/revanced/integrations/shared/checks/Check.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package app.revanced.integrations.shared.checks;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.text.Html;
import android.widget.Button;
import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.shared.Utils;
import app.revanced.integrations.youtube.settings.Settings;

import static android.text.Html.FROM_HTML_MODE_COMPACT;
import static app.revanced.integrations.shared.StringRef.str;

abstract class Check {
private static final Uri GOOD_SOURCE = Uri.parse("https://revanced.app");
private static final AlertDialog.Builder CHECK_FAILED_DIALOG_BUILDER = new AlertDialog.Builder(Utils.getContext())
.setCancelable(false)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(str("revanced_check_environment_failed_title"))
.setPositiveButton(str("revanced_check_environment_dialog_open_official_source_button"), (dialog, which) -> {
final var intent = new Intent(Intent.ACTION_VIEW, GOOD_SOURCE);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Utils.getContext().startActivity(intent);
})
.setNegativeButton(str("revanced_check_environment_dialog_ignore_button"), (dialog, which) -> {
final int current = Settings.CHECK_ENVIRONMENT_WARNING_ISSUED_COUNT.get();
Settings.CHECK_ENVIRONMENT_WARNING_ISSUED_COUNT.save(current + 1);

dialog.dismiss();
});


private final String failedReasonStringKey;

/**
* @param failedReasonStringKey The string key of the reason why the check failed to be shown to the user.
*/
Check(String failedReasonStringKey) {
this.failedReasonStringKey = failedReasonStringKey;
}

protected abstract boolean run();

static boolean shouldRun() {
return Settings.CHECK_ENVIRONMENT_WARNING_ISSUED_COUNT.get() < 2;
}

static void disableForever() {
Logger.printDebug(() -> "Environment checks disabled forever.");

Settings.CHECK_ENVIRONMENT_WARNING_ISSUED_COUNT.save(Integer.MAX_VALUE);
}

@SuppressLint("NewApi")
static void issueWarning(Check... failedChecks) {
final var reasons = new StringBuilder();

reasons.append("<ul>");

for (var check : failedChecks) {
reasons.append("<li>").append(str(check.failedReasonStringKey));
}

reasons.append("</ul>");

final var finalMessage = Html.fromHtml(
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved
String.format(str("revanced_check_environment_failed_message"), reasons),
FROM_HTML_MODE_COMPACT
);
AlertDialog dialog = CHECK_FAILED_DIALOG_BUILDER.setMessage(finalMessage).create();

var dismissButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
// TODO: setEnabled called on null? If this line is commented out getting:
// Unable to add window -- token null is not valid; is your activity running?
dismissButton.setEnabled(false);
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved

dialog.show();

Utils.runOnMainThread(getCountdownRunnable(dismissButton));
}

private static Runnable getCountdownRunnable(Button dismissButton) {
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved
// Using a reference to an array to be able to modify the value in the Runnable.
final int[] secondsRemaining = {5};

return new Runnable() {
@Override
public void run() {
// Reduce the remaining time by 1 second, but only show the countdown when 3 seconds are left
// to not draw the user's attention to the dismiss button too early.
if (secondsRemaining[0] > 0) {
if (secondsRemaining[0] <= 3) {
dismissButton.setText(String.format(
str("revanced_check_environment_dialog_ignore_button_countdown"),
secondsRemaining[0])
);
}

secondsRemaining[0]--;

Utils.runOnMainThreadDelayed(this, 1000);
} else {
dismissButton.setText(str("revanced_check_environment_dialog_ignore_button"));
dismissButton.setEnabled(true);
}
}
};
}
}
Loading
Loading