当前位置:网站首页>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;
}
边栏推荐
- 【Verilog基础】关于Clock信号的一些概念总结(clock setup/hold、clock tree、clock skew、clock latency、clock transition..)
- CGR 21 (D,E,F)
- 赛芯电子冲刺科创板:拟募资6.2亿 实控人谭健为美国籍
- Mathematical modeling for war preparation 33- grey prediction model 2
- restartProcessIfVisible的流程
- MicroBlaze serial port learning · 2
- 几百行代码实现一个 JSON 解析器
- Cesium-1.72 learning (add points, lines, cubes, etc.)
- On July 2, I invited you to TD Hero online conference
- Halcon knowledge: matrix topic [02]
猜你喜欢

15年做糊21款硬件,谷歌到底栽在哪儿?

Etcd教程 — 第八章 Etcd之Compact、Watch和Lease API

ArcMap operation series: 80 plane to latitude and longitude 84

How the edge computing platform helps the development of the Internet of things

Home office discussion on the experience of remote assistance to quickly improve efficiency | community essay solicitation

【活动报名】探秘元宇宙,就差你了!7月2号我在深圳现场等你!

异常类_日志框架

After 15 years of working on 21 types of hardware, where is Google?
![[download attached] installation and use of penetration test artifact Nessus](/img/ef/b6a37497010a8320cf5a49a01c2dff.png)
[download attached] installation and use of penetration test artifact Nessus
Mysql8.0 method and steps for enabling remote connection permission
随机推荐
[download attached] installation and use of penetration test artifact Nessus
Explain in detail the use of for loop, break and continue in go language
Mathematical modeling for war preparation 36 time series model 2
24:第三章:开发通行证服务:7:自定义异常(来表征程序中出现的错误);创建GraceExceptionHandler来全局统一处理异常(根据异常信息,构建对应的API统一返回对象的,JSON数据);
Two methods for MySQL to open remote connection permission
Carry two load balancing notes and find them in the future
IndexSearch
Interpretation of gaussdb's innovative features: partial result cache accelerates operators by caching intermediate results
POJ Project Summer
Hologres shared cluster helps Taobao subscribe to the extreme refined operation
[time series database incluxdb] code example for configuring incluxdb+ data visualization and simple operation with C under Windows Environment
go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
[machine learning] K-means clustering analysis
19:00 p.m. tonight, knowledge empowerment phase 2 live broadcast - control panel interface design of openharmony smart home project
Mysql8 error: error 1410 (42000): you are not allowed to create a user with grant solution
2022 Blue Bridge Cup group B - expense reimbursement - (linear dp| status DP)
Anaconda下安装Jupyter notebook
[Verilog basics] summary of some concepts about clock signals (clock setup/hold, clock tree, clock skew, clock latency, clock transition..)
Asp. NETCORE uses cache and AOP to prevent repeated commit
MySQL transaction / lock / log summary