WifiStateMachinePrime.java revision 4569b3880ba8d741d466e2f880f91b29b56d5e18
1/* 2 * Copyright (C) 2016 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 17package com.android.server.wifi; 18 19import android.os.Message; 20 21import com.android.internal.util.State; 22import com.android.internal.util.StateMachine; 23 24/** 25 * This class provides the implementation for different WiFi operating modes. 26 * 27 * NOTE: The class is a WIP and is in active development. It is intended to replace the existing 28 * WifiStateMachine.java class when the rearchitecture is complete. 29 */ 30public class WifiStateMachinePrime { 31 private static final String TAG = "WifiStateMachinePrime"; 32 33 private ModeStateMachine mModeStateMachine; 34 35 WifiStateMachinePrime() { 36 mModeStateMachine = new ModeStateMachine(TAG); 37 } 38 39 private class ModeStateMachine extends StateMachine { 40 // Commands for the state machine. 41 public static final int CMD_START_CLIENT_MODE = 0; 42 public static final int CMD_START_SCAN_ONLY_MODE = 1; 43 public static final int CMD_START_SOFT_AP_MODE = 2; 44 45 46 // Create the base modes for WSM. 47 private final State mClientModeState = new ClientModeState(); 48 private final State mScanOnlyModeState = new ScanOnlyModeState(); 49 private final State mSoftAPModeState = new SoftAPModeState(); 50 51 // Create the active versions of the modes for WSM. 52 private final State mClientModeActiveState = new ClientModeActiveState(); 53 private final State mScanOnlyModeActiveState = new ScanOnlyModeActiveState(); 54 private final State mSoftAPModeActiveState = new SoftAPModeActiveState(); 55 56 ModeStateMachine(String name) { 57 super(name); 58 59 // CHECKSTYLE:OFF IndentationCheck 60 addState(mClientModeState); 61 addState(mClientModeActiveState, mClientModeState); 62 addState(mScanOnlyModeState); 63 addState(mScanOnlyModeActiveState, mScanOnlyModeState); 64 addState(mSoftAPModeState); 65 addState(mSoftAPModeActiveState, mSoftAPModeState); 66 // CHECKSTYLE:ON IndentationCheck 67 } 68 69 private String getCurrentMode() { 70 try { 71 return getCurrentState().getName(); 72 } catch (NullPointerException e) { 73 // current state is not set 74 return null; 75 } 76 } 77 78 class ClientModeState extends State { 79 80 @Override 81 public boolean processMessage(Message message) { 82 return NOT_HANDLED; 83 } 84 85 @Override 86 public void exit() { 87 88 } 89 } 90 91 class ScanOnlyModeState extends State { 92 93 @Override 94 public boolean processMessage(Message message) { 95 // handle Mode changes and any events requiring setup or restarting services 96 97 return NOT_HANDLED; 98 } 99 100 @Override 101 public void exit() { 102 // tear down running services 103 } 104 } 105 106 class SoftAPModeState extends State { 107 108 @Override 109 public boolean processMessage(Message message) { 110 return NOT_HANDLED; 111 } 112 113 @Override 114 public void exit() { 115 } 116 } 117 118 class ModeActiveState extends State { 119 ActiveModeManager mActiveModeManager; 120 121 @Override 122 public boolean processMessage(Message message) { 123 // handle messages for changing modes here 124 return NOT_HANDLED; 125 } 126 127 @Override 128 public void exit() { 129 // clean up objects from an active state - check with mode handlers to make sure 130 // they are stopping properly. 131 mActiveModeManager.stop(); 132 } 133 } 134 135 class ClientModeActiveState extends ModeActiveState { 136 @Override 137 public void enter() { 138 this.mActiveModeManager = new ClientModeManager(); 139 } 140 } 141 142 class ScanOnlyModeActiveState extends ModeActiveState { 143 @Override 144 public void enter() { 145 this.mActiveModeManager = new ScanOnlyModeManager(); 146 } 147 } 148 149 class SoftAPModeActiveState extends ModeActiveState { 150 @Override 151 public void enter() { 152 // The SoftApManager is not empty at this time, will populate in later CLs. 153 //this.mActiveModeManager = new SoftApManager(); 154 } 155 } 156 } // class ModeStateMachine 157} 158