-
Notifications
You must be signed in to change notification settings - Fork 913
StrandHogg detection #4498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StrandHogg detection #4498
Changes from 9 commits
e454fab
647e22c
6013a29
14675a5
f14dc23
fa17b83
15b3ef6
885a861
d9e3f60
e9814ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ package im.vector.app.core.extensions | |
|
|
||
| import android.app.Activity | ||
| import android.content.Intent | ||
| import android.os.Build | ||
| import android.os.Parcelable | ||
| import android.view.ViewGroup | ||
| import android.view.WindowManager | ||
|
|
@@ -29,6 +30,7 @@ import androidx.appcompat.app.AppCompatActivity | |
| import androidx.fragment.app.Fragment | ||
| import androidx.fragment.app.FragmentTransaction | ||
| import im.vector.app.R | ||
| import timber.log.Timber | ||
|
|
||
| fun ComponentActivity.registerStartForActivityResult(onResult: (ActivityResult) -> Unit): ActivityResultLauncher<Intent> { | ||
| return registerForActivityResult(ActivityResultContracts.StartActivityForResult(), onResult) | ||
|
|
@@ -114,9 +116,25 @@ fun AppCompatActivity.hideKeyboard() { | |
| currentFocus?.hideKeyboard() | ||
| } | ||
|
|
||
| /** | ||
| * The current activity must be the root of a task to call onBackPressed, otherwise finish activities with the same task affinity. | ||
| */ | ||
| fun AppCompatActivity.validateBackPressed(onBackPressed: () -> Unit) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add documentation to explain that this should be only used for top-level activities. A developer which is not aware of this could think that it's a good practice to use it for all activities.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Funny: I had the same mental path "A developer which is not aware of this could think that it's a good practice to use it for all activities". And now I see this comment in GitHub, and the comment in the code :) |
||
| if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R && supportFragmentManager.backStackEntryCount == 0) { | ||
| if (isTaskRoot) { | ||
| onBackPressed() | ||
| } else { | ||
| Timber.e("Application is potentially corrupted by an unknown activity") | ||
| finishAffinity() | ||
| } | ||
| } else { | ||
| onBackPressed() | ||
| } | ||
| } | ||
|
|
||
| fun Activity.restart() { | ||
| startActivity(intent) | ||
| finish() | ||
| startActivity(intent) | ||
| } | ||
|
|
||
| fun Activity.keepScreenOn() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a blocker since we're not using the build cache, wanted to highlight generating new values on each build/gradle configuration cycle may cause some of the android gradle tasks to become non cachable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, something else I did not think about.
We want to have stable builds, i.e. the same code generates the same binary (related: #842, and context in element-hq/riot-android#3131). It's important for F-Droid.
With this change it will not be the case anymore.
I have not idea how to handle that now.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we use the short git hash for the suffix? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should propably compute the task affinity suffix from tags or commit hash ?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't use it as is. taskAffinity has same format as namespace :
https://developer.android.com/studio/build/configure-app-module#set-application-id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could use the git hash as a seed for the
random()Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea to compute a suffix using git hash and just remove forbidden chars (but is there any?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So many having a
appTaskAffinitySuffixlikea${git_hash_8_digits}with aaprefix to ensure it's always starting with a letter would fit all our needs. WDYT @yostyle ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already have
gitRevision. I'm going to reuse it.