mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
Changed: Remove TermuxConstants reference from PackageUtils
This commit is contained in:
@@ -19,7 +19,6 @@ import com.termux.shared.data.DataUtils;
|
|||||||
import com.termux.shared.interact.MessageDialogUtils;
|
import com.termux.shared.interact.MessageDialogUtils;
|
||||||
import com.termux.shared.logger.Logger;
|
import com.termux.shared.logger.Logger;
|
||||||
import com.termux.shared.reflection.ReflectionUtils;
|
import com.termux.shared.reflection.ReflectionUtils;
|
||||||
import com.termux.shared.termux.TermuxConstants;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@@ -53,15 +52,19 @@ public class PackageUtils {
|
|||||||
* @param packageName The package name whose {@link Context} to get.
|
* @param packageName The package name whose {@link Context} to get.
|
||||||
* @param exitAppOnError If {@code true} and failed to get package context, then a dialog will
|
* @param exitAppOnError If {@code true} and failed to get package context, then a dialog will
|
||||||
* be shown which when dismissed will exit the app.
|
* be shown which when dismissed will exit the app.
|
||||||
|
* @param helpUrl The help user to add to {@link R.string#error_get_package_context_failed_help_url_message}.
|
||||||
* @return Returns the {@link Context}. This will {@code null} if an exception is raised.
|
* @return Returns the {@link Context}. This will {@code null} if an exception is raised.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Context getContextForPackageOrExitApp(@NonNull Context context, String packageName, final boolean exitAppOnError) {
|
public static Context getContextForPackageOrExitApp(@NonNull Context context, String packageName,
|
||||||
|
final boolean exitAppOnError, @Nullable String helpUrl) {
|
||||||
Context packageContext = getContextForPackage(context, packageName);
|
Context packageContext = getContextForPackage(context, packageName);
|
||||||
|
|
||||||
if (packageContext == null && exitAppOnError) {
|
if (packageContext == null && exitAppOnError) {
|
||||||
String errorMessage = context.getString(R.string.error_get_package_context_failed_message,
|
String errorMessage = context.getString(R.string.error_get_package_context_failed_message,
|
||||||
packageName, TermuxConstants.TERMUX_GITHUB_REPO_URL);
|
packageName);
|
||||||
|
if (!DataUtils.isNullOrEmpty(helpUrl))
|
||||||
|
errorMessage += "\n" + context.getString(R.string.error_get_package_context_failed_help_url_message, helpUrl);
|
||||||
Logger.logError(LOG_TAG, errorMessage);
|
Logger.logError(LOG_TAG, errorMessage);
|
||||||
MessageDialogUtils.exitAppWithErrorMessage(context,
|
MessageDialogUtils.exitAppWithErrorMessage(context,
|
||||||
context.getString(R.string.error_get_package_context_failed_title),
|
context.getString(R.string.error_get_package_context_failed_title),
|
||||||
|
@@ -117,7 +117,11 @@ public class TermuxUtils {
|
|||||||
return PackageUtils.getContextForPackage(context, TermuxConstants.TERMUX_WIDGET_PACKAGE_NAME);
|
return PackageUtils.getContextForPackage(context, TermuxConstants.TERMUX_WIDGET_PACKAGE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Wrapper for {@link PackageUtils#getContextForPackageOrExitApp(Context, String, boolean, String)}. */
|
||||||
|
public static Context getContextForPackageOrExitApp(@NonNull Context context, String packageName,
|
||||||
|
final boolean exitAppOnError) {
|
||||||
|
return PackageUtils.getContextForPackageOrExitApp(context, packageName, exitAppOnError, TermuxConstants.TERMUX_GITHUB_REPO_URL);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if Termux app is installed and enabled. This can be used by external apps that don't
|
* Check if Termux app is installed and enabled. This can be used by external apps that don't
|
||||||
|
@@ -10,6 +10,7 @@ import androidx.annotation.Nullable;
|
|||||||
import com.termux.shared.logger.Logger;
|
import com.termux.shared.logger.Logger;
|
||||||
import com.termux.shared.android.PackageUtils;
|
import com.termux.shared.android.PackageUtils;
|
||||||
import com.termux.shared.settings.preferences.SharedPreferenceUtils;
|
import com.termux.shared.settings.preferences.SharedPreferenceUtils;
|
||||||
|
import com.termux.shared.termux.TermuxUtils;
|
||||||
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_API_APP;
|
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_API_APP;
|
||||||
import com.termux.shared.termux.TermuxConstants;
|
import com.termux.shared.termux.TermuxConstants;
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ public class TermuxAPIAppSharedPreferences {
|
|||||||
* @return Returns the {@link TermuxAPIAppSharedPreferences}. This will {@code null} if an exception is raised.
|
* @return Returns the {@link TermuxAPIAppSharedPreferences}. This will {@code null} if an exception is raised.
|
||||||
*/
|
*/
|
||||||
public static TermuxAPIAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
public static TermuxAPIAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
||||||
Context termuxTaskerPackageContext = PackageUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_API_PACKAGE_NAME, exitAppOnError);
|
Context termuxTaskerPackageContext = TermuxUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_API_PACKAGE_NAME, exitAppOnError);
|
||||||
if (termuxTaskerPackageContext == null)
|
if (termuxTaskerPackageContext == null)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
|
@@ -13,6 +13,7 @@ import com.termux.shared.settings.preferences.SharedPreferenceUtils;
|
|||||||
import com.termux.shared.termux.TermuxConstants;
|
import com.termux.shared.termux.TermuxConstants;
|
||||||
import com.termux.shared.logger.Logger;
|
import com.termux.shared.logger.Logger;
|
||||||
import com.termux.shared.data.DataUtils;
|
import com.termux.shared.data.DataUtils;
|
||||||
|
import com.termux.shared.termux.TermuxUtils;
|
||||||
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_APP;
|
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_APP;
|
||||||
|
|
||||||
public class TermuxAppSharedPreferences {
|
public class TermuxAppSharedPreferences {
|
||||||
@@ -59,7 +60,7 @@ public class TermuxAppSharedPreferences {
|
|||||||
* @return Returns the {@link TermuxAppSharedPreferences}. This will {@code null} if an exception is raised.
|
* @return Returns the {@link TermuxAppSharedPreferences}. This will {@code null} if an exception is raised.
|
||||||
*/
|
*/
|
||||||
public static TermuxAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
public static TermuxAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
||||||
Context termuxPackageContext = PackageUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_PACKAGE_NAME, exitAppOnError);
|
Context termuxPackageContext = TermuxUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_PACKAGE_NAME, exitAppOnError);
|
||||||
if (termuxPackageContext == null)
|
if (termuxPackageContext == null)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
|
@@ -10,6 +10,7 @@ import androidx.annotation.Nullable;
|
|||||||
import com.termux.shared.logger.Logger;
|
import com.termux.shared.logger.Logger;
|
||||||
import com.termux.shared.android.PackageUtils;
|
import com.termux.shared.android.PackageUtils;
|
||||||
import com.termux.shared.settings.preferences.SharedPreferenceUtils;
|
import com.termux.shared.settings.preferences.SharedPreferenceUtils;
|
||||||
|
import com.termux.shared.termux.TermuxUtils;
|
||||||
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_BOOT_APP;
|
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_BOOT_APP;
|
||||||
import com.termux.shared.termux.TermuxConstants;
|
import com.termux.shared.termux.TermuxConstants;
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ public class TermuxBootAppSharedPreferences {
|
|||||||
* @return Returns the {@link TermuxBootAppSharedPreferences}. This will {@code null} if an exception is raised.
|
* @return Returns the {@link TermuxBootAppSharedPreferences}. This will {@code null} if an exception is raised.
|
||||||
*/
|
*/
|
||||||
public static TermuxBootAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
public static TermuxBootAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
||||||
Context termuxTaskerPackageContext = PackageUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_BOOT_PACKAGE_NAME, exitAppOnError);
|
Context termuxTaskerPackageContext = TermuxUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_BOOT_PACKAGE_NAME, exitAppOnError);
|
||||||
if (termuxTaskerPackageContext == null)
|
if (termuxTaskerPackageContext == null)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
|
@@ -11,6 +11,7 @@ import com.termux.shared.data.DataUtils;
|
|||||||
import com.termux.shared.logger.Logger;
|
import com.termux.shared.logger.Logger;
|
||||||
import com.termux.shared.android.PackageUtils;
|
import com.termux.shared.android.PackageUtils;
|
||||||
import com.termux.shared.settings.preferences.SharedPreferenceUtils;
|
import com.termux.shared.settings.preferences.SharedPreferenceUtils;
|
||||||
|
import com.termux.shared.termux.TermuxUtils;
|
||||||
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_FLOAT_APP;
|
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_FLOAT_APP;
|
||||||
import com.termux.shared.termux.TermuxConstants;
|
import com.termux.shared.termux.TermuxConstants;
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ public class TermuxFloatAppSharedPreferences {
|
|||||||
* @return Returns the {@link TermuxFloatAppSharedPreferences}. This will {@code null} if an exception is raised.
|
* @return Returns the {@link TermuxFloatAppSharedPreferences}. This will {@code null} if an exception is raised.
|
||||||
*/
|
*/
|
||||||
public static TermuxFloatAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
public static TermuxFloatAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
||||||
Context termuxFloatPackageContext = PackageUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_FLOAT_PACKAGE_NAME, exitAppOnError);
|
Context termuxFloatPackageContext = TermuxUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_FLOAT_PACKAGE_NAME, exitAppOnError);
|
||||||
if (termuxFloatPackageContext == null)
|
if (termuxFloatPackageContext == null)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
|
@@ -10,6 +10,7 @@ import androidx.annotation.Nullable;
|
|||||||
import com.termux.shared.logger.Logger;
|
import com.termux.shared.logger.Logger;
|
||||||
import com.termux.shared.android.PackageUtils;
|
import com.termux.shared.android.PackageUtils;
|
||||||
import com.termux.shared.settings.preferences.SharedPreferenceUtils;
|
import com.termux.shared.settings.preferences.SharedPreferenceUtils;
|
||||||
|
import com.termux.shared.termux.TermuxUtils;
|
||||||
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_STYLING_APP;
|
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_STYLING_APP;
|
||||||
import com.termux.shared.termux.TermuxConstants;
|
import com.termux.shared.termux.TermuxConstants;
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ public class TermuxStylingAppSharedPreferences {
|
|||||||
* @return Returns the {@link TermuxStylingAppSharedPreferences}. This will {@code null} if an exception is raised.
|
* @return Returns the {@link TermuxStylingAppSharedPreferences}. This will {@code null} if an exception is raised.
|
||||||
*/
|
*/
|
||||||
public static TermuxStylingAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
public static TermuxStylingAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
||||||
Context termuxTaskerPackageContext = PackageUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_STYLING_PACKAGE_NAME, exitAppOnError);
|
Context termuxTaskerPackageContext = TermuxUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_STYLING_PACKAGE_NAME, exitAppOnError);
|
||||||
if (termuxTaskerPackageContext == null)
|
if (termuxTaskerPackageContext == null)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
|
@@ -10,6 +10,7 @@ import androidx.annotation.Nullable;
|
|||||||
import com.termux.shared.android.PackageUtils;
|
import com.termux.shared.android.PackageUtils;
|
||||||
import com.termux.shared.settings.preferences.SharedPreferenceUtils;
|
import com.termux.shared.settings.preferences.SharedPreferenceUtils;
|
||||||
import com.termux.shared.termux.TermuxConstants;
|
import com.termux.shared.termux.TermuxConstants;
|
||||||
|
import com.termux.shared.termux.TermuxUtils;
|
||||||
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_TASKER_APP;
|
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_TASKER_APP;
|
||||||
import com.termux.shared.logger.Logger;
|
import com.termux.shared.logger.Logger;
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ public class TermuxTaskerAppSharedPreferences {
|
|||||||
* @return Returns the {@link TermuxTaskerAppSharedPreferences}. This will {@code null} if an exception is raised.
|
* @return Returns the {@link TermuxTaskerAppSharedPreferences}. This will {@code null} if an exception is raised.
|
||||||
*/
|
*/
|
||||||
public static TermuxTaskerAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
public static TermuxTaskerAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
||||||
Context termuxTaskerPackageContext = PackageUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_TASKER_PACKAGE_NAME, exitAppOnError);
|
Context termuxTaskerPackageContext = TermuxUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_TASKER_PACKAGE_NAME, exitAppOnError);
|
||||||
if (termuxTaskerPackageContext == null)
|
if (termuxTaskerPackageContext == null)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
|
@@ -10,6 +10,7 @@ import androidx.annotation.Nullable;
|
|||||||
import com.termux.shared.logger.Logger;
|
import com.termux.shared.logger.Logger;
|
||||||
import com.termux.shared.android.PackageUtils;
|
import com.termux.shared.android.PackageUtils;
|
||||||
import com.termux.shared.settings.preferences.SharedPreferenceUtils;
|
import com.termux.shared.settings.preferences.SharedPreferenceUtils;
|
||||||
|
import com.termux.shared.termux.TermuxUtils;
|
||||||
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_WIDGET_APP;
|
import com.termux.shared.termux.settings.preferences.TermuxPreferenceConstants.TERMUX_WIDGET_APP;
|
||||||
import com.termux.shared.termux.TermuxConstants;
|
import com.termux.shared.termux.TermuxConstants;
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ public class TermuxWidgetAppSharedPreferences {
|
|||||||
* @return Returns the {@link TermuxWidgetAppSharedPreferences}. This will {@code null} if an exception is raised.
|
* @return Returns the {@link TermuxWidgetAppSharedPreferences}. This will {@code null} if an exception is raised.
|
||||||
*/
|
*/
|
||||||
public static TermuxWidgetAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
public static TermuxWidgetAppSharedPreferences build(@NonNull final Context context, final boolean exitAppOnError) {
|
||||||
Context termuxTaskerPackageContext = PackageUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_WIDGET_PACKAGE_NAME, exitAppOnError);
|
Context termuxTaskerPackageContext = TermuxUtils.getContextForPackageOrExitApp(context, TermuxConstants.TERMUX_WIDGET_PACKAGE_NAME, exitAppOnError);
|
||||||
if (termuxTaskerPackageContext == null)
|
if (termuxTaskerPackageContext == null)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user