sdm660-common: XiamiParts: Add FPS Info Overlay

* Ported from: https://github.com/Corvus-Devices/device_xiaomi_lavender.git

Signed-off-by: OdSazib <odsazib@gmail.com>
This commit is contained in:
OdSazib 2020-03-28 22:45:00 +06:00
parent 471da74c21
commit 7580f5f636
No known key found for this signature in database
GPG key ID: A2D2E5C18BB04462
12 changed files with 464 additions and 1 deletions

View file

@ -88,6 +88,22 @@
<action android:name="android.service.quicksettings.action.QS_TILE"/>
</intent-filter>
</service>
<service
android:name=".FPSInfoService"
android:exported="false">
</service>
<service
android:name=".FPSTileService"
android:icon="@drawable/ic_fps_info"
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>
</application>
</manifest>

View file

@ -0,0 +1,10 @@
<!-- drawable/fps_info.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
<path android:fillColor="#000000" android:pathData="M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,4A8,8 0 0,1 20,12C20,14.4 19,16.5 17.3,18C15.9,16.7 14,16 12,16C10,16 8.2,16.7 6.7,18C5,16.5 4,14.4 4,12A8,8 0 0,1 12,4M10,6A1,1 0 0,0 9,7A1,1 0 0,0 10,8A1,1 0 0,0 11,7A1,1 0 0,0 10,6M14,6A1,1 0 0,0 13,7A1,1 0 0,0 14,8A1,1 0 0,0 15,7A1,1 0 0,0 14,6M17.09,8.94C16.96,8.94 16.84,8.97 16.7,9L13.5,10.32L13.23,10.43C12.67,10 11.91,9.88 11.25,10.15C10.23,10.56 9.73,11.73 10.15,12.75C10.56,13.77 11.73,14.27 12.75,13.85C13.41,13.59 13.88,13 14,12.28L14.23,12.18L17.45,10.88L17.47,10.87C18,10.66 18.23,10.08 18.03,9.56C17.87,9.18 17.5,8.93 17.09,8.94M7,9A1,1 0 0,0 6,10A1,1 0 0,0 7,11A1,1 0 0,0 8,10A1,1 0 0,0 7,9Z" />
</vector>

View file

@ -94,4 +94,8 @@
<string name="edit_value">Choose new Value</string>
<string name="default_value">Default Value</string>
<string name="edit_hint">Value between %1$d and %2$d</string>
<!-- FPS Info -->
<string name="fps_info_title">FPS Overlay</string>
<string name="fps_info_summary">Show overlay with with current frames per second</string>
</resources>

View file

@ -66,6 +66,12 @@
android:targetClass="org.lineageos.settings.doze.DozeSettingsActivity"
android:targetPackage="org.lineageos.settings.doze" />
</Preference>
<SwitchPreference
android:key="fps_info"
android:icon="@drawable/ic_fps_info"
android:title="@string/fps_info_title"
android:summary="@string/fps_info_summary"
android:persistent="true" />
<Preference
android:key="device_jason"

View file

@ -20,6 +20,8 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
import org.lineageos.settings.device.kcal.Utils;
@ -29,6 +31,8 @@ public class BootReceiver extends BroadcastReceiver implements Utils {
public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
if (Settings.Secure.getInt(context.getContentResolver(), PREF_ENABLED, 0) == 1) {
FileUtils.setValue(KCAL_ENABLE, Settings.Secure.getInt(context.getContentResolver(),
PREF_ENABLED, 0));
@ -65,5 +69,10 @@ public class BootReceiver extends BroadcastReceiver implements Utils {
context.getContentResolver(), DeviceSettings.PREF_HALL_WAKEUP, 1) == 1 ? "Y" : "N");
FileUtils.setProp(DeviceSettings.HALL_WAKEUP_PROP, Settings.Secure.getInt(
context.getContentResolver(), DeviceSettings.PREF_HALL_WAKEUP, 1) == 1);
boolean enabled = sharedPrefs.getBoolean(DeviceSettings.PREF_KEY_FPS_INFO, false);
if (enabled) {
context.startService(new Intent(context, FPSInfoService.class));
}
}
}

View file

@ -22,6 +22,10 @@ import android.os.Bundle;
import androidx.preference.PreferenceFragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
import androidx.preference.SwitchPreference;
import org.lineageos.settings.device.kcal.KCalSettingsActivity;
import org.lineageos.settings.device.preferences.SecureSettingListPreference;
@ -41,6 +45,8 @@ public class DeviceSettings extends PreferenceFragment implements
public static final String CATEGORY_NOTIF = "notification_led";
public static final String PREF_NOTIF_LED = "notification_led_brightness";
public static final String NOTIF_LED_PATH = "/sys/class/leds/white/max_brightness";
public static final String PREF_KEY_FPS_INFO = "fps_info";
// value of vtg_min and vtg_max
public static final int MIN_VIBRATION = 116;
@ -67,10 +73,15 @@ public class DeviceSettings extends PreferenceFragment implements
private static final String PREF_DEVICE_JASON = "device_jason";
private SecureSettingListPreference mTHERMAL;
private static Context mContext;
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preferences_xiaomi_parts, rootKey);
mContext = this.getContext();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
if (FileUtils.fileWritable(NOTIF_LED_PATH)) {
NotificationLedSeekBarPreference notifLedBrightness =
@ -91,6 +102,10 @@ public class DeviceSettings extends PreferenceFragment implements
if (isAppNotInstalled(DEVICE_JASON_PACKAGE_NAME)) {
displayCategory.removePreference(findPreference(PREF_DEVICE_JASON));
}
SwitchPreference fpsInfo = (SwitchPreference) findPreference(PREF_KEY_FPS_INFO);
fpsInfo.setChecked(prefs.getBoolean(PREF_KEY_FPS_INFO, false));
fpsInfo.setOnPreferenceChangeListener(this);
Preference kcal = findPreference(PREF_DEVICE_KCAL);
@ -138,6 +153,16 @@ public class DeviceSettings extends PreferenceFragment implements
FileUtils.setProp(HALL_WAKEUP_PROP, (boolean) value);
break;
case PREF_KEY_FPS_INFO:
boolean enabled = (Boolean) value;
Intent fpsinfo = new Intent(this.getContext(), FPSInfoService.class);
if (enabled) {
this.getContext().startService(fpsinfo);
} else {
this.getContext().stopService(fpsinfo);
}
break;
default:
break;
}

View file

@ -0,0 +1,311 @@
/*
* 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.device;
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.Rect;
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.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.util.Log;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.StringBuffer;
import java.lang.Math;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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/devices/virtual/graphics/fb0/measured_fps";
private IDreamManager mDreamManager;
private class FPSView extends View {
private Paint mOnlinePaint;
private float mAscent;
private int mFH;
private int mMaxWidth;
private int mNeededWidth;
private int mNeededHeight;
private boolean mDataAvail;
private Handler mCurFPSHandler = new Handler() {
public void handleMessage(Message msg) {
if(msg.obj==null){
return;
}
if(msg.what==1){
String msgData = (String) msg.obj;
msgData = msgData.substring(0, Math.min(msgData.length(), 9));
mFps = msgData;
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("sans-serif-condensed", Typeface.BOLD);
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);
final String maxWidthStr="60.1";
mMaxWidth = (int)mOnlinePaint.measureText(maxWidthStr);
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;
}
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 = FPSInfoService.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.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 static String readOneLine(String fname) {
BufferedReader br;
String line = null;
try {
br = new BufferedReader(new FileReader(fname), 512);
try {
line = br.readLine();
} finally {
br.close();
}
} catch (Exception e) {
return null;
}
return line;
}
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.isDozing()) {
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;
}
}

View file

@ -0,0 +1,68 @@
/**
* 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.device;
import android.app.ActivityManager;
import android.content.Intent;
import android.os.Handler;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import org.lineageos.settings.device.R;
// TODO: Add FPS drawables
public class FPSTileService extends TileService {
private final String PREF_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();
}
}

View file

@ -15,11 +15,17 @@
#
on boot
# XiaomiParts
# XiaomiParts
chown system system /sys/devices/virtual/timed_output/vibrator/vtg_level
chmod 0660 /sys/devices/virtual/timed_output/vibrator/vtg_level
chown system system /sys/module/hall/parameters/hall_toggle
chmod 0660 /sys/module/hall/parameters/hall_toggle
# FPS
chown system system /sys/devices/virtual/graphics/fb0/measured_fps
chmod 0660 /sys/devices/virtual/graphics/fb0/measured_fps
chown system system /sys/class/graphics/fb0/measured_fps
chmod 0660 /sys/class/graphics/fb0/measured_fps
# KCal
chown system system /sys/devices/platform/kcal_ctrl.0/kcal_cont

View file

@ -22,3 +22,6 @@ type hall_dev, sysfs_type, fs_type;
type kcal_dev, sysfs_type, fs_type;
type thermal_data_file, file_type, data_file_type;
# XiamiParts
type sysfs_fpsinfo, sysfs_type, fs_type;

View file

@ -34,3 +34,7 @@ genfscon sysfs /touchpanel u:object_r:sysfs
genfscon sysfs /devices/soc/800f000.qcom,spmi/spmi-0/spmi0-03/800f000.qcom,spmi:qcom,pm660l@3:qcom,leds@d000/leds/button-backlight u:object_r:sysfs_graphics:s0
genfscon sysfs /devices/soc/800f000.qcom,spmi/spmi-0/spmi0-03/800f000.qcom,spmi:qcom,pm660l@3:qcom,leds@d000/leds/button-backlight1 u:object_r:sysfs_graphics:s0
genfscon sysfs /devices/soc/800f000.qcom,spmi/spmi-0/spmi0-03/800f000.qcom,spmi:qcom,pm660l@3:qcom,leds@d000/leds/white u:object_r:sysfs_graphics:s0
# XiaomiParts
genfscon sysfs /devices/virtual/graphics/fb0/measured_fps u:object_r:sysfs_fpsinfo:s0
genfscon sysfs /class/graphics/fb0/measured_fps u:object_r:sysfs_fpsinfo:s0

View file

@ -12,5 +12,6 @@ allow system_app sysfs_vibrator:dir search;
allow system_app sysfs_graphics:dir search;
allow system_app sysfs_graphics:file rw_file_perms;
allow system_app sysfs_leds:dir search;
allow system_app sysfs_fpsinfo:file rw_file_perms;
set_prop(system_app, system_prop);