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 {
fat {
dimension "none"
buildConfigField "boolean", "USE_PLAY_SERVICES", "false"
}
gplay {
dimension "none"
applicationId "chat.delta"
apply plugin: "com.google.gms.google-services"
buildConfigField "boolean", "USE_PLAY_SERVICES", "true"
}
}

View file

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

View file

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

View file

@ -173,9 +173,7 @@ public class Prefs {
}
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
boolean defaultPush = !BuildConfig.APPLICATION_ID.equals("com.b44t.messenger");
return getBooleanPreference(context, "pref_push_enabled", defaultPush);
return BuildConfig.USE_PLAY_SERVICES && getBooleanPreference(context, "pref_push_enabled", true);
}
public static boolean isHardCompressionEnabled(Context context) {