Fix crashing issue on bootup

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-01-28 21:28:13 +01:00
parent dd2c02e46a
commit bedf9f1ae8
4 changed files with 28 additions and 0 deletions

View file

@ -323,6 +323,10 @@ public class MainApp extends MultiDexApplication {
createChannel(notificationManager, NotificationUtils.NOTIFICATION_CHANNEL_FILE_SYNC, createChannel(notificationManager, NotificationUtils.NOTIFICATION_CHANNEL_FILE_SYNC,
R.string.notification_channel_file_sync_name, R.string.notification_channel_file_sync_name,
R.string.notification_channel_file_sync_description, context); R.string.notification_channel_file_sync_description, context);
createChannel(notificationManager, NotificationUtils.NOTIFICATION_CHANNEL_FILE_OBSERVER,
R.string.notification_channel_file_observer_name, R.string
.notification_channel_file_observer_description, context);
} else { } else {
Log_OC.e(TAG, "Notification manager is null"); Log_OC.e(TAG, "Notification manager is null");
} }

View file

@ -22,22 +22,28 @@
package com.owncloud.android.services.observer; package com.owncloud.android.services.observer;
import android.accounts.Account; import android.accounts.Account;
import android.app.Notification;
import android.app.Service; import android.app.Service;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.os.IBinder; import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import com.owncloud.android.MainApp; import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileDownloader;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.ui.notifications.NotificationUtils;
import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.ThemeUtils;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
@ -68,6 +74,8 @@ public class FileObserverService extends Service {
private final static String ARG_FILE = "ARG_FILE"; private final static String ARG_FILE = "ARG_FILE";
private final static String ARG_ACCOUNT = "ARG_ACCOUNT"; private final static String ARG_ACCOUNT = "ARG_ACCOUNT";
private static final int FOREGROUND_SERVICE_ID = 333;
private static final String TAG = FileObserverService.class.getSimpleName(); private static final String TAG = FileObserverService.class.getSimpleName();
private Map<String, FolderObserver> mFolderObserversMap; private Map<String, FolderObserver> mFolderObserversMap;
@ -115,6 +123,19 @@ public class FileObserverService extends Service {
Log_OC.d(TAG, "onCreate"); Log_OC.d(TAG, "onCreate");
super.onCreate(); super.onCreate();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
Notification notification = new NotificationCompat.Builder(this,
NotificationUtils.NOTIFICATION_CHANNEL_FILE_OBSERVER)
.setContentTitle(getResources().getString(R.string.notification_channel_file_observer_name))
.setContentText(getResources().getString(R.string.notification_channel_file_observer_description))
.setSmallIcon(R.drawable.notification_icon)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.notification_icon))
.setColor(ThemeUtils.primaryColor())
.build();
startForeground(FOREGROUND_SERVICE_ID, notification);
}
mDownloadReceiver = new DownloadCompletedReceiver(); mDownloadReceiver = new DownloadCompletedReceiver();
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.addAction(FileDownloader.getDownloadAddedMessage()); filter.addAction(FileDownloader.getDownloadAddedMessage());

View file

@ -38,6 +38,7 @@ public class NotificationUtils {
public static final String NOTIFICATION_CHANNEL_UPLOAD = "NOTIFICATION_CHANNEL_UPLOAD"; public static final String NOTIFICATION_CHANNEL_UPLOAD = "NOTIFICATION_CHANNEL_UPLOAD";
public static final String NOTIFICATION_CHANNEL_MEDIA = "NOTIFICATION_CHANNEL_MEDIA"; public static final String NOTIFICATION_CHANNEL_MEDIA = "NOTIFICATION_CHANNEL_MEDIA";
public static final String NOTIFICATION_CHANNEL_FILE_SYNC = "NOTIFICATION_CHANNEL_FILE_SYNC"; public static final String NOTIFICATION_CHANNEL_FILE_SYNC = "NOTIFICATION_CHANNEL_FILE_SYNC";
public static final String NOTIFICATION_CHANNEL_FILE_OBSERVER = "NOTIFICATION_CHANNEL_FILE_OBSERVER";
/** /**
* Factory method for {@link android.support.v4.app.NotificationCompat.Builder} instances. * Factory method for {@link android.support.v4.app.NotificationCompat.Builder} instances.

View file

@ -736,6 +736,8 @@
<string name="notification_channel_media_description">Music player progress</string> <string name="notification_channel_media_description">Music player progress</string>
<string name="notification_channel_file_sync_name">File sync</string> <string name="notification_channel_file_sync_name">File sync</string>
<string name="notification_channel_file_sync_description">Shows file sync progress and results</string> <string name="notification_channel_file_sync_description">Shows file sync progress and results</string>
<string name="notification_channel_file_observer_name">File observer</string>
<string name="notification_channel_file_observer_description">Monitors files for changes</string>
<string name="account_not_found">Account not found!</string> <string name="account_not_found">Account not found!</string>