2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 22:25:08 +00:00

Handle closing some resources that we were missing to close

This commit is contained in:
Albert Vaca
2015-04-04 13:53:46 -07:00
parent cc17402609
commit b7faa97292
5 changed files with 24 additions and 7 deletions

View File

@@ -125,6 +125,7 @@ public class LanLink extends BaseLink {
callback.sendProgress((int)(progress / np.getPayloadSize())); callback.sendProgress((int)(progress / np.getPayloadSize()));
} }
} }
stream.close();
Log.i("KDE/LanLink", "Finished sending payload"); Log.i("KDE/LanLink", "Finished sending payload");
} catch (Exception e) { } catch (Exception e) {
Log.e("KDE/sendPackage", "Exception: "+e); Log.e("KDE/sendPackage", "Exception: "+e);
@@ -176,13 +177,15 @@ public class LanLink extends BaseLink {
if (np.hasPayloadTransferInfo()) { if (np.hasPayloadTransferInfo()) {
Socket socket = null;
try { try {
Socket socket = new Socket(); socket = new Socket();
int tcpPort = np.getPayloadTransferInfo().getInt("port"); int tcpPort = np.getPayloadTransferInfo().getInt("port");
InetSocketAddress address = (InetSocketAddress)session.getRemoteAddress(); InetSocketAddress address = (InetSocketAddress)session.getRemoteAddress();
socket.connect(new InetSocketAddress(address.getAddress(), tcpPort)); socket.connect(new InetSocketAddress(address.getAddress(), tcpPort));
np.setPayload(socket.getInputStream(), np.getPayloadSize()); np.setPayload(socket.getInputStream(), np.getPayloadSize());
} catch (Exception e) { } catch (Exception e) {
try { socket.close(); } catch(Exception ignored) { }
e.printStackTrace(); e.printStackTrace();
Log.e("KDE/LanLink", "Exception connecting to payload remote socket"); Log.e("KDE/LanLink", "Exception connecting to payload remote socket");
} }

View File

@@ -81,7 +81,9 @@ public class StorageHelper {
if (storage.exists() && storage.isDirectory()) { if (storage.exists() && storage.isDirectory()) {
String mounts = null; String mounts = null;
try { try {
mounts = new Scanner( new File("/proc/mounts") ).useDelimiter("\\A").next(); Scanner scanner = new Scanner( new File("/proc/mounts") );
mounts = scanner.useDelimiter("\\A").next();
scanner.close();
//Log.e("Mounts",mounts); //Log.e("Mounts",mounts);
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@@ -64,13 +64,14 @@ public class NotificationFilterActivity extends ActionBarActivity {
res.moveToNext(); res.moveToNext();
i++; i++;
} }
res.close();
appDatabase.close(); appDatabase.close();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,android.R.id.text1, appName); android.R.layout.simple_list_item_multiple_choice,android.R.id.text1, appName);
listView.setAdapter(adapter); listView.setAdapter(adapter);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
for (i = 0 ; i < res.getCount(); i++){ for (i = 0 ; i < isFiltered.length; i++){
if (isFiltered[i]) { if (isFiltered[i]) {
listView.setItemChecked(i, true); listView.setItemChecked(i, true);
} }
@@ -85,6 +86,7 @@ public class NotificationFilterActivity extends ActionBarActivity {
appDatabase.close(); appDatabase.close();
} }
}); });
} }
// Delete apps from database which are uninstalled // Delete apps from database which are uninstalled
@@ -101,6 +103,7 @@ public class NotificationFilterActivity extends ActionBarActivity {
} }
res.moveToNext(); res.moveToNext();
} }
res.close();
} }
appDatabase.close(); appDatabase.close();

View File

@@ -235,12 +235,13 @@ public class ShareActivity extends ActionBarActivity {
try { try {
size = new File(uri.getPath()).length(); size = new File(uri.getPath()).length();
np.setPayload(inputStream, size);
} catch(Exception e) { } catch(Exception e) {
Log.e("ShareActivity", "Could not obtain file size"); Log.e("ShareActivity", "Could not obtain file size");
e.printStackTrace(); e.printStackTrace();
} }
np.setPayload(inputStream, size);
}else{ }else{
// Probably a content:// uri, so we query the Media content provider // Probably a content:// uri, so we query the Media content provider

View File

@@ -141,8 +141,9 @@ public class SharePlugin extends Plugin {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
OutputStream output = null;
try { try {
OutputStream output = new FileOutputStream(destinationFullPath.getPath()); output = new FileOutputStream(destinationFullPath.getPath());
byte data[] = new byte[1024]; byte data[] = new byte[1024];
long progress = 0, prevProgressPercentage = 0; long progress = 0, prevProgressPercentage = 0;
int count; int count;
@@ -162,9 +163,16 @@ public class SharePlugin extends Plugin {
} }
output.flush(); output.flush();
output.close();
input.close();
} catch (Exception e) {
Log.e("SharePlugin", "Receiver thread exception");
e.printStackTrace();
} finally {
try { output.close(); } catch (Exception e) {}
try { input.close(); } catch (Exception e) {}
}
try {
Log.i("SharePlugin", "Transfer finished"); Log.i("SharePlugin", "Transfer finished");
//Make sure it is added to the Android Gallery //Make sure it is added to the Android Gallery