Skip to content

Commit

Permalink
Merge pull request #9 from inmaldrerah/master
Browse files Browse the repository at this point in the history
Detect MIUI by getprop and set max brightness accordingly
  • Loading branch information
cjyyx authored Mar 8, 2024
2 parents f840ff4 + 3e7b724 commit 89b8e09
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 26 additions & 3 deletions app/src/main/java/com/cjyyxn/screenfilter/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

@SuppressLint("StaticFieldLeak")
Expand All @@ -21,9 +23,30 @@ public class AppConfig {
/**
* Settings.System.SCREEN_BRIGHTNESS 相关的值
* 安卓开发者文档中说取值是 0-255
* 但 MIUI14 中是 1-128
*/
public static final int SETTING_SCREEN_BRIGHTNESS = 128;
public static final int SETTING_SCREEN_BRIGHTNESS = getSettingScreenBrightness();

private static String getSystemProperty(String prop) {
try {
Process p = Runtime.getRuntime().exec("getprop " + prop);
try (BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024)) {
return input.readLine();
} finally {
p.destroy();
}
} catch (IOException e) {
return null;
}
}

private static int getSettingScreenBrightness() {
String miui = getSystemProperty("ro.miui.ui.version.name");
if (miui != null && !miui.isEmpty()) {
return 128;
}
return 255;
}

/**
* 亮度调节系数,与亮度调节算法有关,取值 [0,1]
*/
Expand Down

0 comments on commit 89b8e09

Please sign in to comment.