Arthur Eubanks | 23e2f73 | 2018-01-08 16:35:28 -0800 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 16 | package com.android.tradefed.targetprep; |
| 17 | |
| 18 | import com.android.tradefed.build.IBuildInfo; |
| 19 | import com.android.tradefed.config.Option; |
| 20 | import com.android.tradefed.device.DeviceNotAvailableException; |
| 21 | import com.android.tradefed.device.ITestDevice; |
| 22 | |
| 23 | import java.util.ArrayList; |
| 24 | import java.util.List; |
| 25 | |
| 26 | /** |
| 27 | * Add packages to whitelist to allow it to run in the background. |
| 28 | */ |
| 29 | public 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 | } |