

This ensures secure interaction between the application and the window manager (by making it impossible to add windows on top of other applications), and also makes it easy for the activity manager to make direct requests to the window manager.Īnd the code that throws “BadTokenException” The activity manager gives this token to both the (*application) and the window manager, and it sends the token to the window manager each time it wants to add a new window to the screen. When an application starts up for the first time, the ActivityManagerService creates a special kind of window token called an application window token, which uniquely identifies the application’s top-level container window.

Without window tokens, this necessary identification step wouldn’t be possible and the window manager wouldn’t be able to protect itself from malicious applications. If the tokens don’t match, the window manager rejects the request and throws a BadTokenException. The window manager protects against this by requiring applications to pass their application’s window token as part of each request to add or remove a window. Window tokens are important for security reasons because they make it impossible for malicious applications to draw on top of the windows of other applications.

|| (WMS) is a system service that manages the windows on Android.Īs the name suggest, a window token is a special type of Binder token used by window manager to uniquely identify a window in the system. WindowManager接口的实现类是 WindowManagerImpl。从 理解Window一文中得知获取到的WindowManager其实就是 WindowManagerImpl类型实例 (以参数wm不为空为例): public WindowManagerImpl createLocalWindowManager(Window parentWindow) else if ( != oldInsetLeft Public void updateViewLayout(View view, ViewGroup.LayoutParams params) Public void addView(View view, ViewGroup.LayoutParams params) WindowManager也是接口,继承自 ViewManager接口,它的实现类是 WindowManagerImpl。都在 android.view包中。
