2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-02 15:15:09 +00:00

Fixes some potential null pointer exceptions reported by Coverity

This commit is contained in:
Albert Vaca
2015-04-04 14:25:02 -07:00
parent 11012e21e5
commit 9cf9f43118
4 changed files with 68 additions and 59 deletions

View File

@@ -328,6 +328,8 @@ 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");
} }
if (bytes != null) {
//Log.e("KDE/LanLinkProvider","Sending packet to "+iplist.size()+" ips"); //Log.e("KDE/LanLinkProvider","Sending packet to "+iplist.size()+" ips");
for (String ipstr : iplist) { for (String ipstr : iplist) {
try { try {
@@ -335,11 +337,13 @@ public class LanLinkProvider extends BaseLinkProvider {
DatagramPacket packet = new DatagramPacket(bytes, bytes.length, client, port); DatagramPacket packet = new DatagramPacket(bytes, bytes.length, client, port);
socket.send(packet); socket.send(packet);
//Log.i("KDE/LanLinkProvider","Udp identity package sent to address "+packet.getAddress()); //Log.i("KDE/LanLinkProvider","Udp identity package sent to address "+packet.getAddress());
} catch(Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Log.e("KDE/LanLinkProvider","Sending udp identity package failed. Invalid address? ("+ipstr+")"); Log.e("KDE/LanLinkProvider", "Sending udp identity package failed. Invalid address? (" + ipstr + ")");
} }
} }
}
socket.close(); socket.close();
} }

View File

@@ -144,6 +144,7 @@ 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 != null) {
if (extras.containsKey(Intent.EXTRA_STREAM)) { if (extras.containsKey(Intent.EXTRA_STREAM)) {
try { try {
@@ -172,7 +173,7 @@ public class ShareActivity extends ActionBarActivity {
if (subject != null && subject.endsWith("YouTube")) { if (subject != null && subject.endsWith("YouTube")) {
int index = text.indexOf(": http://youtu.be/"); int index = text.indexOf(": http://youtu.be/");
if (index > 0) { if (index > 0) {
text = text.substring(index+2); //Skip ": " text = text.substring(index + 2); //Skip ": "
} }
} }
@@ -180,7 +181,7 @@ public class ShareActivity extends ActionBarActivity {
try { try {
new URL(text); new URL(text);
isUrl = true; isUrl = true;
} catch(Exception e) { } catch (Exception e) {
isUrl = false; isUrl = false;
} }
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SHARE); NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SHARE);
@@ -191,8 +192,7 @@ public class ShareActivity extends ActionBarActivity {
} }
device.sendPackage(np); device.sendPackage(np);
} }
}
finish(); finish();
} }

View File

@@ -108,9 +108,12 @@ 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();
if (focus != null) {
inputManager.hideSoftInputFromWindow(focus.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS); InputMethodManager.HIDE_NOT_ALWAYS);
} }
}
void saveList() { void saveList() {
// add entry to list and save to preferences (unless empty) // add entry to list and save to preferences (unless empty)

View File

@@ -46,11 +46,13 @@ 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) {
titleView.setText(title);
if (clickListener != null) { if (clickListener != null) {
titleView.setOnClickListener(clickListener); titleView.setOnClickListener(clickListener);
v.setBackgroundDrawable(layoutInflater.getContext().getResources().getDrawable(R.drawable.abc_list_selector_holo_dark)); v.setBackgroundDrawable(layoutInflater.getContext().getResources().getDrawable(R.drawable.abc_list_selector_holo_dark));
} }
}
return v; return v;
} }