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

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/38012.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

HTML网页代码预览器

HTML网页代码预览器 可以用于学习和实验HTML和CSS&#xff0c;比较方便。源码参考自网络。 功能 实时预览&#xff1a;当你在左侧的“代码编辑器”中输入代码时&#xff0c;右侧的“预览窗口”会实时显示你的网页效果&#xff08;注意&#xff0c;不能体现嵌入的JavaScript运…

Arm Linux ceres库编译

由于工作需要&#xff0c;需在国产化系统上编译ceres库&#xff0c;手上有一块树莓派&#xff0c;就在树莓派上面进行测试编译ceres库&#xff0c;总体来说比较顺利。只出现了一点小问题 参考链接&#xff1a; Ceres中文教程-安装 按照上面Linux编译过程 目录 1、在线安装依赖…

【算法学习计划】动态规划 -- 背包问题(01背包和完全背包)

目录 DP41 【模板】01背包 leetcode 416.分割等和子集 leetcode 494.目标和 leetcode 1049.最后一块石头的重量Ⅱ DP42 【模板】完全背包 leetcode 322.零钱兑换 leetcode 518.零钱兑换Ⅱ leetcode 279.完全平方数 今天&#xff0c;我们将通过 8 道题目&#xff0c;来带…

138. 随机链表的复制

题目&#xff1a; 给你一个长度为 n 的链表&#xff0c;每个节点包含一个额外增加的随机指针 random &#xff0c;该指针可以指向链表中的任何节点或空节点。 构造这个链表的 深拷贝。 深拷贝应该正好由 n 个 全新 节点组成&#xff0c;其中每个新节点的值都设为其对应的原节…

网络HTTPS协议

Https HTTPS&#xff08;Hypertext Transfer Protocol Secure&#xff09;是 HTTP 协议的加密版本&#xff0c;它使用 SSL/TLS 协议来加密客户端和服务器之间的通信。具体来说&#xff1a; • 加密通信&#xff1a;在用户请求访问一个 HTTPS 网站时&#xff0c;客户端&#x…

19921 多重背包

19921 多重背包 ⭐️难度&#xff1a;中等 &#x1f31f;考点&#xff1a;动态规划、背包问题 &#x1f4d6; &#x1f4da; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner;public class Main {static int N …

C/C++蓝桥杯算法真题打卡(Day5)

一、P8772 [蓝桥杯 2022 省 A] 求和 - 洛谷 算法代码&#xff1a; #include<bits/stdc.h> // 包含标准库中的所有头文件&#xff0c;方便编程 using namespace std; // 使用标准命名空间&#xff0c;避免每次调用标准库函数时都要加 std::int main() {int n; …

【大模型基础_毛玉仁】3.5 Prompt相关应用

目录 3.5 相关应用3.5.1 基于大语言模型的Agent3.5.2 数据合成3.5.3 Text-to-SQL3.5.4 GPTs 3.5 相关应用 Prompt工程应用广泛&#xff0c;能提升大语言模型处理基础及复杂任务的能力&#xff0c;在构建Agent、数据合成、Text-to-SQL转换和设计个性化GPTs等方面不可或缺。 . …

主成分分析PCA与奇异值分解SVD

线性代数 SVD 奇异值分解&#xff08;Singular Value Decomposition&#xff0c;简称 SVD&#xff09;是线性代数中的一种基本工具&#xff0c;它将任意一个 (m * n) 矩阵 (A) 分解成三个简单矩阵的乘积&#xff0c;即 其中&#xff1a; (U) 是一个 (m*m) 的正交&#xff08…

自主代理的摩尔定律:AI 的指数级革命

图像由 Gemini 生成 前言&#xff1a;AI 正在以超过摩尔定律的速度迅速提升其自主工作能力&#xff0c;研究显示&#xff0c;AI 能够可靠完成的任务时长正以每 7 个月翻一倍的速度增长。这种指数级的发展趋势意味着&#xff0c;AI 不再只是应对简单问答或短任务的工具&#xff…

气膜文化馆:打造沉浸式文娱新空间—轻空间

演唱会、展览、音乐剧……都能办&#xff1f; 当然&#xff01;气膜文化馆不仅适用于体育赛事&#xff0c;在文化娱乐方面同样大放异彩&#xff01; 声学优化&#xff0c;打造极致听觉体验 气膜文化馆采用专业声学设计&#xff0c;避免传统场馆的回声干扰&#xff0c;提供更清…

【数据标准】数据标准化框架体系-对象类数据标准

导读&#xff1a;对象类数据标准化框架通过统一数据定义、分类和标记&#xff0c;解决数据孤岛与不一致问题&#xff0c;支撑数据分析、AI应用与合规需求。企业需结合自身业务特性&#xff0c;灵活选择国际标准&#xff08;如ISO&#xff09;、行业规范或自建体系&#xff0c;并…

【江协科技STM32】软件SPI读写W25Q64芯片(学习笔记)

SPI通信协议及S为5Q64简介&#xff1a;【STM32】SPI通信协议&W25Q64Flash存储器芯片&#xff08;学习笔记&#xff09;-CSDN博客 STM32与W25Q64模块接线&#xff1a; SPI初始化&#xff1a; 片选SS、始终SCK、MOSI都是主机输出引脚&#xff0c;输出引脚配置为推挽输出&…

C 语 言 --- 扫 雷 游 戏(初 阶 版)

C 语 言 --- 扫 雷 游 戏 初 阶 版 代 码 全 貌 与 功 能 介 绍扫雷游戏的功能说明游 戏 效 果 展 示游 戏 代 码 详 解game.htest.cgame.c 总结 &#x1f4bb;作 者 简 介&#xff1a;曾 与 你 一 样 迷 茫&#xff0c;现 以 经 验 助 你 入 门 C 语 言 &#x1f4a1;个 人 主…

数据库基础知识

目录 一、什么是数据库&#xff1f; 二、基本使用方法 &#xff08;1&#xff09;启动服务器进程 &#xff08;2&#xff09;连接服务器 &#xff08;3&#xff09;基本sql语句 三、MySQL架构 四、SQL语句分类 五、存储引擎是什么 一、什么是数据库&#xff1f; 数据库…

在线生成自定义二维码

在线生成自定义二维码 1. 引言 二维码已成为现代互联网的重要工具&#xff0c;广泛应用于链接分享、支付、身份认证等场景。然而&#xff0c;很多在线二维码生成工具功能有限&#xff0c;难以满足个性化需求。如果你需要 自定义颜色、Logo、不同形状的二维码&#xff0c;那么…

DeepSeek处理多模态数据的技术要点和实现方式

DeepSeek具备处理多模态数据的能力&#xff0c;以下是相关技术要点和实现方式。 1. ‌多模态模型架构‌ ‌单流/双流网络‌&#xff1a;通过将文本和图像输入统一编码器&#xff08;单流&#xff09;或分别编码后交互&#xff08;双流&#xff09;实现模态融合‌。‌预训练模…

系统架构设计知识体系总结

1.技术选型 1.什么是技术选型&#xff1f; 技术选型是指评估和选择在项目或系统开发中使用的最合适的技术和工具的过程。这涉及考虑基于其能力、特性、与项目需求的兼容性、可扩展性、性能、维护和其他因素的各种可用选项。技术选型的目标是确定与项目目标相符合、能够有效解…

数智读书笔记系列022《算力网络-云网融合2.0时代的网络架构与关键技术》读书笔记

一、书籍核心价值与定位 1.1 书籍概述:中国联通研究院的权威之作 《算力网络 —— 云网融合 2.0 时代的网络架构与关键技术》由中国联通研究院算力网络攻关团队精心撰写,是业界首部系统性探讨云网融合 2.0 与算力网络的专著。在云网融合从 1.0 迈向 2.0 的关键节点,本书的…

知识图谱中NLP新技术

知识图谱与自然语言处理&#xff08;NLP&#xff09;的结合是当前人工智能领域的前沿方向&#xff0c;其技术发展呈现多维度融合与场景深化的特点。以下从核心技术突破、应用场景创新及未来趋势三个层面&#xff0c;系统梳理知识图谱中NLP的最新进展&#xff1a; 一、核心技术突…