diff options
4 files changed, 134 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index 6b00c86bf699..d8206276f31a 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -1414,7 +1414,12 @@ final class ActivityStack { * this function updates the rest of our state to match that fact. */ private void completeResumeLocked(ActivityRecord next) { + boolean wasVisible = next.visible; next.visible = true; + if (!wasVisible) { + // Visibility has changed, so take a note of it so we call the TaskStackChangedListener + mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; + } next.idle = false; next.results = null; next.newIntents = null; diff --git a/services/tests/servicestests/Android.mk b/services/tests/servicestests/Android.mk index b76392c967f6..3f5b96ea6a19 100644 --- a/services/tests/servicestests/Android.mk +++ b/services/tests/servicestests/Android.mk @@ -53,6 +53,8 @@ ifeq (true,$(EMMA_INSTRUMENT)) LOCAL_JACK_FLAGS := --multi-dex native endif # EMMA_INSTRUMENT_STATIC +LOCAL_STATIC_JAVA_LIBRARIES += ub-uiautomator + include $(BUILD_PACKAGE) ######################################################################### diff --git a/services/tests/servicestests/AndroidManifest.xml b/services/tests/servicestests/AndroidManifest.xml index b8ace28fc093..514f095cbd58 100644 --- a/services/tests/servicestests/AndroidManifest.xml +++ b/services/tests/servicestests/AndroidManifest.xml @@ -43,6 +43,7 @@ <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <uses-permission android:name="android.permission.PACKET_KEEPALIVE_OFFLOAD" /> <uses-permission android:name="android.permission.GET_INTENT_SENDER_INTENT" /> + <uses-permission android:name="android.permission.MANAGE_ACTIVITY_STACKS" /> <application> <uses-library android:name="android.test.runner" /> @@ -155,6 +156,9 @@ </intent-filter> </activity-alias> + <activity android:name="com.android.server.am.TaskStackChangedListenerTest$ActivityA" /> + <activity android:name="com.android.server.am.TaskStackChangedListenerTest$ActivityB" /> + </application> <instrumentation diff --git a/services/tests/servicestests/src/com/android/server/am/TaskStackChangedListenerTest.java b/services/tests/servicestests/src/com/android/server/am/TaskStackChangedListenerTest.java new file mode 100644 index 000000000000..b47d17efef70 --- /dev/null +++ b/services/tests/servicestests/src/com/android/server/am/TaskStackChangedListenerTest.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.server.am; + +import static android.support.test.InstrumentationRegistry.getInstrumentation; + +import android.app.Activity; +import android.app.ActivityManagerNative; +import android.app.IActivityManager; +import android.app.ITaskStackListener; +import android.content.Context; +import android.content.Intent; +import android.os.RemoteException; +import android.support.test.InstrumentationRegistry; +import android.support.test.filters.MediumTest; +import android.support.test.runner.AndroidJUnit4; +import android.support.test.uiautomator.UiDevice; + +import com.android.internal.annotations.GuardedBy; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@MediumTest +@RunWith(AndroidJUnit4.class) +public class TaskStackChangedListenerTest extends ITaskStackListener.Stub { + + private IActivityManager mService; + + private static final Object sLock = new Object(); + @GuardedBy("sLock") + private static boolean sTaskStackChangedCalled; + private static boolean sActivityBResumed; + + @Before + public void setUp() throws Exception { + mService = ActivityManagerNative.getDefault(); + mService.registerTaskStackListener(this); + } + + @Test + public void testTaskStackChanged_afterFinish() throws Exception { + Context ctx = InstrumentationRegistry.getContext(); + ctx.startActivity(new Intent(ctx, ActivityA.class)); + UiDevice.getInstance(getInstrumentation()).waitForIdle(); + synchronized (sLock) { + Assert.assertTrue(sTaskStackChangedCalled); + } + Assert.assertTrue(sActivityBResumed); + } + + @Override + public void onTaskStackChanged() throws RemoteException { + synchronized (sLock) { + sTaskStackChangedCalled = true; + } + } + + @Override + public void onActivityPinned() throws RemoteException { + } + + @Override + public void onPinnedActivityRestartAttempt() throws RemoteException { + } + + @Override + public void onPinnedStackAnimationEnded() throws RemoteException { + } + + @Override + public void onActivityForcedResizable(String packageName, int taskId) throws RemoteException { + } + + @Override + public void onActivityDismissingDockedStack() throws RemoteException { + } + + public static class ActivityA extends Activity { + + private boolean mActivityBLaunched = false; + + @Override + protected void onPostResume() { + super.onPostResume(); + if (mActivityBLaunched) { + return; + } + mActivityBLaunched = true; + finish(); + startActivity(new Intent(this, ActivityB.class)); + } + } + + public static class ActivityB extends Activity { + + @Override + protected void onPostResume() { + super.onPostResume(); + synchronized (sLock) { + sTaskStackChangedCalled = false; + } + sActivityBResumed = true; + finish(); + } + } +} |