()
| 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>() { |
| 140 | @Override |
| 141 | public void onChanged(TupleUnsent unsent) { |
| 142 | if (unsent == null || !unsent.equals(lastUnsent)) { |
| 143 | lastUnsent = unsent; |
| 144 | EntityLog.log(ServiceSend.this, "Unsent=" + (unsent == null ? null : unsent.count)); |
| 145 | |
| 146 | try { |
| 147 | NotificationManager nm = |
| 148 | Helper.getSystemService(ServiceSend.this, NotificationManager.class); |
| 149 | if (NotificationHelper.areNotificationsEnabled(nm)) |
| 150 | nm.notify(NotificationHelper.NOTIFICATION_SEND, getNotificationService(false)); |
| 151 | } catch (Throwable ex) { |
| 152 | Log.w(ex); |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | }); |
| 157 | |
| 158 | // Observe send operations |
| 159 | db.operation().liveSend().observe(owner, new Observer<List<EntityOperation>>() { |
| 160 | @Override |
| 161 | public void onChanged(List<EntityOperation> operations) { |
| 162 | if (operations == null) |
| 163 | operations = new ArrayList<>(); |
nothing calls this directly
no test coverage detected