• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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.cts.tradefed.device;
17 
18 import com.android.cts.util.AbiUtils;
19 import com.android.ddmlib.Log;
20 import com.android.tradefed.device.DeviceNotAvailableException;
21 import com.android.tradefed.device.ITestDevice;
22 import com.android.tradefed.result.ITestInvocationListener;
23 import com.android.tradefed.testtype.InstrumentationTest;
24 
25 import java.io.File;
26 import java.util.HashSet;
27 import java.util.Set;
28 
29 /**
30  * Collects info from device under test.
31  * <p/>
32  * This class simply serves as a conduit for grabbing info from device using the device info
33  * collector apk, and forwarding that data directly to the {@link ITestInvocationListener} as run
34  * metrics.
35  */
36 public class DeviceInfoCollector {
37 
38     private static final String LOG_TAG = "DeviceInfoCollector";
39     private static final String APK_NAME = "TestDeviceSetup";
40     public static final String APP_PACKAGE_NAME = "android.tests.devicesetup";
41     private static final String INSTRUMENTATION_NAME = "android.tests.getinfo.DeviceInfoInstrument";
42     public static final Set<String> IDS = new HashSet<String>();
43     static {
44         for (String abi : AbiUtils.getAbisSupportedByCts()) {
AbiUtils.createId(abi, APP_PACKAGE_NAME)45             IDS.add(AbiUtils.createId(abi, APP_PACKAGE_NAME));
46         }
47     }
48 
49     /**
50      * Installs and runs the device info collector instrumentation, and forwards results
51      * to the listener.
52      *
53      * @param device
54      * @param listener
55      * @throws DeviceNotAvailableException
56      */
collectDeviceInfo(ITestDevice device, String abi, File testApkDir, ITestInvocationListener listener)57     public static void collectDeviceInfo(ITestDevice device, String abi, File testApkDir,
58             ITestInvocationListener listener) throws DeviceNotAvailableException {
59         File apkFile = new File(testApkDir, String.format("%s.apk", APK_NAME));
60         if (!apkFile.exists()) {
61             Log.e(LOG_TAG, String.format("Could not find %s", apkFile.getAbsolutePath()));
62         }
63         // collect the instrumentation bundle results using instrumentation test
64         // should work even though no tests will actually be run
65         InstrumentationTest instrTest = new InstrumentationTest();
66         instrTest.setDevice(device);
67         instrTest.setInstallFile(apkFile);
68         // no need to collect tests and re-run
69         instrTest.setRerunMode(false);
70         instrTest.setPackageName(APP_PACKAGE_NAME);
71         instrTest.setRunName(AbiUtils.createId(abi, APP_PACKAGE_NAME));
72         instrTest.setRunnerName(INSTRUMENTATION_NAME);
73         instrTest.run(listener);
74     }
75 }
76