ImsFrameworkService.java revision 02ffa5a99c8d4faf90cbb7639cf0cf41f9f7121d
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.example.imsframework;
18
19import android.app.Service;
20import android.content.Intent;
21import android.os.IBinder;
22import android.util.Log;
23
24/**
25 * Example service to handle IMS setup after boot completed event.
26 *
27 * Setting {@code android:persistent="true"} in the manifest will cause
28 * {@link ImsFrameworkApp#onCreate()} to be called at system startup,
29 * before {@link Intent#ACTION_BOOT_COMPLETED} is broadcast, so early
30 * initialization can be performed there, such as registering to receive
31 * telephony state change broadcasts that can't be declared in the manifest.
32 */
33public class ImsFrameworkService extends Service {
34    private static final String TAG = "ImsFrameworkService";
35
36    @Override
37    public int onStartCommand(Intent intent, int flags, int startId) {
38        String action = intent.getAction();
39        Log.d(TAG, "Service starting for intent " + action);
40        if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
41            Log.d(TAG, "Received ACTION_BOOT_COMPLETED");
42            handleBootCompleted();
43        }
44        stopSelf();     // stop service after handling the action
45        return START_NOT_STICKY;
46    }
47
48    private void handleBootCompleted() {
49        // Code to execute after boot completes, e.g. connecting to the IMS PDN
50    }
51
52    @Override
53    public IBinder onBind(Intent intent) {
54        return null;    // clients can't bind to this service
55    }
56}
57