blob: 491f9e47ccfc2c9831c9eb67a8bc385e895114db [file] [log] [blame]
Arthur Eubanks23e2f732018-01-08 16:35:28 -08001/*
2 * Copyright (C) 2018 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 */
16package com.android.tradefed.targetprep;
17
18import com.android.tradefed.build.IBuildInfo;
19import com.android.tradefed.config.Option;
20import com.android.tradefed.device.DeviceNotAvailableException;
21import com.android.tradefed.device.ITestDevice;
22
23import java.util.ArrayList;
24import java.util.List;
25
26/**
27 * Add packages to whitelist to allow it to run in the background.
28 */
29public class AddWhitelistPackage extends BaseTargetPreparer implements ITargetCleaner {
30
31 @Option(
32 name = "whitelist-package-time",
33 description = "Duration to put package in whitelist",
34 isTimeVal = true
35 )
36 private long mDurationMillis;
37
38 @Option(
39 name = "whitelist-package-name",
40 description = "Name of package to put in whitelist"
41 )
42 private List<String> mPackages = new ArrayList<>();
43
44 @Override
45 public void setUp(ITestDevice device, IBuildInfo buildInfo)
46 throws TargetSetupError, BuildError, DeviceNotAvailableException {
47 for (String pkg : mPackages) {
48 device.executeShellCommand(
49 String.format("dumpsys deviceidle tempwhitelist -d %d %s", mDurationMillis,
50 pkg));
51 }
52 }
53
54 @Override
55 public void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e)
56 throws DeviceNotAvailableException {
57 for (String pkg : mPackages) {
58 device.executeShellCommand(
59 String.format("dumpsys deviceidle tempwhitelist -r %s", pkg));
60 }
61 }
62}