2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9.service;
|
2009-11-22 12:01:04 -05:00
|
|
|
|
|
|
|
import android.app.Service;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.IBinder;
|
|
|
|
import android.os.PowerManager;
|
|
|
|
import android.os.PowerManager.WakeLock;
|
|
|
|
import android.util.Log;
|
2009-12-14 21:50:53 -05:00
|
|
|
import com.fsck.k9.K9;
|
2009-11-22 12:01:04 -05:00
|
|
|
|
|
|
|
public abstract class CoreService extends Service
|
|
|
|
{
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-22 12:01:04 -05:00
|
|
|
protected static void addWakeLockId(Intent i, Integer wakeLockId)
|
|
|
|
{
|
|
|
|
if (wakeLockId != null)
|
|
|
|
{
|
|
|
|
i.putExtra(BootReceiver.WAKE_LOCK_ID, wakeLockId);
|
|
|
|
}
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-22 12:01:04 -05:00
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void onStart(Intent intent, int startId)
|
|
|
|
{
|
|
|
|
|
2009-11-22 12:01:04 -05:00
|
|
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
2009-12-14 21:50:53 -05:00
|
|
|
WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "K9");
|
2009-11-22 12:01:04 -05:00
|
|
|
wakeLock.setReferenceCounted(false);
|
2009-12-14 21:50:53 -05:00
|
|
|
wakeLock.acquire(K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT);
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
Log.i(K9.LOG_TAG, "CoreService: " + this.getClass().getName() + ".onStart(" + intent + ", " + startId);
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-22 12:01:04 -05:00
|
|
|
int wakeLockId = intent.getIntExtra(BootReceiver.WAKE_LOCK_ID, -1);
|
|
|
|
if (wakeLockId != -1)
|
|
|
|
{
|
|
|
|
BootReceiver.releaseWakeLock(this, wakeLockId);
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-22 12:01:04 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
super.onStart(intent, startId);
|
|
|
|
startService(intent, startId);
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
if (wakeLock != null)
|
|
|
|
{
|
|
|
|
wakeLock.release();
|
|
|
|
}
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-22 12:01:04 -05:00
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
|
|
|
|
2009-11-22 12:01:04 -05:00
|
|
|
public abstract void startService(Intent intent, int startId);
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-22 12:01:04 -05:00
|
|
|
@Override
|
|
|
|
public IBinder onBind(Intent arg0)
|
|
|
|
{
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-22 12:01:04 -05:00
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void onDestroy()
|
|
|
|
{
|
2009-12-14 21:50:53 -05:00
|
|
|
Log.i(K9.LOG_TAG, "CoreService: " + this.getClass().getName() + ".onDestroy()");
|
2009-11-22 12:01:04 -05:00
|
|
|
super.onDestroy();
|
2009-11-24 19:40:29 -05:00
|
|
|
// MessagingController.getInstance(getApplication()).removeListener(mListener);
|
2009-11-22 12:01:04 -05:00
|
|
|
}
|
|
|
|
}
|