mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-12 15:24:09 +01:00
Delete notification groups on upgrade
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
13768d6ceb
commit
1678a2e7ab
@ -29,29 +29,64 @@ import android.content.pm.PackageManager;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.nextcloud.talk.R;
|
||||||
|
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||||
|
import com.nextcloud.talk.models.database.UserEntity;
|
||||||
import com.nextcloud.talk.utils.NotificationUtils;
|
import com.nextcloud.talk.utils.NotificationUtils;
|
||||||
|
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||||
|
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||||
|
|
||||||
|
import java.util.zip.CRC32;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import autodagger.AutoInjector;
|
||||||
|
|
||||||
|
@AutoInjector(NextcloudTalkApplication.class)
|
||||||
public class PackageReplacedReceiver extends BroadcastReceiver {
|
public class PackageReplacedReceiver extends BroadcastReceiver {
|
||||||
private static final String TAG = "PackageReplacedReceiver";
|
private static final String TAG = "PackageReplacedReceiver";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
UserUtils userUtils;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
AppPreferences appPreferences;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (intent != null && intent.getAction() != null &&
|
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
|
||||||
|
|
||||||
|
if (!appPreferences.getIsNotificationChannelUpgradedToV2() && intent != null && intent.getAction() != null &&
|
||||||
intent.getAction().equals("android.intent.action.MY_PACKAGE_REPLACED")) {
|
intent.getAction().equals("android.intent.action.MY_PACKAGE_REPLACED")) {
|
||||||
try {
|
try {
|
||||||
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
||||||
if (packageInfo.versionCode == 99 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (packageInfo.versionCode > 42 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
NotificationManager notificationManager =
|
NotificationManager notificationManager =
|
||||||
(NotificationManager) context.getSystemService(Context
|
(NotificationManager) context.getSystemService(Context
|
||||||
.NOTIFICATION_SERVICE);
|
.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
|
|
||||||
if (notificationManager != null) {
|
if (notificationManager != null) {
|
||||||
|
CRC32 crc32;
|
||||||
|
UserEntity userEntity;
|
||||||
|
String groupName;
|
||||||
|
for (Object userEntityObject : userUtils.getUsers()) {
|
||||||
|
crc32 = new CRC32();
|
||||||
|
userEntity = (UserEntity) userEntityObject;
|
||||||
|
groupName = String.format(context.getResources().getString(R.string
|
||||||
|
.nc_notification_channel), userEntity.getDisplayName(), userEntity.getBaseUrl());
|
||||||
|
crc32.update(groupName.getBytes());
|
||||||
|
notificationManager.deleteNotificationChannelGroup(Long.toString(crc32.getValue()));
|
||||||
|
}
|
||||||
notificationManager.deleteNotificationChannel(NotificationUtils.NOTIFICATION_CHANNEL_CALLS);
|
notificationManager.deleteNotificationChannel(NotificationUtils.NOTIFICATION_CHANNEL_CALLS);
|
||||||
notificationManager.deleteNotificationChannel(NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES);
|
notificationManager.deleteNotificationChannel(NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES);
|
||||||
|
|
||||||
|
appPreferences.setNotificationChannelIsUpgradedToV2(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
Log.e(TAG, "Failed to find package info");
|
Log.e(TAG, "Failed to fetch package info");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,6 +158,15 @@ public interface AppPreferences {
|
|||||||
@RemoveMethod
|
@RemoveMethod
|
||||||
void removeMessageRingtoneUri();
|
void removeMessageRingtoneUri();
|
||||||
|
|
||||||
|
@KeyByString("notification_channels_upgrade_to_v2")
|
||||||
|
boolean getIsNotificationChannelUpgradedToV2();
|
||||||
|
|
||||||
|
@KeyByString("notification_channels_upgrade_to_v2")
|
||||||
|
void setNotificationChannelIsUpgradedToV2(boolean value);
|
||||||
|
|
||||||
|
@KeyByString("notification_channels_upgrade_to_v2")
|
||||||
|
@RemoveMethod
|
||||||
|
void removeNotificationChannelUpgradeToV2();
|
||||||
|
|
||||||
@ClearMethod
|
@ClearMethod
|
||||||
void clear();
|
void clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user