Drop notification for keyserver update progress
We don't have the notification permission reliably here, and the notification shows up and is gone so quickly that it provides little value anyways.
This commit is contained in:
@@ -3,31 +3,23 @@ package org.sufficientlysecure.keychain.keysync;
|
|||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.app.NotificationCompat;
|
|
||||||
import androidx.core.app.NotificationCompat.Builder;
|
|
||||||
import androidx.work.Worker;
|
import androidx.work.Worker;
|
||||||
import androidx.work.WorkerParameters;
|
import androidx.work.WorkerParameters;
|
||||||
import org.sufficientlysecure.keychain.Constants.NotificationIds;
|
|
||||||
import org.sufficientlysecure.keychain.NotificationChannelManager;
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
|
||||||
import org.sufficientlysecure.keychain.daos.KeyWritableRepository;
|
import org.sufficientlysecure.keychain.daos.KeyWritableRepository;
|
||||||
import org.sufficientlysecure.keychain.network.orbot.OrbotHelper;
|
import org.sufficientlysecure.keychain.network.orbot.OrbotHelper;
|
||||||
import org.sufficientlysecure.keychain.operations.KeySyncOperation;
|
import org.sufficientlysecure.keychain.operations.KeySyncOperation;
|
||||||
import org.sufficientlysecure.keychain.operations.KeySyncParcel;
|
import org.sufficientlysecure.keychain.operations.KeySyncParcel;
|
||||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity;
|
import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity;
|
||||||
import org.sufficientlysecure.keychain.util.ResourceUtils;
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
|
||||||
public class KeyserverSyncWorker extends Worker {
|
public class KeyserverSyncWorker extends Worker {
|
||||||
private AtomicBoolean cancellationSignal = new AtomicBoolean(false);
|
private final AtomicBoolean cancellationSignal = new AtomicBoolean(false);
|
||||||
|
|
||||||
public KeyserverSyncWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
|
public KeyserverSyncWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
|
||||||
super(context, workerParams);
|
super(context, workerParams);
|
||||||
@@ -36,12 +28,15 @@ public class KeyserverSyncWorker extends Worker {
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Result doWork() {
|
public Result doWork() {
|
||||||
KeyWritableRepository keyWritableRepository = KeyWritableRepository.create(getApplicationContext());
|
KeyWritableRepository keyWritableRepository =
|
||||||
|
KeyWritableRepository.create(getApplicationContext());
|
||||||
|
|
||||||
Timber.d("Starting key sync…");
|
Timber.d("Starting key sync…");
|
||||||
Progressable notificationProgressable = notificationShowForProgress();
|
KeySyncOperation keySync =
|
||||||
KeySyncOperation keySync = new KeySyncOperation(getApplicationContext(), keyWritableRepository, notificationProgressable, cancellationSignal);
|
new KeySyncOperation(getApplicationContext(), keyWritableRepository, null,
|
||||||
ImportKeyResult result = keySync.execute(KeySyncParcel.createRefreshOutdated(), CryptoInputParcel.createCryptoInputParcel());
|
cancellationSignal);
|
||||||
|
ImportKeyResult result = keySync.execute(KeySyncParcel.createRefreshOutdated(),
|
||||||
|
CryptoInputParcel.createCryptoInputParcel());
|
||||||
return handleUpdateResult(result);
|
return handleUpdateResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +59,8 @@ public class KeyserverSyncWorker extends Worker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSilentStartDisabled() {
|
protected void onSilentStartDisabled() {
|
||||||
OrbotRequiredDialogActivity.showOrbotRequiredNotification(getApplicationContext());
|
OrbotRequiredDialogActivity.showOrbotRequiredNotification(
|
||||||
|
getApplicationContext());
|
||||||
}
|
}
|
||||||
}.startOrbotAndListen(getApplicationContext(), false);
|
}.startOrbotAndListen(getApplicationContext(), false);
|
||||||
return Result.retry();
|
return Result.retry();
|
||||||
@@ -72,55 +68,12 @@ public class KeyserverSyncWorker extends Worker {
|
|||||||
Timber.d("Keyserver sync cancelled");
|
Timber.d("Keyserver sync cancelled");
|
||||||
return Result.failure();
|
return Result.failure();
|
||||||
} else {
|
} else {
|
||||||
Timber.d("Keyserver sync completed: Updated: %d, Failed: %d", result.mUpdatedKeys, result.mBadKeys);
|
Timber.d("Keyserver sync completed: Updated: %d, Failed: %d", result.mUpdatedKeys,
|
||||||
|
result.mBadKeys);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Progressable notificationShowForProgress() {
|
|
||||||
final Context context = getApplicationContext();
|
|
||||||
NotificationManager notificationManager =
|
|
||||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
||||||
if (notificationManager == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
NotificationChannelManager.getInstance(context).createNotificationChannelsIfNecessary();
|
|
||||||
|
|
||||||
NotificationCompat.Builder builder = new Builder(context, NotificationChannelManager.KEYSERVER_SYNC)
|
|
||||||
.setSmallIcon(R.drawable.ic_stat_notify_24dp)
|
|
||||||
.setLargeIcon(ResourceUtils.getDrawableAsNotificationBitmap(context, R.mipmap.ic_launcher))
|
|
||||||
.setContentTitle(context.getString(R.string.notify_title_keysync))
|
|
||||||
.setPriority(NotificationCompat.PRIORITY_MIN)
|
|
||||||
.setTimeoutAfter(5000)
|
|
||||||
.setVibrate(null)
|
|
||||||
.setSound(null)
|
|
||||||
.setProgress(0, 0, true);
|
|
||||||
|
|
||||||
return new Progressable() {
|
|
||||||
@Override
|
|
||||||
public void setProgress(Integer ignored, int current, int total) {
|
|
||||||
if (total == 0) {
|
|
||||||
notificationManager.cancel(NotificationIds.KEYSERVER_SYNC);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.setProgress(total, current, false);
|
|
||||||
if (current == total) {
|
|
||||||
builder.setContentTitle(context.getString(R.string.notify_title_keysync_finished, total));
|
|
||||||
builder.setContentText(null);
|
|
||||||
} else {
|
|
||||||
builder.setContentText(context.getString(R.string.notify_content_keysync, current, total));
|
|
||||||
}
|
|
||||||
notificationManager.notify(NotificationIds.KEYSERVER_SYNC, builder.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPreventCancel() {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStopped() {
|
public void onStopped() {
|
||||||
super.onStopped();
|
super.onStopped();
|
||||||
|
|||||||
Reference in New Issue
Block a user