介绍
因客户需求设备需要添加wifi的指示灯连接时不亮灯,未连接时闪烁绿灯,修改过程中我们要考虑充电灯和解开锁屏状态时对状态灯的影响
修改
连接和断开wifi时我们通过log发现WifiConnectivityManager.java中handleConnectionStateChanged方法会打出wifi连接和断开的log,那么我们只需在此处判断连接状态添加上灯光处理方法即可
路径:frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiConnectivityManager.java
//*/soda water.20230915 wifi indicator light
import android.provider.Settings;
import com.android.server.lights.LightsManager;
import com.android.server.LocalServices;
import com.android.server.lights.Light;
import android.graphics.Color;
import com.android.server.BatteryService;
//*/
//*/soda water.20230915 wifi indicator light
private final Context mContext;
private Light mNotificationLight;
//*/
WifiConnectivityManager(Context context, ScoringParams scoringParams,
ClientModeImpl stateMachine,
WifiInjector injector, WifiConfigManager configManager, WifiInfo wifiInfo,
WifiNetworkSelector networkSelector, WifiConnectivityHelper connectivityHelper,
WifiLastResortWatchdog wifiLastResortWatchdog, OpenNetworkNotifier openNetworkNotifier,
CarrierNetworkNotifier carrierNetworkNotifier,
CarrierNetworkConfig carrierNetworkConfig, WifiMetrics wifiMetrics, Looper looper,
Clock clock, LocalLog localLog) {
//*/soda water.20230915 wifi indicator light
mContext = context;
//*/
public void handleConnectionStateChanged(int state) {
localLog("handleConnectionStateChanged: state=" + stateToString(state));
//*/soda water.20230915 wifi indicator light
try {
LightsManager lights = LocalServices.getService(LightsManager.class);
mNotificationLight = lights.getLight(LightsManager.LIGHT_ID_NOTIFICATIONS);
int wifiswitch = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.WIFI_ON);
if(wifiswitch == 1){
switch (state) {
case WIFI_STATE_CONNECTED:
mNotificationLight.turnOff();
BatteryService.updateNotificationLights(false);
localLog("soda wate1");
break;
case WIFI_STATE_DISCONNECTED:
mNotificationLight.setFlashing(Color.GREEN, Light.LIGHT_FLASH_TIMED,500,500);
BatteryService.updateNotificationLights(true);
localLog("soda wate2");
break;
}
}else{
mNotificationLight.turnOff();
BatteryService.updateNotificationLights(false);
localLog("soda wate3");
}
} catch (Settings.SettingNotFoundException e) {
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.WIFI_ON, 0);
}
//*/
mWifiState = state;
解锁时和其他充电时可以屏蔽其他事件触发灯光操作
路径:frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java
} else if (action.equals(Intent.ACTION_USER_PRESENT)) {
// turn off LED when user passes through lock screen
/*/soda water.20230915 wifi indicator light 此处解锁时会关闭所有灯光
mNotificationLight.turnOff();
//*/
}
//*/soda water.20230915 wifi indicator light 这部分修改是在锁屏和正常状态下会触发灯光 需屏蔽掉
try {
if(Settings.Global.getInt(getContext().getContentResolver(), Settings.Global.WIFI_ON) == 1){
}else{
// Don't flash while we are in a call or screen is on
if (ledNotification == null || mInCall/*guoyong || mScreenOn*/ || mMtkPplManager.getPplLockStatus()) {
mNotificationLight.turnOff();
//*/soda water notification led
BatteryService.updateNotificationLights(false);
android.util.Log.d("soda water","isFlashing = false 1");
//*/
isScreenOn = false;//add guoyong
} else {
//*/guoyong start
PowerManager pm=(PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK,"bright");
if (!isScreenOn) {
isScreenOn = true;
wl.acquire();
}
//*/end
NotificationRecord.Light light = ledNotification.getLight();
if (light != null && mNotificationPulseEnabled) {
// pulse repeatedly
if(BatteryService.getPttStatus() == 0){
mNotificationLight.setFlashing(Color.GREEN, Light.LIGHT_FLASH_TIMED,
0, 0);
BatteryService.updateNotificationLights(true);
}
}
}
android.util.Log.d("soda water","isFlashing = false 4");
}
} catch (Settings.SettingNotFoundException e) {
}
//*/soda water.20230915 wifi indicator light
}
屏蔽充电灯的影响
路径:frameworks/base/services/core/java/com/android/server/BatteryService.java
public void updateLightsLocked() {
final int level = mHealthInfo.batteryLevel;
final int status = mHealthInfo.batteryStatus;
//*/ soda water.20230915
if(mNotificationFlashing){
mBatteryLight.turnOff();
return;
}
//*/