Update wifi p2p to direct user to enable location
Location is required for Wifi Direct so if it is not enabled we disable the preference. Additionally, this fixes some minor update issues in Wifi Wakeup that was also affecting wifi p2p. Basically they weren't updating when location settings changed until you left the screen and came back. Now they do. Test: robotests, manual Bug: 120552223 Change-Id: Ibd386fcfbef881cae3d871152675f1cab5e4a041
This commit is contained in:
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package com.android.settings.wifi.p2p;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.location.LocationManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -49,6 +51,17 @@ public class WifiP2pPreferenceController extends AbstractPreferenceController
|
||||
}
|
||||
};
|
||||
private final IntentFilter mFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
||||
private final LocationManager mLocationManager;
|
||||
private final BroadcastReceiver mLocationReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (mWifiDirectPref != null) {
|
||||
updateState(mWifiDirectPref);
|
||||
}
|
||||
}
|
||||
};
|
||||
private final IntentFilter mLocationFilter =
|
||||
new IntentFilter(LocationManager.MODE_CHANGED_ACTION);
|
||||
|
||||
private Preference mWifiDirectPref;
|
||||
|
||||
@@ -57,6 +70,7 @@ public class WifiP2pPreferenceController extends AbstractPreferenceController
|
||||
super(context);
|
||||
mWifiManager = wifiManager;
|
||||
lifecycle.addObserver(this);
|
||||
mLocationManager = (LocationManager) context.getSystemService(Service.LOCATION_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,14 +80,22 @@ public class WifiP2pPreferenceController extends AbstractPreferenceController
|
||||
togglePreferences();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
preference.setEnabled(mLocationManager.isLocationEnabled() && mWifiManager.isWifiEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
mContext.registerReceiver(mReceiver, mFilter);
|
||||
mContext.registerReceiver(mLocationReceiver, mLocationFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mContext.unregisterReceiver(mReceiver);
|
||||
mContext.unregisterReceiver(mLocationReceiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,7 +110,9 @@ public class WifiP2pPreferenceController extends AbstractPreferenceController
|
||||
|
||||
private void togglePreferences() {
|
||||
if (mWifiDirectPref != null) {
|
||||
mWifiDirectPref.setEnabled(mWifiManager.isWifiEnabled());
|
||||
mWifiDirectPref.setEnabled(
|
||||
mWifiManager.isWifiEnabled()
|
||||
&& mLocationManager.isLocationEnabled());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user