aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorraghavt20 <raghavtandon2000@gmail.com>2019-11-22 02:18:10 +0100
committernebrassy <nebras30@gmail.com>2022-06-12 16:31:01 +0200
commit524470415e7e6558d8de8888c414e12cffa101ae (patch)
tree5b8a88d9e2d96102cd5fd15193046f6be4090b51
parent4984c90e8f071fae23798ed15dcc9530030a14b0 (diff)
[SQUASH] vayu: parts: introduce FPS counter QS Tile
Squash of the following: vayu: parts: introduce FPS overlay vayu: parts: adapt FPS Info based on exposed data from kernel * Current kernel emits measured_fps inside /sys/class/drm/card0/sde-crtc-0. It also has a different output format than the original patches. So adapt it so measured fps can be displayed properly. * Shift position by 50px more so the fps counter is 100% visible without getting cutted by the hardware corner. * Also, cleanup some unused imports and redundant file reader since we're already has that inside utils/. vayu: parts: Add FPS overlay QS tile vayu: parts: Digital-style icon for FPSInfo QS Tile vayu: parts: FPSInfoService: Switch to isDreaming check Co-authored-by: Nauval Rizky <enuma.alrizky@gmail.com> Co-authored-by: Marko Man <darkobas@gmail.com> Co-authored-by: Ido Ben-Hur <idoybh2@gmail.com> Signed-off-by: raghavt20 <raghavtandon2000@gmail.com> Change-Id: I2545fcda587098407d711c53c831daeb67cd4b3d
-rw-r--r--parts/AndroidManifest.xml16
-rw-r--r--parts/res/drawable/ic_fps.xml30
-rw-r--r--parts/res/values/strings.xml3
-rw-r--r--parts/src/org/lineageos/settings/fpsinfo/FPSInfoService.java288
-rw-r--r--parts/src/org/lineageos/settings/fpsinfo/FPSTileService.java66
-rw-r--r--rootdir/etc/init.qcom.rc6
-rw-r--r--sepolicy/vendor/genfs_contexts3
-rw-r--r--sepolicy/vendor/system_app.te3
8 files changed, 415 insertions, 0 deletions
diff --git a/parts/AndroidManifest.xml b/parts/AndroidManifest.xml
index cc3abe5..d56853d 100644
--- a/parts/AndroidManifest.xml
+++ b/parts/AndroidManifest.xml
@@ -79,6 +79,22 @@
android:permission="XiaomiDozeService">
</service>
+ <service
+ android:name=".fpsinfo.FPSInfoService"
+ android:exported="false">
+ </service>
+
+ <service
+ android:name=".fpsinfo.FPSTileService"
+ android:icon="@drawable/ic_fps"
+ android:label="@string/fps_info_title"
+ android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
+ <intent-filter>
+ <action
+ android:name="android.service.quicksettings.action.QS_TILE"/>
+ </intent-filter>
+ </service>
+
<activity
android:name=".doze.DozeSettingsActivity"
android:label="@string/ambient_display_title"
diff --git a/parts/res/drawable/ic_fps.xml b/parts/res/drawable/ic_fps.xml
new file mode 100644
index 0000000..ac01639
--- /dev/null
+++ b/parts/res/drawable/ic_fps.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 Chaldeastudio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:pathData="m10.428,5.7129 l-0.5254,1.3984v3.666l1.0488,1.0488 0.3496,-0.3496v-4.8906c-0.1164,-0.4656 -0.4074,-0.7566 -0.873,-0.873zM14.0979,11.3008 L13.3987,12 14.0979,12.6992h4.5391l0.6992,-0.6992 -0.6992,-0.6992h-4.5391z"
+ android:fillColor="#000"
+ android:fillAlpha="0.25"/>
+ <path
+ android:pathData="m4.8594,5.7129c-0.4656,0.1164 -0.7566,0.4074 -0.873,0.873l1.3965,0.5254h4.1738l0.5234,-1.3984zM13.5899,5.7129c-0.4656,0.1164 -0.7566,0.4074 -0.873,0.873l1.3965,0.5254h4.1738l0.5234,-1.3984zM19.1602,5.7129 L18.6348,7.1113v3.666l1.0488,1.0488 0.3496,-0.3496v-4.8906c-0.1164,-0.4656 -0.4074,-0.7566 -0.873,-0.873zM3.9672,6.9356v4.541l0.3496,0.3496 1.0488,-1.0488v-3.3164zM12.6996,6.9356v4.541l0.3477,0.3496 1.0488,-1.0488v-3.3164zM5.3656,11.3008 L4.6664,12 5.3656,12.6992h4.5391l0.6992,-0.6992 -0.6992,-0.6992zM4.3168,12.1739 L3.9672,12.5235v4.541l1.3984,-0.5254v-3.3164zM10.9535,12.1739 L9.9047,13.2227v3.666l0.5234,1.3984c0.4656,-0.1164 0.7566,-0.4074 0.873,-0.873v-4.8906zM13.0473,12.1739 L12.6996,12.5235v4.541l1.3965,-0.5254v-3.3164zM19.684,12.1739 L18.6352,13.2227v3.666l0.5254,1.3984c0.4656,-0.1164 0.7566,-0.4074 0.873,-0.873v-4.8906zM5.366,16.8886 L3.9676,17.414c0.1164,0.4656 0.4074,0.7566 0.873,0.873h5.2402l-0.5254,-1.3984zM14.0965,16.8886 L12.7,17.414c0.1164,0.4656 0.4074,0.7566 0.873,0.873h5.2383l-0.5234,-1.3984z"
+ android:fillColor="#000"/>
+</vector>
diff --git a/parts/res/values/strings.xml b/parts/res/values/strings.xml
index 9929968..9c8e233 100644
--- a/parts/res/values/strings.xml
+++ b/parts/res/values/strings.xml
@@ -163,4 +163,7 @@
<!-- Menu -->
<string name="kcal_presets">@string/presets_dialog_title</string>
<string name="kcal_reset">Reset</string>
+
+ <!-- FPS Counter -->
+ <string name="fps_info_title">FPS Counter</string>
</resources>
diff --git a/parts/src/org/lineageos/settings/fpsinfo/FPSInfoService.java b/parts/src/org/lineageos/settings/fpsinfo/FPSInfoService.java
new file mode 100644
index 0000000..1e39a0b
--- /dev/null
+++ b/parts/src/org/lineageos/settings/fpsinfo/FPSInfoService.java
@@ -0,0 +1,288 @@
+/*
+ * Copyright (C) 2019 The OmniROM Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.lineageos.settings.fpsinfo;
+
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.PixelFormat;
+import android.graphics.Typeface;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.service.dreams.DreamService;
+import android.service.dreams.IDreamManager;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.View;
+import android.view.WindowManager;
+
+import java.lang.Math;
+import java.lang.StringBuffer;
+
+import org.lineageos.settings.utils.FileUtils;;
+
+public class FPSInfoService extends Service {
+ private View mView;
+ private Thread mCurFPSThread;
+ private final String TAG = "FPSInfoService";
+ private String mFps = null;
+
+ private static final String MEASURED_FPS = "/sys/class/drm/card0/sde-crtc-0/measured_fps";
+
+ private IDreamManager mDreamManager;
+
+ private class FPSView extends View {
+ private Paint mOnlinePaint;
+ private float mAscent;
+ private int mFH;
+ private int mMaxWidth = 0;
+
+ private int mNeededWidth;
+ private int mNeededHeight;
+
+ private boolean mDataAvail;
+
+ private Handler mCurFPSHandler = new Handler() {
+ public void handleMessage(Message msg) {
+ if(msg.obj == null || msg.what != 1) {
+ return;
+ }
+
+ String msgData = (String) msg.obj;
+ msgData = msgData.trim().split("\\s+")[1];
+ mFps = msgData + " FPS";
+ mDataAvail = true;
+ updateDisplay();
+ }
+ };
+
+ FPSView(Context c) {
+ super(c);
+ float density = c.getResources().getDisplayMetrics().density;
+ int paddingPx = Math.round(5 * density);
+ setPadding(paddingPx, paddingPx, paddingPx, paddingPx);
+ setBackgroundColor(Color.argb(0x60, 0, 0, 0));
+
+ final int textSize = Math.round(12 * density);
+
+ Typeface typeface = Typeface.create("monospace", Typeface.NORMAL);
+
+ mOnlinePaint = new Paint();
+ mOnlinePaint.setTypeface(typeface);
+ mOnlinePaint.setAntiAlias(true);
+ mOnlinePaint.setTextSize(textSize);
+ mOnlinePaint.setColor(Color.WHITE);
+ mOnlinePaint.setShadowLayer(5.0f, 0.0f, 0.0f, Color.BLACK);
+
+ mAscent = mOnlinePaint.ascent();
+ float descent = mOnlinePaint.descent();
+ mFH = (int)(descent - mAscent + .5f);
+
+ updateDisplay();
+ }
+
+ @Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ }
+
+ @Override
+ protected void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
+ mCurFPSHandler.removeMessages(1);
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ setMeasuredDimension(resolveSize(mNeededWidth, widthMeasureSpec),
+ resolveSize(mNeededHeight, heightMeasureSpec));
+ }
+
+ private String getFPSInfoString() {
+ return mFps;
+ }
+
+ @Override
+ public void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ if (!mDataAvail) {
+ return;
+ }
+
+ final int W = mNeededWidth;
+ final int LEFT = getWidth()-1;
+
+ int x = LEFT - mPaddingLeft;
+ int top = mPaddingTop + 2;
+ int bottom = mPaddingTop + mFH - 2;
+
+ int y = mPaddingTop - (int)mAscent;
+
+ String s=getFPSInfoString();
+ canvas.drawText(s, LEFT-mPaddingLeft-mMaxWidth,
+ y-1, mOnlinePaint);
+ y += mFH;
+ }
+
+ void updateDisplay() {
+ if (!mDataAvail) {
+ return;
+ }
+
+ if (mOnlinePaint != null) {
+ mMaxWidth = (int) mOnlinePaint.measureText(mFps);
+ }
+
+ int neededWidth = mPaddingLeft + mPaddingRight + mMaxWidth;
+ int neededHeight = mPaddingTop + mPaddingBottom + 40;
+ if (neededWidth != mNeededWidth || neededHeight != mNeededHeight) {
+ mNeededWidth = neededWidth;
+ mNeededHeight = neededHeight;
+ requestLayout();
+ } else {
+ invalidate();
+ }
+ }
+
+ public Handler getHandler(){
+ return mCurFPSHandler;
+ }
+ }
+
+ protected class CurFPSThread extends Thread {
+ private boolean mInterrupt = false;
+ private Handler mHandler;
+
+ public CurFPSThread(Handler handler){
+ mHandler=handler;
+ }
+
+ public void interrupt() {
+ mInterrupt = true;
+ }
+
+ @Override
+ public void run() {
+ try {
+ while (!mInterrupt) {
+ sleep(1000);
+ StringBuffer sb=new StringBuffer();
+ String fpsVal = FileUtils.readOneLine(MEASURED_FPS);
+ mHandler.sendMessage(mHandler.obtainMessage(1, fpsVal));
+ }
+ } catch (InterruptedException e) {
+ return;
+ }
+ }
+ };
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+
+ mView = new FPSView(this);
+ WindowManager.LayoutParams params = new WindowManager.LayoutParams(
+ WindowManager.LayoutParams.WRAP_CONTENT,
+ WindowManager.LayoutParams.WRAP_CONTENT,
+ WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY,
+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
+ WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
+ PixelFormat.TRANSLUCENT);
+ params.y = 50;
+ params.gravity = Gravity.LEFT | Gravity.TOP;
+ params.setTitle("FPS Info");
+
+ startThread();
+
+ mDreamManager = IDreamManager.Stub.asInterface(
+ ServiceManager.checkService(DreamService.DREAM_SERVICE));
+ IntentFilter screenStateFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
+ screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF);
+ registerReceiver(mScreenStateReceiver, screenStateFilter);
+
+ WindowManager wm = (WindowManager)getSystemService(WINDOW_SERVICE);
+ wm.addView(mView, params);
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ stopThread();
+ ((WindowManager)getSystemService(WINDOW_SERVICE)).removeView(mView);
+ mView = null;
+ unregisterReceiver(mScreenStateReceiver);
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ private BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
+ Log.d(TAG, "ACTION_SCREEN_ON " + isDozeMode());
+ if (!isDozeMode()) {
+ startThread();
+ mView.setVisibility(View.VISIBLE);
+ }
+ } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
+ Log.d(TAG, "ACTION_SCREEN_OFF");
+ mView.setVisibility(View.GONE);
+ stopThread();
+ }
+ }
+ };
+
+ private boolean isDozeMode() {
+ try {
+ if (mDreamManager != null && mDreamManager.isDreaming()) {
+ return true;
+ }
+ } catch (RemoteException e) {
+ return false;
+ }
+ return false;
+ }
+
+ private void startThread() {
+ Log.d(TAG, "started CurFPSThread");
+ mCurFPSThread = new CurFPSThread(mView.getHandler());
+ mCurFPSThread.start();
+ }
+
+ private void stopThread() {
+ if (mCurFPSThread != null && mCurFPSThread.isAlive()) {
+ Log.d(TAG, "stopping CurFPSThread");
+ mCurFPSThread.interrupt();
+ try {
+ mCurFPSThread.join();
+ } catch (InterruptedException e) {
+ }
+ }
+ mCurFPSThread = null;
+ }
+}
diff --git a/parts/src/org/lineageos/settings/fpsinfo/FPSTileService.java b/parts/src/org/lineageos/settings/fpsinfo/FPSTileService.java
new file mode 100644
index 0000000..e11addb
--- /dev/null
+++ b/parts/src/org/lineageos/settings/fpsinfo/FPSTileService.java
@@ -0,0 +1,66 @@
+/**
+ * Copyright (C) 2020 DerpFest ROM
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.lineageos.settings.fpsinfo;
+
+import android.app.ActivityManager;
+import android.content.Intent;
+import android.os.Handler;
+import android.service.quicksettings.Tile;
+import android.service.quicksettings.TileService;
+
+// TODO: Add FPS drawables
+public class FPSTileService extends TileService {
+
+ private final String KEY_FPS_INFO = "fps_info";
+
+ private boolean isShowing = false;
+
+ public FPSTileService() { }
+
+ @Override
+ public void onStartListening() {
+ super.onStartListening();
+ ActivityManager manager =
+ (ActivityManager) getSystemService(this.ACTIVITY_SERVICE);
+ for (ActivityManager.RunningServiceInfo service :
+ manager.getRunningServices(Integer.MAX_VALUE)) {
+ if (FPSInfoService.class.getName().equals(
+ service.service.getClassName())) {
+ isShowing = true;
+ }
+ }
+ updateTile();
+ }
+
+ @Override
+ public void onClick() {
+ Intent fpsinfo = new Intent(this, FPSInfoService.class);
+ if (!isShowing)
+ this.startService(fpsinfo);
+ else
+ this.stopService(fpsinfo);
+ isShowing = !isShowing;
+ updateTile();
+ }
+
+ private void updateTile() {
+ final Tile tile = getQsTile();
+ tile.setState(isShowing ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
+ tile.updateTile();
+ }
+
+}
diff --git a/rootdir/etc/init.qcom.rc b/rootdir/etc/init.qcom.rc
index ebf38b1..0ef5f40 100644
--- a/rootdir/etc/init.qcom.rc
+++ b/rootdir/etc/init.qcom.rc
@@ -494,6 +494,12 @@ on property:vendor.media.target_variant=*
on property:vold.decrypt=trigger_restart_framework
start wcnss-service
+
+ # FPS Info permissions
+ chown system graphics /sys/class/drm/sde-crtc-0/measured_fps
+ chmod 0666 /sys/class/drm/sde-crtc-0/measured_fps
+
+ start vendor.qcom-post-boot
service vendor.qrtr-ns /vendor/bin/qrtr-ns -f
class core
diff --git a/sepolicy/vendor/genfs_contexts b/sepolicy/vendor/genfs_contexts
index ceb6dc6..3699114 100644
--- a/sepolicy/vendor/genfs_contexts
+++ b/sepolicy/vendor/genfs_contexts
@@ -135,3 +135,6 @@ genfscon sysfs /devices/virtual/misc/msm_qcelp/wakeup
genfscon sysfs /devices/virtual/misc/msm_wma/wakeup u:object_r:sysfs_wakeup:s0
genfscon sysfs /devices/virtual/misc/msm_wmapro/wakeup u:object_r:sysfs_wakeup:s0
genfscon sysfs /devices/platform/soc/884000.i2c/i2c-3/3-005a/wakeup u:object_r:sysfs_wakeup:s0
+
+# FPS Info
+genfscon sysfs /sys/devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/sde-crtc-0/measured_fps u:object_r:vendor_sysfs_graphics:s0
diff --git a/sepolicy/vendor/system_app.te b/sepolicy/vendor/system_app.te
index c4966ea..31528f2 100644
--- a/sepolicy/vendor/system_app.te
+++ b/sepolicy/vendor/system_app.te
@@ -6,3 +6,6 @@ allow system_app kcal_dev:dir search;
allow system_app kcal_dev:file rw_file_perms;
r_dir_file(system_app, vendor_sysfs_battery_supply)
+
+# Fps Info
+allow system_app vendor_sysfs_graphics:file { getattr open read };