2 * Copyright (C) 2010 Felix Bechstein
4 * This file is part of WebSMS.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free Software
8 * Foundation; either version 3 of the License, or (at your option) any later
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License along with
17 * this program; If not, see <http://www.gnu.org/licenses/>.
19 package de
.ub0r
.android
.websms
.connector
.common
;
21 import android
.app
.Service
;
22 import android
.content
.Context
;
23 import android
.content
.Intent
;
24 import android
.os
.IBinder
;
25 import android
.util
.Log
;
28 * {@link Service} run by the connectors BroadcastReceiver.
32 public abstract class ConnectorService
extends Service
{
33 /** Tag for output. */
34 private static final String TAG
= "WebSMS.IO";
36 /** Wrapper for API5 commands. */
37 private HelperAPI5Service helperAPI5s
= null;
39 /** Number of running Tasks. */
40 private int running
= 0;
46 public final IBinder
onBind(final Intent intent
) {
54 public final void onCreate() {
57 this.helperAPI5s
= new HelperAPI5Service();
58 if (!this.helperAPI5s
.isAvailable()) {
59 this.helperAPI5s
= null;
61 } catch (VerifyError e
) {
62 this.helperAPI5s
= null;
63 Log
.d(TAG
, "no api5 running", e
);
70 public final synchronized void register() {
71 Log
.d(TAG
, "register()");
72 Log
.d(TAG
, "currentIOOps=" + this.running
);
74 Log
.d(TAG
, "currentIOOps=" + this.running
);
78 * Unregister a IO task.
80 public final synchronized void unregister() {
81 Log
.d(TAG
, "unregister()");
82 Log
.d(TAG
, "currentIOOps=" + this.running
);
84 if (this.running
<= 0) {
87 Log
.d(TAG
, "currentIOOps=" + this.running
);
94 public final void onStart(final Intent intent
, final int startId
) {
96 final String a
= intent
.getAction();
98 (a
.equals(CommandReceiver
.ACTION_CONNECTOR_RUN_BOOSTRAP
)
100 CommandReceiver
.ACTION_CONNECTOR_RUN_UPDATE
) // .
101 || a
.equals(CommandReceiver
.ACTION_CONNECTOR_RUN_SEND
))) {
102 // TODO: setForeground / startForeground
103 this.startConnectorTask(this, intent
);
112 public final int onStartCommand(final Intent intent
, final int flags
,
114 this.onStart(intent
, startId
);
115 return START_NOT_STICKY
;
119 * Start a connectorTask.
126 protected abstract void startConnectorTask(final Context context
,
127 final Intent intent
);