mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-02 07:05:09 +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();
|
e.printStackTrace();
|
||||||
Log.e("KDE/LanLinkProvider","Failed to create DatagramSocket");
|
Log.e("KDE/LanLinkProvider","Failed to create DatagramSocket");
|
||||||
}
|
}
|
||||||
//Log.e("KDE/LanLinkProvider","Sending packet to "+iplist.size()+" ips");
|
|
||||||
for (String ipstr : iplist) {
|
if (bytes != null) {
|
||||||
try {
|
//Log.e("KDE/LanLinkProvider","Sending packet to "+iplist.size()+" ips");
|
||||||
InetAddress client = InetAddress.getByName(ipstr);
|
for (String ipstr : iplist) {
|
||||||
DatagramPacket packet = new DatagramPacket(bytes, bytes.length, client, port);
|
try {
|
||||||
socket.send(packet);
|
InetAddress client = InetAddress.getByName(ipstr);
|
||||||
//Log.i("KDE/LanLinkProvider","Udp identity package sent to address "+packet.getAddress());
|
DatagramPacket packet = new DatagramPacket(bytes, bytes.length, client, port);
|
||||||
} catch(Exception e) {
|
socket.send(packet);
|
||||||
e.printStackTrace();
|
//Log.i("KDE/LanLinkProvider","Udp identity package sent to address "+packet.getAddress());
|
||||||
Log.e("KDE/LanLinkProvider","Sending udp identity package failed. Invalid address? ("+ipstr+")");
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Log.e("KDE/LanLinkProvider", "Sending udp identity package failed. Invalid address? (" + ipstr + ")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.close();
|
socket.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -144,56 +144,56 @@ public class ShareActivity extends ActionBarActivity {
|
|||||||
Device device = devicesList.get(i-1); //NOTE: -1 because of the title!
|
Device device = devicesList.get(i-1); //NOTE: -1 because of the title!
|
||||||
|
|
||||||
Bundle extras = intent.getExtras();
|
Bundle extras = intent.getExtras();
|
||||||
if (extras.containsKey(Intent.EXTRA_STREAM)) {
|
if (extras != null) {
|
||||||
|
if (extras.containsKey(Intent.EXTRA_STREAM)) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ArrayList<Uri> uriList;
|
ArrayList<Uri> uriList;
|
||||||
if (!Intent.ACTION_SEND.equals(intent.getAction())) {
|
if (!Intent.ACTION_SEND.equals(intent.getAction())) {
|
||||||
uriList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
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 {
|
} else {
|
||||||
Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
|
np.set("text", text);
|
||||||
uriList = new ArrayList<Uri>();
|
|
||||||
uriList.add(uri);
|
|
||||||
}
|
}
|
||||||
|
device.sendPackage(np);
|
||||||
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 {
|
|
||||||
np.set("text", text);
|
|
||||||
}
|
|
||||||
device.sendPackage(np);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -108,8 +108,11 @@ public class CustomDevicesActivity extends ListActivity {
|
|||||||
InputMethodManager inputManager = (InputMethodManager)
|
InputMethodManager inputManager = (InputMethodManager)
|
||||||
getSystemService(Context.INPUT_METHOD_SERVICE);
|
getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
|
View focus = getCurrentFocus();
|
||||||
InputMethodManager.HIDE_NOT_ALWAYS);
|
if (focus != null) {
|
||||||
|
inputManager.hideSoftInputFromWindow(focus.getWindowToken(),
|
||||||
|
InputMethodManager.HIDE_NOT_ALWAYS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveList() {
|
void saveList() {
|
||||||
|
@@ -46,10 +46,12 @@ public class SmallEntryItem implements ListAdapter.Item {
|
|||||||
View v = layoutInflater.inflate(android.R.layout.simple_list_item_1, null);
|
View v = layoutInflater.inflate(android.R.layout.simple_list_item_1, null);
|
||||||
|
|
||||||
TextView titleView = (TextView)v.findViewById(android.R.id.text1);
|
TextView titleView = (TextView)v.findViewById(android.R.id.text1);
|
||||||
if (titleView != null) titleView.setText(title);
|
if (titleView != null) {
|
||||||
if (clickListener != null) {
|
titleView.setText(title);
|
||||||
titleView.setOnClickListener(clickListener);
|
if (clickListener != null) {
|
||||||
v.setBackgroundDrawable(layoutInflater.getContext().getResources().getDrawable(R.drawable.abc_list_selector_holo_dark));
|
titleView.setOnClickListener(clickListener);
|
||||||
|
v.setBackgroundDrawable(layoutInflater.getContext().getResources().getDrawable(R.drawable.abc_list_selector_holo_dark));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
|
Reference in New Issue
Block a user