• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.net.wifi.WifiInfo;
20 
21 /**
22  * Experimental scorer
23  */
24 public class AggressiveConnectedScore extends ConnectedScore {
25 
26     private final ScoringParams mScoringParams;
27 
28     private int mFrequencyMHz = 5000;
29     private int mRssi = 0;
30 
AggressiveConnectedScore(ScoringParams scoringParams, Clock clock)31     public AggressiveConnectedScore(ScoringParams scoringParams, Clock clock) {
32         super(clock);
33         mScoringParams = scoringParams;
34     }
35 
36     @Override
updateUsingRssi(int rssi, long millis, double standardDeviation)37     public void updateUsingRssi(int rssi, long millis, double standardDeviation) {
38         mRssi = rssi;
39     }
40 
41     @Override
updateUsingWifiInfo(WifiInfo wifiInfo, long millis)42     public void updateUsingWifiInfo(WifiInfo wifiInfo, long millis) {
43         mFrequencyMHz = wifiInfo.getFrequency();
44         mRssi = wifiInfo.getRssi();
45     }
46 
47     @Override
reset()48     public void reset() {
49         mFrequencyMHz = 5000;
50     }
51 
52     /**
53      * Generate the Wi-Fi network score.
54      * @return the generated Wi-Fi network score.
55      */
56     @Override
generateScore()57     public int generateScore() {
58         final int transitionScore = isPrimary() ? WIFI_TRANSITION_SCORE
59                 : WIFI_SECONDARY_TRANSITION_SCORE;
60         int threshRssi = mScoringParams.getSufficientRssi(mFrequencyMHz);
61         int score = (mRssi - threshRssi) + transitionScore;
62         return score;
63     }
64 }
65