Android Framework中的PolicyManager简介

Android Framework中的策略管理器(PolicyManager)简介及编程实例 策略管理器(PolicyManager)是Android Framework中的一个重要组件,它提供了一种机制,允许开发者对设备上的各种策略进行管理和控制。策略管理器(PolicyManager)是Android Framework中的一个重要组件,用于管理和控制设备上的各种策略。通过策略管理器,开发者可以实现应用程序的安全性、隐私性和权限控制等功能。下面是一个简单的编程实例,演示如何使用策略管理器禁用应用程序的摄像头访问权限。下面是一个简单的编程示例,演示如何使用策略管理器禁用应用程序的摄像头访问权限。 阅读详情

PolicyManager类位于framework\base\core\java\com\android\internal\policy目录中的PolicyManager.java文件中。PolicyManager主要用于创建Window类、LayoutInflater类和WindowManagerPolicy类,它扮演着简单工厂模式中的工厂类角色,而抽象产品角色由IPolicy接口实现,具体产品角色由Policy类实现。它们的关系如下图所示:


从下面三个类的代码可以看出,都使用了hide注解,因此,这三个类都是不对外公开的API,只限于Framework内部使用。

抽象产品类IPolicy实现如下(IPolicy.java):

  1. package com.android.internal.policy;  
  2.   
  3. import android.content.Context;  
  4. import android.view.LayoutInflater;  
  5. import android.view.Window;  
  6. import android.view.WindowManagerPolicy;  
  7.   
  8. /** 
  9.  * {@hide} 
  10.  */  
  11.   
  12. /* The implementation of this interface must be called Policy and contained 
  13.  * within the com.android.internal.policy.impl package */  
  14. public interface IPolicy {  
  15.     public Window makeNewWindow(Context context);  
  16.   
  17.     public LayoutInflater makeNewLayoutInflater(Context context);  
  18.   
  19.     public WindowManagerPolicy makeNewWindowManager();  
  20. }  

具体产品类Policy实现如下(Policy.java):

  1. package com.android.internal.policy.impl;  
  2.   
  3. import android.content.Context;  
  4. import android.util.Log;  
  5.   
  6. import com.android.internal.policy.IPolicy;  
  7. import com.android.internal.policy.impl.PhoneLayoutInflater;  
  8. import com.android.internal.policy.impl.PhoneWindow;  
  9. import com.android.internal.policy.impl.PhoneWindowManager;  
  10.   
  11. /** 
  12.  * {@hide} 
  13.  */  
  14.   
  15. // Simple implementation of the policy interface that spawns the right  
  16. // set of objects  
  17. public class Policy implements IPolicy {  
  18.     private static final String TAG = "PhonePolicy";  
  19.   
  20.     //需要在Policy类创建时预先加载的一些类  
  21.     private static final String[] preload_classes = {  
  22.         "com.android.internal.policy.impl.PhoneLayoutInflater",  
  23.         "com.android.internal.policy.impl.PhoneWindow",  
  24.         "com.android.internal.policy.impl.PhoneWindow$1",  
  25.         "com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback",  
  26.         "com.android.internal.policy.impl.PhoneWindow$DecorView",  
  27.         "com.android.internal.policy.impl.PhoneWindow$PanelFeatureState",  
  28.  "com.android.internal.policy.impl.PhoneWindow$PanelFeatureState$SavedState",  
  29.     };  
  30.   
  31.     static {  
  32.         // 出于性能考虑,在Policy类加载时提前加载会用到的相关类  
  33.         for (String s : preload_classes) {  
  34.             try {  
  35.         //加载指定类到Java虚拟机中,并执行类中的静态代码段  
  36.                 Class.forName(s);  
  37.             } catch (ClassNotFoundException ex) {  
  38.                 Log.e(TAG, "Could not preload class for phone policy: " + s);  
  39.             }  
  40.         }  
  41.     }  
  42.   
  43.     public PhoneWindow makeNewWindow(Context context) {  
  44.         return new PhoneWindow(context);  
  45.     }  
  46.   
  47.     public PhoneLayoutInflater makeNewLayoutInflater(Context context) {  
  48.         return new PhoneLayoutInflater(context);  
  49.     }  
  50.   
  51.     //PhoneWindowManager实现了WindowManagerPolicy接口      
  52.     //这里返回值直接写成WindowManagerPolicy更合理些  
  53.     public PhoneWindowManager makeNewWindowManager() {  
  54.         return new PhoneWindowManager();  
  55.     }  
  56. }  

工厂类PolicyManager实现如下(PolicyManager.java):

  1. <pre class="java" name="code">package com.android.internal.policy;  
  2.   
  3. import android.content.Context;  
  4. import android.view.LayoutInflater;  
  5. import android.view.Window;  
  6. import android.view.WindowManagerPolicy;  
  7.   
  8. import com.android.internal.policy.IPolicy;  
  9.   
  10. /** 
  11.  * {@hide} 
  12.  */  
  13.   
  14. public final class PolicyManager {  
  15.     private static final String POLICY_IMPL_CLASS_NAME =  
  16.         "com.android.internal.policy.impl.Policy";  
  17.   
  18.     private static final IPolicy sPolicy;  
  19.   
  20.     static {  
  21.        // 运行时动态装载IPolicy实现类  
  22.         try {  
  23.            //加载Policy类的同时会执行其中的静态代码段  
  24.             Class policyClass = Class.forName(POLICY_IMPL_CLASS_NAME);  
  25.             sPolicy = (IPolicy)policyClass.newInstance();  
  26.         } catch (ClassNotFoundException ex) {  
  27.             throw new RuntimeException(  
  28.                     POLICY_IMPL_CLASS_NAME + " could not be loaded", ex);  
  29.         } catch (InstantiationException ex) {  
  30.             throw new RuntimeException(  
  31.                     POLICY_IMPL_CLASS_NAME + " could not be instantiated", ex);  
  32.         } catch (IllegalAccessException ex) {  
  33.             throw new RuntimeException(  
  34.                     POLICY_IMPL_CLASS_NAME + " could not be instantiated", ex);  
  35.         }  
  36.     }  
  37.   
  38.     // 构造函数私有,保证是单例类  
  39.     private PolicyManager() {}  
  40.   
  41.     // The static methods to spawn new policy-specific objects  
  42.     public static Window makeNewWindow(Context context) {  
  43.         return sPolicy.makeNewWindow(context);  
  44.     }  
  45.   
  46.     public static LayoutInflater makeNewLayoutInflater(Context context) {  
  47.         return sPolicy.makeNewLayoutInflater(context);  
  48.     }  
  49.   
  50.     public static WindowManagerPolicy makeNewWindowManager() {  
  51.         return sPolicy.makeNewWindowManager();  
  52.     }  
  53. }</pre><br>  
  54. <br>  
  55. <p></p>  
  56. <p></p>  
  57. <p></p>  
  58. <pre></pre>  
  59. <pre></pre>  
一种基于因果干预的少样本学习的故障诊断模型 本文提出CIRNet,一种融合元学习与因果干预的少样本故障诊断框架。针对传统方法易学习伪相关特征的问题,CIRNet通过构建结构因果模型,采用类级和特征级双调整策略消除先验知识干扰。实验在多个轴承/齿轮数据集上验证其有效性,在跨组件任务中准确率最高达93.41%,特征可视化显示更好的类可分性。相比现有方法,CIRNet显著提升了模型泛化能力和可解释性。 阅读详情

相关推荐

uniapp实现app版本发现新版本后,自动更新

app实现自动更新

oldolder的博客 1284

android的Policymanager 作用

PolicyManager类位于framework\base\core\java\com\android\internal\policy目录中的PolicyManager.java文件中。PolicyManager主要用于创建Window类、LayoutInflater类和WindowManagerPolicy类,它扮演着简单工厂模式中的工厂类角色,而抽象产品角色由IPolicy接口实现,具体产品

6494

MCGSPro动画部件实战:用文本分段实现智能报警提示(附工程文件)

本文详细介绍了在MCGSPro组态软件中,如何利用动画部件的文本分段功能,高效实现触摸屏上的智能报警提示。通过绑定整数变量作为索引,一个部件即可动态切换多种状态信息,解决了传统方法画面臃肿、维护繁琐的痛点。文章提供了从变量定义、部件配置到逻辑联动的完整实战教程,并分享了工程文件复用与性能优化技巧。

weixin_28347369的博客 170

如何通过PolicyManager创建一个新的Window

当程序员去创建一个新的window的时候,发现new的时候右好多方法未实现,在android中有这样一个类可以生成一个新的window,但是由于该类被android设置为@hide类型的类,所以程序员无法使用。但是程序员总是有办法的,通过java的反射机制就可以访问到该类,并且调用到生成window的方法。贴上代码如下: public void createWindow(){ try {

jerboy的专栏 856

【GPFS专题5】---IBM Spectrum Scale (GPFS) 日常运维命令大全

掌握这些命令是有效管理 GPFS 集群的基础。实际生产环境中,建议结合自动化脚本和监控系统(如 IBM Storage Insights)实现高效运维。定期备份配置、监控性能指标,并进行灾备演练,是保障数据安全和系统稳定的关键。

jundao1997的专栏 841

论文翻译:arxiv-2023 Do-Not-Answer: A Dataset for Evaluating Safeguards in LLMs

随着大型语言模型(LLMs)的快速发展,出现了新的、难以预测的有害能力。这要求开发者能够通过评估“危险能力”来识别风险,以便负责任地部署LLMs。在这项工作中,我们收集了第一个开源数据集,用于评估LLMs中的安全保障,并以低成本部署更安全的开源LLMs。我们的数据集经过策划和筛选,只包含负责任的语言模型不应遵循的指令。我们注释并评估了六个流行的LLMs对这些指令的响应。基于我们的注释,我们继续训练了几个类似BERT的分类器,并发现这些小型分类器在自动安全评估上能够取得与GPT-4相当的成果。

CSPhD-winston的博客 1132

Modem2G/3G/4G/5G:高通Policy Manager(概述,优势,架构与API,配置与debug方法)

By:GentlemanTsao 本篇主要介绍1 Policy Manager概述2 为什么使用policy manager弱耦合:方便修改:动态配置:3 policy manager架构与API3.1 policy manager包括两部分:3.2 上层架构:3.3 Policy生效过程4 如何修改Policyman XML4.1 Policyman包含的XML文件4.2 三种类型:Lists, booleans, and timersListBooleansTimers4.3 Policyman XML

GentelmanTsao的博客 4234

YOLOv12改进前必看 - YAML模型配置文件详细解读(再也不用担心通道数不匹配) 附网络结构图

YOLOv12的模型配置文件在中,里面包含yolov12的以及的不同大小的模型,本文将详细介绍一下YOLOv12模型文件中各参数的含义。

Limiiiing的博客 3278

Android使用隐藏api的方法(使用被@hide的api)

今天去方案公司,看了build来build的去,我独自把Android系统的Audio整个流程部分复习一篇,看了他们辛苦的build,深感同情,看了一部分Audio程序,发现一些被表示@hide的常量和方法,自己总有一种占有欲和支配欲太强了,所以打算把@hide去掉,也参考网上的一些方法,不过晚上大部分的意见是通过反射的方法,我在下面总结,通过发射的方法我第一次见,是我打算写一个APP去...

FLY_THINK2012的博客 352

Claude Code 100个真实案例 - 用AI绘制CAD机械图纸(工程师看了直呼内行)

本案例展示如何使用 Claude Code 配合 Python 的 `ezdxf` 库,从零开始生成专业级 CAD 机械图纸。我们将绘制一个完整的法兰盘零件图,包含主视图、俯视图、标注尺寸、粗糙度标记和标题栏,最终生成标准 DXF 文件,可直接在 AutoCAD 或 FreeCAD 中打开编辑。

yueyeguzhuo的专栏 902

【制作100个unity游戏之30】使用unity实现一款2d俯视角RPG战斗游戏,主要使用InputSystem+有限状态机+A*寻路实现(完结,附带项目源码)

【制作100个unity游戏之30】使用unity实现一款2d俯视角RPG战斗游戏,主要使用InputSystem+有限状态机+A*寻路实现

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 4657

Android 7系统网络(五)Framework层(上)—ConnectivityService核心机制

ConnectivityService 是 Framework 层最核心的网络服务,负责管理系统中所有网络连接的状态。如果把 Android 网络比作一座城市,ConnectivityService 就是交通调度中心——它决定哪个网络是"默认网络"、何时切换网络、如何处理应用的网络请求。源码路径职责说明管理 NetworkAgent维护所有活跃网络连接(WiFi、移动数据、以太网等)的代理评分与选择比较各网络的评分,决定默认网络处理 NetworkRequest应用请求特定类型网络时的分配。

AfinalStone的专栏 220

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Android framework层 按键的处理流程

事件处理流程 1)InputManager负责读取事件并把事件送到frameworks的java层 2)WindowManagerService里会有一个InputMonitor类来监听事件变化并做相应的分发处理。 3)在WindowManagerService会有一个WindowManagerPolicy来做消息拦截处理。 4)WindowManagerService会把消息发给最上面运

Tony的专栏 4761

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

android 如何调用 隐藏的 API 接口

怎样查看并且使用 Android 隐藏 API 和内部 APIhttps://www.jianshu.com/p/fbf45770ecc8 android 隐藏API显式调用以及内部资源使用方法https://blog.youkuaiyun.com/hp910315/article/details/77749414 Android应用开发中如何使用隐藏的APIhttps://www.cnblogs.com/j...

weixin_33759269的博客 583

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

上一篇: ViewGroup的onMeasure和onLayout分析
下一篇: Android view 工作流程《上》
cding1818
博客等级 码龄17年 963粉丝 154原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值