Merge "Correct StartingWindowInfo for non-top activity." into sc-dev am: 6b43ea0a73

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15287622

Change-Id: I7dd3ab48d7c58521af19a7718be320a7e580749e
This commit is contained in:
Wei Sheng Shih
2021-07-20 06:11:59 +00:00
committed by Automerger Merge Worker
5 changed files with 75 additions and 59 deletions

View File

@@ -253,6 +253,7 @@ import android.app.servertransaction.TopResumedActivityChangeItem;
import android.app.servertransaction.TransferSplashScreenViewStateItem;
import android.app.usage.UsageEvents.Event;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.LocusId;
import android.content.pm.ActivityInfo;
@@ -6346,7 +6347,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
void showStartingWindow(boolean taskSwitch) {
showStartingWindow(null /* prev */, false /* newTask */, taskSwitch,
0 /* splashScreenTheme */, null);
false /* startActivity */, null);
}
/**
@@ -6381,7 +6382,16 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
return null;
}
private boolean shouldUseEmptySplashScreen(ActivityRecord sourceRecord) {
private boolean shouldUseEmptySplashScreen(ActivityRecord sourceRecord, boolean startActivity) {
if (sourceRecord == null && !startActivity) {
// Use empty style if this activity is not top activity. This could happen when adding
// a splash screen window to the warm start activity which is re-create because top is
// finishing.
final ActivityRecord above = task.getActivityAbove(this);
if (above != null) {
return true;
}
}
if (mPendingOptions != null) {
final int optionsStyle = mPendingOptions.getSplashScreenStyle();
if (optionsStyle == SplashScreen.SPLASH_SCREEN_STYLE_EMPTY) {
@@ -6408,8 +6418,41 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
return true;
}
private int getSplashscreenTheme() {
// Find the splash screen theme. User can override the persisted theme by
// ActivityOptions.
String splashScreenThemeResName = mPendingOptions != null
? mPendingOptions.getSplashScreenThemeResName() : null;
if (splashScreenThemeResName == null || splashScreenThemeResName.isEmpty()) {
try {
splashScreenThemeResName = mAtmService.getPackageManager()
.getSplashScreenTheme(packageName, mUserId);
} catch (RemoteException ignore) {
// Just use the default theme
}
}
int splashScreenThemeResId = 0;
if (splashScreenThemeResName != null && !splashScreenThemeResName.isEmpty()) {
try {
final Context packageContext = mAtmService.mContext
.createPackageContext(packageName, 0);
splashScreenThemeResId = packageContext.getResources()
.getIdentifier(splashScreenThemeResName, null, null);
} catch (PackageManager.NameNotFoundException
| Resources.NotFoundException ignore) {
// Just use the default theme
}
}
return splashScreenThemeResId;
}
/**
* @param prev Previous activity which contains a starting window.
* @param startActivity Whether this activity is just created from starter.
* @param sourceRecord The source activity which start this activity.
*/
void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch,
int splashScreenTheme, ActivityRecord sourceRecord) {
boolean startActivity, ActivityRecord sourceRecord) {
if (mTaskOverlay) {
// We don't show starting window for overlay activities.
return;
@@ -6423,8 +6466,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
final CompatibilityInfo compatInfo =
mAtmService.compatibilityInfoForPackageLocked(info.applicationInfo);
mSplashScreenStyleEmpty = shouldUseEmptySplashScreen(sourceRecord);
mSplashScreenStyleEmpty = shouldUseEmptySplashScreen(sourceRecord, startActivity);
final int splashScreenTheme = startActivity ? getSplashscreenTheme() : 0;
final int resolvedTheme = evaluateStartingWindowTheme(prev, packageName, theme,
splashScreenTheme);

View File

@@ -69,7 +69,7 @@ public class StartingSurfaceController {
synchronized (mService.mGlobalLock) {
final Task task = activity.getTask();
if (task != null && mService.mAtmService.mTaskOrganizerController.addStartingWindow(
task, activity.token, theme, null /* taskSnapshot */)) {
task, activity, theme, null /* taskSnapshot */)) {
return new ShellStartingSurface(task);
}
}
@@ -149,7 +149,7 @@ public class StartingSurfaceController {
}
if (DEBUG_ENABLE_SHELL_DRAWER) {
mService.mAtmService.mTaskOrganizerController.addStartingWindow(task,
activity.token, 0 /* launchTheme */, taskSnapshot);
activity, 0 /* launchTheme */, taskSnapshot);
return new ShellStartingSurface(task);
}
}

View File

@@ -151,14 +151,12 @@ import android.app.PictureInPictureParams;
import android.app.RemoteAction;
import android.app.TaskInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
@@ -3400,26 +3398,25 @@ class Task extends TaskFragment {
return info;
}
StartingWindowInfo getStartingWindowInfo() {
/**
* Returns a {@link StartingWindowInfo} with information from this task and the target activity.
* @param activity Target activity which to show the starting window.
*/
StartingWindowInfo getStartingWindowInfo(ActivityRecord activity) {
final StartingWindowInfo info = new StartingWindowInfo();
info.taskInfo = getTaskInfo();
info.isKeyguardOccluded =
mAtmService.mKeyguardController.isDisplayOccluded(DEFAULT_DISPLAY);
final ActivityRecord topActivity = getTopMostActivity();
if (topActivity != null) {
info.startingWindowTypeParameter =
topActivity.mStartingData != null
? topActivity.mStartingData.mTypeParams
: 0;
final WindowState mainWindow = topActivity.findMainWindow();
if (mainWindow != null) {
info.mainWindowLayoutParams = mainWindow.getAttrs();
}
// If the developer has persist a different configuration, we need to override it to the
// starting window because persisted configuration does not effect to Task.
info.taskInfo.configuration.setTo(topActivity.getConfiguration());
info.startingWindowTypeParameter = activity.mStartingData.mTypeParams;
final WindowState mainWindow = activity.findMainWindow();
if (mainWindow != null) {
info.mainWindowLayoutParams = mainWindow.getAttrs();
}
// If the developer has persist a different configuration, we need to override it to the
// starting window because persisted configuration does not effect to Task.
info.taskInfo.configuration.setTo(activity.getConfiguration());
final ActivityRecord topFullscreenActivity = getTopFullscreenActivity();
if (topFullscreenActivity != null) {
final WindowState topFullscreenOpaqueWindow =
@@ -5072,33 +5069,8 @@ class Task extends TaskFragment {
}
}
// Find the splash screen theme. User can override the persisted theme by
// ActivityOptions.
String splashScreenThemeResName = options != null
? options.getSplashScreenThemeResName() : null;
if (splashScreenThemeResName == null || splashScreenThemeResName.isEmpty()) {
try {
splashScreenThemeResName = mAtmService.getPackageManager()
.getSplashScreenTheme(r.packageName, r.mUserId);
} catch (RemoteException ignore) {
// Just use the default theme
}
}
int splashScreenThemeResId = 0;
if (splashScreenThemeResName != null && !splashScreenThemeResName.isEmpty()) {
try {
final Context packageContext = mAtmService.mContext
.createPackageContext(r.packageName, 0);
splashScreenThemeResId = packageContext.getResources()
.getIdentifier(splashScreenThemeResName, null, null);
} catch (PackageManager.NameNotFoundException
| Resources.NotFoundException ignore) {
// Just use the default theme
}
}
r.showStartingWindow(prev, newTask, isTaskSwitch(r, focusedTopActivity),
splashScreenThemeResId, sourceRecord);
true /* startActivity */, sourceRecord);
}
} else {
// If this is the first activity, don't do any fancy animations,

View File

@@ -113,16 +113,16 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
return mTaskOrganizer.asBinder();
}
void addStartingWindow(Task task, IBinder appToken, int launchTheme,
void addStartingWindow(Task task, ActivityRecord activity, int launchTheme,
TaskSnapshot taskSnapshot) {
final StartingWindowInfo info = task.getStartingWindowInfo();
final StartingWindowInfo info = task.getStartingWindowInfo(activity);
if (launchTheme != 0) {
info.splashScreenThemeResId = launchTheme;
}
info.mTaskSnapshot = taskSnapshot;
// make this happen prior than prepare surface
try {
mTaskOrganizer.addStartingWindow(info, appToken);
mTaskOrganizer.addStartingWindow(info, activity.token);
} catch (RemoteException e) {
Slog.e(TAG, "Exception sending onTaskStart callback", e);
}
@@ -302,9 +302,9 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
mUid = uid;
}
void addStartingWindow(Task t, IBinder appToken, int launchTheme,
void addStartingWindow(Task t, ActivityRecord activity, int launchTheme,
TaskSnapshot taskSnapshot) {
mOrganizer.addStartingWindow(t, appToken, launchTheme, taskSnapshot);
mOrganizer.addStartingWindow(t, activity, launchTheme, taskSnapshot);
}
void removeStartingWindow(Task t, boolean prepareAnimation) {
@@ -563,15 +563,15 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
return !ArrayUtils.contains(UNSUPPORTED_WINDOWING_MODES, winMode);
}
boolean addStartingWindow(Task task, IBinder appToken, int launchTheme,
boolean addStartingWindow(Task task, ActivityRecord activity, int launchTheme,
TaskSnapshot taskSnapshot) {
final Task rootTask = task.getRootTask();
if (rootTask == null || rootTask.mTaskOrganizer == null) {
if (rootTask == null || rootTask.mTaskOrganizer == null || activity.mStartingData == null) {
return false;
}
final TaskOrganizerState state =
mTaskOrganizerStates.get(rootTask.mTaskOrganizer.asBinder());
state.addStartingWindow(task, appToken, launchTheme, taskSnapshot);
state.addStartingWindow(task, activity, launchTheme, taskSnapshot);
return true;
}

View File

@@ -2562,19 +2562,19 @@ public class ActivityRecordTests extends WindowTestsBase {
final ActivityRecord sourceRecord = new ActivityBuilder(mAtm)
.setCreateTask(true).setLaunchedFromUid(Process.SYSTEM_UID).build();
sourceRecord.showStartingWindow(null /* prev */, true /* newTask */, false,
0 /* splashScreenTheme */, null);
true /* startActivity */, null);
final ActivityRecord secondRecord = new ActivityBuilder(mAtm)
.setTask(sourceRecord.getTask()).build();
secondRecord.showStartingWindow(null /* prev */, true /* newTask */, false,
0 /* splashScreenTheme */, sourceRecord);
true /* startActivity */, sourceRecord);
assertFalse(secondRecord.mSplashScreenStyleEmpty);
secondRecord.onStartingWindowDrawn();
final ActivityRecord finalRecord = new ActivityBuilder(mAtm)
.setTask(sourceRecord.getTask()).build();
finalRecord.showStartingWindow(null /* prev */, true /* newTask */, false,
0 /* splashScreenTheme */, secondRecord);
true /* startActivity */, secondRecord);
assertTrue(finalRecord.mSplashScreenStyleEmpty);
}