Implement proper WifiRTT availability checking
This commit is contained in:
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@@ -7,7 +7,7 @@ android {
|
||||
defaultConfig {
|
||||
applicationId "de.fhws.indoor.sensorreadout"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 23
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
multiDexEnabled true
|
||||
|
||||
@@ -490,7 +490,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
if(activeSensors.contains("WIFI")) {
|
||||
boolean useWifiFtm = preferences.getBoolean("prefUseWifiFTM", false);
|
||||
if(useWifiFtm && WiFiRTT.isSupported()) {
|
||||
if(useWifiFtm && WiFiRTT.isSupported(this)) {
|
||||
Log.i("Sensors", "Using Wifi[FTM]");
|
||||
// log wifi RTT using sensor number 17
|
||||
final WiFiRTT wifirtt = new WiFiRTT(this);
|
||||
|
||||
@@ -11,7 +11,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
setPreferencesFromResource(R.xml.preferences, rootKey);
|
||||
if(!WiFiRTT.isSupported()) {
|
||||
if(!WiFiRTT.isSupported(getContext())) {
|
||||
SwitchPreferenceCompat useFtmPreference = (SwitchPreferenceCompat)findPreference("prefUseWifiFTM");
|
||||
useFtmPreference.setEnabled(false);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import android.net.wifi.rtt.RangingRequest;
|
||||
import android.net.wifi.rtt.RangingResult;
|
||||
import android.net.wifi.rtt.RangingResultCallback;
|
||||
import android.net.wifi.rtt.WifiRttManager;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import android.os.Build;
|
||||
@@ -163,10 +165,15 @@ public class WiFiRTT extends mySensor {
|
||||
}
|
||||
};
|
||||
|
||||
public static final boolean isSupported() {
|
||||
return (Build.VERSION.SDK_INT >= 28);
|
||||
|
||||
//TODO markusb Implement a proper test for whether FTM is supported
|
||||
// If this needs a context / activity, no problem
|
||||
@RequiresApi(api = Build.VERSION_CODES.P)
|
||||
public static final boolean isSupported(Context context) {
|
||||
if(!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_RTT)) {
|
||||
return false;
|
||||
}
|
||||
WifiRttManager rttManager = (WifiRttManager) context.getSystemService(Context.WIFI_RTT_RANGING_SERVICE);
|
||||
if(rttManager == null) {
|
||||
return false;
|
||||
}
|
||||
return rttManager.isAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user