1 /*
2  * Copyright (C) 2015 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.cts.app.os;
18 
19 import com.android.tradefed.build.IBuildInfo;
20 import com.android.tradefed.device.CollectingOutputReceiver;
21 import com.android.tradefed.device.ITestDevice;
22 import com.android.tradefed.testtype.DeviceTestCase;
23 import com.android.tradefed.testtype.IBuildReceiver;
24 
25 public class OsHostTests extends DeviceTestCase implements IBuildReceiver {
26     private static final String TEST_APP_PACKAGE = "com.android.cts.app.os.test";
27     private static final String TEST_NON_EXPORTED_ACTIVITY_CLASS = "TestNonExported";
28 
29     private static final String START_NON_EXPORTED_ACTIVITY_COMMAND = String.format(
30             "am start -n %s/%s.%s",
31             TEST_APP_PACKAGE, TEST_APP_PACKAGE, TEST_NON_EXPORTED_ACTIVITY_CLASS);
32 
33     /**
34      * A reference to the device under test.
35      */
36     private ITestDevice mDevice;
37 
38     @Override
setBuild(IBuildInfo buildInfo)39     public void setBuild(IBuildInfo buildInfo) {
40     }
41 
42     @Override
setUp()43     protected void setUp() throws Exception {
44         super.setUp();
45 
46         // Get the device, this gives a handle to run commands and install APKs.
47         mDevice = getDevice();
48     }
49 
50     /**
51      * Test whether non-exported activities are properly not launchable.
52      *
53      * @throws Exception
54      */
testNonExportedActivities()55     public void testNonExportedActivities() throws Exception {
56         // Attempt to launch the non-exported activity in the test app
57         CollectingOutputReceiver outputReceiver = new CollectingOutputReceiver();
58         mDevice.executeShellCommand(START_NON_EXPORTED_ACTIVITY_COMMAND, outputReceiver);
59         final String output = outputReceiver.getOutput();
60 
61         assertTrue(output.contains("Permission Denial") && output.contains(" not exported"));
62     }
63 }
64