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
;
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
;
26 import de
.ub0r
.android
.andGMXsms
.HelperAPI5Service
;
29 * {@link Service} run by the connectors BroadcastReceiver.
33 public abstract class ConnectorService
extends Service
{
34 /** Tag for output. */
35 private static final String TAG
= "WebSMS.IO";
37 /** Wrapper for API5 commands. */
38 private HelperAPI5Service helperAPI5s
= null;
40 /** Number of running Tasks. */
41 private int running
= 0;
47 public final IBinder
onBind(final Intent intent
) {
55 public final void onCreate() {
58 this.helperAPI5s
= new HelperAPI5Service();
59 if (!this.helperAPI5s
.isAvailable()) {
60 this.helperAPI5s
= null;
62 } catch (VerifyError e
) {
63 this.helperAPI5s
= null;
64 Log
.d(TAG
, "no api5 running", e
);
71 public final synchronized void register() {
72 Log
.d(TAG
, "register()");
73 Log
.d(TAG
, "currentIOOps=" + this.running
);
75 Log
.d(TAG
, "currentIOOps=" + this.running
);
79 * Unregister a IO task.
81 public final synchronized void unregister() {
82 Log
.d(TAG
, "unregister()");
83 Log
.d(TAG
, "currentIOOps=" + this.running
);
85 if (this.running
<= 0) {
88 Log
.d(TAG
, "currentIOOps=" + this.running
);
95 public final void onStart(final Intent intent
, final int startId
) {
97 final String a
= intent
.getAction();
99 (a
.equals(Constants
.ACTION_CONNECTOR_RUN_BOOSTRAP
)
101 Constants
.ACTION_CONNECTOR_RUN_UPDATE
) // .
102 || a
.equals(Constants
.ACTION_CONNECTOR_RUN_SEND
))) {
103 // TODO: setForeground / startForeground
104 this.startConnectorTask(this, intent
);
113 public final int onStartCommand(final Intent intent
, final int flags
,
115 this.onStart(intent
, startId
);
116 return START_NOT_STICKY
;
120 * Start a connectorTask.
127 protected abstract void startConnectorTask(final Context context
,
128 final Intent intent
);