From 00aec3a7e271c25161461e00d59b66d811481605 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 16 Jun 2021 08:46:40 +0200 Subject: [PATCH] Don't kill my app --- .../eu/faircode/email/FragmentOptions.java | 38 +++++++++--- .../main/java/eu/faircode/email/Helper.java | 58 +++++++++++++++++++ app/src/main/res/layout/dialog_setup.xml | 28 ++++++++- app/src/main/res/values/strings.xml | 2 + 4 files changed, 117 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index bfb84570c4..be88be75bf 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -28,6 +28,8 @@ import android.content.Intent; import android.content.SharedPreferences; import android.database.Cursor; import android.database.MatrixCursor; +import android.graphics.Paint; +import android.net.Uri; import android.os.Bundle; import android.text.SpannableStringBuilder; import android.text.TextUtils; @@ -364,35 +366,55 @@ public class FragmentOptions extends FragmentBase { @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { - View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_setup, null); + final Context context = getContext(); + View dview = LayoutInflater.from(context).inflate(R.layout.dialog_setup, null); + TextView tvDozeDevice = dview.findViewById(R.id.tvDozeDevice); + TextView tvDozeAndroid = dview.findViewById(R.id.tvDozeAndroid); CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain); Group grp2 = dview.findViewById(R.id.grp2); Group grp3 = dview.findViewById(R.id.grp3); + tvDozeDevice.setPaintFlags(tvDozeDevice.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + tvDozeDevice.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Helper.view(context, Uri.parse(Helper.DONTKILL_URI), true); + } + }); + cbNotAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); prefs.edit().putBoolean("setup_reminder", !isChecked).apply(); } }); - boolean hasPermissions = Helper.hasPermission(getContext(), Manifest.permission.READ_CONTACTS); - Boolean isIgnoring = Helper.isIgnoringOptimizations(getContext()); + boolean hasPermissions = Helper.hasPermission(context, Manifest.permission.READ_CONTACTS); + Boolean isIgnoring = Helper.isIgnoringOptimizations(context); + boolean isKilling = Helper.isKilling() && !(isIgnoring == null || isIgnoring); + boolean isRequired = Helper.isDozeRequired() && !(isIgnoring == null || isIgnoring); + + tvDozeDevice.setVisibility(isKilling && !isRequired ? View.VISIBLE : View.GONE); + tvDozeAndroid.setVisibility(isRequired ? View.VISIBLE : View.GONE); + cbNotAgain.setVisibility(isRequired ? View.GONE : View.VISIBLE); grp2.setVisibility(hasPermissions ? View.GONE : View.VISIBLE); grp3.setVisibility(isIgnoring == null || isIgnoring ? View.GONE : View.VISIBLE); - return new AlertDialog.Builder(getContext()) + AlertDialog.Builder builder = new AlertDialog.Builder(context) .setView(dview) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { sendResult(Activity.RESULT_OK); } - }) - .setNegativeButton(android.R.string.cancel, null) - .create(); + }); + + if (!isRequired) + builder.setNegativeButton(android.R.string.cancel, null); + + return builder.create(); } } diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 8ae5c31902..ef8b930e59 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -164,6 +164,7 @@ public class Helper { static final String TEST_URI = "https://play.google.com/apps/testing/" + BuildConfig.APPLICATION_ID; static final String GRAVATAR_PRIVACY_URI = "https://meta.stackexchange.com/questions/44717/is-gravatar-a-privacy-risk"; static final String LICENSE_URI = "https://www.gnu.org/licenses/gpl-3.0.html"; + static final String DONTKILL_URI = "https://dontkillmyapp.com/"; static final Pattern EMAIL_ADDRESS = Pattern.compile( @@ -875,14 +876,71 @@ public class Helper { return "Samsung".equalsIgnoreCase(Build.MANUFACTURER); } + static boolean isOnePlus() { + return "OnePlus".equalsIgnoreCase(Build.MANUFACTURER); + } + + static boolean isHuawei() { + return "HUAWEI".equalsIgnoreCase(Build.MANUFACTURER); + } + static boolean isXiaomi() { return "Xiaomi".equalsIgnoreCase(Build.MANUFACTURER); } + static boolean isMeizu() { + return "Meizu".equalsIgnoreCase(Build.MANUFACTURER); + } + + static boolean isAsus() { + return "asus".equalsIgnoreCase(Build.MANUFACTURER); + } + + static boolean isWiko() { + return "WIKO".equalsIgnoreCase(Build.MANUFACTURER); + } + + static boolean isLenovo() { + return "LENOVO".equalsIgnoreCase(Build.MANUFACTURER); + } + + static boolean isOppo() { + return "OPPO".equalsIgnoreCase(Build.MANUFACTURER); + } + + static boolean isRealme() { + return "realme".equalsIgnoreCase(Build.MANUFACTURER); + } + + static boolean isBlackview() { + return "Blackview".equalsIgnoreCase(Build.MANUFACTURER); + } + static boolean isSurfaceDuo() { return ("Microsoft".equalsIgnoreCase(Build.MANUFACTURER) && "Surface Duo".equals(Build.MODEL)); } + static boolean isKilling() { + // https://dontkillmyapp.com/ + return (isSamsung() || + isOnePlus() || + isHuawei() || + isXiaomi() || + isMeizu() || + isAsus() || + isWiko() || + isLenovo() || + isOppo() || + // Vivo + isRealme() || + isBlackview() || + BuildConfig.DEBUG); + } + + static boolean isDozeRequired() { + return (Build.VERSION.SDK_INT > Build.VERSION_CODES.R); + } + static void reportNoViewer(Context context, Uri uri) { reportNoViewer(context, new Intent().setData(uri)); } diff --git a/app/src/main/res/layout/dialog_setup.xml b/app/src/main/res/layout/dialog_setup.xml index 5385539253..387144a6de 100644 --- a/app/src/main/res/layout/dialog_setup.xml +++ b/app/src/main/res/layout/dialog_setup.xml @@ -83,6 +83,32 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/title3" /> + + + + + app:layout_constraintTop_toBottomOf="@id/tvDozeAndroid" /> In the next Android dialog change "Not optimized" to "All apps", select this app and select "Don\'t optimize" High battery usage? Sync stopped? + This is probably required for this device + This is required for this Android version Background restrictions are enabled Data saver is enabled Show advanced options