OSDN Git Service

Add bt anomaly action in testing app
[android-x86/packages-apps-Settings.git] / tests / anomaly-tester / src / com / android / settings / anomaly / tester / service / AnomalyService.java
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.settings.anomaly.tester.service;
18
19 import android.annotation.Nullable;
20 import android.app.IntentService;
21 import android.content.Intent;
22 import android.os.ResultReceiver;
23
24 import com.android.settings.anomaly.tester.utils.AnomalyActions;
25
26 /**
27  * Service to run the anomaly action
28  */
29 public class AnomalyService extends IntentService {
30     private static final String TAG = AnomalyService.class.getSimpleName();
31
32     public AnomalyService() {
33         super(AnomalyService.class.getSimpleName());
34     }
35
36     @Override
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);
42
43         AnomalyActions.doAction(this, action, durationMs);
44
45         if (resultReceiver != null) {
46             resultReceiver.send(0 /* resultCode */, intent.getExtras());
47         }
48     }
49 }