mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-22 18:07:55 +00:00
Tell the user that no Wi-Fi is connected and click to fix it
This commit is contained in:
parent
4d10dca624
commit
7f283d8995
9
res/drawable/ic_wifi.xml
Normal file
9
res/drawable/ic_wifi.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFFFF"
|
||||||
|
android:pathData="M1,9l2,2c4.97,-4.97 13.03,-4.97 18,0l2,-2C16.93,2.93 7.08,2.93 1,9zM9,17l3,3 3,-3c-1.65,-1.66 -4.34,-1.66 -6,0zM5,13l2,2c2.76,-2.76 7.24,-2.76 10,0l2,-2C15.14,9.14 8.87,9.14 5,13z"/>
|
||||||
|
</vector>
|
@ -99,15 +99,6 @@
|
|||||||
android:text="@string/unreachable_description"
|
android:text="@string/unreachable_description"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/on_data_message"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:text="@string/on_data_message"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
13
res/layout/pairing_explanation_text.xml
Normal file
13
res/layout/pairing_explanation_text.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<TextView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
android:text="@string/pairing_description"
|
||||||
|
android:clickable="false"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
>
|
||||||
|
|
||||||
|
</TextView>
|
16
res/layout/pairing_explanation_text_no_wifi.xml
Normal file
16
res/layout/pairing_explanation_text_no_wifi.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<TextView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
android:text="@string/no_wifi"
|
||||||
|
android:drawableLeft="@drawable/ic_wifi"
|
||||||
|
android:drawableTint="?attr/colorControlNormal"
|
||||||
|
android:clickable="true"
|
||||||
|
>
|
||||||
|
|
||||||
|
</TextView>
|
@ -256,7 +256,7 @@
|
|||||||
<string name="device_rename_confirm">Rename</string>
|
<string name="device_rename_confirm">Rename</string>
|
||||||
<string name="refresh">Refresh</string>
|
<string name="refresh">Refresh</string>
|
||||||
<string name="unreachable_description">This paired device is not reachable. Make sure it is connected to your same network.</string>
|
<string name="unreachable_description">This paired device is not reachable. Make sure it is connected to your same network.</string>
|
||||||
<string name="on_data_message">It looks like you are on a mobile data connection. KDE Connect only works on local networks.</string>
|
<string name="no_wifi">You\'re not connected to a Wi-Fi network, so you may not be able to see any devices. Click here to enable Wi-Fi.</string>
|
||||||
<string name="no_file_browser">There are no file browsers installed.</string>
|
<string name="no_file_browser">There are no file browsers installed.</string>
|
||||||
<string name="pref_plugin_telepathy">Send SMS</string>
|
<string name="pref_plugin_telepathy">Send SMS</string>
|
||||||
<string name="pref_plugin_telepathy_desc">Send text messages from your desktop</string>
|
<string name="pref_plugin_telepathy_desc">Send text messages from your desktop</string>
|
||||||
|
@ -31,7 +31,6 @@ import org.kde.kdeconnect.Backends.BaseLinkProvider;
|
|||||||
import org.kde.kdeconnect.BackgroundService;
|
import org.kde.kdeconnect.BackgroundService;
|
||||||
import org.kde.kdeconnect.Device;
|
import org.kde.kdeconnect.Device;
|
||||||
import org.kde.kdeconnect.Helpers.DeviceHelper;
|
import org.kde.kdeconnect.Helpers.DeviceHelper;
|
||||||
import org.kde.kdeconnect.Helpers.NetworkHelper;
|
|
||||||
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper;
|
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper;
|
||||||
import org.kde.kdeconnect.Helpers.StringsHelper;
|
import org.kde.kdeconnect.Helpers.StringsHelper;
|
||||||
import org.kde.kdeconnect.NetworkPacket;
|
import org.kde.kdeconnect.NetworkPacket;
|
||||||
@ -356,12 +355,6 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void broadcastUdpPacket() {
|
private void broadcastUdpPacket() {
|
||||||
|
|
||||||
if (NetworkHelper.isOnMobileNetwork(context)) {
|
|
||||||
Log.w("LanLinkProvider", "On 3G network, not sending broadcast.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
ArrayList<String> iplist = CustomDevicesActivity
|
ArrayList<String> iplist = CustomDevicesActivity
|
||||||
.getCustomDeviceList(PreferenceManager.getDefaultSharedPreferences(context));
|
.getCustomDeviceList(PreferenceManager.getDefaultSharedPreferences(context));
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
package org.kde.kdeconnect.Helpers;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
public class NetworkHelper {
|
|
||||||
|
|
||||||
public static boolean isOnMobileNetwork(Context context) {
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (context == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
return false; //No good way to know it
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
boolean mobile = false;
|
|
||||||
final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
Network[] networks = connMgr.getAllNetworks();
|
|
||||||
for (Network network : networks) {
|
|
||||||
NetworkInfo info = connMgr.getNetworkInfo(network);
|
|
||||||
if (info == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
|
|
||||||
mobile = info.isConnected();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//Log.e(info.getTypeName(),""+info.isAvailable());
|
|
||||||
if (info.isAvailable())
|
|
||||||
return false; //We are connected to at least one non-mobile network
|
|
||||||
}
|
|
||||||
if (mobile) { //We suspect we are on a mobile net
|
|
||||||
try (LineNumberReader is = new LineNumberReader(new FileReader("/proc/net/arp"))) {
|
|
||||||
//Check the number of network neighbours, on data it should be 0
|
|
||||||
is.skip(Long.MAX_VALUE);
|
|
||||||
//Log.e("NetworkHelper", "procnetarp has " + is.getLineNumber() + " lines");
|
|
||||||
if (is.getLineNumber() > 1) { //The first line are the headers
|
|
||||||
return false; //I have neighbours, so this doesn't look like a mobile network
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e("NetworkHelper", "Exception reading procnetarp", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mobile;
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e("isOnMobileNetwork", "Something went wrong, but this is non-critical.", e);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -41,20 +41,17 @@ import androidx.fragment.app.Fragment;
|
|||||||
|
|
||||||
import org.kde.kdeconnect.BackgroundService;
|
import org.kde.kdeconnect.BackgroundService;
|
||||||
import org.kde.kdeconnect.Device;
|
import org.kde.kdeconnect.Device;
|
||||||
import org.kde.kdeconnect.Helpers.NetworkHelper;
|
|
||||||
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper;
|
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper;
|
||||||
import org.kde.kdeconnect.Plugins.Plugin;
|
import org.kde.kdeconnect.Plugins.Plugin;
|
||||||
import org.kde.kdeconnect.UserInterface.List.PluginListHeaderItem;
|
import org.kde.kdeconnect.UserInterface.List.PluginListHeaderItem;
|
||||||
import org.kde.kdeconnect.UserInterface.List.FailedPluginListItem;
|
import org.kde.kdeconnect.UserInterface.List.FailedPluginListItem;
|
||||||
import org.kde.kdeconnect.UserInterface.List.ListAdapter;
|
import org.kde.kdeconnect.UserInterface.List.ListAdapter;
|
||||||
import org.kde.kdeconnect.UserInterface.List.PluginItem;
|
import org.kde.kdeconnect.UserInterface.List.PluginItem;
|
||||||
import org.kde.kdeconnect.UserInterface.List.SmallEntryItem;
|
|
||||||
import org.kde.kdeconnect_tp.R;
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.ConcurrentModificationException;
|
import java.util.ConcurrentModificationException;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
@ -90,7 +87,6 @@ public class DeviceFragment extends Fragment {
|
|||||||
@BindView(R.id.pair_request_buttons) View pairRequestButtons;
|
@BindView(R.id.pair_request_buttons) View pairRequestButtons;
|
||||||
@BindView(R.id.error_message_container) View errorMessageContainer;
|
@BindView(R.id.error_message_container) View errorMessageContainer;
|
||||||
@BindView(R.id.not_reachable_message) TextView notReachableMessage;
|
@BindView(R.id.not_reachable_message) TextView notReachableMessage;
|
||||||
@BindView(R.id.on_data_message) TextView onDataMessage;
|
|
||||||
@BindView(R.id.buttons_list) ListView buttonsList;
|
@BindView(R.id.buttons_list) ListView buttonsList;
|
||||||
|
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
@ -310,12 +306,10 @@ public class DeviceFragment extends Fragment {
|
|||||||
|
|
||||||
boolean paired = device.isPaired();
|
boolean paired = device.isPaired();
|
||||||
boolean reachable = device.isReachable();
|
boolean reachable = device.isReachable();
|
||||||
boolean onData = NetworkHelper.isOnMobileNetwork(DeviceFragment.this.getContext());
|
|
||||||
|
|
||||||
pairingButtons.setVisibility(paired ? View.GONE : View.VISIBLE);
|
pairingButtons.setVisibility(paired ? View.GONE : View.VISIBLE);
|
||||||
errorMessageContainer.setVisibility((paired && !reachable) ? View.VISIBLE : View.GONE);
|
errorMessageContainer.setVisibility((paired && !reachable) ? View.VISIBLE : View.GONE);
|
||||||
notReachableMessage.setVisibility((paired && !reachable && !onData) ? View.VISIBLE : View.GONE);
|
notReachableMessage.setVisibility((paired && !reachable) ? View.VISIBLE : View.GONE);
|
||||||
onDataMessage.setVisibility((paired && !reachable && onData) ? View.VISIBLE : View.GONE);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
pluginListItems = new ArrayList<>();
|
pluginListItems = new ArrayList<>();
|
||||||
|
@ -24,7 +24,14 @@ import android.app.Activity;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.LinkProperties;
|
||||||
|
import android.net.Network;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.NetworkRequest;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
@ -36,7 +43,6 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.kde.kdeconnect.BackgroundService;
|
import org.kde.kdeconnect.BackgroundService;
|
||||||
import org.kde.kdeconnect.Device;
|
import org.kde.kdeconnect.Device;
|
||||||
import org.kde.kdeconnect.Helpers.NetworkHelper;
|
|
||||||
import org.kde.kdeconnect.UserInterface.List.ListAdapter;
|
import org.kde.kdeconnect.UserInterface.List.ListAdapter;
|
||||||
import org.kde.kdeconnect.UserInterface.List.PairingDeviceItem;
|
import org.kde.kdeconnect.UserInterface.List.PairingDeviceItem;
|
||||||
import org.kde.kdeconnect.UserInterface.List.SectionItem;
|
import org.kde.kdeconnect.UserInterface.List.SectionItem;
|
||||||
@ -65,6 +71,8 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
private boolean listRefreshCalledThisFrame = false;
|
private boolean listRefreshCalledThisFrame = false;
|
||||||
|
|
||||||
private TextView headerText;
|
private TextView headerText;
|
||||||
|
private TextView noWifiHeader;
|
||||||
|
private Object networkChangeListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||||
@ -83,14 +91,49 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
mSwipeRefreshLayout.setOnRefreshListener(
|
mSwipeRefreshLayout.setOnRefreshListener(
|
||||||
this::updateComputerListAction
|
this::updateComputerListAction
|
||||||
);
|
);
|
||||||
headerText = new TextView(inflater.getContext());
|
headerText = (TextView) inflater.inflate(R.layout.pairing_explanation_text, null);
|
||||||
headerText.setText(getString(R.string.pairing_description));
|
headerText.setOnClickListener(null);
|
||||||
headerText.setPadding(0, (int) (16 * getResources().getDisplayMetrics().density), 0, (int) (12 * getResources().getDisplayMetrics().density));
|
headerText.setOnLongClickListener(null);
|
||||||
|
noWifiHeader = (TextView) inflater.inflate(R.layout.pairing_explanation_text_no_wifi, null);
|
||||||
|
noWifiHeader.setOnClickListener(view -> {
|
||||||
|
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
|
||||||
|
});
|
||||||
((ListView) listRootView).addHeaderView(headerText);
|
((ListView) listRootView).addHeaderView(headerText);
|
||||||
|
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
networkChangeListener = new ConnectivityManager.NetworkCallback() {
|
||||||
|
@Override
|
||||||
|
public void onAvailable(Network network) {
|
||||||
|
updateDeviceList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLost(Network network) {
|
||||||
|
updateDeviceList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
|
||||||
|
updateDeviceList();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ConnectivityManager connManager = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
connManager.registerNetworkCallback(new NetworkRequest.Builder().build(), (ConnectivityManager.NetworkCallback) networkChangeListener);
|
||||||
|
}
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
ConnectivityManager connManager = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
connManager.unregisterNetworkCallback((ConnectivityManager.NetworkCallback) networkChangeListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
@ -126,13 +169,27 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
}
|
}
|
||||||
listRefreshCalledThisFrame = true;
|
listRefreshCalledThisFrame = true;
|
||||||
|
|
||||||
headerText.setText(getString(NetworkHelper.isOnMobileNetwork(getContext()) ? R.string.on_data_message : R.string.pairing_description));
|
Collection<Device> devices = service.getDevices().values();
|
||||||
//Disable tap animation
|
boolean someDevicesReachable = false;
|
||||||
headerText.setOnClickListener(null);
|
for (Device device : devices) {
|
||||||
headerText.setOnLongClickListener(null);
|
if (device.isReachable()) {
|
||||||
|
someDevicesReachable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
((ListView) rootView.findViewById(R.id.devices_list)).removeHeaderView(headerText);
|
||||||
|
((ListView) rootView.findViewById(R.id.devices_list)).removeHeaderView(noWifiHeader);
|
||||||
|
|
||||||
|
ConnectivityManager connManager = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||||
|
//Check if we're on Wi-Fi. If we still see a device, don't do anything special
|
||||||
|
if (someDevicesReachable || wifi.isConnected()) {
|
||||||
|
((ListView) rootView.findViewById(R.id.devices_list)).addHeaderView(headerText);
|
||||||
|
} else {
|
||||||
|
((ListView) rootView.findViewById(R.id.devices_list)).addHeaderView(noWifiHeader);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Collection<Device> devices = service.getDevices().values();
|
|
||||||
final ArrayList<ListAdapter.Item> items = new ArrayList<>();
|
final ArrayList<ListAdapter.Item> items = new ArrayList<>();
|
||||||
|
|
||||||
SectionItem connectedSection;
|
SectionItem connectedSection;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user