2014-09-30 00:48:11 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2014-09-30 00:48:11 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2014-09-30 00:48:11 +02:00
|
|
|
*/
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
package org.telegram.messenger;
|
2014-09-30 00:48:11 +02:00
|
|
|
|
|
|
|
import android.app.Service;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.IBinder;
|
2019-05-14 14:08:05 +02:00
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
import androidx.core.app.NotificationManagerCompat;
|
2014-09-30 00:48:11 +02:00
|
|
|
|
|
|
|
public class VideoEncodingService extends Service implements NotificationCenter.NotificationCenterDelegate {
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private NotificationCompat.Builder builder;
|
|
|
|
private String path;
|
|
|
|
private int currentProgress;
|
2018-07-30 04:07:02 +02:00
|
|
|
private int currentAccount;
|
2014-09-30 00:48:11 +02:00
|
|
|
|
|
|
|
public VideoEncodingService() {
|
|
|
|
super();
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.stopEncodingService);
|
2014-09-30 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public IBinder onBind(Intent arg2) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onDestroy() {
|
2019-09-10 12:56:11 +02:00
|
|
|
super.onDestroy();
|
|
|
|
try {
|
|
|
|
stopForeground(true);
|
|
|
|
} catch (Throwable ignore) {
|
|
|
|
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
NotificationManagerCompat.from(ApplicationLoader.applicationContext).cancel(4);
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.stopEncodingService);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.FileUploadProgressChanged);
|
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("destroy video service");
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-07-30 04:07:02 +02:00
|
|
|
public void didReceivedNotification(int id, int account, Object... args) {
|
2014-09-30 00:48:11 +02:00
|
|
|
if (id == NotificationCenter.FileUploadProgressChanged) {
|
2018-07-30 04:07:02 +02:00
|
|
|
String fileName = (String) args[0];
|
|
|
|
if (account == currentAccount && path != null && path.equals(fileName)) {
|
2014-09-30 00:48:11 +02:00
|
|
|
Float progress = (Float) args[1];
|
|
|
|
Boolean enc = (Boolean) args[2];
|
2018-07-30 04:07:02 +02:00
|
|
|
currentProgress = (int) (progress * 100);
|
2014-09-30 00:48:11 +02:00
|
|
|
builder.setProgress(100, currentProgress, currentProgress == 0);
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
|
|
|
NotificationManagerCompat.from(ApplicationLoader.applicationContext).notify(4, builder.build());
|
|
|
|
} catch (Throwable e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
}
|
|
|
|
} else if (id == NotificationCenter.stopEncodingService) {
|
2018-07-30 04:07:02 +02:00
|
|
|
String filepath = (String) args[0];
|
|
|
|
account = (Integer) args[1];
|
|
|
|
if (account == currentAccount && (filepath == null || filepath.equals(path))) {
|
2014-09-30 00:48:11 +02:00
|
|
|
stopSelf();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
|
|
path = intent.getStringExtra("path");
|
2018-07-30 04:07:02 +02:00
|
|
|
int oldAccount = currentAccount;
|
|
|
|
currentAccount = intent.getIntExtra("currentAccount", UserConfig.selectedAccount);
|
|
|
|
if (oldAccount != currentAccount) {
|
|
|
|
NotificationCenter.getInstance(oldAccount).removeObserver(this, NotificationCenter.FileUploadProgressChanged);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.FileUploadProgressChanged);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
boolean isGif = intent.getBooleanExtra("gif", false);
|
2014-09-30 00:48:11 +02:00
|
|
|
if (path == null) {
|
|
|
|
stopSelf();
|
|
|
|
return Service.START_NOT_STICKY;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("start video service");
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
if (builder == null) {
|
2018-08-27 10:33:11 +02:00
|
|
|
NotificationsController.checkOtherNotificationsChannel();
|
2014-09-30 00:48:11 +02:00
|
|
|
builder = new NotificationCompat.Builder(ApplicationLoader.applicationContext);
|
|
|
|
builder.setSmallIcon(android.R.drawable.stat_sys_upload);
|
|
|
|
builder.setWhen(System.currentTimeMillis());
|
2018-07-30 04:07:02 +02:00
|
|
|
builder.setChannelId(NotificationsController.OTHER_NOTIFICATIONS_CHANNEL);
|
2014-09-30 00:48:11 +02:00
|
|
|
builder.setContentTitle(LocaleController.getString("AppName", R.string.AppName));
|
2016-10-11 13:57:01 +02:00
|
|
|
if (isGif) {
|
|
|
|
builder.setTicker(LocaleController.getString("SendingGif", R.string.SendingGif));
|
|
|
|
builder.setContentText(LocaleController.getString("SendingGif", R.string.SendingGif));
|
|
|
|
} else {
|
|
|
|
builder.setTicker(LocaleController.getString("SendingVideo", R.string.SendingVideo));
|
|
|
|
builder.setContentText(LocaleController.getString("SendingVideo", R.string.SendingVideo));
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
}
|
|
|
|
currentProgress = 0;
|
|
|
|
builder.setProgress(100, currentProgress, currentProgress == 0);
|
|
|
|
startForeground(4, builder.build());
|
|
|
|
NotificationManagerCompat.from(ApplicationLoader.applicationContext).notify(4, builder.build());
|
|
|
|
return Service.START_NOT_STICKY;
|
|
|
|
}
|
|
|
|
}
|