当前位置: 首页 > article >正文

Lineageos 22.1(Android 15)制定应用强制横屏

一、前言

有时候需要系统的某个应用强制衡平显示,不管他是如何配置的。我们只需要简单的拿到top的Task下面的ActivityRecord,并判断包名来强制实现。

二、调整wms

com.android.server.wm.DisplayRotation

 /*** Given an orientation constant, returns the appropriate surface rotation, taking into account* sensors, docking mode, rotation lock, and other factors.** @param orientation  An orientation constant, such as*                     {@link ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}.* @param lastRotation The most recently used rotation.* @return The surface rotation to use.*/@Surface.Rotationint rotationForOrientation(@ScreenOrientation int orientation,@Surface.Rotation int lastRotation) {ProtoLog.v(WM_DEBUG_ORIENTATION,"rotationForOrientation(orient=%s (%d), last=%s (%d)); user=%s (%d) %s",ActivityInfo.screenOrientationToString(orientation), orientation,Surface.rotationToString(lastRotation), lastRotation,Surface.rotationToString(mUserRotation), mUserRotation,mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED? "USER_ROTATION_LOCKED" : "");if (isFixedToUserRotation()) {return mUserRotation;}+    if(isTopActivityIsMyPackage()){+       return Surface.ROTATION_90;+    }@Surface.Rotationint sensorRotation = mOrientationListener != null? mOrientationListener.getProposedRotation() // may be -1: -1;if (mFoldController != null && mFoldController.shouldIgnoreSensorRotation()) {sensorRotation = -1;}if (mDeviceStateController.shouldReverseRotationDirectionAroundZAxis(mDisplayContent)) {sensorRotation = RotationUtils.reverseRotationDirectionAroundZAxis(sensorRotation);}mLastSensorRotation = sensorRotation;if (sensorRotation < 0) {sensorRotation = lastRotation;}final int lidState = mDisplayPolicy.getLidState();final int dockMode = mDisplayPolicy.getDockMode();final boolean hdmiPlugged = mDisplayPolicy.isHdmiPlugged();final boolean carDockEnablesAccelerometer =mDisplayPolicy.isCarDockEnablesAccelerometer();final boolean deskDockEnablesAccelerometer =mDisplayPolicy.isDeskDockEnablesAccelerometer();@Surface.Rotationfinal int preferredRotation;if (!isDefaultDisplay) {// For secondary displays we ignore things like displays sensors, docking mode and// rotation lock, and always prefer user rotation.preferredRotation = mUserRotation;} else if (lidState == LID_OPEN && mLidOpenRotation >= 0) {// Ignore sensor when lid switch is open and rotation is forced.preferredRotation = mLidOpenRotation;} else if (dockMode == Intent.EXTRA_DOCK_STATE_CAR&& (carDockEnablesAccelerometer || mCarDockRotation >= 0)) {// Ignore sensor when in car dock unless explicitly enabled.// This case can override the behavior of NOSENSOR, and can also// enable 180 degree rotation while docked.preferredRotation = carDockEnablesAccelerometer ? sensorRotation : mCarDockRotation;} else if ((dockMode == Intent.EXTRA_DOCK_STATE_DESK|| dockMode == Intent.EXTRA_DOCK_STATE_LE_DESK|| dockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)&& (deskDockEnablesAccelerometer || mDeskDockRotation >= 0)&& !(orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED|| orientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR)) {// Ignore sensor when in desk dock unless explicitly enabled.// This case can enable 180 degree rotation while docked.preferredRotation = deskDockEnablesAccelerometer ? sensorRotation : mDeskDockRotation;} else if (hdmiPlugged && mDemoHdmiRotationLock) {// Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.// Note that the dock orientation overrides the HDMI orientation.preferredRotation = mDemoHdmiRotation;} else if (hdmiPlugged && dockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED&& mUndockedHdmiRotation >= 0) {// Ignore sensor when plugged into HDMI and an undocked orientation has// been specified in the configuration (only for legacy devices without// full multi-display support).// Note that the dock orientation overrides the HDMI orientation.preferredRotation = mUndockedHdmiRotation;} else if (mDemoRotationLock) {// Ignore sensor when demo rotation lock is enabled.// Note that the dock orientation and HDMI rotation lock override this.preferredRotation = mDemoRotation;} else if (mDisplayPolicy.isPersistentVrModeEnabled()) {// While in VR, apps always prefer a portrait rotation. This does not change// any apps that explicitly set landscape, but does cause sensors be ignored,// and ignored any orientation lock that the user has set (this conditional// should remain above the ORIENTATION_LOCKED conditional below).preferredRotation = mPortraitRotation;} else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {// Application just wants to remain locked in the last rotation.preferredRotation = lastRotation;} else if (!mSupportAutoRotation) {if (mFixedToUserRotation == IWindowManager.FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTATION) {preferredRotation = mUserRotation;} else {// If we don't support auto-rotation then bail out here and ignore// the sensor and any rotation lock settings.preferredRotation = -1;}} else if (((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE|| isTabletopAutoRotateOverrideEnabled())&& (orientation == ActivityInfo.SCREEN_ORIENTATION_USER|| orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED|| orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE|| orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT|| orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))|| orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR|| orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR|| orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE|| orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {// Otherwise, use sensor only if requested by the application or enabled// by default for USER or UNSPECIFIED modes.  Does not apply to NOSENSOR.boolean allowed = true;if (orientation != ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR&& orientation != ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {allowed = RotationPolicy.isRotationAllowed(sensorRotation, mUserRotationAngles,getAllowAllRotations() != ALLOW_ALL_ROTATIONS_DISABLED);}if (allowed) {preferredRotation = sensorRotation;} else {preferredRotation = lastRotation;}} else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED&& orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR&& orientation != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE&& orientation != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT&& orientation != ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE&& orientation != ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {// Apply rotation lock. Does not apply to NOSENSOR or specific rotations.// The idea is that the user rotation expresses a weak preference for the direction// of gravity and as NOSENSOR is never affected by gravity, then neither should// NOSENSOR be affected by rotation lock (although it will be affected by docks).// Also avoid setting user rotation when app has preference over one particular rotation// to avoid leaving the rotation to the reverse of it which has the compatible// orientation, but isn't what app wants, when the user rotation is the reverse of the// preferred rotation.preferredRotation = mUserRotation;} else {// No overriding preference.// We will do exactly what the application asked us to do.preferredRotation = -1;}switch (orientation) {case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:// Return portrait unless overridden.if (isAnyPortrait(preferredRotation)) {return preferredRotation;}return mPortraitRotation;case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:// Return landscape unless overridden.if (isLandscapeOrSeascape(preferredRotation)) {return preferredRotation;}return mLandscapeRotation;case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:// Return reverse portrait unless overridden.if (isAnyPortrait(preferredRotation)) {return preferredRotation;}return mUpsideDownRotation;case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:// Return seascape unless overridden.if (isLandscapeOrSeascape(preferredRotation)) {return preferredRotation;}return mSeascapeRotation;case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:// Return either landscape rotation.if (isLandscapeOrSeascape(preferredRotation)) {return preferredRotation;}if (isLandscapeOrSeascape(lastRotation)) {return lastRotation;}return mLandscapeRotation;case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:// Return either portrait rotation.if (isAnyPortrait(preferredRotation)) {return preferredRotation;}if (isAnyPortrait(lastRotation)) {return lastRotation;}return mPortraitRotation;default:// For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,// just return the preferred orientation we already calculated.if (preferredRotation >= 0) {return preferredRotation;}return Surface.ROTATION_0;}}

这里是传入一个配置的选装方法和当前的方法,来判断后面要进行旋转的操作,我们Activity没有配置横竖屏的时候传入的
orientation都是SCREEN_ORIENTATION_UNSPECIFIED(-1),不过我们强制横屏可以不考虑这么多,加一个方法判断即可。

 boolean isTopActivityIsMyPackage(){try {Task rootTask = mDisplayContent.getTopRootTask();if(rootTask!=null&&rootTask.hasChild()&&rootTask.getChildAt(0) instanceof ActivityRecord){return  ((ActivityRecord) rootTask.getChildAt(0)).packageName.equals("com.example.cloudclient");}}catch (Exception e){return false;}return false;}

这里的包名换成自己的就行,然后编译打包重启

make -j12 services
adb push lineageos/out/target/product/blueline/system/framework/services.jar /system/framework/services.jar

在这里插入图片描述

相关文章:

Lineageos 22.1(Android 15)制定应用强制横屏

一、前言 有时候需要系统的某个应用强制衡平显示&#xff0c;不管他是如何配置的。我们只需要简单的拿到top的Task下面的ActivityRecord&#xff0c;并判断包名来强制实现。 二、调整wms com.android.server.wm.DisplayRotation /*** Given an orientation constant, return…...

【Python】【PyQt5】设置事件绑定(例为按钮点击显示提示框)

前言 上篇文章我们讲了如何创作一个UI界面&#xff0c;并将其使用代码显示出来&#xff0c;这篇文章我们来讲讲事件的绑定 为增加文章趣味性&#xff0c;此篇文章我们将以点击窗口中的按钮来后并显示一个提示框 修改上次代码&#xff08;优化&#xff09; 上篇文章我所讲的要…...

node-ddk, electron组件, 自定义本地文件协议,打开本地文件

node-ddk 文件协议 https://blog.csdn.net/eli960/article/details/146207062 也可以下载demo直接演示 http://linuxmail.cn/go#node-ddk 安全 考虑到安全, 本系统禁止使用 file:/// 在主窗口, 自定义文件协议,可以多个 import main, { NODEDDK } from "node-ddk/m…...

SpringBoot-3-JWT令牌

目录 引入 引入依赖 拦截器 创建工具类 创建拦截器的包及拦截器 注册拦截器 修改一下登录成功后token的代码 测试 引入 试想一下&#xff0c;以上我们的访问都是直接访问对应的接口。比如说用户登录的时候就访问登录的接口。 那么如果有人他不访问你的登录接口&#…...

ChatGPT vs DeepSeek vs Copilot vs Claude:谁将问鼎AI王座?

李升伟 整理 2025年的人工智能领域创新涌动&#xff0c;ChatGPT、DeepSeek、Copilot和Claude四大模型各领风骚。这些AI系统各具特色&#xff0c;分别专注于编程、创意写作、技术推理和AI伦理等不同领域。本文将深入解析这些AI模型的功能特性及其优势领域。 核心AI模型解析 C…...

git使用经验(一)

git使用经验&#xff08;一&#xff09; 我之前已经下载了别人的代码&#xff0c;我想在此基础上进行修改&#xff0c;并移动到自己的私有仓库&#xff0c;方便上传到自己的私有仓库自己进行版本控制 git clone下来别人的代码&#xff0c;删除有关git的隐藏文件 进入到自己的…...

文件上传的小点总结

1.文件上传漏洞 服务器端脚本语言对上传文件没有严格的验证和过滤&#xff0c;就可以给攻击者上传恶意脚本文件的可能。 文件上传检测绕过&#xff1a; 简单思路&#xff1a;&#xff08;这里以前端上传图片为例&#xff09; ①开启phpstudy&#xff0c;启动apache即可&…...

基于WebRtc,GB28181,Rtsp/Rtmp,SIP,JT1078,H265/WEB融合视频会议接入方案

智能融合视频会议系统方案—多协议、多场景、全兼容的一站式视频协作平台 OvMeet,LiveMeet针对用户​核心痛点实现功能与用户价值 &#xff0c;Web平台实现MCU多协议&#xff0c;H265/H264等不同编码监控&#xff0c;直播&#xff0c;会议&#xff0c;调度资源统一融合在一套界…...

Python常用库全解析:从数据处理到机器学习

适合人群&#xff1a;Python初学者 | 数据分析师 | 机器学习爱好者 目录 一、NumPy&#xff1a;科学计算的核心库 1. 核心功能 2. 应用领域 3. 常用方法示例 二、Pandas&#xff1a;数据分析的瑞士军刀 1. 核心功能 2. 应用领域 3. 常用方法示例 三、Matplotlib&#…...

基于漂浮式海上风电场系统的浮式风力发电机matlab仿真

目录 1.课题概述 2.系统仿真结果 3.核心程序与模型 4.系统原理简介 5.完整工程文件 1.课题概述 基于漂浮式海上风电场系统的浮式风力发电机matlab仿真&#xff0c;通过MATLAB数值仿真对浮式风力发电机的性能做模拟与仿真。 2.系统仿真结果 3.核心程序与模型 版本&#x…...

深入探索ArkUI中的@LocalBuilder装饰器:构建高效可维护的UI组件

在ArkUI框架中&#xff0c;组件化开发是提升代码复用性和维护性的关键手段。随着项目复杂度的增加&#xff0c;开发者常常面临如何在保持组件封装性的同时&#xff0c;灵活处理组件内部逻辑的问题。传统的Builder装饰器虽然提供了强大的自定义构建能力&#xff0c;但在某些场景…...

【QA】外观模式在Qt中有哪些应用?

1. QWidget及其布局管理系统 外观模式体现 QWidget 是Qt中所有用户界面对象的基类&#xff0c;而布局管理系统&#xff08;如 QVBoxLayout、QHBoxLayout、QGridLayout 等&#xff09;就像是一个外观类。客户端代码&#xff08;开发者编写的界面代码&#xff09;通常不需要直接…...

在ASP.NET Core中使用NLog:配置与性能优化指南

在ASP.NET Core中使用NLog&#xff1a;配置与性能优化指南 在ASP.NET Core中使用NLog&#xff1a;配置与性能优化指南1. 安装NLog包2. 基础配置2.1 创建nlog.config文件2.2 程序启动配置 3. 在代码中使用日志4. 性能优化配置4.1 异步日志处理4.2 自动清理旧日志4.3 缓冲写入优化…...

yaffs

YAFFS&#xff08;Yet Another Flash File System&#xff09;是专为NAND闪存设计的日志结构文件系统&#xff0c;其核心原理围绕NAND闪存的特性优化数据管理。以下是其关键原理的详细说明&#xff1a; 1. NAND闪存适配 写入限制&#xff1a;NAND闪存需按页写入&#xff08;通…...

快速查询手机是否处于联网状态?

手机是否处于联网状态对于我们日常生活中的沟通、工作和娱乐都至关重要。有时候我们需要迅速了解一个手机号码的在网状态&#xff0c;例如是正常使用、停机、不在网等。而要实现这一功能&#xff0c;我们可以利用挖数据平台提供的在线查询工具&#xff0c;通过API接口来查询手机…...

使用 .NET Core 的本地 DeepSeek-R1

使用 .NET 在我的 MacBook Pro 上与当地 LLM 聊天的历程。 如今&#xff0c;只需使用浏览器即可轻松使用 ChatGPT 或其他 genAI。作为开发人员&#xff0c;我们可以通过直接集成 OpenAI API 等来做更复杂的事情。如果我们想在自己的机器上运行 LLM&#xff0c;只是为了找人聊天…...

LeetCode 206 Reverse Linked List 反转链表 Java

举例1&#xff1a; 输入&#xff1a; [1,2,3,4,5]&#xff0c; 输出&#xff1a; [5,4,3,2,1]. 举例2&#xff1a; 输入&#xff1a; [] 输出&#xff1a;[] 思路&#xff1a;方法有三种&#xff0c;分别是递归&#xff0c;栈&#xff0c;双指针&#xff0c;本篇使用栈&a…...

SQL Server查询计划操作符(7.3)——查询计划相关操作符(11)

7.3. 查询计划相关操作符 98&#xff09;Table Scan&#xff1a;该操作符从查询计划参数列确定的表中获取所有数据行。如果其参数列中出现WHERE:()谓词&#xff0c;则只返回满足该谓词的数据行。该操作符为逻辑操作符和物理操作符。该操作符具体如图7.3-98节点1所示。 图 7.3-…...

xy轴不等比缩放问题——AUTOCAD c#二次开发

在 AutoCAD .net api里&#xff0c;部分实体&#xff0c;像文字、属性、插入块等&#xff0c;是不支持非等比缩放的。 如需对AutoCAD中图形进行xyz方向不等比缩放&#xff0c;则需进行额外的函数封装。 选择图元&#xff0c;指定缩放基准点&#xff0c;scaleX 0.5, scaleY …...

【原创首发】开源基于AT32 SIP/VOIP电话

前言 本次为了反馈各位粉丝的关注&#xff0c;特此分享 AT32_VOIP 工程&#xff0c;此功能其实跟我之前发过的《STM32F429的VOIP功能》是一样的&#xff0c;只是用了AT32F437。 其实那个工程是一个比较Demo中的Demo&#xff0c;很多功能和硬件依赖性太大了。后面项目中发现AT…...

本地部署 LangManus

本地部署 LangManus 0. 引言1. 部署 LangManus2. 部署 LangManus Web UI 0. 引言 LangManus 是一个社区驱动的 AI 自动化框架&#xff0c;它建立在开源社区的卓越工作基础之上。我们的目标是将语言模型与专业工具&#xff08;如网络搜索、爬虫和 Python 代码执行&#xff09;相…...

一篇文章入门Python Flask框架前后端数据库开发实践(pycharm在anaconda环境下)

Python Flask 是一个轻量级的 Web 应用框架&#xff0c;也被称为微框架。它以简洁、灵活和易于上手的特点而受到开发者的喜爱。 核心特点 轻量级&#xff1a;Flask 核心代码简洁&#xff0c;仅包含 Web 开发的基本功能&#xff0c;不强制使用特定的数据库、模板引擎等&#xf…...

SpringBoot分布式定时任务实战:告别重复执行的烦恼

场景再现&#xff1a;你刚部署完基于SpringBoot的集群服务&#xff0c;凌晨3点突然收到监控告警——优惠券发放量超出预算两倍&#xff01;检查日志发现&#xff0c;两个节点同时执行了定时任务。这种分布式环境下的定时任务难题&#xff0c;该如何彻底解决&#xff1f; 本文将…...

AI+金融 应用 使用DeepSeek、Qwen等大模型输入自然语言,得到通达信等行情软件公式代码,导入后使用

AI金融 应用 使用DeepSeek、Qwen等大模型输入自然语言&#xff0c;得到通达信等行情软件公式代码&#xff0c;导入后使用。不会编程&#xff0c;也能行情软件中实现个性化条件选股&#xff0c;个性化技术指标。 AIbxm低估值趋势选股策略&#xff0c;参考提示词&#xff1a; 编…...

C++20 中的同步输出流:`std::basic_osyncstream` 深入解析与应用实践

文章目录 一、std::basic_osyncstream 的背景与动机二、std::basic_osyncstream 的基本原理三、std::basic_osyncstream 的使用方法&#xff08;一&#xff09;基本用法&#xff08;二&#xff09;多线程环境下的使用&#xff08;三&#xff09;与文件流的结合 四、std::basic_…...

Android 关于compose的一些坑和理解

** 1.如何在 WindowManager.addView 中使用 Jetpack Compose** 一、引出问题 Android 开发中&#xff0c;很常见的一个场景&#xff0c;通过 WindowManager.addView() 添加一个 View 到屏幕上。Android 最新的视图框架 Jetpack Compose&#xff0c;如何应用进来。这个被添加的…...

LeetCode 30 —— 30.串联所有单词的子串

题目&#xff1a; 给定一个字符串 s 和一些长度相同的单词 words。找出 s 中恰好可以由 words 中所有单词串联形成的子串的起始位置。 注意子串要与 words 中的单词完全匹配&#xff0c;中间不能有其他字符&#xff0c;但不需要考虑 words 中单词串联的顺序。 示例 1&#xff…...

go语言中的strings库

strings库 func EqualFold func EqualFold(s, t string) bool判断两个utf-8编码字符串&#xff08;将unicode大写、小写、标题三种格式字符视为相同&#xff09;是否相同。 func main() {fmt.Println(strings.EqualFold("hello", "hello")) //truefmt.…...

【嵌入式硬件】三款DCDC调试笔记

关于开关电源芯片&#xff0c;重点关注输入电源范围、输出电流、最低压降。 1.MP9943: 以MP9943为例&#xff0c;输入电压范围4-36V&#xff0c;输出最大电流3A&#xff0c;最低压降为0.3V 调整FB使正常输出为5.06V 给定6V空载、5V空载、5V带2A负载的情况&#xff1a; 6V带2A…...

Cannot find module @rollup/rollup-win32-x64-msvc

方法1 在package.json中添加postinstall: "scripts": {"postinstall": "node -e \"const { platform } process; if (platform win32) { require(child_process).execSync(npm install rollup/rollup-win32-x64-msvc, { stdio: inherit });…...