Ensure we read/write to/from current SharedPreferences

When getting SharedPreferences of other termux sharedUserId app packages, we get its Context first and if its null, it would mean that the package is not installed or likely has a different signature. For this case, we force exit the app in some places, since that shouldn't occur. Previously, if it was null, we were defaulting to getting SharedPreferences of current package context instead, which would mix keys of other packages with current one. SharedPreferences of other app packages aren't being used currently, so this isn't an issue, this commit just fixes the issue for future.

Force exit will also be triggered if Termux is forked and TermuxConstants.TERMUX_PACKAGE_NAME is not updated to the same value as applicationId since TermuxActivity.onCreate() will fail to get SharedPreferences of TermuxConstants.TERMUX_PACKAGE_NAME.

Moreover, its normally not allowed to install apps with different signatures, but if its done, we "may" need AndroidManifest `queries` entries in andorid 11, check PackageUtils.getSigningCertificateSHA256DigestForPackage() for details.
This commit is contained in:
agnostic-apollo
2021-05-14 03:54:13 +05:00
parent af115c9966
commit 79df863b75
17 changed files with 218 additions and 36 deletions

View File

@@ -61,6 +61,13 @@
<string name="error_file_not_executable">The %1$s at path is not executable. Permission Denied.</string>
<!-- PackageUtils -->
<string name="error_get_package_context_failed_title">Failed To Get Package Context</string>
<string name="error_get_package_context_failed_message">Failed to get package context for the \"%1$s\" package. This may be because the app package is not installed or it has different APK signature from the current app. Check install instruction at %2$s for more details.</string>
<!-- PermissionUtils -->
<string name="message_sudo_please_grant_permissions">Please grant permissions on next screen</string>
<string name="error_display_over_other_apps_permission_not_granted">&TERMUX_APP_NAME; requires \"Display over other apps\" permission to start terminal sessions from background on Android >= 10. Grants it from Settings -> Apps -> &TERMUX_APP_NAME; -> Advanced</string>
@@ -72,11 +79,6 @@
<!-- TermuxUtils -->
<string name="msg_report_issue">If you want to report this issue, then copy its text from the options menu (3-dots on top right) and post an issue on one of the following links.\n\nIf you are posting a Termux app crash report, then please provide details on what you were doing that caused the crash and how to reproduce it, if possible.\n\nIf you are posting an issue on Github, then post it in the repository at which the report belongs at. You may optionally remove any device specific info that you consider private or don\'t want to share or that is not relevant to the issue.</string>
<!-- ShellUtils -->
<string name="error_sending_sigkill_to_process">Sending SIGKILL to process on user request or because android is killing the execution service</string>
<string name="error_execution_cancelled">Execution has been cancelled since execution service is being killed</string>
@@ -87,6 +89,11 @@
<!-- TermuxUtils -->
<string name="msg_report_issue">If you want to report this issue, then copy its text from the options menu (3-dots on top right) and post an issue on one of the following links.\n\nIf you are posting a Termux app crash report, then please provide details on what you were doing that caused the crash and how to reproduce it, if possible.\n\nIf you are posting an issue on Github, then post it in the repository at which the report belongs at. You may optionally remove any device specific info that you consider private or don\'t want to share or that is not relevant to the issue.</string>
<!-- Log Level -->
<string name="log_level_title">Log Level</string>
<string name="log_level_off">"Off"</string>