disable push notifications setting if apk was built without support

This commit is contained in:
adbenitez 2024-06-12 03:49:45 +02:00
parent 1b80bc32dd
commit 178331ce2a
4 changed files with 12 additions and 6 deletions

View file

@ -111,11 +111,13 @@ android {
productFlavors { productFlavors {
fat { fat {
dimension "none" dimension "none"
buildConfigField "boolean", "USE_PLAY_SERVICES", "false"
} }
gplay { gplay {
dimension "none" dimension "none"
applicationId "chat.delta" applicationId "chat.delta"
apply plugin: "com.google.gms.google-services" apply plugin: "com.google.gms.google-services"
buildConfigField "boolean", "USE_PLAY_SERVICES", "true"
} }
} }

View file

@ -227,11 +227,15 @@ public class ApplicationContext extends MultiDexApplication {
fetchWorkRequest); fetchWorkRequest);
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
if (BuildConfig.USE_PLAY_SERVICES) {
if (Prefs.isPushEnabled(this)) { if (Prefs.isPushEnabled(this)) {
FcmReceiveService.register(this); FcmReceiveService.register(this);
} else { } else {
Log.i(TAG, "FCM disabled in user settings"); Log.i(TAG, "FCM disabled in user settings");
} }
} else {
Log.i(TAG, "FCM disabled at build time");
}
} }
public JobManager getJobManager() { public JobManager getJobManager() {

View file

@ -21,6 +21,7 @@ import androidx.preference.Preference;
import android.text.TextUtils; import android.text.TextUtils;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity; import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.BuildConfig;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.connect.DcHelper; import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.connect.KeepAliveService; import org.thoughtcrime.securesms.connect.KeepAliveService;
@ -74,6 +75,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
CheckBoxPreference usePushService = this.findPreference("pref_push_enabled"); CheckBoxPreference usePushService = this.findPreference("pref_push_enabled");
usePushService.setChecked(Prefs.isPushEnabled(getContext())); usePushService.setChecked(Prefs.isPushEnabled(getContext()));
usePushService.setEnabled(BuildConfig.USE_PLAY_SERVICES);
usePushService.setOnPreferenceChangeListener((preference, newValue) -> { usePushService.setOnPreferenceChangeListener((preference, newValue) -> {
final boolean enabled = (Boolean) newValue; final boolean enabled = (Boolean) newValue;
if (!enabled) { if (!enabled) {

View file

@ -173,9 +173,7 @@ public class Prefs {
} }
public static boolean isPushEnabled(Context context) { public static boolean isPushEnabled(Context context) {
// Do not use PUSH for the the default application ID "com.b44t.messenger" which is used eg. used by F-Droid return BuildConfig.USE_PLAY_SERVICES && getBooleanPreference(context, "pref_push_enabled", true);
boolean defaultPush = !BuildConfig.APPLICATION_ID.equals("com.b44t.messenger");
return getBooleanPreference(context, "pref_push_enabled", defaultPush);
} }
public static boolean isHardCompressionEnabled(Context context) { public static boolean isHardCompressionEnabled(Context context) {