1 /*
2  * Copyright (C) 2013 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 
17 package com.android.phone;
18 
19 import android.app.PendingIntent;
20 import android.app.Service;
21 import android.content.Intent;
22 import android.os.IBinder;
23 import android.util.Log;
24 
25 /**
26  * Service for performing HfaActivation without any UI.
27  */
28 public class HfaService extends Service {
29     private static final String TAG = HfaService.class.getSimpleName();
30 
31     private HfaLogic mHfaLogic;
32 
33     @Override
onCreate()34     public void onCreate() {
35         Log.i(TAG, "service started");
36     }
37 
38     @Override
onStartCommand(Intent intent, int flags, int startId)39     public int onStartCommand(Intent intent, int flags, int startId) {
40         final PendingIntent otaResponseIntent = intent.getParcelableExtra(
41                 OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT);
42 
43         mHfaLogic = new HfaLogic(this, new HfaLogic.HfaLogicCallback() {
44             @Override
45             public void onSuccess() {
46                 Log.i(TAG, "onSuccess");
47                 onComplete();
48             }
49 
50             @Override
51             public void onError(String msg) {
52                 Log.i(TAG, "onError: " + msg);
53                 // We do not respond from this service. On success or failure
54                 // we do the same thing...finish.
55                 onComplete();
56             }
57         }, otaResponseIntent);
58         mHfaLogic.start();
59 
60         return START_REDELIVER_INTENT;
61     }
62 
63     @Override
onBind(Intent intent)64     public IBinder onBind(Intent intent) {
65         return null;
66     }
67 
onComplete()68     private void onComplete() {
69         stopSelf();
70     }
71 }
72