Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/src/main/aidl/android/openfde/ILight.aidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
**
** Copyright (C) 2021 The WayDroid 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 android.openfde;
interface ILight {
int setBacklight(int brightness);
int getBacklight();
}
76 changes: 76 additions & 0 deletions app/src/main/java/com/boringdroid/systemui/utils/Light.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.boringdroid.systemui.utils;

import android.content.Context;
import android.openfde.ILight;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;

public class Light {
private static final String TAG = "openfdelight";
public static final String LIGHT_SERVICE = "openfdelight";

/**
* Unable to determine status, an error occured
*/
public static final int ERROR_UNDEFINED = -1;

private static ILight sService;
private static Light sInstance;

private Context mContext;

private Light(Context context) {
mContext = context == null ? null : context.getApplicationContext();
sService = getService();
}

public static Light getInstance(Context context) {
if (sInstance == null) {
sInstance = new Light(context);
}
return sInstance;
}

public static ILight getService() {
if (sService != null) {
return sService;
}
IBinder b = ServiceManager.getService(LIGHT_SERVICE);

if (b == null) {
Log.e(TAG, "null service. SAD!");
return null;
}

sService = ILight.Stub.asInterface(b);
return sService;
}

public int setBacklight(int brightness) {
ILight service = getService();
if (service == null) {
return ERROR_UNDEFINED;
}
try {
return service.setBacklight(brightness);
} catch (RemoteException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
return ERROR_UNDEFINED;
}

public int getBacklight() {
ILight service = getService();
if (service == null) {
return ERROR_UNDEFINED;
}
try {
return service.getBacklight();
} catch (RemoteException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
return ERROR_UNDEFINED;
}
}
13 changes: 2 additions & 11 deletions app/src/main/java/com/boringdroid/systemui/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -400,17 +400,8 @@ object Utils {
}

fun getScreenBrightness(context: Context): Int {
return try {
// 获取系统亮度值(范围 0-255)
val brightness = Settings.System.getInt(
context.contentResolver,
Settings.System.SCREEN_BRIGHTNESS
)
brightness
} catch (e: Settings.SettingNotFoundException) {
// 如果设置不存在,返回默认值(如 128)
128
}
val backlight = Light.getInstance(context).backlight
return if (backlight > 0) backlight else 255
}

fun setScreenBrightness(context: Context, brightness: Int) {
Expand Down
Loading