diff options
18 files changed, 152 insertions, 1368 deletions
diff --git a/Android.mk b/Android.mk index 4695a1970cbc..74717ff74c51 100644 --- a/Android.mk +++ b/Android.mk @@ -71,8 +71,6 @@ LOCAL_SRC_FILES += \ core/java/android/accounts/IAccountManagerResponse.aidl \ core/java/android/accounts/IAccountAuthenticator.aidl \ core/java/android/accounts/IAccountAuthenticatorResponse.aidl \ - core/java/android/app/IActivityContainer.aidl \ - core/java/android/app/IActivityContainerCallback.aidl \ core/java/android/app/IActivityController.aidl \ core/java/android/app/IActivityManager.aidl \ core/java/android/app/IActivityPendingResult.aidl \ diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java index f003061cec3a..ab075ee0e9f2 100644 --- a/cmds/am/src/com/android/commands/am/Am.java +++ b/cmds/am/src/com/android/commands/am/Am.java @@ -16,70 +16,25 @@ package com.android.commands.am; -import static android.app.ActivityManager.RESIZE_MODE_SYSTEM; -import static android.app.ActivityManager.RESIZE_MODE_USER; -import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; -import static android.app.ActivityManager.StackId.INVALID_STACK_ID; - import android.app.ActivityManager; -import android.app.ActivityManager.StackInfo; -import android.app.IActivityContainer; -import android.app.IActivityController; import android.app.IActivityManager; -import android.app.IInstrumentationWatcher; -import android.app.Instrumentation; -import android.app.IStopUserCallback; -import android.app.ProfilerInfo; -import android.app.UiAutomationConnection; -import android.app.usage.ConfigurationStats; -import android.app.usage.IUsageStatsManager; -import android.app.usage.UsageStatsManager; -import android.content.ComponentCallbacks2; -import android.content.ComponentName; -import android.content.Context; -import android.content.IIntentReceiver; -import android.content.Intent; import android.content.pm.IPackageManager; -import android.content.pm.InstrumentationInfo; -import android.content.pm.ParceledListSlice; -import android.content.pm.UserInfo; -import android.content.res.Configuration; -import android.graphics.Rect; -import android.os.Binder; -import android.os.Build; -import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.os.ResultReceiver; import android.os.SELinux; import android.os.ServiceManager; import android.os.ShellCallback; -import android.os.ShellCommand; -import android.os.SystemProperties; import android.os.UserHandle; -import android.text.TextUtils; import android.util.AndroidException; -import android.util.ArrayMap; -import android.util.Log; -import android.view.IWindowManager; import com.android.internal.os.BaseCommand; -import com.android.internal.util.HexDump; -import com.android.internal.util.Preconditions; -import java.io.BufferedReader; import java.io.File; import java.io.FileDescriptor; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStreamReader; import java.io.PrintStream; -import java.io.PrintWriter; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; public class Am extends BaseCommand { diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java deleted file mode 100644 index 29b83dc3b315..000000000000 --- a/core/java/android/app/ActivityView.java +++ /dev/null @@ -1,517 +0,0 @@ -/* - * Copyright (C) 2013 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 android.app; - -import static android.app.ActivityManager.START_CANCELED; - -import android.content.Context; -import android.content.ContextWrapper; -import android.content.IIntentSender; -import android.content.Intent; -import android.content.IntentSender; -import android.graphics.SurfaceTexture; -import android.os.IBinder; -import android.os.Message; -import android.os.OperationCanceledException; -import android.os.RemoteException; -import android.util.AttributeSet; -import android.util.DisplayMetrics; -import android.util.Log; -import android.view.InputDevice; -import android.view.InputEvent; -import android.view.MotionEvent; -import android.view.Surface; -import android.view.TextureView; -import android.view.TextureView.SurfaceTextureListener; -import android.view.View; -import android.view.ViewGroup; -import android.view.WindowManager; -import dalvik.system.CloseGuard; - -import java.lang.ref.WeakReference; -import java.util.ArrayDeque; -import java.util.concurrent.Executor; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import com.android.internal.annotations.GuardedBy; - - -/** @hide */ -public class ActivityView extends ViewGroup { - private static final String TAG = "ActivityView"; - private static final boolean DEBUG = false; - - private static final int MSG_SET_SURFACE = 1; - - private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors(); - private static final int MINIMUM_POOL_SIZE = 1; - private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1; - private static final int KEEP_ALIVE = 1; - - private static final ThreadFactory sThreadFactory = new ThreadFactory() { - private final AtomicInteger mCount = new AtomicInteger(1); - - public Thread newThread(Runnable r) { - return new Thread(r, "ActivityView #" + mCount.getAndIncrement()); - } - }; - - private static final BlockingQueue<Runnable> sPoolWorkQueue = - new LinkedBlockingQueue<Runnable>(128); - - /** - * An {@link Executor} that can be used to execute tasks in parallel. - */ - private static final Executor sExecutor = new ThreadPoolExecutor(MINIMUM_POOL_SIZE, - MAXIMUM_POOL_SIZE, KEEP_ALIVE, TimeUnit.SECONDS, sPoolWorkQueue, sThreadFactory); - - - private static class SerialExecutor implements Executor { - private final ArrayDeque<Runnable> mTasks = new ArrayDeque<Runnable>(); - private Runnable mActive; - - public synchronized void execute(final Runnable r) { - mTasks.offer(new Runnable() { - public void run() { - try { - r.run(); - } finally { - scheduleNext(); - } - } - }); - if (mActive == null) { - scheduleNext(); - } - } - - protected synchronized void scheduleNext() { - if ((mActive = mTasks.poll()) != null) { - sExecutor.execute(mActive); - } - } - } - - private final SerialExecutor mExecutor = new SerialExecutor(); - - private final int mDensityDpi; - private final TextureView mTextureView; - - @GuardedBy("mActivityContainerLock") - private ActivityContainerWrapper mActivityContainer; - private Object mActivityContainerLock = new Object(); - - private Activity mActivity; - private int mWidth; - private int mHeight; - private Surface mSurface; - private int mLastVisibility; - private ActivityViewCallback mActivityViewCallback; - - - public ActivityView(Context context) { - this(context, null); - } - - public ActivityView(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public ActivityView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - - while (context instanceof ContextWrapper) { - if (context instanceof Activity) { - mActivity = (Activity)context; - break; - } - context = ((ContextWrapper)context).getBaseContext(); - } - if (mActivity == null) { - throw new IllegalStateException("The ActivityView's Context is not an Activity."); - } - - try { - mActivityContainer = new ActivityContainerWrapper( - ActivityManager.getService().createVirtualActivityContainer( - mActivity.getActivityToken(), new ActivityContainerCallback(this))); - } catch (RemoteException e) { - throw new RuntimeException("ActivityView: Unable to create ActivityContainer. " - + e); - } - - mTextureView = new TextureView(context); - mTextureView.setSurfaceTextureListener(new ActivityViewSurfaceTextureListener()); - addView(mTextureView); - - WindowManager wm = (WindowManager)mActivity.getSystemService(Context.WINDOW_SERVICE); - DisplayMetrics metrics = new DisplayMetrics(); - wm.getDefaultDisplay().getMetrics(metrics); - mDensityDpi = metrics.densityDpi; - - mLastVisibility = getVisibility(); - - if (DEBUG) Log.v(TAG, "ctor()"); - } - - @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) { - mTextureView.layout(0, 0, r - l, b - t); - } - - @Override - protected void onVisibilityChanged(View changedView, final int visibility) { - super.onVisibilityChanged(changedView, visibility); - - if (mSurface != null && (visibility == View.GONE || mLastVisibility == View.GONE)) { - if (DEBUG) Log.v(TAG, "visibility changed; enqueing runnable"); - final Surface surface = (visibility == View.GONE) ? null : mSurface; - setSurfaceAsync(surface, mWidth, mHeight, mDensityDpi, false); - } - mLastVisibility = visibility; - } - - private boolean injectInputEvent(InputEvent event) { - return mActivityContainer != null && mActivityContainer.injectEvent(event); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - return injectInputEvent(event) || super.onTouchEvent(event); - } - - @Override - public boolean onGenericMotionEvent(MotionEvent event) { - if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) { - if (injectInputEvent(event)) { - return true; - } - } - return super.onGenericMotionEvent(event); - } - - @Override - public void onAttachedToWindow() { - if (DEBUG) Log.v(TAG, "onAttachedToWindow(): mActivityContainer=" + mActivityContainer + - " mSurface=" + mSurface); - } - - @Override - public void onDetachedFromWindow() { - if (DEBUG) Log.v(TAG, "onDetachedFromWindow(): mActivityContainer=" + mActivityContainer + - " mSurface=" + mSurface); - } - - public boolean isAttachedToDisplay() { - return mSurface != null; - } - - public void startActivity(Intent intent) { - if (mActivityContainer == null) { - throw new IllegalStateException("Attempt to call startActivity after release"); - } - if (mSurface == null) { - throw new IllegalStateException("Surface not yet created."); - } - if (DEBUG) Log.v(TAG, "startActivity(): intent=" + intent + " " + - (isAttachedToDisplay() ? "" : "not") + " attached"); - if (mActivityContainer.startActivity(intent) == START_CANCELED) { - throw new OperationCanceledException(); - } - } - - public void startActivity(IntentSender intentSender) { - if (mActivityContainer == null) { - throw new IllegalStateException("Attempt to call startActivity after release"); - } - if (mSurface == null) { - throw new IllegalStateException("Surface not yet created."); - } - if (DEBUG) Log.v(TAG, "startActivityIntentSender(): intentSender=" + intentSender + " " + - (isAttachedToDisplay() ? "" : "not") + " attached"); - final IIntentSender iIntentSender = intentSender.getTarget(); - if (mActivityContainer.startActivityIntentSender(iIntentSender) == START_CANCELED) { - throw new OperationCanceledException(); - } - } - - public void startActivity(PendingIntent pendingIntent) { - if (mActivityContainer == null) { - throw new IllegalStateException("Attempt to call startActivity after release"); - } - if (mSurface == null) { - throw new IllegalStateException("Surface not yet created."); - } - if (DEBUG) Log.v(TAG, "startActivityPendingIntent(): PendingIntent=" + pendingIntent + " " - + (isAttachedToDisplay() ? "" : "not") + " attached"); - final IIntentSender iIntentSender = pendingIntent.getTarget(); - if (mActivityContainer.startActivityIntentSender(iIntentSender) == START_CANCELED) { - throw new OperationCanceledException(); - } - } - - public void release() { - if (DEBUG) Log.v(TAG, "release() mActivityContainer=" + mActivityContainer + - " mSurface=" + mSurface); - if (mActivityContainer == null) { - Log.e(TAG, "Duplicate call to release"); - return; - } - synchronized (mActivityContainerLock) { - mActivityContainer.release(); - mActivityContainer = null; - } - - if (mSurface != null) { - mSurface.release(); - mSurface = null; - } - - mTextureView.setSurfaceTextureListener(null); - } - - private void setSurfaceAsync(final Surface surface, final int width, final int height, - final int densityDpi, final boolean callback) { - mExecutor.execute(new Runnable() { - public void run() { - try { - synchronized (mActivityContainerLock) { - if (mActivityContainer != null) { - mActivityContainer.setSurface(surface, width, height, densityDpi); - } - } - } catch (RemoteException e) { - throw new RuntimeException( - "ActivityView: Unable to set surface of ActivityContainer. ", - e); - } - if (callback) { - post(new Runnable() { - @Override - public void run() { - if (mActivityViewCallback != null) { - if (surface != null) { - mActivityViewCallback.onSurfaceAvailable(ActivityView.this); - } else { - mActivityViewCallback.onSurfaceDestroyed(ActivityView.this); - } - } - } - }); - } - } - }); - } - - /** - * Set the callback to use to report certain state changes. - * - * Note: If the surface has been created prior to this call being made, then - * ActivityViewCallback.onSurfaceAvailable will be called from within setCallback. - * - * @param callback The callback to report events to. - * - * @see ActivityViewCallback - */ - public void setCallback(ActivityViewCallback callback) { - mActivityViewCallback = callback; - - if (mSurface != null) { - mActivityViewCallback.onSurfaceAvailable(this); - } - } - - public static abstract class ActivityViewCallback { - /** - * Called when all activities in the ActivityView have completed and been removed. Register - * using {@link ActivityView#setCallback(ActivityViewCallback)}. Each ActivityView may - * have at most one callback registered. - */ - public abstract void onAllActivitiesComplete(ActivityView view); - /** - * Called when the surface is ready to be drawn to. Calling startActivity prior to this - * callback will result in an IllegalStateException. - */ - public abstract void onSurfaceAvailable(ActivityView view); - /** - * Called when the surface has been removed. Calling startActivity after this callback - * will result in an IllegalStateException. - */ - public abstract void onSurfaceDestroyed(ActivityView view); - } - - private class ActivityViewSurfaceTextureListener implements SurfaceTextureListener { - @Override - public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, - int height) { - if (mActivityContainer == null) { - return; - } - if (DEBUG) Log.d(TAG, "onSurfaceTextureAvailable: width=" + width + " height=" - + height); - mWidth = width; - mHeight = height; - mSurface = new Surface(surfaceTexture); - setSurfaceAsync(mSurface, mWidth, mHeight, mDensityDpi, true); - } - - @Override - public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, - int height) { - if (mActivityContainer == null) { - return; - } - if (DEBUG) Log.d(TAG, "onSurfaceTextureSizeChanged: w=" + width + " h=" + height); - } - - @Override - public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) { - if (mActivityContainer == null) { - return true; - } - if (DEBUG) Log.d(TAG, "onSurfaceTextureDestroyed"); - mSurface.release(); - mSurface = null; - setSurfaceAsync(null, mWidth, mHeight, mDensityDpi, true); - return true; - } - - @Override - public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) { -// Log.d(TAG, "onSurfaceTextureUpdated"); - } - - } - - private static class ActivityContainerCallback extends IActivityContainerCallback.Stub { - private final WeakReference<ActivityView> mActivityViewWeakReference; - - ActivityContainerCallback(ActivityView activityView) { - mActivityViewWeakReference = new WeakReference<>(activityView); - } - - @Override - public void setVisible(IBinder container, boolean visible) { - if (DEBUG) Log.v(TAG, "setVisible(): container=" + container + " visible=" + visible + - " ActivityView=" + mActivityViewWeakReference.get()); - } - - @Override - public void onAllActivitiesComplete(IBinder container) { - final ActivityView activityView = mActivityViewWeakReference.get(); - if (activityView != null) { - final ActivityViewCallback callback = activityView.mActivityViewCallback; - if (callback != null) { - final WeakReference<ActivityViewCallback> callbackRef = - new WeakReference<>(callback); - activityView.post(new Runnable() { - @Override - public void run() { - ActivityViewCallback callback = callbackRef.get(); - if (callback != null) { - callback.onAllActivitiesComplete(activityView); - } - } - }); - } - } - } - } - - private static class ActivityContainerWrapper { - private final IActivityContainer mIActivityContainer; - private final CloseGuard mGuard = CloseGuard.get(); - boolean mOpened; // Protected by mGuard. - - ActivityContainerWrapper(IActivityContainer container) { - mIActivityContainer = container; - mOpened = true; - mGuard.open("release"); - } - - void setSurface(Surface surface, int width, int height, int density) - throws RemoteException { - mIActivityContainer.setSurface(surface, width, height, density); - } - - int startActivity(Intent intent) { - try { - return mIActivityContainer.startActivity(intent); - } catch (RemoteException e) { - throw new RuntimeException("ActivityView: Unable to startActivity. " + e); - } - } - - int startActivityIntentSender(IIntentSender intentSender) { - try { - return mIActivityContainer.startActivityIntentSender(intentSender); - } catch (RemoteException e) { - throw new RuntimeException( - "ActivityView: Unable to startActivity from IntentSender. " + e); - } - } - - int getDisplayId() { - try { - return mIActivityContainer.getDisplayId(); - } catch (RemoteException e) { - return -1; - } - } - - boolean injectEvent(InputEvent event) { - try { - return mIActivityContainer.injectEvent(event); - } catch (RemoteException e) { - return false; - } - } - - void release() { - synchronized (mGuard) { - if (mOpened) { - if (DEBUG) Log.v(TAG, "ActivityContainerWrapper: release called"); - try { - mIActivityContainer.release(); - mGuard.close(); - } catch (RemoteException e) { - } - mOpened = false; - } - } - } - - @Override - protected void finalize() throws Throwable { - if (DEBUG) Log.v(TAG, "ActivityContainerWrapper: finalize called"); - try { - if (mGuard != null) { - mGuard.warnIfOpen(); - release(); - } - } finally { - super.finalize(); - } - } - - } -} diff --git a/core/java/android/app/IActivityContainer.aidl b/core/java/android/app/IActivityContainer.aidl deleted file mode 100644 index 1ff3c87bef6e..000000000000 --- a/core/java/android/app/IActivityContainer.aidl +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) 2013, 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 android.app; - -import android.app.IActivityContainerCallback; -import android.content.Intent; -import android.content.IIntentSender; -import android.os.IBinder; -import android.view.InputEvent; -import android.view.Surface; - -/** @hide */ -interface IActivityContainer { - void addToDisplay(int displayId); - void setSurface(in Surface surface, int width, int height, int density); - int startActivity(in Intent intent); - int startActivityIntentSender(in IIntentSender intentSender); - int getDisplayId(); - int getStackId(); - boolean injectEvent(in InputEvent event); - void release(); -} diff --git a/core/java/android/app/IActivityContainerCallback.aidl b/core/java/android/app/IActivityContainerCallback.aidl deleted file mode 100644 index 99d0a6f8189e..000000000000 --- a/core/java/android/app/IActivityContainerCallback.aidl +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2013, 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 android.app; - -import android.os.IBinder; - -/** @hide */ -interface IActivityContainerCallback { - oneway void setVisible(IBinder container, boolean visible); - oneway void onAllActivitiesComplete(IBinder container); -} diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl index df1a412d464e..fa9d7ca8ebc5 100644 --- a/core/java/android/app/IActivityManager.aidl +++ b/core/java/android/app/IActivityManager.aidl @@ -20,8 +20,6 @@ import android.app.ActivityManager; import android.app.ApplicationErrorReport; import android.app.ContentProviderHolder; import android.app.IApplicationThread; -import android.app.IActivityContainer; -import android.app.IActivityContainerCallback; import android.app.IActivityController; import android.app.IAppTask; import android.app.IInstrumentationWatcher; @@ -355,8 +353,6 @@ interface IActivityManager { void killUid(int appId, int userId, in String reason); void setUserIsMonkey(boolean monkey); void hang(in IBinder who, boolean allowRestart); - IActivityContainer createVirtualActivityContainer(in IBinder parentActivityToken, - in IActivityContainerCallback callback); void moveTaskToStack(int taskId, int stackId, boolean toTop); /** * Resizes the input stack id to the given bounds. @@ -436,7 +432,7 @@ interface IActivityManager { // Start of M transactions void notifyCleartextNetwork(int uid, in byte[] firstPacket); - IActivityContainer createStackOnDisplay(int displayId); + int createStackOnDisplay(int displayId); int getFocusedStackId(); void setTaskResizeable(int taskId, int resizeableMode); boolean requestAssistContextExtras(int requestType, in IResultReceiver receiver, diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index f59d18ebe6a4..b46e5e54d158 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -164,7 +164,6 @@ import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILIT import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBLE_BEHIND; import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; -import static com.android.server.am.ActivityStackSupervisor.ActivityContainer.FORCE_NEW_TASK_FLAGS; import static com.android.server.am.ActivityStackSupervisor.CREATE_IF_NEEDED; import static com.android.server.am.ActivityStackSupervisor.DEFER_RESUME; import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_ONLY; @@ -211,8 +210,6 @@ import android.app.ApplicationThreadConstants; import android.app.BroadcastOptions; import android.app.ContentProviderHolder; import android.app.Dialog; -import android.app.IActivityContainer; -import android.app.IActivityContainerCallback; import android.app.IActivityController; import android.app.IActivityManager; import android.app.IAppTask; @@ -4122,8 +4119,7 @@ public class ActivityManagerService extends IActivityManager.Stub ri.activityInfo.packageName, ri.activityInfo.name)); mActivityStarter.startActivityLocked(null, intent, null /*ephemeralIntent*/, null, ri.activityInfo, null /*rInfo*/, null, null, null, null, 0, 0, 0, - null, 0, 0, 0, null, false, false, null, null, null, - "startSetupActivity"); + null, 0, 0, 0, null, false, false, null, null, "startSetupActivity"); } } } @@ -4461,26 +4457,6 @@ public class ActivityManagerService extends IActivityManager.Stub UserHandle.getCallingUserId()); } - final int startActivity(Intent intent, ActivityStackSupervisor.ActivityContainer container) { - enforceNotIsolatedCaller("ActivityContainer.startActivity"); - final int userId = mUserController.handleIncomingUser(Binder.getCallingPid(), - Binder.getCallingUid(), mStackSupervisor.mCurrentUser, false, - ActivityManagerService.ALLOW_FULL_ONLY, "ActivityContainer", null); - - // TODO: Switch to user app stacks here. - String mimeType = intent.getType(); - final Uri data = intent.getData(); - if (mimeType == null && data != null && "content".equals(data.getScheme())) { - mimeType = getProviderMimeType(data, userId); - } - container.checkEmbeddedAllowedInner(userId, intent, mimeType); - - intent.addFlags(FORCE_NEW_TASK_FLAGS); - return mActivityStarter.startActivityMayWait(null, -1, null, intent, mimeType, null, null, - null, null, 0, 0, null, null, null, null, false, userId, container, null, - "startActivity"); - } - @Override public final int startActivityAsUser(IApplicationThread caller, String callingPackage, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, @@ -4491,8 +4467,7 @@ public class ActivityManagerService extends IActivityManager.Stub // TODO: Switch to user app stacks here. return mActivityStarter.startActivityMayWait(caller, -1, callingPackage, intent, resolvedType, null, null, resultTo, resultWho, requestCode, startFlags, - profilerInfo, null, null, bOptions, false, userId, null, null, - "startActivityAsUser"); + profilerInfo, null, null, bOptions, false, userId, null, "startActivityAsUser"); } @Override @@ -4555,7 +4530,7 @@ public class ActivityManagerService extends IActivityManager.Stub try { int ret = mActivityStarter.startActivityMayWait(null, targetUid, targetPackage, intent, resolvedType, null, null, resultTo, resultWho, requestCode, startFlags, null, - null, null, bOptions, ignoreTargetSecurity, userId, null, null, + null, null, bOptions, ignoreTargetSecurity, userId, null, "startActivityAsCaller"); return ret; } catch (SecurityException e) { @@ -4585,7 +4560,7 @@ public class ActivityManagerService extends IActivityManager.Stub // TODO: Switch to user app stacks here. mActivityStarter.startActivityMayWait(caller, -1, callingPackage, intent, resolvedType, null, null, resultTo, resultWho, requestCode, startFlags, profilerInfo, res, null, - bOptions, false, userId, null, null, "startActivityAndWait"); + bOptions, false, userId, null, "startActivityAndWait"); return res; } @@ -4599,7 +4574,7 @@ public class ActivityManagerService extends IActivityManager.Stub // TODO: Switch to user app stacks here. int ret = mActivityStarter.startActivityMayWait(caller, -1, callingPackage, intent, resolvedType, null, null, resultTo, resultWho, requestCode, startFlags, - null, null, config, bOptions, false, userId, null, null, "startActivityWithConfig"); + null, null, config, bOptions, false, userId, null, "startActivityWithConfig"); return ret; } @@ -4630,7 +4605,7 @@ public class ActivityManagerService extends IActivityManager.Stub } } int ret = pir.sendInner(0, fillInIntent, resolvedType, whitelistToken, null, null, - resultTo, resultWho, requestCode, flagsMask, flagsValues, bOptions, null); + resultTo, resultWho, requestCode, flagsMask, flagsValues, bOptions); return ret; } @@ -4656,7 +4631,7 @@ public class ActivityManagerService extends IActivityManager.Stub // TODO: Switch to user app stacks here. return mActivityStarter.startActivityMayWait(null, callingUid, callingPackage, intent, resolvedType, session, interactor, null, null, 0, startFlags, profilerInfo, null, - null, bOptions, false, userId, null, null, "startVoiceActivity"); + null, bOptions, false, userId, null, "startVoiceActivity"); } @Override @@ -4675,7 +4650,7 @@ public class ActivityManagerService extends IActivityManager.Stub ALLOW_FULL_ONLY, "startAssistantActivity", null); return mActivityStarter.startActivityMayWait(null, callingUid, callingPackage, intent, resolvedType, null, null, null, null, 0, 0, null, null, null, bOptions, false, - userId, null, null, "startAssistantActivity"); + userId, null, "startAssistantActivity"); } @Override @@ -4848,7 +4823,7 @@ public class ActivityManagerService extends IActivityManager.Stub null /*ephemeralIntent*/, r.resolvedType, aInfo, null /*rInfo*/, null, null, resultTo != null ? resultTo.appToken : null, resultWho, requestCode, -1, r.launchedFromUid, r.launchedFromPackage, -1, r.launchedFromUid, 0, options, - false, false, null, null, null, "startNextMatchingActivity"); + false, false, null, null, "startNextMatchingActivity"); Binder.restoreCallingIdentity(origId); r.finishing = wasFinishing; @@ -4880,16 +4855,15 @@ public class ActivityManagerService extends IActivityManager.Stub final int startActivityInPackage(int uid, String callingPackage, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, Bundle bOptions, int userId, - IActivityContainer container, TaskRecord inTask, String reason) { + TaskRecord inTask, String reason) { userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, false, ALLOW_FULL_ONLY, "startActivityInPackage", null); // TODO: Switch to user app stacks here. - int ret = mActivityStarter.startActivityMayWait(null, uid, callingPackage, intent, + return mActivityStarter.startActivityMayWait(null, uid, callingPackage, intent, resolvedType, null, null, resultTo, resultWho, requestCode, startFlags, - null, null, null, bOptions, false, userId, container, inTask, reason); - return ret; + null, null, null, bOptions, false, userId, inTask, reason); } @Override @@ -10479,44 +10453,25 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public IActivityContainer createVirtualActivityContainer(IBinder parentActivityToken, - IActivityContainerCallback callback) throws RemoteException { - enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "createActivityContainer()"); - synchronized (this) { - if (parentActivityToken == null) { - throw new IllegalArgumentException("parent token must not be null"); - } - ActivityRecord r = ActivityRecord.forTokenLocked(parentActivityToken); - if (r == null) { - return null; - } - if (callback == null) { - throw new IllegalArgumentException("callback must not be null"); - } - return mStackSupervisor.createVirtualActivityContainer(r, callback); - } - } - - @Override - public IActivityContainer createStackOnDisplay(int displayId) throws RemoteException { + public int createStackOnDisplay(int displayId) throws RemoteException { enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "createStackOnDisplay()"); synchronized (this) { final int stackId = mStackSupervisor.getNextStackId(); final ActivityStack stack = mStackSupervisor.createStackOnDisplay(stackId, displayId, true /*onTop*/); if (stack == null) { - return null; + return INVALID_STACK_ID; } - return stack.mActivityContainer; + return stack.mStackId; } } @Override public int getActivityDisplayId(IBinder activityToken) throws RemoteException { synchronized (this) { - ActivityStack stack = ActivityRecord.getStackLocked(activityToken); - if (stack != null && stack.mActivityContainer.isAttachedLocked()) { - return stack.mActivityContainer.getDisplayId(); + final ActivityStack stack = ActivityRecord.getStackLocked(activityToken); + if (stack != null && stack.mDisplayId != INVALID_DISPLAY) { + return stack.mDisplayId; } return DEFAULT_DISPLAY; } @@ -24364,7 +24319,7 @@ public class ActivityManagerService extends IActivityManager.Stub } return mActivityStarter.startActivityMayWait(appThread, -1, callingPackage, intent, resolvedType, null, null, null, null, 0, 0, null, null, - null, bOptions, false, callingUser, null, tr, "AppTaskImpl"); + null, bOptions, false, callingUser, tr, "AppTaskImpl"); } @Override diff --git a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java index 9273b3c49074..45357cb67fd1 100644 --- a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java +++ b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java @@ -19,7 +19,6 @@ package com.android.server.am; import android.app.ActivityManager; import android.app.ActivityOptions; import android.app.AppGlobals; -import android.app.IActivityContainer; import android.app.IActivityController; import android.app.IActivityManager; import android.app.IStopUserCallback; @@ -1959,9 +1958,17 @@ final class ActivityManagerShellCommand extends ShellCommand { throw new RuntimeException(e.getMessage(), e); } - IActivityContainer container = mInterface.createStackOnDisplay(displayId); - if (container != null) { - container.startActivity(intent); + final int stackId = mInterface.createStackOnDisplay(displayId); + if (stackId != INVALID_STACK_ID) { + // TODO: Need proper support if this is used by test... +// container.startActivity(intent); +// ActivityOptions options = ActivityOptions.makeBasic(); +// options.setLaunchDisplayId(displayId); +// options.setLaunchStackId(stackId); +// mInterface.startAct +// mInterface.startActivityAsUser(null, null, intent, mimeType, +// null, null, 0, mStartFlags, profilerInfo, +// options != null ? options.toBundle() : null, mUserId); } return 0; } diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index 6f68c7a1df5f..9a1d9282d9bc 100644 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -164,7 +164,6 @@ import com.android.internal.util.XmlUtils; import com.android.server.AttributeCache; import com.android.server.AttributeCache.Entry; import com.android.server.am.ActivityStack.ActivityState; -import com.android.server.am.ActivityStackSupervisor.ActivityContainer; import com.android.server.wm.AppWindowContainerController; import com.android.server.wm.AppWindowContainerListener; import com.android.server.wm.TaskWindowContainerController; @@ -306,7 +305,6 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo int launchCount; // count of launches since last state long lastLaunchTime; // time of last launch of this activity ComponentName requestedVrComponent; // the requested component for handling VR mode. - ArrayList<ActivityContainer> mChildContainers = new ArrayList<>(); String stringName; // for caching of toString(). @@ -320,7 +318,6 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo boolean mTaskOverlay = false; // Task is always on-top of other activities in the task. boolean mUpdateTaskThumbnailWhenHidden; - ActivityContainer mInitialActivityContainer; TaskDescription taskDescription; // the recents information for this activity boolean mLaunchTaskBehind; // this activity is actively being launched with @@ -798,8 +795,8 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo ActivityInfo aInfo, Configuration _configuration, ActivityRecord _resultTo, String _resultWho, int _reqCode, boolean _componentSpecified, boolean _rootVoiceInteraction, - ActivityStackSupervisor supervisor, - ActivityContainer container, ActivityOptions options, ActivityRecord sourceRecord) { + ActivityStackSupervisor supervisor, ActivityOptions options, + ActivityRecord sourceRecord) { service = _service; appToken = new Token(this); info = aInfo; @@ -830,7 +827,6 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo idle = false; hasBeenLaunched = false; mStackSupervisor = supervisor; - mInitialActivityContainer = container; mRotationAnimationHint = aInfo.rotationAnimation; @@ -1595,11 +1591,6 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo mUpdateTaskThumbnailWhenHidden = false; } setVisibility(visible); - final ArrayList<ActivityContainer> containers = mChildContainers; - for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) { - final ActivityContainer container = containers.get(containerNdx); - container.setVisible(visible); - } mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; } @@ -2615,8 +2606,6 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo startFreezingScreenLocked(app, 0); - mStackSupervisor.removeChildActivityContainers(this); - try { if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + this @@ -2795,7 +2784,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo 0 /* launchedFromPid */, launchedFromUid, launchedFromPackage, intent, resolvedType, aInfo, service.getConfiguration(), null /* resultTo */, null /* resultWho */, 0 /* reqCode */, componentSpecified, false /* rootVoiceInteraction */, - stackSupervisor, null /* container */, null /* options */, null /* sourceRecord */); + stackSupervisor, null /* options */, null /* sourceRecord */); r.persistentState = persistentState; r.taskDescription = taskDescription; diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index ab76529cf5f6..ce8aa5edad47 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -30,6 +30,7 @@ import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD; +import static android.view.Display.INVALID_DISPLAY; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_APP; @@ -124,7 +125,6 @@ import com.android.internal.app.IVoiceInteractor; import com.android.internal.os.BatteryStatsImpl; import com.android.server.Watchdog; import com.android.server.am.ActivityManagerService.ItemMatcher; -import com.android.server.am.ActivityStackSupervisor.ActivityContainer; import com.android.server.wm.StackWindowController; import com.android.server.wm.StackWindowListener; import com.android.server.wm.WindowManagerService; @@ -205,7 +205,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai @Override protected ConfigurationContainer getParent() { - return mActivityContainer.mActivityDisplay; + return getDisplay(); } @Override @@ -336,8 +336,8 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai int mCurrentUser; final int mStackId; - final ActivityContainer mActivityContainer; /** The other stacks, in order, on the attached display. Updated at attach/detach time. */ + // TODO: This list doesn't belong here... ArrayList<ActivityStack> mStacks; /** The attached Display's unique identifier, or -1 if detached */ int mDisplayId; @@ -447,24 +447,21 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai return count; } - ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer, - RecentTasks recentTasks, boolean onTop) { - mActivityContainer = activityContainer; - mStackSupervisor = activityContainer.getOuter(); - mService = mStackSupervisor.mService; + ActivityStack(ActivityStackSupervisor.ActivityDisplay display, int stackId, + ActivityStackSupervisor supervisor, RecentTasks recentTasks, boolean onTop) { + mStackSupervisor = supervisor; + mService = supervisor.mService; mHandler = new ActivityStackHandler(mService.mHandler.getLooper()); mWindowManager = mService.mWindowManager; - mStackId = activityContainer.mStackId; + mStackId = stackId; mCurrentUser = mService.mUserController.getCurrentUserIdLocked(); mRecentTasks = recentTasks; mTaskPositioner = mStackId == FREEFORM_WORKSPACE_STACK_ID ? new LaunchingTaskPositioner() : null; - final ActivityStackSupervisor.ActivityDisplay display = mActivityContainer.mActivityDisplay; mTmpRect2.setEmpty(); mWindowContainerController = createStackWindowController(display.mDisplayId, onTop, mTmpRect2); - activityContainer.mStack = this; - mStackSupervisor.mActivityContainers.put(mStackId, activityContainer); + mStackSupervisor.mStacks.put(mStackId, this); postAddToDisplay(display, mTmpRect2.isEmpty() ? null : mTmpRect2, onTop); } @@ -521,7 +518,11 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai * either destroyed completely or re-parented. */ private void removeFromDisplay() { - mDisplayId = Display.INVALID_DISPLAY; + final ActivityStackSupervisor.ActivityDisplay display = getDisplay(); + if (display != null) { + display.detachStack(this); + } + mDisplayId = INVALID_DISPLAY; mStacks = null; if (mTaskPositioner != null) { mTaskPositioner.reset(); @@ -537,14 +538,18 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai /** Removes the stack completely. Also calls WindowManager to do the same on its side. */ void remove() { removeFromDisplay(); - mStackSupervisor.deleteActivityContainerRecord(mStackId); + mStackSupervisor.mStacks.remove(mStackId); mWindowContainerController.removeContainer(); mWindowContainerController = null; onParentChanged(); } + ActivityStackSupervisor.ActivityDisplay getDisplay() { + return mStackSupervisor.getActivityDisplay(mDisplayId); + } + void getDisplaySize(Point out) { - mActivityContainer.mActivityDisplay.mDisplay.getSize(out); + getDisplay().mDisplay.getSize(out); } /** @@ -829,8 +834,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai } final boolean isOnHomeDisplay() { - return isAttached() && - mActivityContainer.mActivityDisplay.mDisplayId == DEFAULT_DISPLAY; + return isAttached() && mDisplayId == DEFAULT_DISPLAY; } void moveToFront(String reason) { @@ -1257,12 +1261,6 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai return false; } - if (mActivityContainer.mParentActivity == null) { - // Top level stack, not a child. Look for child stacks. - mStackSupervisor.pauseChildStacks(prev, userLeaving, uiSleeping, resuming, - pauseImmediately); - } - if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); mResumedActivity = null; @@ -1965,8 +1963,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai * {@link Display#FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD} applied. */ private boolean canShowWithInsecureKeyguard() { - final ActivityStackSupervisor.ActivityDisplay activityDisplay - = mActivityContainer.mActivityDisplay; + final ActivityStackSupervisor.ActivityDisplay activityDisplay = getDisplay(); if (activityDisplay == null) { throw new IllegalStateException("Stack is not attached to any display, stackId=" + mStackId); @@ -2108,7 +2105,6 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai * occurred and the activity will be notified immediately. */ void notifyActivityDrawnLocked(ActivityRecord r) { - mActivityContainer.setDrawn(); if ((r == null) || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { @@ -2236,12 +2232,8 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai final boolean hasRunningActivity = next != null; - final ActivityRecord parent = mActivityContainer.mParentActivity; - final boolean isParentNotResumed = parent != null && parent.state != ActivityState.RESUMED; - if (hasRunningActivity - && (isParentNotResumed || !mActivityContainer.isAttachedLocked())) { - // Do not resume this stack if its parent is not resumed. - // TODO: If in a loop, make sure that parent stack resumeTopActivity is called 1st. + // TODO: Maybe this entire condition can get removed? + if (hasRunningActivity && getDisplay() == null) { return false; } @@ -3809,7 +3801,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai } } if (noActivitiesInStack) { - mActivityContainer.onTaskListEmptyLocked(); + remove(); } } @@ -3920,7 +3912,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai destIntent, null /*ephemeralIntent*/, null, aInfo, null /*rInfo*/, null, null, parent.appToken, null, 0, -1, parent.launchedFromUid, parent.launchedFromPackage, -1, parent.launchedFromUid, 0, null, - false, true, null, null, null, "navigateUpTo"); + false, true, null, null, "navigateUpTo"); foundParentInTask = res == ActivityManager.START_SUCCESS; } catch (RemoteException e) { foundParentInTask = false; @@ -4005,7 +3997,6 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai } private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { - mStackSupervisor.removeChildActivityContainers(r); finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); r.makeFinishingLocked(); if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, @@ -4620,7 +4611,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai * focus may be on another display. */ private ActivityStack getTopStackOnDisplay() { - final ArrayList<ActivityStack> stacks = mActivityContainer.mActivityDisplay.mStacks; + final ArrayList<ActivityStack> stacks = getDisplay().mStacks; return stacks.isEmpty() ? null : stacks.get(stacks.size() - 1); } @@ -5097,7 +5088,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai mStacks.add(0, this); } if (!isHomeOrRecentsStack()) { - mActivityContainer.onTaskListEmptyLocked(); + remove(); } } diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 90d9149a2f66..d9b7d761a7d2 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -36,8 +36,6 @@ import static android.app.ActivityManager.StackId.PINNED_STACK_ID; import static android.app.ActivityManager.StackId.RECENTS_STACK_ID; import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY; import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; -import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK; -import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.Process.SYSTEM_UID; import static android.os.PowerManager.PARTIAL_WAKE_LOCK; @@ -50,7 +48,6 @@ import static android.view.Display.TYPE_VIRTUAL; import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_PICTURE_IN_PICTURE_EXPANDED_TO_FULLSCREEN; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; -import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONTAINERS; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOCUS; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_IDLE; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK; @@ -72,7 +69,6 @@ import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK; import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES; import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH; import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS; -import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBLE_BEHIND; import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.am.ActivityManagerService.ANIMATE; @@ -112,7 +108,6 @@ import android.app.ActivityManager.StackId; import android.app.ActivityManager.StackInfo; import android.app.ActivityOptions; import android.app.AppOpsManager; -import android.app.IActivityContainerCallback; import android.app.ProfilerInfo; import android.app.ResultInfo; import android.app.StatusBarManager; @@ -120,7 +115,6 @@ import android.app.WaitResult; import android.app.admin.IDevicePolicyManager; import android.content.ComponentName; import android.content.Context; -import android.content.IIntentSender; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; @@ -132,10 +126,7 @@ import android.content.res.Configuration; import android.graphics.Rect; import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager.DisplayListener; -import android.hardware.display.DisplayManagerGlobal; import android.hardware.display.DisplayManagerInternal; -import android.hardware.display.VirtualDisplay; -import android.hardware.input.InputManager; import android.hardware.input.InputManagerInternal; import android.os.Binder; import android.os.Bundle; @@ -151,7 +142,6 @@ import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; import android.os.Trace; -import android.os.TransactionTooLargeException; import android.os.UserHandle; import android.os.UserManager; import android.os.WorkSource; @@ -168,9 +158,8 @@ import android.util.Slog; import android.util.SparseArray; import android.util.SparseIntArray; import android.view.Display; -import android.view.InputEvent; -import android.view.Surface; +import com.android.internal.annotations.VisibleForTesting; import com.android.internal.content.ReferrerIntent; import com.android.internal.logging.MetricsLogger; import com.android.internal.os.TransferPipe; @@ -194,7 +183,6 @@ import java.util.Set; public class ActivityStackSupervisor extends ConfigurationContainer implements DisplayListener { private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStackSupervisor" : TAG_AM; - private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; private static final String TAG_IDLE = TAG + POSTFIX_IDLE; private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; @@ -205,7 +193,6 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D private static final String TAG_STATES = TAG + POSTFIX_STATES; private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; static final String TAG_TASKS = TAG + POSTFIX_TASKS; - private static final String TAG_VISIBLE_BEHIND = TAG + POSTFIX_VISIBLE_BEHIND; /** How long we wait until giving up on the last activity telling us it is idle. */ static final int IDLE_TIMEOUT = 10 * 1000; @@ -224,10 +211,8 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D static final int HANDLE_DISPLAY_ADDED = FIRST_SUPERVISOR_STACK_MSG + 5; static final int HANDLE_DISPLAY_CHANGED = FIRST_SUPERVISOR_STACK_MSG + 6; static final int HANDLE_DISPLAY_REMOVED = FIRST_SUPERVISOR_STACK_MSG + 7; - static final int CONTAINER_CALLBACK_VISIBILITY = FIRST_SUPERVISOR_STACK_MSG + 8; static final int LOCK_TASK_START_MSG = FIRST_SUPERVISOR_STACK_MSG + 9; static final int LOCK_TASK_END_MSG = FIRST_SUPERVISOR_STACK_MSG + 10; - static final int CONTAINER_CALLBACK_TASK_LIST_EMPTY = FIRST_SUPERVISOR_STACK_MSG + 11; static final int LAUNCH_TASK_BEHIND_COMPLETE = FIRST_SUPERVISOR_STACK_MSG + 12; static final int SHOW_LOCK_TASK_ESCAPE_MESSAGE_MSG = FIRST_SUPERVISOR_STACK_MSG + 13; static final int REPORT_MULTI_WINDOW_MODE_CHANGED_MSG = FIRST_SUPERVISOR_STACK_MSG + 14; @@ -414,7 +399,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D // TODO: Add listener for removal of references. /** Mapping from (ActivityStack/TaskStack).mStackId to their current state */ - SparseArray<ActivityContainer> mActivityContainers = new SparseArray<>(); + SparseArray<ActivityStack> mStacks = new SparseArray<>(); // TODO: There should be an ActivityDisplayController coordinating am/wm interaction. /** Mapping from displayId to display current state */ @@ -680,31 +665,15 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } boolean isFocusedStack(ActivityStack stack) { - if (stack == null) { - return false; - } - - final ActivityRecord parent = stack.mActivityContainer.mParentActivity; - if (parent != null) { - stack = parent.getStack(); - } - return stack == mFocusedStack; + return stack != null && stack == mFocusedStack; } /** The top most stack on its display. */ boolean isFrontStackOnDisplay(ActivityStack stack) { - return isFrontOfStackList(stack, stack.mActivityContainer.mActivityDisplay.mStacks); + return isFrontOfStackList(stack, stack.getDisplay().mStacks); } private boolean isFrontOfStackList(ActivityStack stack, List<ActivityStack> stackList) { - if (stack == null) { - return false; - } - - final ActivityRecord parent = stack.mActivityContainer.mParentActivity; - if (parent != null) { - stack = parent.getStack(); - } return stack == stackList.get((stackList.size() - 1)); } @@ -1097,21 +1066,6 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D return pausing; } - void pauseChildStacks(ActivityRecord parent, boolean userLeaving, boolean uiSleeping, - ActivityRecord resuming, boolean dontWait) { - // TODO: Put all stacks in supervisor and iterate through them instead. - for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { - ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; - for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { - final ActivityStack stack = stacks.get(stackNdx); - if (stack.mResumedActivity != null && - stack.mActivityContainer.mParentActivity == parent) { - stack.startPausingLocked(userLeaving, uiSleeping, resuming, dontWait); - } - } - } - } - void cancelInitializingActivities() { for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; @@ -2210,9 +2164,9 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D protected <T extends ActivityStack> T getStack(int stackId, boolean createStaticStackIfNeeded, boolean createOnTop) { - final ActivityContainer activityContainer = mActivityContainers.get(stackId); - if (activityContainer != null) { - return (T) activityContainer.mStack; + final ActivityStack stack = mStacks.get(stackId); + if (stack != null) { + return (T) stack; } if (!createStaticStackIfNeeded || !StackId.isStaticStack(stackId)) { return null; @@ -2355,33 +2309,6 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D (StackId.isResizeableByDockedStack(stackId) && getStack(DOCKED_STACK_ID) != null); } - ActivityContainer createVirtualActivityContainer(ActivityRecord parentActivity, - IActivityContainerCallback callback) { - ActivityContainer activityContainer = - new VirtualActivityContainer(parentActivity, callback); - mActivityContainers.put(activityContainer.mStackId, activityContainer); - if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, - "createActivityContainer: " + activityContainer); - parentActivity.mChildContainers.add(activityContainer); - return activityContainer; - } - - void removeChildActivityContainers(ActivityRecord parentActivity) { - final ArrayList<ActivityContainer> childStacks = parentActivity.mChildContainers; - for (int containerNdx = childStacks.size() - 1; containerNdx >= 0; --containerNdx) { - ActivityContainer container = childStacks.remove(containerNdx); - if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "removeChildActivityContainers: removing " - + container); - container.release(); - } - } - - void deleteActivityContainerRecord(int stackId) { - if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, - "deleteActivityContainerRecord: callers=" + Debug.getCallers(4)); - mActivityContainers.remove(stackId); - } - void resizeStackLocked(int stackId, Rect bounds, Rect tempTaskBounds, Rect tempTaskInsetBounds, boolean preserveWindows, boolean allowResizeInDockedMode, boolean deferResume) { if (stackId == DOCKED_STACK_ID) { @@ -2646,12 +2573,18 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D if (activityDisplay == null) { return null; } + return createStack(stackId, activityDisplay, onTop); - final ActivityContainer activityContainer = - new ActivityContainer(stackId, activityDisplay, onTop); - return activityContainer.mStack; } + ActivityStack createStack(int stackId, ActivityDisplay display, boolean onTop) { + switch (stackId) { + case PINNED_STACK_ID: + return new PinnedActivityStack(display, stackId, this, mRecentTasks, onTop); + default: + return new ActivityStack(display, stackId, this, mRecentTasks, onTop); + } + } void removeStackInSurfaceTransaction(int stackId) { final ActivityStack stack = getStack(stackId); @@ -2879,23 +2812,24 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown displayId=" + displayId); } - final ActivityContainer activityContainer = mActivityContainers.get(stackId); - if (activityContainer != null) { - if (activityContainer.isAttachedLocked()) { - if (activityContainer.getDisplayId() == displayId) { - throw new IllegalArgumentException("Trying to move stackId=" + stackId - + " to its current displayId=" + displayId); - } - - activityContainer.moveToDisplayLocked(activityDisplay, onTop); - } else { - throw new IllegalStateException("moveStackToDisplayLocked: Stack with stackId=" - + stackId + " is not attached to any display."); - } - } else { + final ActivityStack stack = mStacks.get(stackId); + if (stack == null) { throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown stackId=" + stackId); } + + final ActivityDisplay currentDisplay = stack.getDisplay(); + if (currentDisplay == null) { + throw new IllegalStateException("moveStackToDisplayLocked: Stack with stack=" + stack + + " is not attached to any display."); + } + + if (currentDisplay.mDisplayId == displayId) { + throw new IllegalArgumentException("Trying to move stack=" + stack + + " to its current displayId=" + displayId); + } + + stack.reparent(activityDisplay, onTop); // TODO(multi-display): resize stacks properly if moved from split-screen. } @@ -2923,7 +2857,6 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D // Ensure that we're not moving a task to a dynamic stack if device doesn't support // multi-display. // TODO(multi-display): Support non-dynamic stacks on secondary displays. - // TODO: Check ActivityView after fixing b/35349678. if (StackId.isDynamicStack(stackId) && !mService.mSupportsMultiDisplay) { throw new IllegalArgumentException("Device doesn't support multi-display, can not" + " reparent task=" + task + " to stackId=" + stackId); @@ -3107,11 +3040,6 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D + stack); continue; } - if (!stack.mActivityContainer.isEligibleForNewTasks()) { - if (DEBUG_TASKS) Slog.d(TAG_TASKS, - "Skipping stack: (new task not allowed) " + stack); - continue; - } stack.findTaskLocked(r, mTmpFindTaskResult); // It is possible to have tasks in multiple stacks with the same root affinity, so // we should keep looking after finding an affinity match to see if there is a @@ -3626,7 +3554,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D pw.print(prefix); pw.println("mCurTaskIdForUser=" + mCurTaskIdForUser); pw.print(prefix); pw.println("mUserStackInFront=" + mUserStackInFront); - pw.print(prefix); pw.println("mActivityContainers=" + mActivityContainers); + pw.print(prefix); pw.println("mStacks=" + mStacks); pw.print(prefix); pw.print("mLockTaskModeState=" + lockTaskModeToString()); final SparseArray<String[]> packages = mService.mLockTaskPackages; if (packages.size() > 0) { @@ -3920,6 +3848,10 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D return getActivityDisplayOrCreateLocked(displayId) != null; } + ActivityDisplay getActivityDisplay(int displayId) { + return mActivityDisplays.get(displayId); + } + /** * Get an existing instance of {@link ActivityDisplay} or create new if there is a * corresponding record in display manager. @@ -4481,16 +4413,6 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D case HANDLE_DISPLAY_REMOVED: { handleDisplayRemoved(msg.arg1); } break; - case CONTAINER_CALLBACK_VISIBILITY: { - final ActivityContainer container = (ActivityContainer) msg.obj; - final IActivityContainerCallback callback = container.mCallback; - if (callback != null) { - try { - callback.setVisible(container.asBinder(), msg.arg1 == 1); - } catch (RemoteException e) { - } - } - } break; case LOCK_TASK_START_MSG: { // When lock task starts, we disable the status bars. try { @@ -4563,16 +4485,6 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } mLockTaskNotify.showToast(LOCK_TASK_MODE_PINNED); } break; - case CONTAINER_CALLBACK_TASK_LIST_EMPTY: { - final ActivityContainer container = (ActivityContainer) msg.obj; - final IActivityContainerCallback callback = container.mCallback; - if (callback != null) { - try { - callback.onAllActivitiesComplete(container.asBinder()); - } catch (RemoteException e) { - } - } - } break; case LAUNCH_TASK_BEHIND_COMPLETE: { synchronized (mService) { ActivityRecord r = ActivityRecord.forTokenLocked((IBinder) msg.obj); @@ -4586,340 +4498,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } } - class ActivityContainer extends android.app.IActivityContainer.Stub { - final static int FORCE_NEW_TASK_FLAGS = FLAG_ACTIVITY_NEW_TASK | - FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION; - final int mStackId; - IActivityContainerCallback mCallback = null; - ActivityStack mStack; - ActivityRecord mParentActivity = null; - String mIdString; - - boolean mVisible = true; - - /** Display this ActivityStack is currently on. Null if not attached to a Display. */ - ActivityDisplay mActivityDisplay; - - final static int CONTAINER_STATE_HAS_SURFACE = 0; - final static int CONTAINER_STATE_NO_SURFACE = 1; - final static int CONTAINER_STATE_FINISHING = 2; - int mContainerState = CONTAINER_STATE_HAS_SURFACE; - - ActivityContainer(int stackId, ActivityDisplay activityDisplay, boolean onTop) { - synchronized (mService) { - mStackId = stackId; - mActivityDisplay = activityDisplay; - mIdString = "ActivtyContainer{" + mStackId + "}"; - - createStack(stackId, onTop); - if (DEBUG_STACK) Slog.d(TAG_STACK, "Creating " + this); - } - } - - protected void createStack(int stackId, boolean onTop) { - switch (stackId) { - case PINNED_STACK_ID: - new PinnedActivityStack(this, mRecentTasks, onTop); - break; - default: - new ActivityStack(this, mRecentTasks, onTop); - break; - } - } - - /** - * Adds the stack to specified display. Also calls WindowManager to do the same from - * {@link ActivityStack#reparent(ActivityDisplay, boolean)}. - * @param activityDisplay The display to add the stack to. - */ - void addToDisplayLocked(ActivityDisplay activityDisplay) { - if (DEBUG_STACK) Slog.d(TAG_STACK, "addToDisplayLocked: " + this - + " to display=" + activityDisplay); - if (mActivityDisplay != null) { - throw new IllegalStateException("ActivityContainer is already attached, " + - "displayId=" + mActivityDisplay.mDisplayId); - } - mActivityDisplay = activityDisplay; - mStack.reparent(activityDisplay, true /* onTop */); - } - - @Override - public void addToDisplay(int displayId) { - synchronized (mService) { - final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); - if (activityDisplay == null) { - return; - } - addToDisplayLocked(activityDisplay); - } - } - - @Override - public int getDisplayId() { - synchronized (mService) { - if (mActivityDisplay != null) { - return mActivityDisplay.mDisplayId; - } - } - return -1; - } - - @Override - public int getStackId() { - synchronized (mService) { - return mStackId; - } - } - - @Override - public boolean injectEvent(InputEvent event) { - final long origId = Binder.clearCallingIdentity(); - try { - synchronized (mService) { - if (mActivityDisplay != null) { - return mInputManagerInternal.injectInputEvent(event, - mActivityDisplay.mDisplayId, - InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); - } - } - return false; - } finally { - Binder.restoreCallingIdentity(origId); - } - } - - @Override - public void release() { - synchronized (mService) { - if (mContainerState == CONTAINER_STATE_FINISHING) { - return; - } - mContainerState = CONTAINER_STATE_FINISHING; - - long origId = Binder.clearCallingIdentity(); - try { - mStack.finishAllActivitiesLocked(false); - mService.mActivityStarter.removePendingActivityLaunchesLocked(mStack); - } finally { - Binder.restoreCallingIdentity(origId); - } - } - } - - /** - * Remove the stack completely. Must be called only when there are no tasks left in it, - * as this method does not finish running activities. - */ - void removeLocked() { - if (DEBUG_STACK) Slog.d(TAG_STACK, "removeLocked: " + this + " from display=" - + mActivityDisplay + " Callers=" + Debug.getCallers(2)); - if (mActivityDisplay != null) { - removeFromDisplayLocked(); - } - mStack.remove(); - } - - /** - * Remove the stack from its current {@link ActivityDisplay}, so it can be either destroyed - * completely or re-parented. - */ - private void removeFromDisplayLocked() { - if (DEBUG_STACK) Slog.d(TAG_STACK, "removeFromDisplayLocked: " + this - + " current displayId=" + mActivityDisplay.mDisplayId); - - mActivityDisplay.detachStack(mStack); - mActivityDisplay = null; - } - - /** - * Move the stack to specified display. - * @param activityDisplay Target display to move the stack to. - * @param onTop Indicates whether container should be place on top or on bottom. - */ - void moveToDisplayLocked(ActivityDisplay activityDisplay, boolean onTop) { - if (DEBUG_STACK) Slog.d(TAG_STACK, "moveToDisplayLocked: " + this + " from display=" - + mActivityDisplay + " to display=" + activityDisplay - + " Callers=" + Debug.getCallers(2)); - - removeFromDisplayLocked(); - - mActivityDisplay = activityDisplay; - mStack.reparent(activityDisplay, onTop); - } - - @Override - public final int startActivity(Intent intent) { - return mService.startActivity(intent, this); - } - - @Override - public final int startActivityIntentSender(IIntentSender intentSender) - throws TransactionTooLargeException { - mService.enforceNotIsolatedCaller("ActivityContainer.startActivityIntentSender"); - - if (!(intentSender instanceof PendingIntentRecord)) { - throw new IllegalArgumentException("Bad PendingIntent object"); - } - - final int userId = mService.mUserController.handleIncomingUser(Binder.getCallingPid(), - Binder.getCallingUid(), mCurrentUser, false, - ActivityManagerService.ALLOW_FULL_ONLY, "ActivityContainer", null); - - final PendingIntentRecord pendingIntent = (PendingIntentRecord) intentSender; - checkEmbeddedAllowedInner(userId, pendingIntent.key.requestIntent, - pendingIntent.key.requestResolvedType); - - return pendingIntent.sendInner(0, null, null, null, null, null, null, null, 0, - FORCE_NEW_TASK_FLAGS, FORCE_NEW_TASK_FLAGS, null, this); - } - - void checkEmbeddedAllowedInner(int userId, Intent intent, String resolvedType) { - ActivityInfo aInfo = resolveActivity(intent, resolvedType, 0, null, userId); - if (aInfo != null && (aInfo.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { - throw new SecurityException( - "Attempt to embed activity that has not set allowEmbedded=\"true\""); - } - } - - @Override - public IBinder asBinder() { - return this; - } - - @Override - public void setSurface(Surface surface, int width, int height, int density) { - mService.enforceNotIsolatedCaller("ActivityContainer.attachToSurface"); - } - - ActivityStackSupervisor getOuter() { - return ActivityStackSupervisor.this; - } - - boolean isAttachedLocked() { - return mActivityDisplay != null; - } - - // TODO: Make sure every change to ActivityRecord.visible results in a call to this. - void setVisible(boolean visible) { - if (mVisible != visible) { - mVisible = visible; - if (mCallback != null) { - mHandler.obtainMessage(CONTAINER_CALLBACK_VISIBILITY, visible ? 1 : 0, - 0 /* unused */, this).sendToTarget(); - } - } - } - - void setDrawn() { - } - - // You can always start a new task on a regular ActivityStack. - boolean isEligibleForNewTasks() { - return true; - } - - void onTaskListEmptyLocked() { - removeLocked(); - mHandler.obtainMessage(CONTAINER_CALLBACK_TASK_LIST_EMPTY, this).sendToTarget(); - } - - @Override - public String toString() { - return mIdString + (mActivityDisplay == null ? "N" : "A"); - } - } - - private class VirtualActivityContainer extends ActivityContainer { - Surface mSurface; - boolean mDrawn = false; - - VirtualActivityContainer(ActivityRecord parent, IActivityContainerCallback callback) { - super(getNextStackId(), parent.getStack().mActivityContainer.mActivityDisplay, - true /* onTop */); - mParentActivity = parent; - mCallback = callback; - mContainerState = CONTAINER_STATE_NO_SURFACE; - mIdString = "VirtualActivityContainer{" + mStackId + ", parent=" + mParentActivity + "}"; - } - - @Override - public void setSurface(Surface surface, int width, int height, int density) { - super.setSurface(surface, width, height, density); - - synchronized (mService) { - final long origId = Binder.clearCallingIdentity(); - try { - setSurfaceLocked(surface, width, height, density); - } finally { - Binder.restoreCallingIdentity(origId); - } - } - } - - private void setSurfaceLocked(Surface surface, int width, int height, int density) { - if (mContainerState == CONTAINER_STATE_FINISHING) { - return; - } - VirtualActivityDisplay virtualActivityDisplay = - (VirtualActivityDisplay) mActivityDisplay; - if (virtualActivityDisplay == null) { - virtualActivityDisplay = - new VirtualActivityDisplay(width, height, density); - mActivityDisplay = virtualActivityDisplay; - mActivityDisplays.put(virtualActivityDisplay.mDisplayId, virtualActivityDisplay); - addToDisplayLocked(virtualActivityDisplay); - } - - if (mSurface != null) { - mSurface.release(); - } - - mSurface = surface; - if (surface != null) { - resumeFocusedStackTopActivityLocked(); - } else { - mContainerState = CONTAINER_STATE_NO_SURFACE; - ((VirtualActivityDisplay) mActivityDisplay).setSurface(null); - if (mStack.mPausingActivity == null && mStack.mResumedActivity != null) { - mStack.startPausingLocked(false, true, null, false); - } - } - - setSurfaceIfReadyLocked(); - - if (DEBUG_STACK) Slog.d(TAG_STACK, - "setSurface: " + this + " to display=" + virtualActivityDisplay); - } - - @Override - boolean isAttachedLocked() { - return mSurface != null && super.isAttachedLocked(); - } - - @Override - void setDrawn() { - synchronized (mService) { - mDrawn = true; - setSurfaceIfReadyLocked(); - } - } - - // Never start a new task on an ActivityView if it isn't explicitly specified. - @Override - boolean isEligibleForNewTasks() { - return false; - } - - private void setSurfaceIfReadyLocked() { - if (DEBUG_STACK) Slog.v(TAG_STACK, "setSurfaceIfReadyLocked: mDrawn=" + mDrawn + - " mContainerState=" + mContainerState + " mSurface=" + mSurface); - if (mDrawn && mSurface != null && mContainerState == CONTAINER_STATE_NO_SURFACE) { - ((VirtualActivityDisplay) mActivityDisplay).setSurface(mSurface); - mContainerState = CONTAINER_STATE_HAS_SURFACE; - } - } - } - + // TODO: Move to its own file. /** Exactly one of these classes per Display in the system. Capable of holding zero or more * attached {@link ActivityStack}s */ class ActivityDisplay extends ConfigurationContainer { @@ -4934,7 +4513,9 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D /** Array of all UIDs that are present on the display. */ private IntArray mDisplayAccessUIDs = new IntArray(); + @VisibleForTesting ActivityDisplay() { + mActivityDisplays.put(mDisplayId, this); } // After instantiation, check that mDisplay is not null before using this. The alternative @@ -5011,43 +4592,6 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } } - class VirtualActivityDisplay extends ActivityDisplay { - VirtualDisplay mVirtualDisplay; - - VirtualActivityDisplay(int width, int height, int density) { - DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); - mVirtualDisplay = dm.createVirtualDisplay(mService.mContext, null /* projection */, - VIRTUAL_DISPLAY_BASE_NAME, width, height, density, null /* surface */, - DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | - DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY, null /* callback */, - null /* handler */, null /* uniqueId */); - - init(mVirtualDisplay.getDisplay()); - - mWindowManager.onDisplayAdded(mDisplayId); - } - - void setSurface(Surface surface) { - if (mVirtualDisplay != null) { - mVirtualDisplay.setSurface(surface); - } - } - - @Override - void detachStack(ActivityStack stack) { - super.detachStack(stack); - if (mVirtualDisplay != null) { - mVirtualDisplay.release(); - mVirtualDisplay = null; - } - } - - @Override - public String toString() { - return "VirtualActivityDisplay={" + mDisplayId + "}"; - } - } - ActivityStack findStackBehind(ActivityStack stack) { // TODO(multi-display): We are only looking for stacks on the default display. final ActivityDisplay display = mActivityDisplays.get(DEFAULT_DISPLAY); @@ -5154,7 +4698,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); userId = task.userId; int result = mService.startActivityInPackage(callingUid, callingPackage, intent, null, - null, null, 0, 0, bOptions, userId, null, task, "startActivityFromRecents"); + null, null, 0, 0, bOptions, userId, task, "startActivityFromRecents"); if (launchStackId == DOCKED_STACK_ID) { setResizingDuringAnimation(task); } diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java index 4f04066c6076..749583225bb2 100644 --- a/services/core/java/com/android/server/am/ActivityStarter.java +++ b/services/core/java/com/android/server/am/ActivityStarter.java @@ -90,12 +90,10 @@ import android.annotation.NonNull; import android.app.ActivityManager; import android.app.ActivityOptions; import android.app.AppGlobals; -import android.app.IActivityContainer; import android.app.IApplicationThread; import android.app.PendingIntent; import android.app.ProfilerInfo; import android.app.WaitResult; -import android.content.ComponentName; import android.content.IIntentSender; import android.content.Intent; import android.content.IntentSender; @@ -260,8 +258,7 @@ class ActivityStarter { IBinder resultTo, String resultWho, int requestCode, int callingPid, int callingUid, String callingPackage, int realCallingPid, int realCallingUid, int startFlags, ActivityOptions options, boolean ignoreTargetSecurity, boolean componentSpecified, - ActivityRecord[] outActivity, ActivityStackSupervisor.ActivityContainer container, - TaskRecord inTask, String reason) { + ActivityRecord[] outActivity, TaskRecord inTask, String reason) { if (TextUtils.isEmpty(reason)) { throw new IllegalArgumentException("Need to specify a reason."); @@ -274,7 +271,7 @@ class ActivityStarter { aInfo, rInfo, voiceSession, voiceInteractor, resultTo, resultWho, requestCode, callingPid, callingUid, callingPackage, realCallingPid, realCallingUid, startFlags, options, ignoreTargetSecurity, componentSpecified, mLastStartActivityRecord, - container, inTask); + inTask); if (outActivity != null) { // mLastStartActivityRecord[0] is set in the call to startActivity above. @@ -292,8 +289,7 @@ class ActivityStarter { IBinder resultTo, String resultWho, int requestCode, int callingPid, int callingUid, String callingPackage, int realCallingPid, int realCallingUid, int startFlags, ActivityOptions options, boolean ignoreTargetSecurity, boolean componentSpecified, - ActivityRecord[] outActivity, ActivityStackSupervisor.ActivityContainer container, - TaskRecord inTask) { + ActivityRecord[] outActivity, TaskRecord inTask) { int err = ActivityManager.START_SUCCESS; // Pull the optional Ephemeral Installer-only bundle out of the options early. final Bundle verificationBundle @@ -505,10 +501,8 @@ class ActivityStarter { if (DEBUG_PERMISSIONS_REVIEW) { Slog.i(TAG, "START u" + userId + " {" + intent.toShortString(true, true, true, false) + "} from uid " + callingUid + " on display " - + (container == null ? (mSupervisor.mFocusedStack == null ? - DEFAULT_DISPLAY : mSupervisor.mFocusedStack.mDisplayId) : - (container.mActivityDisplay == null ? DEFAULT_DISPLAY : - container.mActivityDisplay.mDisplayId))); + + (mSupervisor.mFocusedStack == null + ? DEFAULT_DISPLAY : mSupervisor.mFocusedStack.mDisplayId)); } } } @@ -530,7 +524,7 @@ class ActivityStarter { ActivityRecord r = new ActivityRecord(mService, callerApp, callingPid, callingUid, callingPackage, intent, resolvedType, aInfo, mService.getGlobalConfiguration(), resultRecord, resultWho, requestCode, componentSpecified, voiceSession != null, - mSupervisor, container, options, sourceRecord); + mSupervisor, options, sourceRecord); if (outActivity != null) { outActivity[0] = r; } @@ -649,7 +643,7 @@ class ActivityStarter { null /*callingPackage*/, 0 /*realCallingPid*/, 0 /*realCallingUid*/, 0 /*startFlags*/, null /*options*/, false /*ignoreTargetSecurity*/, false /*componentSpecified*/, mLastHomeActivityStartRecord /*outActivity*/, - null /*container*/, null /*inTask*/, "startHomeActivity: " + reason); + null /*inTask*/, "startHomeActivity: " + reason); if (mSupervisor.inResumeTopActivity) { // If we are in resume section already, home activity will be initialized, but not // resumed (to avoid recursive resume) and will stay that way until something pokes it @@ -674,7 +668,7 @@ class ActivityStarter { IBinder resultTo, String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, WaitResult outResult, Configuration globalConfig, Bundle bOptions, boolean ignoreTargetSecurity, int userId, - IActivityContainer iContainer, TaskRecord inTask, String reason) { + TaskRecord inTask, String reason) { // Refuse possible leaked file descriptors if (intent != null && intent.hasFileDescriptors()) { throw new IllegalArgumentException("File descriptors passed in Intent"); @@ -727,14 +721,7 @@ class ActivityStarter { ActivityInfo aInfo = mSupervisor.resolveActivity(intent, rInfo, startFlags, profilerInfo); ActivityOptions options = ActivityOptions.fromBundle(bOptions); - ActivityStackSupervisor.ActivityContainer container = - (ActivityStackSupervisor.ActivityContainer)iContainer; synchronized (mService) { - if (container != null && container.mParentActivity != null && - container.mParentActivity.state != RESUMED) { - // Cannot start a child activity if the parent is not resumed. - return ActivityManager.START_CANCELED; - } final int realCallingPid = Binder.getCallingPid(); final int realCallingUid = Binder.getCallingUid(); int callingPid; @@ -747,12 +734,7 @@ class ActivityStarter { callingPid = callingUid = -1; } - final ActivityStack stack; - if (container == null || container.mStack.isOnHomeDisplay()) { - stack = mSupervisor.mFocusedStack; - } else { - stack = container.mStack; - } + final ActivityStack stack = mSupervisor.mFocusedStack; stack.mConfigWillChange = globalConfig != null && mService.getGlobalConfiguration().diff(globalConfig) != 0; if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, @@ -828,8 +810,8 @@ class ActivityStarter { aInfo, rInfo, voiceSession, voiceInteractor, resultTo, resultWho, requestCode, callingPid, callingUid, callingPackage, realCallingPid, realCallingUid, startFlags, - options, ignoreTargetSecurity, componentSpecified, outRecord, container, - inTask, reason); + options, ignoreTargetSecurity, componentSpecified, outRecord, inTask, + reason); Binder.restoreCallingIdentity(origId); @@ -954,7 +936,7 @@ class ActivityStarter { resolvedTypes[i], aInfo, null /*rInfo*/, null, null, resultTo, null, -1, callingPid, callingUid, callingPackage, realCallingPid, realCallingUid, 0, - options, false, componentSpecified, outActivity, null, null, reason); + options, false, componentSpecified, outActivity, null, reason); if (res < 0) { return res; } @@ -2069,13 +2051,6 @@ class ActivityStarter { return currentStack; } - final ActivityStackSupervisor.ActivityContainer container = r.mInitialActivityContainer; - if (container != null) { - // The first time put it on the desired stack, after this put on task stack. - r.mInitialActivityContainer = null; - return container.mStack; - } - if (canLaunchIntoFocusedStack(r, newTask)) { if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG_FOCUS, "computeStackFocus: Have a focused stack=" + mSupervisor.mFocusedStack); @@ -2140,13 +2115,11 @@ class ActivityStarter { default: // Dynamic stacks behave similarly to the fullscreen stack and can contain any // resizeable task. - // TODO: Check ActivityView after fixing b/35349678. canUseFocusedStack = isDynamicStack(focusedStackId) && r.canBeLaunchedOnDisplay(focusedStack.mDisplayId); } - return canUseFocusedStack - && (!newTask || focusedStack.mActivityContainer.isEligibleForNewTasks()) + return canUseFocusedStack && !newTask // We strongly prefer to launch activities on the same display as their source. && (mSourceDisplayId == focusedStack.mDisplayId); } @@ -2212,9 +2185,7 @@ class ActivityStarter { // The parent activity doesn't want to launch the activity on top of itself, but // instead tries to put it onto other side in side-by-side mode. - final ActivityStack parentStack = task != null ? task.getStack() - : r.mInitialActivityContainer != null ? r.mInitialActivityContainer.mStack - : mSupervisor.mFocusedStack; + final ActivityStack parentStack = task != null ? task.getStack(): mSupervisor.mFocusedStack; if (parentStack != mSupervisor.mFocusedStack) { // If task's parent stack is not focused - use it during adjacent launch. @@ -2265,7 +2236,6 @@ class ActivityStarter { case ASSISTANT_STACK_ID: return r.isAssistantActivity(); default: - // TODO: Check ActivityView after fixing b/35349678. if (StackId.isDynamicStack(stackId)) { return r.canBeLaunchedOnDisplay(displayId); } diff --git a/services/core/java/com/android/server/am/AppErrors.java b/services/core/java/com/android/server/am/AppErrors.java index 0d1c579f2b81..fc03db1203bd 100644 --- a/services/core/java/com/android/server/am/AppErrors.java +++ b/services/core/java/com/android/server/am/AppErrors.java @@ -409,10 +409,9 @@ class AppErrors { final Set<String> cats = task.intent.getCategories(); if (cats != null && cats.contains(Intent.CATEGORY_LAUNCHER)) { mService.startActivityInPackage(task.mCallingUid, - task.mCallingPackage, task.intent, - null, null, null, 0, 0, - ActivityOptions.makeBasic().toBundle(), - task.userId, null, null, "AppErrors"); + task.mCallingPackage, task.intent, null, null, null, 0, 0, + ActivityOptions.makeBasic().toBundle(), task.userId, null, + "AppErrors"); } } } diff --git a/services/core/java/com/android/server/am/PendingIntentRecord.java b/services/core/java/com/android/server/am/PendingIntentRecord.java index cad5dcf6b565..ee593866da68 100644 --- a/services/core/java/com/android/server/am/PendingIntentRecord.java +++ b/services/core/java/com/android/server/am/PendingIntentRecord.java @@ -20,7 +20,6 @@ import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; import android.app.ActivityManager; -import android.app.IActivityContainer; import android.content.IIntentSender; import android.content.IIntentReceiver; import android.app.PendingIntent; @@ -37,7 +36,6 @@ import android.util.Slog; import android.util.TimeUtils; import com.android.internal.os.IResultReceiver; -import com.android.server.am.ActivityStackSupervisor.ActivityContainer; import java.io.PrintWriter; import java.lang.ref.WeakReference; @@ -234,30 +232,23 @@ final class PendingIntentRecord extends IIntentSender.Stub { public void send(int code, Intent intent, String resolvedType, IBinder whitelistToken, IIntentReceiver finishedReceiver, String requiredPermission, Bundle options) { sendInner(code, intent, resolvedType, whitelistToken, finishedReceiver, - requiredPermission, null, null, 0, 0, 0, options, null); + requiredPermission, null, null, 0, 0, 0, options); } public int sendWithResult(int code, Intent intent, String resolvedType, IBinder whitelistToken, IIntentReceiver finishedReceiver, String requiredPermission, Bundle options) { return sendInner(code, intent, resolvedType, whitelistToken, finishedReceiver, - requiredPermission, null, null, 0, 0, 0, options, null); + requiredPermission, null, null, 0, 0, 0, options); } int sendInner(int code, Intent intent, String resolvedType, IBinder whitelistToken, IIntentReceiver finishedReceiver, String requiredPermission, IBinder resultTo, String resultWho, int requestCode, - int flagsMask, int flagsValues, Bundle options, IActivityContainer container) { + int flagsMask, int flagsValues, Bundle options) { if (intent != null) intent.setDefusable(true); if (options != null) options.setDefusable(true); synchronized (owner) { - final ActivityContainer activityContainer = (ActivityContainer)container; - if (activityContainer != null && activityContainer.mParentActivity != null && - activityContainer.mParentActivity.state - != ActivityStack.ActivityState.RESUMED) { - // Cannot start a child activity if the parent is not resumed. - return ActivityManager.START_CANCELED; - } if (!canceled) { sent = true; if ((key.flags&PendingIntent.FLAG_ONE_SHOT) != 0) { @@ -346,7 +337,7 @@ final class PendingIntentRecord extends IIntentSender.Stub { } else { owner.startActivityInPackage(uid, key.packageName, finalIntent, resolvedType, resultTo, resultWho, requestCode, 0, - options, userId, container, null, "PendingIntentRecord"); + options, userId, null, "PendingIntentRecord"); } } catch (RuntimeException e) { Slog.w(TAG, "Unable to send startActivity intent", e); diff --git a/services/core/java/com/android/server/am/PinnedActivityStack.java b/services/core/java/com/android/server/am/PinnedActivityStack.java index 2010c24000e8..392fbb29d091 100644 --- a/services/core/java/com/android/server/am/PinnedActivityStack.java +++ b/services/core/java/com/android/server/am/PinnedActivityStack.java @@ -20,7 +20,6 @@ import android.app.RemoteAction; import android.content.res.Configuration; import android.graphics.Rect; -import com.android.server.am.ActivityStackSupervisor.ActivityContainer; import com.android.server.wm.PinnedStackWindowController; import com.android.server.wm.PinnedStackWindowListener; @@ -33,9 +32,9 @@ import java.util.List; class PinnedActivityStack extends ActivityStack<PinnedStackWindowController> implements PinnedStackWindowListener { - PinnedActivityStack(ActivityContainer activityContainer, - RecentTasks recentTasks, boolean onTop) { - super(activityContainer, recentTasks, onTop); + PinnedActivityStack(ActivityStackSupervisor.ActivityDisplay display, int stackId, + ActivityStackSupervisor supervisor, RecentTasks recentTasks, boolean onTop) { + super(display, stackId, supervisor, recentTasks, onTop); } @Override diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java index 96d857354f1a..751ecef63728 100644 --- a/services/core/java/com/android/server/am/TaskRecord.java +++ b/services/core/java/com/android/server/am/TaskRecord.java @@ -1045,8 +1045,7 @@ final class TaskRecord extends ConfigurationContainer implements TaskWindowConta } // We need to provide the current orientation of the display on which this task resides, // not the orientation of the task. - final int orientation = - getStack().mActivityContainer.mActivityDisplay.getConfiguration().orientation; + final int orientation = getStack().getDisplay().getConfiguration().orientation; return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, orientation); } diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 9b8d1a7c1c0c..847e7d2c88ab 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -3584,7 +3584,6 @@ public class WindowManagerService extends IWindowManager.Stub } private void updateCircularDisplayMaskIfNeeded() { - // we're fullscreen and not hosted in an ActivityView if (mContext.getResources().getConfiguration().isScreenRound() && mContext.getResources().getBoolean( com.android.internal.R.bool.config_windowShowCircularMask)) { diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java b/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java index 16bc011f97b5..04b5bdebdca1 100644 --- a/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java +++ b/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java @@ -16,6 +16,7 @@ package com.android.server.am; +import static android.app.ActivityManager.StackId.PINNED_STACK_ID; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.any; @@ -78,7 +79,7 @@ public class ActivityTestsBase { int stackId, int displayId, boolean onTop) { if (service.mStackSupervisor instanceof TestActivityStackSupervisor) { return ((TestActivityStackSupervisor) service.mStackSupervisor) - .createTestStack(service, stackId, onTop); + .createTestStack(stackId, onTop); } return null; @@ -96,8 +97,7 @@ public class ActivityTestsBase { 0 /* launchedFromPid */, 0, null, intent, null, aInfo /*aInfo*/, new Configuration(), null /* resultTo */, null /* resultWho */, 0 /* reqCode */, false /*componentSpecified*/, false /* rootVoiceInteraction */, - service.mStackSupervisor, null /* container */, null /* options */, - null /* sourceRecord */); + service.mStackSupervisor, null /* options */, null /* sourceRecord */); activity.mWindowContainerController = mock(AppWindowContainerController.class); if (task != null) { @@ -187,12 +187,24 @@ public class ActivityTestsBase { boolean preserveWindows) { } - public <T extends ActivityStack> T createTestStack(ActivityManagerService service, - int stackId, boolean onTop) { - final TestActivityContainer container = - new TestActivityContainer(service, stackId, mDisplay, onTop); - mActivityContainers.put(stackId, container); - return (T) container.getStack(); + <T extends ActivityStack> T createTestStack(int stackId, boolean onTop) { + return (T) createStack(stackId, mDisplay, onTop); + } + + @Override + ActivityStack createStack(int stackId, ActivityDisplay display, boolean onTop) { + final RecentTasks recents = + new RecentTasks(mService, mService.mStackSupervisor); + if (stackId == PINNED_STACK_ID) { + return new PinnedActivityStack(display, stackId, this, recents, onTop) { + @Override + Rect getDefaultPictureInPictureBounds(float aspectRatio) { + return new Rect(50, 50, 100, 100); + } + }; + } else { + return new TestActivityStack(display, stackId, this, recents, onTop); + } } @Override @@ -204,49 +216,7 @@ public class ActivityTestsBase { return stack; } - return createTestStack(mService, stackId, createOnTop); - } - - private class TestActivityContainer extends ActivityContainer { - private final ActivityManagerService mService; - - private boolean mOnTop; - private int mStackId; - private ActivityStack mStack; - - TestActivityContainer(ActivityManagerService service, int stackId, - ActivityDisplay activityDisplay, boolean onTop) { - super(stackId, activityDisplay, onTop); - mService = service; - } - - @Override - protected void createStack(int stackId, boolean onTop) { - // normally stack creation is done here. However we need to do it on demand since - // we cannot set {@link mService} by the time the super constructor calling this - // method is invoked. - mOnTop = onTop; - mStackId = stackId; - } - - public ActivityStack getStack() { - if (mStack == null) { - final RecentTasks recents = - new RecentTasks(mService, mService.mStackSupervisor); - if (mStackId == ActivityManager.StackId.PINNED_STACK_ID) { - mStack = new PinnedActivityStack(this, recents, mOnTop) { - @Override - Rect getDefaultPictureInPictureBounds(float aspectRatio) { - return new Rect(50, 50, 100, 100); - } - }; - } else { - mStack = new TestActivityStack(this, recents, mOnTop); - } - } - - return mStack; - } + return createTestStack(stackId, createOnTop); } } @@ -277,9 +247,9 @@ public class ActivityTestsBase { extends ActivityStack<T> implements ActivityStackReporter { private int mOnActivityRemovedFromStackCount = 0; private T mContainerController; - TestActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer, - RecentTasks recentTasks, boolean onTop) { - super(activityContainer, recentTasks, onTop); + TestActivityStack(ActivityStackSupervisor.ActivityDisplay display, int stackId, + ActivityStackSupervisor supervisor, RecentTasks recentTasks, boolean onTop) { + super(display, stackId, supervisor, recentTasks, onTop); } @Override |