use of cc.mvdan.accesspoint.WifiApControl in project fdroidclient by f-droid.
the class StartSwapView method uiUpdateWifiNetwork.
private void uiUpdateWifiNetwork() {
viewWifiId.setText(FDroidApp.ipAddressString);
viewWifiId.setVisibility(TextUtils.isEmpty(FDroidApp.ipAddressString) ? View.GONE : View.VISIBLE);
WifiApControl wifiAp = WifiApControl.getInstance(getActivity());
if (wifiAp != null && wifiAp.isWifiApEnabled()) {
WifiConfiguration config = wifiAp.getConfiguration();
viewWifiNetwork.setText(getContext().getString(R.string.swap_active_hotspot, config.SSID));
} else if (TextUtils.isEmpty(FDroidApp.ssid)) {
// not connected to or setup with any wifi network
viewWifiNetwork.setText(R.string.swap_no_wifi_network);
} else {
// connected to a regular wifi network
viewWifiNetwork.setText(FDroidApp.ssid);
}
}
use of cc.mvdan.accesspoint.WifiApControl in project fdroidclient by f-droid.
the class SwapWorkflowActivity method promptToSetupWifiAP.
private void promptToSetupWifiAP() {
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiApControl ap = WifiApControl.getInstance(this);
wifiManager.setWifiEnabled(false);
if (!ap.enable()) {
Log.e(TAG, "Could not enable WiFi AP.");
// TODO: Feedback to user?
} else {
Utils.debugLog(TAG, "WiFi AP enabled.");
// TODO: Seems to be broken some times...
}
}
use of cc.mvdan.accesspoint.WifiApControl in project fdroidclient by f-droid.
the class SwapService method onCreate.
@Override
public void onCreate() {
super.onCreate();
startForeground(NOTIFICATION, createNotification());
localBroadcastManager = LocalBroadcastManager.getInstance(this);
swapPreferences = getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
LocalHTTPDManager.start(this);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter != null) {
SwapService.putBluetoothEnabledBeforeSwap(bluetoothAdapter.isEnabled());
if (bluetoothAdapter.isEnabled()) {
BluetoothManager.start(this);
}
registerReceiver(bluetoothScanModeChanged, new IntentFilter(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED));
}
wifiManager = ContextCompat.getSystemService(getApplicationContext(), WifiManager.class);
if (wifiManager != null) {
SwapService.putWifiEnabledBeforeSwap(wifiManager.isWifiEnabled());
}
appsToSwap.addAll(deserializePackages(swapPreferences.getString(KEY_APPS_TO_SWAP, "")));
Preferences.get().registerLocalRepoHttpsListeners(httpsEnabledListener);
localBroadcastManager.registerReceiver(onWifiChange, new IntentFilter(WifiStateChangeService.BROADCAST));
localBroadcastManager.registerReceiver(bluetoothStatus, new IntentFilter(BluetoothManager.ACTION_STATUS));
localBroadcastManager.registerReceiver(bluetoothPeerFound, new IntentFilter(BluetoothManager.ACTION_FOUND));
localBroadcastManager.registerReceiver(bonjourPeerFound, new IntentFilter(BonjourManager.ACTION_FOUND));
localBroadcastManager.registerReceiver(bonjourPeerRemoved, new IntentFilter(BonjourManager.ACTION_REMOVED));
localBroadcastManager.registerReceiver(localRepoStatus, new IntentFilter(LocalRepoService.ACTION_STATUS));
if (getHotspotActivatedUserPreference()) {
WifiApControl wifiApControl = WifiApControl.getInstance(this);
if (wifiApControl != null) {
wifiApControl.enable();
}
} else if (getWifiVisibleUserPreference()) {
if (wifiManager != null) {
wifiManager.setWifiEnabled(true);
}
}
BonjourManager.start(this);
BonjourManager.setVisible(this, getWifiVisibleUserPreference() || getHotspotActivatedUserPreference());
}
use of cc.mvdan.accesspoint.WifiApControl in project fdroidclient by f-droid.
the class SwapService method onDestroy.
@Override
public void onDestroy() {
compositeDisposable.dispose();
Utils.debugLog(TAG, "Destroying service, will disable swapping if required, and unregister listeners.");
Preferences.get().unregisterLocalRepoHttpsListeners(httpsEnabledListener);
localBroadcastManager.unregisterReceiver(onWifiChange);
localBroadcastManager.unregisterReceiver(bluetoothStatus);
localBroadcastManager.unregisterReceiver(bluetoothPeerFound);
localBroadcastManager.unregisterReceiver(bonjourPeerFound);
localBroadcastManager.unregisterReceiver(bonjourPeerRemoved);
if (bluetoothAdapter != null) {
unregisterReceiver(bluetoothScanModeChanged);
}
BluetoothManager.stop(this);
BonjourManager.stop(this);
LocalHTTPDManager.stop(this);
if (wifiManager != null && !wasWifiEnabledBeforeSwap()) {
wifiManager.setWifiEnabled(false);
}
WifiApControl ap = WifiApControl.getInstance(this);
if (ap != null) {
try {
if (wasHotspotEnabledBeforeSwap()) {
ap.enable();
} else {
ap.disable();
}
} catch (Exception e) {
e.printStackTrace();
}
}
stopPollingConnectedSwapRepo();
if (timer != null) {
timer.cancel();
}
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE);
deleteAllSwapRepos();
super.onDestroy();
}
use of cc.mvdan.accesspoint.WifiApControl in project fdroidclient by f-droid.
the class StartSwapView method uiUpdateWifiNetwork.
private void uiUpdateWifiNetwork() {
viewWifiId.setText(FDroidApp.ipAddressString);
viewWifiId.setVisibility(TextUtils.isEmpty(FDroidApp.ipAddressString) ? View.GONE : View.VISIBLE);
WifiApControl wifiAp = WifiApControl.getInstance(getActivity());
if (wifiAp != null && wifiAp.isWifiApEnabled()) {
WifiConfiguration config = wifiAp.getConfiguration();
TextView textWifiVisible = findViewById(R.id.wifi_visible);
if (textWifiVisible != null) {
textWifiVisible.setText(R.string.swap_visible_hotspot);
}
Context context = getContext();
if (config == null) {
viewWifiNetwork.setText(context.getString(R.string.swap_active_hotspot, context.getString(R.string.swap_blank_wifi_ssid)));
} else {
viewWifiNetwork.setText(context.getString(R.string.swap_active_hotspot, config.SSID));
}
} else if (TextUtils.isEmpty(FDroidApp.ssid)) {
// not connected to or setup with any wifi network
viewWifiNetwork.setText(R.string.swap_no_wifi_network);
} else {
// connected to a regular wifi network
viewWifiNetwork.setText(FDroidApp.ssid);
}
}
Aggregations