| 80 | import biweekly.property.Method; |
| 81 | |
| 82 | public class ServiceSend extends ServiceBase implements SharedPreferences.OnSharedPreferenceChangeListener { |
| 83 | private int retry_max = RETRY_MAX_DEFAULT; |
| 84 | private TupleUnsent lastUnsent = null; |
| 85 | private Network lastActive = null; |
| 86 | private boolean lastSuitable = false; |
| 87 | private int lastProgress = -1; |
| 88 | |
| 89 | private TwoStateOwner owner; |
| 90 | private PowerManager.WakeLock wlOutbox; |
| 91 | private List<Long> handling = new ArrayList<>(); |
| 92 | |
| 93 | private static final ExecutorService executor = |
| 94 | Helper.getBackgroundExecutor(1, "send"); |
| 95 | |
| 96 | private static final long RETRY_WAIT = 5000L; // milliseconds |
| 97 | private static final int CONNECTIVITY_DELAY = 5000; // milliseconds |
| 98 | private static final int PROGRESS_UPDATE_INTERVAL = 1000; // milliseconds |
| 99 | private static final long STOP_DELAY = 2500L; |
| 100 | |
| 101 | static final int PI_SEND = 1; |
| 102 | static final int PI_FIX = 2; |
| 103 | |
| 104 | static final int RETRY_MAX_DEFAULT = 3; |
| 105 | |
| 106 | @Override |
| 107 | public void onCreate() { |
| 108 | EntityLog.log(this, "Service send create"); |
| 109 | super.onCreate(); |
| 110 | try { |
| 111 | startForeground(NotificationHelper.NOTIFICATION_SEND, getNotificationService(false)); |
| 112 | EntityLog.log(this, EntityLog.Type.Debug2, |
| 113 | "onCreate class=" + this.getClass().getName()); |
| 114 | } catch (Throwable ex) { |
| 115 | if (Helper.isPlayStoreInstall()) |
| 116 | Log.i(ex); |
| 117 | else |
| 118 | Log.e(ex); |
| 119 | } |
| 120 | |
| 121 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); |
| 122 | retry_max = prefs.getInt("send_retry_max", RETRY_MAX_DEFAULT); |
| 123 | |
| 124 | owner = new TwoStateOwner(this, "send"); |
| 125 | |
| 126 | PowerManager pm = Helper.getSystemService(this, PowerManager.class); |
| 127 | wlOutbox = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":send"); |
| 128 | |
| 129 | final Runnable quit = new RunnableEx("send:quit") { |
| 130 | @Override |
| 131 | protected void delegate() { |
| 132 | EntityLog.log(ServiceSend.this, "Send quit"); |
| 133 | stopSelf(); |
| 134 | } |
| 135 | }; |
| 136 | |
| 137 | // Observe unsent count |
| 138 | DB db = DB.getInstance(this); |
| 139 | db.operation().liveUnsent().observe(this, new Observer<TupleUnsent>() { |
nothing calls this directly
no test coverage detected