// Path: src/com/irccloud/android/data/IRCCloudDatabase.java
// @Database(entities = {RecentConversation.class, BackgroundTask.class, LogExport.class, Notification.class, Notification_LastSeenEID.class, Notification_ServerNick.class, Avatar.class}, version = IRCCloudDatabase.VERSION, exportSchema = false)
// public abstract class IRCCloudDatabase extends RoomDatabase {
//     public static final String NAME = "irccloud";
//     public static final int VERSION = 13;
// 
//     public abstract RecentConversationsList.RecentConversationsDao RecentConversationsDao();
//     public abstract BackgroundTaskWorker.BackgroundTasksDao BackgroundTasksDao();
//     public abstract LogExportsList.LogExportsDao LogExportsDao();
//     public abstract NotificationsList.NotificationsDao NotificationsDao();
//     public abstract AvatarsList.AvatarsDao AvatarsDao();
// 
//     private static IRCCloudDatabase sInstance;
//     public static IRCCloudDatabase getInstance() {
//         if (sInstance == null) {
//             synchronized (IRCCloudDatabase.class) {
//                 if (sInstance == null) {
//                     sInstance = Room.databaseBuilder(IRCCloudApplication.getInstance().getApplicationContext(), IRCCloudDatabase.class, NAME)
//                             .fallbackToDestructiveMigrationFrom(12)
//                             .fallbackToDestructiveMigration()
//                             .fallbackToDestructiveMigrationOnDowngrade()
//                             .allowMainThreadQueries()
//                             .build();
//                 }
//             }
//         }
//         return sInstance;
//     }
// }
// 
// Path: src/com/irccloud/android/data/model/BackgroundTask.java
// @Entity
// public class BackgroundTask {
//     @Ignore
//     public static final int TYPE_FCM_REGISTER = 1;
//     @Ignore
//     public static final int TYPE_FCM_UNREGISTER = 2;
// 
//     @PrimaryKey
//     @NonNull
//     private String tag;
// 
//     private int type;
// 
//     private String session;
// 
//     private String data;
// 
//     public String getTag() {
//         return tag;
//     }
// 
//     public void setTag(String tag) {
//         this.tag = tag;
//     }
// 
//     public int getType() {
//         return type;
//     }
// 
//     public void setType(int type) {
//         this.type = type;
//     }
// 
//     public String getSession() {
//         return session;
//     }
// 
//     public void setSession(String session) {
//         this.session = session;
//     }
// 
//     public String getData() {
//         return data;
//     }
// 
//     public void setData(String data) {
//         this.data = data;
//     }
// }


import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Looper;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;
import androidx.work.Constraints;
import androidx.work.Data;
import androidx.work.ExistingWorkPolicy;
import androidx.work.ListenableWorker;
import androidx.work.NetworkType;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.messaging.FirebaseMessaging;
import com.irccloud.android.data.IRCCloudDatabase;
import com.irccloud.android.data.model.BackgroundTask;
import org.json.JSONObject;
import java.util.List;

        return Result.failure();
    }

    private Result onGcmRegister(BackgroundTask task) {
        try {
            if(task.getSession() == null || task.getSession().length() == 0)
                return Result.failure();

            IRCCloudLog.Log(Log.INFO, "IRCCloud", "Registering for FCM");
            String token = task.getData();
            if(token != null && token.length() > 0) {
                JSONObject result = NetworkConnection.getInstance().registerGCM(token, task.getSession());
                if (result != null && result.has("success")) {
                    if(result.getBoolean("success")) {
                        IRCCloudLog.Log(Log.INFO, "IRCCloud", "Device successfully registered");
                        IRCCloudDatabase.getInstance().BackgroundTasksDao().delete(task);
                        return Result.success();
                    } else {
                        IRCCloudLog.Log(Log.ERROR, "IRCCloud", "Unable to register device: " + result.toString());
                        return Result.retry();
                    }
                } else {
                    IRCCloudLog.Log(Log.INFO, "IRCCloud", "Rescheduling FCM registration");
                    return Result.retry();
                }
            }
        } catch (Exception e) {
            NetworkConnection.printStackTraceToCrashlytics(e);
        }
// Path: src/com/irccloud/android/data/IRCCloudDatabase.java
// @Database(entities = {RecentConversation.class, BackgroundTask.class, LogExport.class, Notification.class, Notification_LastSeenEID.class, Notification_ServerNick.class, Avatar.class}, version = IRCCloudDatabase.VERSION, exportSchema = false)
// public abstract class IRCCloudDatabase extends RoomDatabase {
//     public static final String NAME = "irccloud";
//     public static final int VERSION = 13;
// 
//     public abstract RecentConversationsList.RecentConversationsDao RecentConversationsDao();
//     public abstract BackgroundTaskWorker.BackgroundTasksDao BackgroundTasksDao();
//     public abstract LogExportsList.LogExportsDao LogExportsDao();
//     public abstract NotificationsList.NotificationsDao NotificationsDao();
//     public abstract AvatarsList.AvatarsDao AvatarsDao();
// 
//     private static IRCCloudDatabase sInstance;
//     public static IRCCloudDatabase getInstance() {
//         if (sInstance == null) {
//             synchronized (IRCCloudDatabase.class) {
//                 if (sInstance == null) {
//                     sInstance = Room.databaseBuilder(IRCCloudApplication.getInstance().getApplicationContext(), IRCCloudDatabase.class, NAME)
//                             .fallbackToDestructiveMigrationFrom(12)
//                             .fallbackToDestructiveMigration()
//                             .fallbackToDestructiveMigrationOnDowngrade()
//                             .allowMainThreadQueries()
//                             .build();
//                 }
//             }
//         }
//         return sInstance;
//     }
// }
// 
// Path: src/com/irccloud/android/data/model/BackgroundTask.java
// @Entity
// public class BackgroundTask {
//     @Ignore
//     public static final int TYPE_FCM_REGISTER = 1;
//     @Ignore
//     public static final int TYPE_FCM_UNREGISTER = 2;
// 
//     @PrimaryKey
//     @NonNull
//     private String tag;
// 
//     private int type;
// 
//     private String session;
// 
//     private String data;
// 
//     public String getTag() {
//         return tag;
//     }
// 
//     public void setTag(String tag) {
//         this.tag = tag;
//     }
// 
//     public int getType() {
//         return type;
//     }
// 
//     public void setType(int type) {
//         this.type = type;
//     }
// 
//     public String getSession() {
//         return session;
//     }
// 
//     public void setSession(String session) {
//         this.session = session;
//     }
// 
//     public String getData() {
//         return data;
//     }
// 
//     public void setData(String data) {
//         this.data = data;
//     }
// }


// Path: src/com/irccloud/android/BackgroundTaskWorker.java
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Looper;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;
import androidx.work.Constraints;
import androidx.work.Data;
import androidx.work.ExistingWorkPolicy;
import androidx.work.ListenableWorker;
import androidx.work.NetworkType;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.messaging.FirebaseMessaging;
import com.irccloud.android.data.IRCCloudDatabase;
import com.irccloud.android.data.model.BackgroundTask;
import org.json.JSONObject;
import java.util.List;


        return Result.failure();
    }

    private Result onGcmRegister(BackgroundTask task) {
        try {
            if(task.getSession() == null || task.getSession().length() == 0)
                return Result.failure();

            IRCCloudLog.Log(Log.INFO, "IRCCloud", "Registering for FCM");
            String token = task.getData();
            if(token != null && token.length() > 0) {
                JSONObject result = NetworkConnection.getInstance().registerGCM(token, task.getSession());
                if (result != null && result.has("success")) {
                    if(result.getBoolean("success")) {
                        IRCCloudLog.Log(Log.INFO, "IRCCloud", "Device successfully registered");
                        IRCCloudDatabase.getInstance().BackgroundTasksDao().delete(task);
                        return Result.success();
                    } else {
                        IRCCloudLog.Log(Log.ERROR, "IRCCloud", "Unable to register device: " + result.toString());
                        return Result.retry();
                    }
                } else {
                    IRCCloudLog.Log(Log.INFO, "IRCCloud", "Rescheduling FCM registration");
                    return Result.retry();
                }
            }
        } catch (Exception e) {
            NetworkConnection.printStackTraceToCrashlytics(e);
        }
        IRCCloudLog.Log(Log.ERROR, "IRCCloud", "FCM registration failed");