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: I743af3c56aec67e1a9487235f1a4a4e64cbaf4a3
This commit is contained in:
Wei Sheng Shih
2021-07-20 06:10:34 +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.servertransaction.TransferSplashScreenViewStateItem;
import android.app.usage.UsageEvents.Event; import android.app.usage.UsageEvents.Event;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.LocusId; import android.content.LocusId;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
@@ -6236,7 +6237,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
void showStartingWindow(boolean taskSwitch) { void showStartingWindow(boolean taskSwitch) {
showStartingWindow(null /* prev */, false /* newTask */, taskSwitch, showStartingWindow(null /* prev */, false /* newTask */, taskSwitch,
0 /* splashScreenTheme */, null); false /* startActivity */, null);
} }
/** /**
@@ -6271,7 +6272,16 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
return null; 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) { if (mPendingOptions != null) {
final int optionsStyle = mPendingOptions.getSplashScreenStyle(); final int optionsStyle = mPendingOptions.getSplashScreenStyle();
if (optionsStyle == SplashScreen.SPLASH_SCREEN_STYLE_EMPTY) { if (optionsStyle == SplashScreen.SPLASH_SCREEN_STYLE_EMPTY) {
@@ -6298,8 +6308,41 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
return true; 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, void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch,
int splashScreenTheme, ActivityRecord sourceRecord) { boolean startActivity, ActivityRecord sourceRecord) {
if (mTaskOverlay) { if (mTaskOverlay) {
// We don't show starting window for overlay activities. // We don't show starting window for overlay activities.
return; return;
@@ -6313,8 +6356,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
final CompatibilityInfo compatInfo = final CompatibilityInfo compatInfo =
mAtmService.compatibilityInfoForPackageLocked(info.applicationInfo); mAtmService.compatibilityInfoForPackageLocked(info.applicationInfo);
mSplashScreenStyleEmpty = shouldUseEmptySplashScreen(sourceRecord); mSplashScreenStyleEmpty = shouldUseEmptySplashScreen(sourceRecord, startActivity);
final int splashScreenTheme = startActivity ? getSplashscreenTheme() : 0;
final int resolvedTheme = evaluateStartingWindowTheme(prev, packageName, theme, final int resolvedTheme = evaluateStartingWindowTheme(prev, packageName, theme,
splashScreenTheme); splashScreenTheme);

View File

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

View File

@@ -179,14 +179,12 @@ import android.app.servertransaction.NewIntentItem;
import android.app.servertransaction.PauseActivityItem; import android.app.servertransaction.PauseActivityItem;
import android.app.servertransaction.ResumeActivityItem; import android.app.servertransaction.ResumeActivityItem;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager; import android.content.pm.IPackageManager;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.Point; import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
@@ -4163,26 +4161,25 @@ class Task extends WindowContainer<WindowContainer> {
return info; 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(); final StartingWindowInfo info = new StartingWindowInfo();
info.taskInfo = getTaskInfo(); info.taskInfo = getTaskInfo();
info.isKeyguardOccluded = info.isKeyguardOccluded =
mAtmService.mKeyguardController.isDisplayOccluded(DEFAULT_DISPLAY); mAtmService.mKeyguardController.isDisplayOccluded(DEFAULT_DISPLAY);
final ActivityRecord topActivity = getTopMostActivity();
if (topActivity != null) { info.startingWindowTypeParameter = activity.mStartingData.mTypeParams;
info.startingWindowTypeParameter = final WindowState mainWindow = activity.findMainWindow();
topActivity.mStartingData != null if (mainWindow != null) {
? topActivity.mStartingData.mTypeParams info.mainWindowLayoutParams = mainWindow.getAttrs();
: 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());
} }
// 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(); final ActivityRecord topFullscreenActivity = getTopFullscreenActivity();
if (topFullscreenActivity != null) { if (topFullscreenActivity != null) {
final WindowState topFullscreenOpaqueWindow = final WindowState topFullscreenOpaqueWindow =
@@ -6691,33 +6688,8 @@ class Task extends WindowContainer<WindowContainer> {
} }
} }
// 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), r.showStartingWindow(prev, newTask, isTaskSwitch(r, focusedTopActivity),
splashScreenThemeResId, sourceRecord); true /* startActivity */, sourceRecord);
} }
} else { } else {
// If this is the first activity, don't do any fancy animations, // If this is the first activity, don't do any fancy animations,

View File

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

View File

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