mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 21:55:10 +00:00
Fixes some potential null pointer exceptions reported by Coverity
This commit is contained in:
@@ -328,18 +328,22 @@ public class LanLinkProvider extends BaseLinkProvider {
|
||||
e.printStackTrace();
|
||||
Log.e("KDE/LanLinkProvider","Failed to create DatagramSocket");
|
||||
}
|
||||
//Log.e("KDE/LanLinkProvider","Sending packet to "+iplist.size()+" ips");
|
||||
for (String ipstr : iplist) {
|
||||
try {
|
||||
InetAddress client = InetAddress.getByName(ipstr);
|
||||
DatagramPacket packet = new DatagramPacket(bytes, bytes.length, client, port);
|
||||
socket.send(packet);
|
||||
//Log.i("KDE/LanLinkProvider","Udp identity package sent to address "+packet.getAddress());
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e("KDE/LanLinkProvider","Sending udp identity package failed. Invalid address? ("+ipstr+")");
|
||||
|
||||
if (bytes != null) {
|
||||
//Log.e("KDE/LanLinkProvider","Sending packet to "+iplist.size()+" ips");
|
||||
for (String ipstr : iplist) {
|
||||
try {
|
||||
InetAddress client = InetAddress.getByName(ipstr);
|
||||
DatagramPacket packet = new DatagramPacket(bytes, bytes.length, client, port);
|
||||
socket.send(packet);
|
||||
//Log.i("KDE/LanLinkProvider","Udp identity package sent to address "+packet.getAddress());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e("KDE/LanLinkProvider", "Sending udp identity package failed. Invalid address? (" + ipstr + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
socket.close();
|
||||
|
||||
}
|
||||
|
@@ -144,56 +144,56 @@ public class ShareActivity extends ActionBarActivity {
|
||||
Device device = devicesList.get(i-1); //NOTE: -1 because of the title!
|
||||
|
||||
Bundle extras = intent.getExtras();
|
||||
if (extras.containsKey(Intent.EXTRA_STREAM)) {
|
||||
if (extras != null) {
|
||||
if (extras.containsKey(Intent.EXTRA_STREAM)) {
|
||||
|
||||
try {
|
||||
try {
|
||||
|
||||
ArrayList<Uri> uriList;
|
||||
if (!Intent.ACTION_SEND.equals(intent.getAction())) {
|
||||
uriList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||
ArrayList<Uri> uriList;
|
||||
if (!Intent.ACTION_SEND.equals(intent.getAction())) {
|
||||
uriList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||
} else {
|
||||
Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
|
||||
uriList = new ArrayList<Uri>();
|
||||
uriList.add(uri);
|
||||
}
|
||||
|
||||
queuedSendUriList(device, uriList);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e("ShareActivity", "Exception");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} else if (extras.containsKey(Intent.EXTRA_TEXT)) {
|
||||
String text = extras.getString(Intent.EXTRA_TEXT);
|
||||
String subject = extras.getString(Intent.EXTRA_SUBJECT);
|
||||
|
||||
//Hack: Detect shared youtube videos, so we can open them in the browser instead of as text
|
||||
if (subject != null && subject.endsWith("YouTube")) {
|
||||
int index = text.indexOf(": http://youtu.be/");
|
||||
if (index > 0) {
|
||||
text = text.substring(index + 2); //Skip ": "
|
||||
}
|
||||
}
|
||||
|
||||
boolean isUrl;
|
||||
try {
|
||||
new URL(text);
|
||||
isUrl = true;
|
||||
} catch (Exception e) {
|
||||
isUrl = false;
|
||||
}
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SHARE);
|
||||
if (isUrl) {
|
||||
np.set("url", text);
|
||||
} else {
|
||||
Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
|
||||
uriList = new ArrayList<Uri>();
|
||||
uriList.add(uri);
|
||||
np.set("text", text);
|
||||
}
|
||||
|
||||
queuedSendUriList(device, uriList);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e("ShareActivity", "Exception");
|
||||
e.printStackTrace();
|
||||
device.sendPackage(np);
|
||||
}
|
||||
|
||||
} else if (extras.containsKey(Intent.EXTRA_TEXT)) {
|
||||
String text = extras.getString(Intent.EXTRA_TEXT);
|
||||
String subject = extras.getString(Intent.EXTRA_SUBJECT);
|
||||
|
||||
//Hack: Detect shared youtube videos, so we can open them in the browser instead of as text
|
||||
if (subject != null && subject.endsWith("YouTube")) {
|
||||
int index = text.indexOf(": http://youtu.be/");
|
||||
if (index > 0) {
|
||||
text = text.substring(index+2); //Skip ": "
|
||||
}
|
||||
}
|
||||
|
||||
boolean isUrl;
|
||||
try {
|
||||
new URL(text);
|
||||
isUrl = true;
|
||||
} catch(Exception e) {
|
||||
isUrl = false;
|
||||
}
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SHARE);
|
||||
if (isUrl) {
|
||||
np.set("url", text);
|
||||
} else {
|
||||
np.set("text", text);
|
||||
}
|
||||
device.sendPackage(np);
|
||||
}
|
||||
|
||||
|
||||
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
@@ -108,8 +108,11 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
InputMethodManager inputManager = (InputMethodManager)
|
||||
getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
|
||||
InputMethodManager.HIDE_NOT_ALWAYS);
|
||||
View focus = getCurrentFocus();
|
||||
if (focus != null) {
|
||||
inputManager.hideSoftInputFromWindow(focus.getWindowToken(),
|
||||
InputMethodManager.HIDE_NOT_ALWAYS);
|
||||
}
|
||||
}
|
||||
|
||||
void saveList() {
|
||||
|
@@ -46,10 +46,12 @@ public class SmallEntryItem implements ListAdapter.Item {
|
||||
View v = layoutInflater.inflate(android.R.layout.simple_list_item_1, null);
|
||||
|
||||
TextView titleView = (TextView)v.findViewById(android.R.id.text1);
|
||||
if (titleView != null) titleView.setText(title);
|
||||
if (clickListener != null) {
|
||||
titleView.setOnClickListener(clickListener);
|
||||
v.setBackgroundDrawable(layoutInflater.getContext().getResources().getDrawable(R.drawable.abc_list_selector_holo_dark));
|
||||
if (titleView != null) {
|
||||
titleView.setText(title);
|
||||
if (clickListener != null) {
|
||||
titleView.setOnClickListener(clickListener);
|
||||
v.setBackgroundDrawable(layoutInflater.getContext().getResources().getDrawable(R.drawable.abc_list_selector_holo_dark));
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
|
Reference in New Issue
Block a user