Home | History | Annotate | Download | only in batterystats
      1 /*
      2  * Copyright (C) 2017 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.server.cts.device.batterystats;
     18 
     19 import static com.android.server.cts.device.batterystats.BatteryStatsBgVsFgActions.KEY_ACTION;
     20 import static com.android.server.cts.device.batterystats.BatteryStatsBgVsFgActions.KEY_REQUEST_CODE;
     21 import static com.android.server.cts.device.batterystats.BatteryStatsBgVsFgActions.doAction;
     22 
     23 import android.app.IntentService;
     24 import android.content.Intent;
     25 import android.util.Log;
     26 
     27 /** An service (to be run as a background process) which performs one of a number of actions. */
     28 public class BatteryStatsBackgroundService extends IntentService {
     29     private static final String TAG = BatteryStatsBackgroundService.class.getSimpleName();
     30 
     31     public BatteryStatsBackgroundService() {
     32         super(BatteryStatsBackgroundService.class.getName());
     33     }
     34 
     35     @Override
     36     public void onHandleIntent(Intent intent) {
     37         String action = intent.getStringExtra(KEY_ACTION);
     38         String requestCode = intent.getStringExtra(KEY_REQUEST_CODE);
     39         Log.i(TAG, "Starting " + action + " from background service as request " + requestCode);
     40 
     41         // Check that app is in background; crash if it isn't.
     42         BatteryStatsBgVsFgActions.checkAppState(this, true, action, requestCode);
     43 
     44         doAction(this, action, requestCode);
     45     }
     46 }
     47