ScoringParams.java revision 43932b3defc6cc2d3e110fa3c3a9f610c33b98e5
1/*
2 * Copyright 2018 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.content.Context;
20
21import com.android.internal.R;
22
23/**
24 * Holds parameters used for scoring networks.
25 *
26 * Doing this in one place means that there's a better chance of consistency between
27 * connected score and network selection.
28 *
29 */
30public class ScoringParams {
31    private static final int EXIT = 0;
32    private static final int ENTRY = 1;
33    private static final int SUFFICIENT = 2;
34    private static final int GOOD = 3;
35    private final int[] mRssi2 = {-83, -80, -73, -60};
36    private final int[] mRssi5 = {-80, -77, -70, -57};
37
38    public ScoringParams() {
39    }
40
41    public ScoringParams(Context context) {
42        mRssi2[EXIT] = context.getResources().getInteger(
43                R.integer.config_wifi_framework_wifi_score_bad_rssi_threshold_24GHz);
44        mRssi2[ENTRY] = context.getResources().getInteger(
45                R.integer.config_wifi_framework_wifi_score_entry_rssi_threshold_24GHz);
46        mRssi2[SUFFICIENT] = context.getResources().getInteger(
47                R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_24GHz);
48        mRssi2[GOOD] = context.getResources().getInteger(
49                R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_24GHz);
50        mRssi5[EXIT] = context.getResources().getInteger(
51                R.integer.config_wifi_framework_wifi_score_bad_rssi_threshold_5GHz);
52        mRssi5[ENTRY] = context.getResources().getInteger(
53                R.integer.config_wifi_framework_wifi_score_entry_rssi_threshold_5GHz);
54        mRssi5[SUFFICIENT] = context.getResources().getInteger(
55                R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_5GHz);
56        mRssi5[GOOD] = context.getResources().getInteger(
57                R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_5GHz);
58    }
59
60    private static final int MINIMUM_5GHZ_BAND_FREQUENCY_IN_MEGAHERTZ = 5000;
61
62    /** Constant to denote someplace in the 2.4 GHz band */
63    public static final int BAND2 = 2400;
64
65    /** Constant to denote someplace in the 5 GHz band */
66    public static final int BAND5 = 5000;
67
68    /**
69     * Returns the RSSI value at which the connection is deemed to be unusable,
70     * in the absence of other indications.
71     */
72    public int getExitRssi(int frequencyMegaHertz) {
73        return getRssiArray(frequencyMegaHertz)[EXIT];
74    }
75
76    /**
77     * Returns the minimum scan RSSI for making a connection attempt.
78     */
79    public int getEntryRssi(int frequencyMegaHertz) {
80        return getRssiArray(frequencyMegaHertz)[ENTRY];
81    }
82
83    /**
84     * Returns a connected RSSI value that indicates the connection is
85     * good enough that we needn't scan for alternatives.
86     */
87    public int getSufficientRssi(int frequencyMegaHertz) {
88        return getRssiArray(frequencyMegaHertz)[SUFFICIENT];
89    }
90
91    /**
92     * Returns a connected RSSI value that indicates a good connection.
93     */
94    public int getGoodRssi(int frequencyMegaHertz) {
95        return getRssiArray(frequencyMegaHertz)[GOOD];
96    }
97
98    private int[] getRssiArray(int frequencyMegaHertz) {
99        if (frequencyMegaHertz < MINIMUM_5GHZ_BAND_FREQUENCY_IN_MEGAHERTZ) {
100            return mRssi2;
101        } else {
102            return mRssi5;
103        }
104    }
105}
106