Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
wifi: Add StaState API
Browse files Browse the repository at this point in the history
Change-Id: I1f51ae6189a909132f566ebddfb6f9cbdf9acb2d
  • Loading branch information
AgentFabulous authored and markakash committed Dec 9, 2020
1 parent 69a2a30 commit 3bd2c14
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
3 changes: 3 additions & 0 deletions service/java/com/android/server/wifi/ActiveModeWarden.java
Original file line number Diff line number Diff line change
Expand Up @@ -966,4 +966,7 @@ public boolean processMessageFiltered(Message msg) {
}
}
}

public void registerStaEventCallback() {}
public void unregisterStaEventCallback() {}
}
12 changes: 12 additions & 0 deletions service/java/com/android/server/wifi/BaseWifiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.net.wifi.IOnWifiUsabilityStatsListener;
import android.net.wifi.IScanResultsCallback;
import android.net.wifi.ISoftApCallback;
import android.net.wifi.IStaStateCallback;
import android.net.wifi.ISuggestionConnectionStatusListener;
import android.net.wifi.ITrafficStateCallback;
import android.net.wifi.ITxPacketCountListener;
Expand Down Expand Up @@ -677,4 +678,15 @@ public void setAutoWakeupEnabled(boolean enable) {
public boolean isAutoWakeupEnabled() {
throw new UnsupportedOperationException();
}

@Override
public void registerStaStateCallback(
IBinder binder, IStaStateCallback callback, int callbackIdentifier) {
throw new UnsupportedOperationException();
}

@Override
public void unregisterStaStateCallback(int callbackIdentifier) {
throw new UnsupportedOperationException();
}
}
7 changes: 7 additions & 0 deletions service/java/com/android/server/wifi/WifiInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class WifiInjector {
private final ScoringParams mScoringParams;
private final ClientModeImpl mClientModeImpl;
private final ActiveModeWarden mActiveModeWarden;
private final WifiStaStateNotifier mWifiStaStateNotifier;
private final WifiSettingsStore mSettingsStore;
private OpenNetworkNotifier mOpenNetworkNotifier;
private final WifiLockManager mLockManager;
Expand Down Expand Up @@ -382,6 +383,8 @@ mWifiNative, new DefaultModeManager(mContext), mBatteryStats, mWifiDiagnostics,
mWifiNetworkSelector.registerNetworkNominator(mNetworkSuggestionNominator);
mWifiNetworkSelector.registerNetworkNominator(mScoredNetworkNominator);

mWifiStaStateNotifier = new WifiStaStateNotifier(wifiLooper, this);

mClientModeImpl.start();
}

Expand Down Expand Up @@ -479,6 +482,10 @@ public ActiveModeWarden getActiveModeWarden() {
return mActiveModeWarden;
}

public WifiStaStateNotifier getWifiStaStateNotifier() {
return mWifiStaStateNotifier;
}

public WifiSettingsStore getWifiSettingsStore() {
return mSettingsStore;
}
Expand Down
29 changes: 29 additions & 0 deletions service/java/com/android/server/wifi/WifiServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import android.net.wifi.IScanResultsCallback;
import android.net.wifi.ISoftApCallback;
import android.net.wifi.ISuggestionConnectionStatusListener;
import android.net.wifi.IStaStateCallback;
import android.net.wifi.ITrafficStateCallback;
import android.net.wifi.IWifiConnectedNetworkScorer;
import android.net.wifi.ScanResult;
Expand Down Expand Up @@ -188,6 +189,8 @@ public class WifiServiceImpl extends BaseWifiService {
private final WifiConfigManager mWifiConfigManager;
private final PasspointManager mPasspointManager;
private final WifiLog mLog;
private WifiStaStateNotifier mWifiStaStateNotifier;

/**
* Verbose logging flag. Toggled by developer options.
*/
Expand Down Expand Up @@ -329,6 +332,7 @@ public WifiServiceImpl(Context context, WifiInjector wifiInjector, AsyncChannel
mWifiScoreCard = mWifiInjector.getWifiScoreCard();
mMemoryStoreImpl = new MemoryStoreImpl(mContext, mWifiInjector,
mWifiScoreCard, mWifiInjector.getWifiHealthMonitor());
mWifiStaStateNotifier = mWifiInjector.getWifiStaStateNotifier();
}

/**
Expand Down Expand Up @@ -3729,6 +3733,31 @@ public void unregisterTrafficStateCallback(int callbackIdentifier) {
mWifiTrafficPoller.removeCallback(callbackIdentifier));
}

@Override
public void registerStaStateCallback(IBinder binder, IStaStateCallback callback,
int callbackIdentifier) {
if (binder == null) {
throw new IllegalArgumentException("Binder must not be null");
}
if (callback == null) {
throw new IllegalArgumentException("Callback must not be null");
}
if (mVerboseLoggingEnabled) {
mLog.info("registerStaStateCallback uid=%").c(Binder.getCallingUid()).flush();
}
mWifiThreadRunner.post(() ->
mWifiStaStateNotifier.addCallback(binder, callback, callbackIdentifier));
}

@Override
public void unregisterStaStateCallback(int callbackIdentifier) {
if (mVerboseLoggingEnabled) {
mLog.info("unregisterStaStateCallback uid=%").c(Binder.getCallingUid()).flush();
}
mWifiThreadRunner.post(() ->
mWifiStaStateNotifier.removeCallback(callbackIdentifier));
}

private long getSupportedFeaturesInternal() {
final AsyncChannel channel = mClientModeImplChannel;
long supportedFeatureSet = 0L;
Expand Down
72 changes: 72 additions & 0 deletions service/java/com/android/server/wifi/WifiStaStateNotifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2020 The Android Open Source 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 com.android.server.wifi;

import android.annotation.NonNull;
import android.net.wifi.IStaStateCallback;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;

import com.android.server.wifi.util.ExternalCallbackTracker;


public class WifiStaStateNotifier {
private final ExternalCallbackTracker<IStaStateCallback> mRegisteredCallbacks;
private static WifiInjector mWifiInjector;
private static final String TAG = "WifiStaStateNotifier";
private static final boolean DEBUG = false;

WifiStaStateNotifier(@NonNull Looper looper, WifiInjector wifiInjector) {
mRegisteredCallbacks = new ExternalCallbackTracker<IStaStateCallback>(new Handler(looper));
mWifiInjector = wifiInjector;
}

public void addCallback(IBinder binder, IStaStateCallback callback,
int callbackIdentifier) {
if (DEBUG) Log.d(TAG, "addCallback");
if (mRegisteredCallbacks.getNumCallbacks() > 0) {
if (DEBUG) Log.e(TAG, "Failed to add callback, only support single request!");
return;
}
if (!mRegisteredCallbacks.add(binder, callback, callbackIdentifier)) {
if (DEBUG) Log.e(TAG, "Failed to add callback");
return;
}
mWifiInjector.getActiveModeWarden().registerStaEventCallback();
}

public void removeCallback(int callbackIdentifier) {
if (DEBUG) Log.d(TAG, "removeCallback");
mRegisteredCallbacks.remove(callbackIdentifier);
mWifiInjector.getActiveModeWarden().unregisterStaEventCallback();
}

public void onStaToBeOff() {
if (DEBUG) Log.d(TAG, "onStaToBeOff");
for (IStaStateCallback callback : mRegisteredCallbacks.getCallbacks()) {
try {
if (DEBUG) Log.d(TAG, "callback onStaToBeOff");
callback.onStaToBeOff();
} catch (RemoteException e) {
// do nothing
}
}
}
}

0 comments on commit 3bd2c14

Please sign in to comment.