当前位置:网站首页>Restartprocessifvisible process
Restartprocessifvisible process
2022-06-30 16:48:00 【AmyTan Xiaoyan】
The main process is as follows :
- At present Activity The front desk shows , Let it app perform onStop as well as onSaveInstanceState Save the data ; Invisible direct killing
- Activity inform system server After execution stop, System kill process ;
- Process is killed handleAppDied when , At present activity reception , So it will pass activity Pull up the process .

/** * Request the process of the activity to restart with its saved state (from * {@link android.app.Activity#onSaveInstanceState}) if possible. It also forces to recompute * the override configuration. Note if the activity is in background, the process will be killed * directly with keeping its record. */
void restartProcessIfVisible() {
// Print related log
Slog.i(TAG, "Request to restart process of " + this);
// Reset the existing override configuration so it can be updated according to the latest
// configuration.
// Clear the native Shrink
clearSizeCompatMode();
// If activity If the corresponding process does not exist, it directly returns
if (!attachedToProcess()) {
return;
}
// The restarting state avoids removing this record when process is died.
// QCOM ADD:
callServiceTrackeronActivityStatechange(RESTARTING_PROCESS, true);
// Set up actiivty The status of is RESTARTING_PROCESS, Later, check and kill the corresponding process according to this status
setState(RESTARTING_PROCESS, "restartActivityProcess");
// activity Not in resume state
if (!mVisibleRequested || mHaveState) {
// Kill its process immediately because the activity should be in background.
// The activity state will be update to {@link #DESTROYED} in
// {@link ActivityStack#cleanUp} when handling process died.
// post To display Thread to execute
mAtmService.mH.post(() -> {
final WindowProcessController wpc;
synchronized (mAtmService.mGlobalLock) {
// If app The process does not exist or app Of procState <= 6( namely activity Not visible but app The process is more important ), Not to deal with
if (!hasProcess()
|| app.getReportedProcState() <= PROCESS_STATE_IMPORTANT_FOREGROUND) {
return;
}
wpc = app;
}
//activity Directly in the background Check and kill the process separately ( Don't know which Task and system server Saved related app data ), call ProcessList Of removeProcessLocked Method
mAtmService.mAmInternal.killProcess(wpc.mName, wpc.mUid, "resetConfig");
});
return;
}
// Start freezing the screen
if (getParent() != null) {
startFreezingScreen();
}
// The process will be killed until the activity reports stopped with saved state (see
// {@link ActivityTaskManagerService.activityStopped}).
try {
// Let the present Activity perform onStop In order to let app Save relevant data to bundle state in
mAtmService.getLifecycleManager().scheduleTransaction(app.getThread(), appToken,
StopActivityItem.obtain(0 /* configChanges */));
} catch (RemoteException e) {
Slog.w(TAG, "Exception thrown during restart " + this, e);
}
// The restart timeout is 2s,activitystop The timeout message will be canceled after the callback , Check and kill the process directly after timeout
mTaskSupervisor.scheduleRestartTimeout(this);
}
@Override
public void activityStopped(IBinder token, Bundle icicle, PersistableBundle persistentState,
CharSequence description) {
if (DEBUG_ALL) Slog.v(TAG, "Activity stopped: token=" + token);
// Refuse possible leaked file descriptors.
if (icicle != null && icicle.hasFileDescriptors()) {
throw new IllegalArgumentException("File descriptors passed in Bundle");
}
final long origId = Binder.clearCallingIdentity();
String restartingName = null;
int restartingUid = 0;
final ActivityRecord r;
synchronized (mGlobalLock) {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityStopped");
// token Corresponding ActivityRecord Exists and has not been removed from Task Remove
r = ActivityRecord.isInRootTaskLocked(token);
if (r != null) {
// ActivityRecord The corresponding process exists & ActivityRecord The status of is RESTARTING_PROCESS
if (r.attachedToProcess() && r.isState(Task.ActivityState.RESTARTING_PROCESS)) {
// The activity was requested to restart from
// {@link #restartActivityProcessIfVisible}.
// Save the relevant name and uid, Because after the execution r.activityStopped after ,actiivty Of state Will turn into STOPPED
restartingName = r.app.mName;
restartingUid = r.app.mUid;
}
// perform Activity stop
r.activityStopped(icicle, persistentState, description);
}
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
}
if (restartingName != null) {
// In order to let the foreground activity can be restarted with its saved state from
// {@link android.app.Activity#onSaveInstanceState}, the kill operation is postponed
// until the activity reports stopped with the state. And the activity record will be
// kept because the record state is restarting, then the activity will be restarted
// immediately if it is still the top one.
// remove 2s timeout
mTaskSupervisor.removeRestartTimeouts(r);
// The killing process
mService.mAmInternal.killProcess(restartingName, restartingUid,
"restartActivityProcess");
}
mService.mAmInternal.trimApplications();
Binder.restoreCallingIdentity(origId);
}
@Override
public void killProcess(String processName, int uid, String reason) {
synchronized (ActivityManagerService.this) {
final ProcessRecord proc = getProcessRecordLocked(processName, uid);
if (proc != null) {
mProcessList.removeProcessLocked(proc, false /* callerWillRestart */,
true /* allowRestart */, ApplicationExitInfo.REASON_OTHER, reason);
}
}
}
@HotPath(caller = HotPath.PROCESS_CHANGE)
@Override
public void handleAppDied(WindowProcessController wpc, boolean restarting,
Runnable finishInstrumentationCallback) {
synchronized (mGlobalLockWithoutBoost) {
mTaskSupervisor.beginDeferResume();
final boolean hasVisibleActivities;
try {
// Remove this application's activities from active lists.
// Is there a visible page
hasVisibleActivities = wpc.handleAppDied();
} finally {
mTaskSupervisor.endDeferResume();
}
if (!restarting && hasVisibleActivities) {
deferWindowLayout();
try {
if (!mRootWindowContainer.resumeFocusedTasksTopActivities()) {
// If there was nothing to resume, and we are not already restarting
// this process, but there is a visible activity that is hosted by the
// process...then make sure all visible activities are running, taking
// care of restarting this process.
mRootWindowContainer.ensureActivitiesVisible(null, 0,
!PRESERVE_WINDOWS);
}
} finally {
continueWindowLayout();
}
}
// MIUI ADD: START
if (MiuiAppContinuityStub.get().isEnabled()) {
ActivityTaskManagerServiceStub.get().handleAppDiedReport(wpc.mName);
}
ActivityTaskManagerServiceStub.get().restartSubScreenUiIfNeeded(wpc.mInfo, "app died");
// END
}
if (wpc.isInstrumenting()) {
finishInstrumentationCallback.run();
}
}
/** * Clean up the activities belonging to this process. * * @return {@code true} if the process has any visible activity. */
boolean handleAppDied() {
// from stopping List and finishing Remove the current... From the list app All of the activity
mAtm.mTaskSupervisor.removeHistoryRecords(this);
boolean hasVisibleActivities = false;
// Whether there is destroying State of activity
final boolean hasInactiveActivities =
mInactiveActivities != null && !mInactiveActivities.isEmpty();
// At present app Having any state activity, Create a new array
final ArrayList<ActivityRecord> activities =
(mHasActivities || hasInactiveActivities) ? new ArrayList<>() : mActivities;
if (mHasActivities) {
activities.addAll(mActivities);
}
if (hasInactiveActivities) {
// Make sure that all activities in this process are handled.
activities.addAll(mInactiveActivities);
}
// If it is force stop Killing /app crash Too many times , Need to put all activity Marked as finishing, Avoid process causes activity Be pulled up repeatedly
if (isRemoved()) {
// The package of the died process should be force-stopped, so make its activities as
// finishing to prevent the process from being started again if the next top (or being
// visible) activity also resides in the same process. This must be done before removal.
for (int i = activities.size() - 1; i >= 0; i--) {
activities.get(i).makeFinishingLocked();
}
}
for (int i = activities.size() - 1; i >= 0; i--) {
final ActivityRecord r = activities.get(i);
if (r.mVisibleRequested || r.isVisible()) {
// While an activity launches a new activity, it's possible that the old activity
// is already requested to be hidden (mVisibleRequested=false), but this visibility
// is not yet committed, so isVisible()=true.
// Whether there are visible activity ( Probably pause or resume state )
hasVisibleActivities = true;
}
final TaskFragment taskFragment = r.getTaskFragment();
// take Task In progress pausing Of activity It also counts as visible
if (taskFragment != null) {
// There may be a pausing activity that hasn't shown any window and was requested
// to be hidden. But pausing is also a visible state, it should be regarded as
// visible, so the caller can know the next activity should be resumed.
hasVisibleActivities |= taskFragment.handleAppDied(this);
}
r.handleAppDied();
}
// Clear operation
clearRecentTasks();
clearActivities();
return hasVisibleActivities;
}
边栏推荐
- Mathematical modeling for war preparation 34-bp neural network prediction 2
- 备战数学建模35-时间序列预测模型
- Mysql8.0 method and steps for enabling remote connection permission
- 2020 Blue Bridge Cup group B - move bricks - (greedy sorting +01 backpack)
- Good partner for cloud skill improvement, senior brother cloud of Amazon officially opened today
- Installing jupyter notebook under Anaconda
- Explain in detail the use of for loop, break and continue in go language
- STL教程7-set、pair对组和仿函数
- There are so many kinds of coupons. First distinguish them clearly and then collect the wool!
- 牛客网:有多少个不同的二叉搜索树
猜你喜欢

Mathematical modeling for war preparation 33- grey prediction model 2

The inspiration from infant cognitive learning may be the key to the next generation of unsupervised machine learning

Tencent two sides: @bean and @component are used on the same class. What happens?
mysql8报错:ERROR 1410 (42000): You are not allowed to create a user with GRANT解决办法

RT-Thread 堆區大小設置

异常类_日志框架

【机器学习】K-means聚类分析

牛客网:有多少个不同的二叉搜索树

搬运两个负载均衡的笔记,日后省的找
Two methods for MySQL to open remote connection permission
随机推荐
The inspiration from infant cognitive learning may be the key to the next generation of unsupervised machine learning
RT thread heap size Setting
抖快B为啥做不好综艺
[Verilog basics] octal and hexadecimal representation of decimal negative numbers
Raft介绍
赛芯电子冲刺科创板:拟募资6.2亿 实控人谭健为美国籍
[activity registration] it's your turn to explore the yuan universe! I will be waiting for you in Shenzhen on July 2!
【活动报名】探秘元宇宙,就差你了!7月2号我在深圳现场等你!
Additional: (not written yet, don't look at ~ ~ ~) corsfilter filter;
[download attached] installation and use of penetration test artifact Nessus
Home office discussion on the experience of remote assistance to quickly improve efficiency | community essay solicitation
MySQL transaction / lock / log summary
八大基本排序(详解)
RTP 发送PS流零拷贝方案
药品管理系统加数据库,一夜做完,加报告
TCP Socket与TCP 连接
荣盛生物冲刺科创板:拟募资12.5亿 年营收2.6亿
What role does "low code" play in enterprise digital transformation?
【Verilog基础】关于Clock信号的一些概念总结(clock setup/hold、clock tree、clock skew、clock latency、clock transition..)
Half year inventory of new consumption in 2022: the industry is cold, but these nine tracks still attract gold