mirror of https://github.com/NekoX-Dev/NekoX.git
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"/>
|
<action android:name="android.media.browse.MediaBrowserService"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
<service
|
<!-- <service-->
|
||||||
android:name="tw.nekomimi.nekogram.NekoXPushService"
|
<!-- android:name="tw.nekomimi.nekogram.NekoXPushService"-->
|
||||||
android:enabled="true"
|
<!-- android:enabled="true"-->
|
||||||
android:label="@string/NekoXPushService"
|
<!-- android:label="@string/NekoXPushService"-->
|
||||||
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
|
<!-- android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">-->
|
||||||
<intent-filter>
|
<!-- <intent-filter>-->
|
||||||
<action android:name="android.service.notification.NotificationListenerService" />
|
<!-- <action android:name="android.service.notification.NotificationListenerService" />-->
|
||||||
</intent-filter>
|
<!-- </intent-filter>-->
|
||||||
</service>
|
<!-- </service>-->
|
||||||
<service android:name=".voip.TelegramConnectionService" android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
|
<service android:name=".voip.TelegramConnectionService" android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.telecom.ConnectionService" />
|
<action android:name="android.telecom.ConnectionService" />
|
||||||
|
|
|
@ -394,31 +394,23 @@ public class ApplicationLoader extends Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void startPushServiceInternal() {
|
private static void startPushServiceInternal() {
|
||||||
if (ExternalGcm.checkPlayServices() || (SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && isNotificationListenerEnabled())) {
|
if (ExternalGcm.checkPlayServices()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SharedPreferences preferences = MessagesController.getGlobalNotificationsSettings();
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
||||||
boolean enabled;
|
boolean enabled;
|
||||||
if (preferences.contains("pushService")) {
|
if (preferences.contains("pushService")) {
|
||||||
enabled = preferences.getBoolean("pushService", true);
|
enabled = preferences.getBoolean("pushService", false);
|
||||||
if (SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
|
||||||
if (!preferences.getBoolean("pushConnection", true)) return;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
enabled = MessagesController.getMainSettings(UserConfig.selectedAccount).getBoolean("keepAliveService", true);
|
enabled = MessagesController.getMainSettings(UserConfig.selectedAccount).getBoolean("keepAliveService", false);
|
||||||
SharedPreferences.Editor editor = preferences.edit();
|
SharedPreferences.Editor editor = preferences.edit();
|
||||||
editor.putBoolean("pushService", enabled);
|
editor.putBoolean("pushService", enabled);
|
||||||
editor.putBoolean("pushConnection", enabled);
|
editor.putBoolean("pushConnection", enabled);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
SharedPreferences preferencesCA = MessagesController.getNotificationsSettings(UserConfig.selectedAccount);
|
ConnectionsManager.getInstance(UserConfig.selectedAccount).setPushConnectionEnabled(enabled);
|
||||||
SharedPreferences.Editor editorCA = preferencesCA.edit();
|
|
||||||
editorCA.putBoolean("pushConnection", enabled);
|
|
||||||
editorCA.putBoolean("pushService", enabled);
|
|
||||||
editorCA.apply();
|
|
||||||
ConnectionsManager.getInstance(UserConfig.selectedAccount).setPushConnectionEnabled(true);
|
|
||||||
}
|
}
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
UIUtil.runOnUIThread(() -> {
|
AndroidUtilities.runOnUIThread(() -> {
|
||||||
try {
|
try {
|
||||||
Log.d("TFOSS", "Trying to start push service every 10 minutes");
|
Log.d("TFOSS", "Trying to start push service every 10 minutes");
|
||||||
// Telegram-FOSS: unconditionally enable push service
|
// 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));
|
applicationContext.stopService(new Intent(applicationContext, NotificationsService.class));
|
||||||
|
|
||||||
PendingIntent pintent = PendingIntent.getService(applicationContext, 0, new Intent(applicationContext, NotificationsService.class), 0);
|
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
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
|
|
|
@ -16,6 +16,7 @@ import android.app.Service;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
@ -31,6 +32,23 @@ public class NotificationsService extends Service {
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
ApplicationLoader.postInitApplication();
|
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
|
@Override
|
||||||
|
|
|
@ -545,23 +545,26 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
|
||||||
editor.putBoolean("badgeNumberMessages", getNotificationsController().showBadgeMessages);
|
editor.putBoolean("badgeNumberMessages", getNotificationsController().showBadgeMessages);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
getNotificationsController().updateBadge();
|
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) {
|
} else if (position == notificationsServiceConnectionRow) {
|
||||||
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
||||||
enabled = preferences.getBoolean("pushConnection", getMessagesController().backgroundConnection);
|
enabled = preferences.getBoolean("pushConnection", getMessagesController().backgroundConnection);
|
||||||
SharedPreferences.Editor editor = preferences.edit();
|
SharedPreferences.Editor editor = preferences.edit();
|
||||||
editor.putBoolean("pushConnection", !enabled);
|
editor.putBoolean("pushConnection", !enabled);
|
||||||
editor.commit();
|
editor.apply();
|
||||||
if (!enabled) {
|
ConnectionsManager.getInstance(currentAccount).setPushConnectionEnabled(!enabled);
|
||||||
ConnectionsManager.getInstance(currentAccount).setPushConnectionEnabled(true);
|
|
||||||
} else {
|
|
||||||
ConnectionsManager.getInstance(currentAccount).setPushConnectionEnabled(false);
|
|
||||||
}
|
|
||||||
} else if (position == accountsAllRow) {
|
} else if (position == accountsAllRow) {
|
||||||
SharedPreferences preferences = MessagesController.getGlobalNotificationsSettings();
|
SharedPreferences preferences = MessagesController.getGlobalNotificationsSettings();
|
||||||
enabled = preferences.getBoolean("AllAccounts", true);
|
enabled = preferences.getBoolean("AllAccounts", true);
|
||||||
SharedPreferences.Editor editor = preferences.edit();
|
SharedPreferences.Editor editor = preferences.edit();
|
||||||
editor.putBoolean("AllAccounts", !enabled);
|
editor.putBoolean("AllAccounts", !enabled);
|
||||||
editor.commit();
|
editor.apply();
|
||||||
SharedConfig.showNotificationsForAllAccounts = !enabled;
|
SharedConfig.showNotificationsForAllAccounts = !enabled;
|
||||||
for (int a : SharedConfig.activeAccounts) {
|
for (int a : SharedConfig.activeAccounts) {
|
||||||
if (SharedConfig.showNotificationsForAllAccounts) {
|
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) {
|
} else if (position == callsVibrateRow) {
|
||||||
if (getParentActivity() == null) {
|
if (getParentActivity() == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -859,7 +846,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
|
||||||
} else if (position == androidAutoAlertRow) {
|
} else if (position == androidAutoAlertRow) {
|
||||||
checkCell.setTextAndCheck("Android Auto", preferences.getBoolean("EnableAutoNotifications", false), true);
|
checkCell.setTextAndCheck("Android Auto", preferences.getBoolean("EnableAutoNotifications", false), true);
|
||||||
} else if (position == notificationsServiceRow) {
|
} 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) {
|
} 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);
|
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) {
|
} else if (position == badgeNumberShowRow) {
|
||||||
|
|
Loading…
Reference in New Issue