mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 05:37:43 +00:00
Handle closing some resources that we were missing to close
This commit is contained in:
parent
cc17402609
commit
b7faa97292
@ -125,6 +125,7 @@ public class LanLink extends BaseLink {
|
||||
callback.sendProgress((int)(progress / np.getPayloadSize()));
|
||||
}
|
||||
}
|
||||
stream.close();
|
||||
Log.i("KDE/LanLink", "Finished sending payload");
|
||||
} catch (Exception e) {
|
||||
Log.e("KDE/sendPackage", "Exception: "+e);
|
||||
@ -176,13 +177,15 @@ public class LanLink extends BaseLink {
|
||||
|
||||
if (np.hasPayloadTransferInfo()) {
|
||||
|
||||
Socket socket = null;
|
||||
try {
|
||||
Socket socket = new Socket();
|
||||
socket = new Socket();
|
||||
int tcpPort = np.getPayloadTransferInfo().getInt("port");
|
||||
InetSocketAddress address = (InetSocketAddress)session.getRemoteAddress();
|
||||
socket.connect(new InetSocketAddress(address.getAddress(), tcpPort));
|
||||
np.setPayload(socket.getInputStream(), np.getPayloadSize());
|
||||
} catch (Exception e) {
|
||||
try { socket.close(); } catch(Exception ignored) { }
|
||||
e.printStackTrace();
|
||||
Log.e("KDE/LanLink", "Exception connecting to payload remote socket");
|
||||
}
|
||||
|
@ -81,7 +81,9 @@ public class StorageHelper {
|
||||
if (storage.exists() && storage.isDirectory()) {
|
||||
String mounts = null;
|
||||
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);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -64,13 +64,14 @@ public class NotificationFilterActivity extends ActionBarActivity {
|
||||
res.moveToNext();
|
||||
i++;
|
||||
}
|
||||
res.close();
|
||||
appDatabase.close();
|
||||
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
|
||||
android.R.layout.simple_list_item_multiple_choice,android.R.id.text1, appName);
|
||||
listView.setAdapter(adapter);
|
||||
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
for (i = 0 ; i < res.getCount(); i++){
|
||||
for (i = 0 ; i < isFiltered.length; i++){
|
||||
if (isFiltered[i]) {
|
||||
listView.setItemChecked(i, true);
|
||||
}
|
||||
@ -85,6 +86,7 @@ public class NotificationFilterActivity extends ActionBarActivity {
|
||||
appDatabase.close();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Delete apps from database which are uninstalled
|
||||
@ -101,6 +103,7 @@ public class NotificationFilterActivity extends ActionBarActivity {
|
||||
}
|
||||
res.moveToNext();
|
||||
}
|
||||
res.close();
|
||||
}
|
||||
appDatabase.close();
|
||||
|
||||
|
@ -235,12 +235,13 @@ public class ShareActivity extends ActionBarActivity {
|
||||
|
||||
try {
|
||||
size = new File(uri.getPath()).length();
|
||||
np.setPayload(inputStream, size);
|
||||
} catch(Exception e) {
|
||||
Log.e("ShareActivity", "Could not obtain file size");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
np.setPayload(inputStream, size);
|
||||
|
||||
}else{
|
||||
// Probably a content:// uri, so we query the Media content provider
|
||||
|
||||
|
@ -141,8 +141,9 @@ public class SharePlugin extends Plugin {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
OutputStream output = null;
|
||||
try {
|
||||
OutputStream output = new FileOutputStream(destinationFullPath.getPath());
|
||||
output = new FileOutputStream(destinationFullPath.getPath());
|
||||
byte data[] = new byte[1024];
|
||||
long progress = 0, prevProgressPercentage = 0;
|
||||
int count;
|
||||
@ -162,9 +163,16 @@ public class SharePlugin extends Plugin {
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
//Make sure it is added to the Android Gallery
|
||||
|
Loading…
x
Reference in New Issue
Block a user