From 543175d7a601bcbd37d5611270e207d1bb5f102f Mon Sep 17 00:00:00 2001 From: Adeel Zafar Date: Thu, 1 Aug 2019 23:28:53 +0500 Subject: [PATCH] Remove hotspot code for API<26 from WifiHotspotManager.java Remove the code for turning on hotspot programmatically for API<26. --- .../wifi_hotspot/WifiHotspotManager.java | 87 +------------------ 1 file changed, 1 insertion(+), 86 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/wifi_hotspot/WifiHotspotManager.java b/app/src/main/java/org/kiwix/kiwixmobile/wifi_hotspot/WifiHotspotManager.java index d745b3ff7..80c2e9b63 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/wifi_hotspot/WifiHotspotManager.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/wifi_hotspot/WifiHotspotManager.java @@ -8,7 +8,6 @@ import android.os.Handler; import android.util.Log; import androidx.annotation.RequiresApi; import androidx.appcompat.app.AlertDialog; -import java.lang.reflect.Method; import org.kiwix.kiwixmobile.R; import org.kiwix.kiwixmobile.webserver.WebServerHelper; @@ -32,23 +31,6 @@ public class WifiHotspotManager { wifiManager = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE); } - // This method enables/disables the wifi access point - // It is used for API<26 - public boolean setWifiEnabled(WifiConfiguration wifiConfig, boolean enabled) { - try { - if (enabled) { //disables wifi hotspot if it's already enabled - wifiManager.setWifiEnabled(false); - } - - Method method = wifiManager.getClass() - .getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class); - return (Boolean) method.invoke(wifiManager, wifiConfig, enabled); - } catch (Exception e) { - Log.e(this.getClass().toString(), "", e); - return false; - } - } - //Workaround to turn on hotspot for Oreo versions @RequiresApi(api = Build.VERSION_CODES.O) public void turnOnHotspot() { @@ -103,87 +85,20 @@ public class WifiHotspotManager { return hotspotReservation != null; } - // This method returns the current state of the Wifi access point - private WIFI_AP_STATE_ENUMS getWifiApState() { - try { - Method method = wifiManager.getClass().getMethod("getWifiApState"); - - int tmp = ((Integer) method.invoke(wifiManager)); - - // Fix for Android 4 - if (tmp >= 10) { - tmp = tmp - 10; - } - - return WIFI_AP_STATE_ENUMS.class.getEnumConstants()[tmp]; - } catch (Exception e) { - Log.e(this.getClass().toString(), "", e); - return WIFI_AP_STATE_ENUMS.WIFI_AP_STATE_FAILED; - } - } - - //This method returns if wifi access point is enabled or not - public boolean isWifiApEnabled() { - return getWifiApState() == WIFI_AP_STATE_ENUMS.WIFI_AP_STATE_ENABLED; - } - - //This method is to get the wifi ap configuration - private WifiConfiguration getWifiApConfiguration() { - try { - Method method = wifiManager.getClass().getMethod("getWifiApConfiguration"); - return (WifiConfiguration) method.invoke(wifiManager); - } catch (Exception e) { - Log.e(this.getClass().toString(), "", e); - return null; - } - } - - //This method is to set the wifi ap configuration - public boolean setWifiApConfiguration(WifiConfiguration wifiConfig) { - try { - Method method = - wifiManager.getClass().getMethod("setWifiApConfiguration", WifiConfiguration.class); - return (Boolean) method.invoke(wifiManager, wifiConfig); - } catch (Exception e) { - Log.e(this.getClass().toString(), "", e); - return false; - } - } - public void hotspotDetailsDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(context, dialogStyle()); WebServerHelper webServerHelper = new WebServerHelper(context); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setPositiveButton(android.R.string.ok, (dialog, id) -> { webServerHelper.startServerDialog(); }); - } else { - builder.setPositiveButton(android.R.string.ok, (dialog, id) -> { - final Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - webServerHelper.startServerDialog(); - } - }, 6000); - }); - } builder.setTitle(context.getString(R.string.hotspot_turned_on)); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setMessage( context.getString(R.string.hotspot_details_message) + "\n" + context.getString( R.string.hotspot_ssid_label) + " " + currentConfig.SSID + "\n" + context.getString( R.string.hotspot_pass_label) + " " + currentConfig.preSharedKey); - } else { - currentConfig = getWifiApConfiguration(); - builder.setMessage( - context.getString(R.string.hotspot_details_message) + "\n" + context.getString( - R.string.hotspot_ssid_label) + " " + currentConfig.SSID + "\n" + context.getString( - R.string.hotspot_pass_label) + " " + currentConfig.preSharedKey); - } + builder.setCancelable(false); AlertDialog dialog = builder.create(); dialog.show();