Skip to content

Commit 9fdc424

Browse files
rachitjain2706Android Build Cherrypicker Worker
authored andcommitted
Fix CtsAppSecurityHostTestCases test cases
Launch another activity instead of home activity since on targets like car UI portrait, launching home intent does not make the current activity go into background. Bug: 292053153 Test: atest -s 3a5a86ec android.appsecurity.cts.OverlayHostTest#testOverlayEnabled_activityWithServiceInBackground_toForeground android.appsecurity.cts.OverlayHostTest#testOverlayEnabled_activityInBackground_toForeground (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:6f852603be8370d5e10d9346f49fb2dae49fdf01) Merged-In: I2a0d4804ba943a7ecbd718774250d313f07622ef Change-Id: I2a0d4804ba943a7ecbd718774250d313f07622ef
1 parent a871a35 commit 9fdc424

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

hostsidetests/appsecurity/test-apps/rro/OverlayTarget/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<uses-library android:name="android.test.runner" />
2121
<activity android:name=".OverlayTargetActivity" android:exported="false"
2222
android:configChanges="@integer/config_changes_assets_paths" />
23+
<activity android:name=".SimpleActivity" android:exported="true" />
2324
<service android:name=".OverlayTargetService" android:exported="false" />
2425
</application>
2526

hostsidetests/appsecurity/test-apps/rro/OverlayTarget/src/com/android/cts/overlay/target/OverlayTargetTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void overlayEnabled_activityInForeground() throws Exception {
8989
public void overlayEnabled_activityInBackground_toForeground() throws Exception {
9090
final OverlayTargetActivity targetActivity = mActivityTestRule.getActivity();
9191
// Activity goes into background
92-
launchHome();
92+
launchSimpleActivity();
9393
mInstrumentation.waitForIdleSync();
9494
final CountDownLatch latch = new CountDownLatch(1);
9595
targetActivity.setConfigurationChangedCallback((activity, config) -> {
@@ -137,9 +137,11 @@ private static void setOverlayEnabled(String overlayPackage, boolean enabled)
137137
() -> expected.equals(getStateForOverlay(overlayPackage)));
138138
}
139139

140-
private static void launchHome() {
141-
SystemUtil.runShellCommand("am start -W -a android.intent.action.MAIN"
142-
+ " -c android.intent.category.HOME");
140+
private void launchSimpleActivity() {
141+
Intent intent = new Intent(Intent.ACTION_MAIN);
142+
intent.setClass(mInstrumentation.getTargetContext(), SimpleActivity.class);
143+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
144+
mInstrumentation.startActivitySync(intent);
143145
}
144146

145147
private static String getStateForOverlay(String overlayPackage) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (C) 2023 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.overlay.target;
18+
19+
import android.app.Activity;
20+
21+
/**
22+
* Another activity doing nothing
23+
*/
24+
public class SimpleActivity extends Activity {
25+
}

0 commit comments

Comments
 (0)