Home | History | Annotate | Download | only in wifi
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.server.wifi;
     18 
     19 import android.util.Log;
     20 
     21 /**
     22  * This class is used to recover the wifi stack from a fatal failure. The recovery mechanism
     23  * involves triggering a stack restart (essentially simulating an airplane mode toggle) using
     24  * {@link WifiController}.
     25  * The current triggers for:
     26  * 1. Last resort watchdog bite.
     27  * 2. HAL/wificond crashes during normal operation.
     28  * 3. TBD: supplicant crashes during normal operation.
     29  */
     30 public class SelfRecovery {
     31     private static final String TAG = "WifiSelfRecovery";
     32 
     33     /**
     34      * Reason codes for the various recovery triggers.
     35      */
     36     public static final int REASON_LAST_RESORT_WATCHDOG = 0;
     37     public static final int REASON_HAL_CRASH = 1;
     38     public static final int REASON_WIFICOND_CRASH = 2;
     39 
     40     private static final String[] REASON_STRINGS = {
     41             "Last Resort Watchdog", // REASON_LAST_RESORT_WATCHDOG
     42             "Hal Crash",            // REASON_HAL_CRASH
     43             "Wificond Crash"        // REASON_WIFICOND_CRASH
     44     };
     45 
     46     private final WifiController mWifiController;
     47 
     48     SelfRecovery(WifiController wifiController) {
     49         mWifiController = wifiController;
     50     }
     51 
     52     /**
     53      * Trigger recovery.
     54      *
     55      * This method does the following:
     56      * 1. Raises a wtf.
     57      * 2. Sends {@link WifiController#CMD_RESTART_WIFI} to {@link WifiController} to initiate the
     58      * stack restart.
     59      * @param reason One of the above |REASON_*| codes.
     60      */
     61     public void trigger(int reason) {
     62         if (reason < REASON_LAST_RESORT_WATCHDOG || reason > REASON_WIFICOND_CRASH) {
     63             Log.e(TAG, "Invalid trigger reason. Ignoring...");
     64             return;
     65         }
     66         Log.wtf(TAG, "Triggering recovery for reason: " + REASON_STRINGS[reason]);
     67         mWifiController.sendMessage(WifiController.CMD_RESTART_WIFI);
     68     }
     69 }
     70