Skip to content

Commit

Permalink
Fix API 29 class deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
iscle committed Jan 12, 2020
1 parent d0d382e commit 5b5b792
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.WifiLock;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
Expand Down Expand Up @@ -39,6 +40,7 @@

import ru.meefik.linuxdeploy.EnvUtils;
import ru.meefik.linuxdeploy.Logger;
import ru.meefik.linuxdeploy.fragment.PropertiesFragment;
import ru.meefik.linuxdeploy.receiver.NetworkReceiver;
import ru.meefik.linuxdeploy.receiver.PowerReceiver;
import ru.meefik.linuxdeploy.PrefStore;
Expand Down Expand Up @@ -116,7 +118,12 @@ public void onCreate(Bundle savedInstanceState) {

// WiFi lock init
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(android.content.Context.WIFI_SERVICE);
wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, getPackageName());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// WIFI_MODE_FULL has been deprecated since API level 29 and will have no impact!
wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, getPackageName());
} else {
wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, getPackageName());
}

// Wake lock
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;

import ru.meefik.linuxdeploy.EnvUtils;
Expand All @@ -16,9 +18,21 @@ public void onReceive(final Context context, Intent intent) {
ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = false;
if (activeNetwork != null) isConnected = activeNetwork.isConnected();
boolean isConnected;

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
Network activeNetwork = cm.getActiveNetwork();
NetworkCapabilities networkCapabilities = cm.getNetworkCapabilities(activeNetwork);

isConnected = networkCapabilities != null
&& (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
|| networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)
|| networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET));
} else {
NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
isConnected = activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

if (isConnected) {
EnvUtils.execService(context, "start", "core/net");
} else {
Expand Down

0 comments on commit 5b5b792

Please sign in to comment.