Window Android 学习
来源:互联网 发布:linux删除mysql数据库 编辑:程序博客网 时间:2024/06/10 20:05
参考博客:
http://www.androiddesignpatterns.com/2013/07/binders-window-tokens.html
参考类:
- com.android.server.wm.AppWindowToken
- com.android.server.wm.WindowManagerService
- android.view.IWindow
- android.view.WindowManagerImpl
Window Tokens
If you've ever scrolled through the official documentation for Android's View
class, chances are you've stumbled across thegetWindowToken()
method and wondered what it meant. As its name implies, a window token is a special type of Binder token that the window manager uses to uniquely identify a window in the system. Window tokens are important for security because they make it impossible for malicious applications to draw on top of the windows of other applications. 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.3 If the tokens don't match, the window manager rejects the request and throws aBadTokenException
. 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.
By this point you might be wondering about the real-world scenarios in which you would need to obtain a window token. Here are some examples:
When an application starts up for the first time, the
ActivityManagerService
4 creates a special kind of window token called an application window token, which uniquely identifies the application's top-level container window.5 The activity manager gives this token to both the application and the window manager, and the application sends the token to the window manager each time it wants to add a new window to the screen. 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. For example, the activity manager can say, "hide all of this token's windows", and the window manager will be able to correctly identify the set of windows which should be closed.Developers implementing their own custom Launchers can interact with the live wallpaper window that sits directly behind them by calling the
sendWallpaperCommand(IBinder windowToken, String action, int x, int y, int z, Bundle extras)
method. To ensure that no other application other than the Launcher is able to interact with the live wallpaper, the framework requires developers to pass a window token as the first argument to the method. If the window token does not identify the current foreground activity window sitting on top of the wallpaper, the command is ignored and a warning is logged.Applications can ask the
InputMethodManager
to hide the soft keyboard by calling thehideSoftInputFromWindow(IBinder windowToken, int flags)
method, but must provide a window token as part of the request. If the token doesn't match the window token belonging to the window currently accepting input, theInputMethodManager
will reject the request. This makes it impossible for malicious applications to force-close a soft keyboard opened by another application.Applications which manually add new windows to the screen (i.e. using the
addView(View, WindowManager.LayoutParams)
method) may need to specify their application's window token by setting theWindowManager.LayoutParams.token
field. It is very unlikely that any normal application would ever have to do this, since thegetWindowManager()
method returns aWindowManager
which will automatically set the token's value for you. That said, if at some point in the future you encounter a situation in which you need to add a panel window to the screen from a background service, know that you would need to manually sign the request with your application window token in order to achieve it. :P
- Window Android 学习
- 【Android学习】Window和WindowManager
- Titanium Mobile 之android学习window创建
- Android Window 一 简单学习整理
- Android Window
- android Activity.setContentView和Window PhoneWindow类学习
- Window和WindowManager(Android开发艺术探索学习笔记)
- Android Starting Window(Preview Window)
- x window 学习资料
- [学习笔记]X Window
- EXT.Window学习
- window编程学习总结
- window.showModalDialog学习笔记
- window phone 学习地址
- window 多线程学习
- window.event对象学习
- Ext.Window 学习示例
- window.onload 学习
- 浏览器不兼容
- 第五周作业—有向图邻接表表示及反向图构造
- UNREFERENCED_PARAMETER
- android的TableLayout布局界面元素填满整个屏幕
- python 发送Email程序
- Window Android 学习
- 数组的总结
- OpenCv矩阵操作函数大全 (1.0接口)
- python中的os模块
- Suricata之源代码(二)
- Box2D C++ 教程-跳跃
- asterisk使用MYSQL认证的配置方法
- 代码面试最常用的10大算法
- 第七周-项目5-模板类中使用友元函数