Home | History | Annotate | Download | only in service
      1 /*
      2  * Copyright (C) 2008 Esmertec AG.
      3  * Copyright (C) 2008 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 package com.android.im.service;
     18 
     19 import android.content.Context;
     20 
     21 import com.android.im.engine.HeartbeatService;
     22 import com.android.im.engine.SmsService;
     23 import com.android.im.engine.SystemService;
     24 
     25 public class AndroidSystemService extends SystemService {
     26     private static AndroidSystemService sInstance;
     27 
     28     private AndroidSystemService() {
     29     }
     30 
     31     public static AndroidSystemService getInstance() {
     32         if (sInstance == null) {
     33             sInstance = new AndroidSystemService();
     34         }
     35         return sInstance;
     36     }
     37 
     38     private Context mContext;
     39     private AndroidHeartBeatService mHeartbeatServcie;
     40     private AndroidSmsService mSmsService;
     41 
     42     public void initialize(Context context) {
     43         mContext = context;
     44     }
     45 
     46     public void shutdown() {
     47         if (mHeartbeatServcie != null) {
     48             mHeartbeatServcie.stopAll();
     49         }
     50         if (mSmsService != null) {
     51             mSmsService.stop();
     52         }
     53     }
     54 
     55     @Override
     56     public HeartbeatService getHeartbeatService() {
     57         if(mContext == null) {
     58             throw new IllegalStateException("Hasn't been initialized yet");
     59         }
     60         if (mHeartbeatServcie == null) {
     61             mHeartbeatServcie = new AndroidHeartBeatService(mContext);
     62         }
     63         return mHeartbeatServcie;
     64     }
     65 
     66     @Override
     67     public SmsService getSmsService() {
     68         if(mContext == null) {
     69             throw new IllegalStateException("Hasn't been initialized yet");
     70         }
     71         if (mSmsService == null) {
     72             mSmsService = new AndroidSmsService(mContext);
     73         }
     74         return mSmsService;
     75     }
     76 
     77 }
     78