2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.anomaly.tester.service;
19 import android.annotation.Nullable;
20 import android.app.IntentService;
21 import android.content.Intent;
22 import android.os.ResultReceiver;
24 import com.android.settings.anomaly.tester.utils.AnomalyActions;
27 * Service to run the anomaly action
29 public class AnomalyService extends IntentService {
30 private static final String TAG = AnomalyService.class.getSimpleName();
32 public AnomalyService() {
33 super(AnomalyService.class.getSimpleName());
37 protected void onHandleIntent(@Nullable Intent intent) {
38 final String action = intent.getStringExtra(AnomalyActions.KEY_ACTION);
39 final long durationMs = intent.getLongExtra(AnomalyActions.KEY_DURATION_MS, 0);
40 final ResultReceiver resultReceiver = intent.getParcelableExtra(
41 AnomalyActions.KEY_RESULT_RECEIVER);
43 AnomalyActions.doAction(this, action, durationMs);
45 if (resultReceiver != null) {
46 resultReceiver.send(0 /* resultCode */, intent.getExtras());