mirror of
https://github.com/NekoX-Dev/NekoX.git
synced 2025-01-19 11:19:55 +01:00
Disable NekoXPushService and use tfoss implementation
This commit is contained in:
parent
9e2f8c6754
commit
a8b667084e
@ -387,15 +387,15 @@
|
||||
<action android:name="android.media.browse.MediaBrowserService"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service
|
||||
android:name="tw.nekomimi.nekogram.NekoXPushService"
|
||||
android:enabled="true"
|
||||
android:label="@string/NekoXPushService"
|
||||
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
|
||||
<intent-filter>
|
||||
<action android:name="android.service.notification.NotificationListenerService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<!-- <service-->
|
||||
<!-- android:name="tw.nekomimi.nekogram.NekoXPushService"-->
|
||||
<!-- android:enabled="true"-->
|
||||
<!-- android:label="@string/NekoXPushService"-->
|
||||
<!-- android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">-->
|
||||
<!-- <intent-filter>-->
|
||||
<!-- <action android:name="android.service.notification.NotificationListenerService" />-->
|
||||
<!-- </intent-filter>-->
|
||||
<!-- </service>-->
|
||||
<service android:name=".voip.TelegramConnectionService" android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
|
||||
<intent-filter>
|
||||
<action android:name="android.telecom.ConnectionService" />
|
||||
|
@ -394,31 +394,23 @@ public class ApplicationLoader extends Application {
|
||||
}
|
||||
|
||||
private static void startPushServiceInternal() {
|
||||
if (ExternalGcm.checkPlayServices() || (SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && isNotificationListenerEnabled())) {
|
||||
if (ExternalGcm.checkPlayServices()) {
|
||||
return;
|
||||
}
|
||||
SharedPreferences preferences = MessagesController.getGlobalNotificationsSettings();
|
||||
SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
||||
boolean enabled;
|
||||
if (preferences.contains("pushService")) {
|
||||
enabled = preferences.getBoolean("pushService", true);
|
||||
if (SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
if (!preferences.getBoolean("pushConnection", true)) return;
|
||||
}
|
||||
enabled = preferences.getBoolean("pushService", false);
|
||||
} else {
|
||||
enabled = MessagesController.getMainSettings(UserConfig.selectedAccount).getBoolean("keepAliveService", true);
|
||||
enabled = MessagesController.getMainSettings(UserConfig.selectedAccount).getBoolean("keepAliveService", false);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("pushService", enabled);
|
||||
editor.putBoolean("pushConnection", enabled);
|
||||
editor.apply();
|
||||
SharedPreferences preferencesCA = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
||||
SharedPreferences.Editor editorCA = preferencesCA.edit();
|
||||
editorCA.putBoolean("pushConnection", enabled);
|
||||
editorCA.putBoolean("pushService", enabled);
|
||||
editorCA.apply();
|
||||
ConnectionsManager.getInstance(UserConfig.selectedAccount).setPushConnectionEnabled(true);
|
||||
ConnectionsManager.getInstance(UserConfig.selectedAccount).setPushConnectionEnabled(enabled);
|
||||
}
|
||||
if (enabled) {
|
||||
UIUtil.runOnUIThread(() -> {
|
||||
AndroidUtilities.runOnUIThread(() -> {
|
||||
try {
|
||||
Log.d("TFOSS", "Trying to start push service every 10 minutes");
|
||||
// Telegram-FOSS: unconditionally enable push service
|
||||
@ -440,7 +432,7 @@ public class ApplicationLoader extends Application {
|
||||
}
|
||||
});
|
||||
|
||||
} else UIUtil.runOnUIThread(() -> {
|
||||
} else AndroidUtilities.runOnUIThread(() -> {
|
||||
applicationContext.stopService(new Intent(applicationContext, NotificationsService.class));
|
||||
|
||||
PendingIntent pintent = PendingIntent.getService(applicationContext, 0, new Intent(applicationContext, NotificationsService.class), 0);
|
||||
@ -452,14 +444,6 @@ public class ApplicationLoader extends Application {
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isNotificationListenerEnabled() {
|
||||
Set<String> packageNames = NotificationManagerCompat.getEnabledListenerPackages(applicationContext);
|
||||
if (packageNames.contains(applicationContext.getPackageName())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
@ -16,6 +16,7 @@ import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.provider.Settings;
|
||||
@ -31,6 +32,23 @@ public class NotificationsService extends Service {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
ApplicationLoader.postInitApplication();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
String CHANNEL_ID = "push_service_channel";
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, LocaleController.getString("NekoXPushService", R.string.NekoXPushService), NotificationManager.IMPORTANCE_DEFAULT);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
// Intent explainIntent = new Intent("android.intent.action.VIEW");
|
||||
// explainIntent.setData(Uri.parse("https://github.com/Telegram-FOSS-Team/Telegram-FOSS/blob/master/Notifications.md"));
|
||||
// PendingIntent explainPendingIntent = PendingIntent.getActivity(this, 0, explainIntent, 0);
|
||||
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
|
||||
// .setContentIntent(explainPendingIntent)
|
||||
.setShowWhen(false)
|
||||
.setOngoing(true)
|
||||
.setSmallIcon(R.drawable.notification)
|
||||
.setContentText(LocaleController.getString("NekoXPushService", R.string.NekoXPushService))
|
||||
.build();
|
||||
startForeground(9999, notification);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -545,23 +545,26 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
|
||||
editor.putBoolean("badgeNumberMessages", getNotificationsController().showBadgeMessages);
|
||||
editor.commit();
|
||||
getNotificationsController().updateBadge();
|
||||
} else if (position == notificationsServiceRow) {
|
||||
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
||||
enabled = preferences.getBoolean("pushService", getMessagesController().keepAliveService);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("pushService", !enabled);
|
||||
editor.apply();
|
||||
ApplicationLoader.startPushService();
|
||||
} else if (position == notificationsServiceConnectionRow) {
|
||||
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
||||
enabled = preferences.getBoolean("pushConnection", getMessagesController().backgroundConnection);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("pushConnection", !enabled);
|
||||
editor.commit();
|
||||
if (!enabled) {
|
||||
ConnectionsManager.getInstance(currentAccount).setPushConnectionEnabled(true);
|
||||
} else {
|
||||
ConnectionsManager.getInstance(currentAccount).setPushConnectionEnabled(false);
|
||||
}
|
||||
editor.apply();
|
||||
ConnectionsManager.getInstance(currentAccount).setPushConnectionEnabled(!enabled);
|
||||
} else if (position == accountsAllRow) {
|
||||
SharedPreferences preferences = MessagesController.getGlobalNotificationsSettings();
|
||||
enabled = preferences.getBoolean("AllAccounts", true);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("AllAccounts", !enabled);
|
||||
editor.commit();
|
||||
editor.apply();
|
||||
SharedConfig.showNotificationsForAllAccounts = !enabled;
|
||||
for (int a : SharedConfig.activeAccounts) {
|
||||
if (SharedConfig.showNotificationsForAllAccounts) {
|
||||
@ -574,22 +577,6 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (position == notificationsServiceRow) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
if (ApplicationLoader.isNotificationListenerEnabled()) {
|
||||
AlertUtil.showToast(LocaleController.getString("DisablePushAlert", R.string.DisablePushAlert));
|
||||
} else {
|
||||
AlertUtil.showToast(LocaleController.getString("EnablePushAlert", R.string.EnablePushAlert));
|
||||
}
|
||||
AndroidUtilities.runOnUIThread(this::openNotificationListenSettings, 500L);
|
||||
} else {
|
||||
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
||||
enabled = preferences.getBoolean("pushService", getMessagesController().keepAliveService);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("pushService", !enabled);
|
||||
editor.apply();
|
||||
ApplicationLoader.startPushService();
|
||||
}
|
||||
} else if (position == callsVibrateRow) {
|
||||
if (getParentActivity() == null) {
|
||||
return;
|
||||
@ -859,7 +846,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
|
||||
} else if (position == androidAutoAlertRow) {
|
||||
checkCell.setTextAndCheck("Android Auto", preferences.getBoolean("EnableAutoNotifications", false), true);
|
||||
} else if (position == notificationsServiceRow) {
|
||||
checkCell.setTextAndValueAndCheck(LocaleController.getString("NotificationsService", R.string.NotificationsService), LocaleController.getString("NotificationsServiceInfo", R.string.NotificationsServiceInfo), Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 ? ApplicationLoader.isNotificationListenerEnabled() : preferences.getBoolean("pushService", getMessagesController().keepAliveService), true, true);
|
||||
checkCell.setTextAndValueAndCheck(LocaleController.getString("NotificationsService", R.string.NotificationsService), LocaleController.getString("NotificationsServiceInfo", R.string.NotificationsServiceInfo), preferences.getBoolean("pushService", getMessagesController().keepAliveService), true, true);
|
||||
} else if (position == notificationsServiceConnectionRow) {
|
||||
checkCell.setTextAndValueAndCheck(LocaleController.getString("NotificationsServiceConnection", R.string.NotificationsServiceConnection), LocaleController.getString("NotificationsServiceConnectionInfo", R.string.NotificationsServiceConnectionInfo), preferences.getBoolean("pushConnection", getMessagesController().backgroundConnection), true, true);
|
||||
} else if (position == badgeNumberShowRow) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user