Android 10.0 添加WIFI指示灯

介绍

因客户需求设备需要添加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;
            }
            //*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不太正常的移动开发工程师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值