1 /*
2  * Copyright (C) 2022 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 android.cts.statsd.validation;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.cts.statsd.metric.MetricsUtils;
22 import android.cts.statsdatom.lib.DeviceUtils;
23 
24 import com.android.tradefed.build.IBuildInfo;
25 import com.android.tradefed.testtype.DeviceTestCase;
26 import com.android.tradefed.testtype.IBuildReceiver;
27 import com.android.tradefed.util.RunUtil;
28 
29 public class StatsFrameworkInitializerTest extends DeviceTestCase implements IBuildReceiver {
30 
31     private IBuildInfo mCtsBuild;
32 
33     @Override
setUp()34     protected void setUp() throws Exception {
35         super.setUp();
36         assertThat(mCtsBuild).isNotNull();
37         DeviceUtils.installTestApp(getDevice(), MetricsUtils.DEVICE_SIDE_TEST_APK,
38                 MetricsUtils.DEVICE_SIDE_TEST_PACKAGE, mCtsBuild);
39         RunUtil.getDefault().sleep(1000);
40     }
41 
42     @Override
tearDown()43     protected void tearDown() throws Exception {
44         DeviceUtils.uninstallTestApp(getDevice(), MetricsUtils.DEVICE_SIDE_TEST_PACKAGE);
45         super.tearDown();
46     }
47 
48     @Override
setBuild(IBuildInfo buildInfo)49     public void setBuild(IBuildInfo buildInfo) {
50         mCtsBuild = buildInfo;
51     }
52 
testStatsFrameworkInitializer_failsWhenCalledOutsideOfSystemServiceRegistry()53     public void testStatsFrameworkInitializer_failsWhenCalledOutsideOfSystemServiceRegistry()
54             throws Exception {
55         DeviceUtils.runDeviceTests(getDevice(), MetricsUtils.DEVICE_SIDE_TEST_PACKAGE,
56                 ".StatsFrameworkInitializerTests", "testRegisterServiceWrappers_expectFail");
57     }
58 
59 }
60