Android6. Detailed explanation of fixed function of 0 screen

Maybe you don't know what it is when you see this title. Let me explain it first, Android 6 0 after setting - > Security - > Screen fixation is turned on, and then long press the home key to display the recent activities. You can select a pushpin button to turn on the screen fixation function.

After the screen is enabled, the screen can only be fixed to the activity switch on the set task.

1、 Set fixed screen

Let's look at @ r first_ 403_ 1108@/src/com/android/@R_ 403_ 1108@/recents/ScreenPinningRequest. Java code. This code is to long press the home key to display several activities, and then press the button of the pushpin. Here, the startlocktaskmodeoncurrent function of AMS is called directly.

Let's take a look at the startLockTaskModeOnCurrent function of AMS. First we call the topRunningActivityLocked of ActivityStackSupervisor to get the first Activity, then we call the startLockTaskModeLocked function, the parameter is TaskRecord.

Let's look at the toprunningactivitylocked function. First, get the top activity from mfocusedstack. If you don't traverse all mstacks to get.

The startlocktaskmodelocked function mainly calls the setlocktaskmodelocked function of activitystacksupervisor. Let's look at this function. Our task is not null. The first time mlocktaskmodetasks is empty, a lock will be sent_ TASK_ START_ MSG message

Let's look at message processing. In message processing, we mainly call the disablekeyguard function of WMS.

2、 After fixing the screen, the activity starts the process

After fixing the screen, if we start other taskrecord activities, we can't start them. Let's take a look at this principle. In the startactivityuncheckedlocked function, the islocktaskmodeviolation function will be called to determine whether to further start the activity process. Let's take a look at this function and call getlockedtasklocked to see mlocktaskmodetasks (those tasks that lock the screen). If the current task is the task that is currently fixing the screen, Directly return false means that you can continue to start the activity process. If not, we need to look at the mlocktaskauth variable of the task.

Let's look at the setLockedTaskAuth function of TaskRecord again. When we build a new TaskRecord, we call the setIntent function, and the setIntent function is called in the TaskRecord constructor. Let's see that the value of this function mlocktaskauth is determined according to mlocktaskmode, which is passed in by activityinfo. This value is parsed by PKMs androidmanifest XML. The default is lock_ TASK_ LAUNCH_ MODE_ Default. When there is no white list, mlocktaskauth is lock_ TASK_ AUTH_ PINNABLE。

Let's take another look at the following code of the islocktaskmodeviolation function. The mlocktaskauth of the task is lock_ TASK_ AUTH_ Pinnable, which is currently on a fixed screen, so mlocktaskmodetasks is not null, and finally returns true. Then the activity startup process cannot go on, that is, it means that starting an ordinary activity will be blocked.

3、 Unpin screen

Finally, let's take a look at the cancel fixed screen. The cancel screen will be cancelled in the phonestatusbar, but there must be a virtual key. That's how the native is set. Finally, the stopLockTaskModeOnCurrent function of AMS is invoked. This function mainly calls the stoplocktaskmode function. In this function, it mainly calls the setlocktaskmodelocked function of activitystacksupervisor. It was also called when fixing the screen, but here we look carefully. The first parameter is null.

Let's look at this function. If it's empty, now call getLockedTaskLocked to get the TaskRecord of the current fixed screen, and then call removeLockedTaskLocked to remove the TaskRecord. If it is not null, then call resumeTopActivitiesLocked to start the next Activity (which is the Activity of the next screen locked TaskRecord).

If it is empty, return directly. But it will return to normal the next time we start a normal activity, because mlocktaskmodetasks is empty.

4、 How to cancel screen fixation without virtual key

As mentioned earlier, if there is no virtual key, you can't cancel the screen fixation. Let's talk about the following ways

1. Use the AM command am task lock stop to call the stoplocktaskmode function of am

2. Another way we can do this is in activity Modify the code in Java and press the return key for a long time to call the stoplocktaskmode method of AMS. The following is the implementation. The stoplocktask provided by the activity itself calls the stoplocktaskmode method of AMS

The above is Android 6 0 screen fixed function detailed explanation, hope to help you, if you have any questions, please leave me a message, Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>