mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Remove unnecessary unmodifiable collection wrappers.
This commit is contained in:
@@ -31,7 +31,6 @@ import java.io.File;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static android.content.Context.MODE_PRIVATE;
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
@@ -63,7 +62,7 @@ public class AndroidUtils {
|
|||||||
abis.add(Build.CPU_ABI);
|
abis.add(Build.CPU_ABI);
|
||||||
if (Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2);
|
if (Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(abis);
|
return abis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setError(TextInputLayout til, String error,
|
public static void setError(TextInputLayout til, String error,
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import java.util.Map.Entry;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CompletionService;
|
import java.util.concurrent.CompletionService;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
@@ -578,7 +579,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
private static class DiscoveryReceiver extends BroadcastReceiver {
|
private static class DiscoveryReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
private final CountDownLatch finished = new CountDownLatch(1);
|
private final CountDownLatch finished = new CountDownLatch(1);
|
||||||
private final List<String> addresses = new ArrayList<>();
|
private final List<String> addresses = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context ctx, Intent intent) {
|
public void onReceive(Context ctx, Intent intent) {
|
||||||
@@ -598,8 +599,9 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
|
|
||||||
private List<String> waitForAddresses() throws InterruptedException {
|
private List<String> waitForAddresses() throws InterruptedException {
|
||||||
finished.await();
|
finished.await();
|
||||||
Collections.shuffle(addresses);
|
List<String> shuffled = new ArrayList<>(addresses);
|
||||||
return Collections.unmodifiableList(addresses);
|
Collections.shuffle(shuffled);
|
||||||
|
return shuffled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
|||||||
blogs.add(b);
|
blogs.add(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(blogs);
|
return blogs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -419,7 +419,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
|||||||
} finally {
|
} finally {
|
||||||
db.endTransaction(txn);
|
db.endTransaction(txn);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(blogs);
|
return blogs;
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -208,7 +207,7 @@ class ClientHelperImpl implements ClientHelper {
|
|||||||
new HashMap<MessageId, BdfDictionary>(raw.size());
|
new HashMap<MessageId, BdfDictionary>(raw.size());
|
||||||
for (Entry<MessageId, Metadata> e : raw.entrySet())
|
for (Entry<MessageId, Metadata> e : raw.entrySet())
|
||||||
parsed.put(e.getKey(), metadataParser.parse(e.getValue()));
|
parsed.put(e.getKey(), metadataParser.parse(e.getValue()));
|
||||||
return Collections.unmodifiableMap(parsed);
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -236,7 +235,7 @@ class ClientHelperImpl implements ClientHelper {
|
|||||||
new HashMap<MessageId, BdfDictionary>(raw.size());
|
new HashMap<MessageId, BdfDictionary>(raw.size());
|
||||||
for (Entry<MessageId, Metadata> e : raw.entrySet())
|
for (Entry<MessageId, Metadata> e : raw.entrySet())
|
||||||
parsed.put(e.getKey(), metadataParser.parse(e.getValue()));
|
parsed.put(e.getKey(), metadataParser.parse(e.getValue()));
|
||||||
return Collections.unmodifiableMap(parsed);
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
|
|||||||
for (T root : roots) {
|
for (T root : roots) {
|
||||||
traverse(orderedList, root, 0);
|
traverse(orderedList, root, 0);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(orderedList);
|
return orderedList;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
if (ids.isEmpty()) return null;
|
if (ids.isEmpty()) return null;
|
||||||
db.lowerRequestedFlag(txn, c, ids);
|
db.lowerRequestedFlag(txn, c, ids);
|
||||||
transaction.attach(new MessagesSentEvent(c, ids));
|
transaction.attach(new MessagesSentEvent(c, ids));
|
||||||
return Collections.unmodifiableList(messages);
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -379,7 +379,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
if (ids.isEmpty()) return null;
|
if (ids.isEmpty()) return null;
|
||||||
db.lowerRequestedFlag(txn, c, ids);
|
db.lowerRequestedFlag(txn, c, ids);
|
||||||
transaction.attach(new MessagesSentEvent(c, ids));
|
transaction.attach(new MessagesSentEvent(c, ids));
|
||||||
return Collections.unmodifiableList(messages);
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
|||||||
}
|
}
|
||||||
List<Forum> forums = new ArrayList<Forum>();
|
List<Forum> forums = new ArrayList<Forum>();
|
||||||
for (Group g : groups) forums.add(parseForum(g));
|
for (Group g : groups) forums.add(parseForum(g));
|
||||||
return Collections.unmodifiableList(forums);
|
return forums;
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
contactCounts = new HashMap<ContactId, Integer>();
|
contactCounts = new HashMap<ContactId, Integer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void registerConnection(ContactId c, TransportId t,
|
public void registerConnection(ContactId c, TransportId t,
|
||||||
boolean incoming) {
|
boolean incoming) {
|
||||||
if (LOG.isLoggable(INFO)) {
|
if (LOG.isLoggable(INFO)) {
|
||||||
@@ -76,6 +77,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void unregisterConnection(ContactId c, TransportId t,
|
public void unregisterConnection(ContactId c, TransportId t,
|
||||||
boolean incoming) {
|
boolean incoming) {
|
||||||
if (LOG.isLoggable(INFO)) {
|
if (LOG.isLoggable(INFO)) {
|
||||||
@@ -112,6 +114,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Collection<ContactId> getConnectedContacts(TransportId t) {
|
public Collection<ContactId> getConnectedContacts(TransportId t) {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
@@ -120,12 +123,13 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
List<ContactId> ids = new ArrayList<ContactId>(m.keySet());
|
List<ContactId> ids = new ArrayList<ContactId>(m.keySet());
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info(ids.size() + " contacts connected");
|
LOG.info(ids.size() + " contacts connected");
|
||||||
return Collections.unmodifiableList(ids);
|
return ids;
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isConnected(ContactId c, TransportId t) {
|
public boolean isConnected(ContactId c, TransportId t) {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
@@ -136,6 +140,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isConnected(ContactId c) {
|
public boolean isConnected(ContactId c) {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -156,12 +156,12 @@ class PluginManagerImpl implements PluginManager, Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<SimplexPlugin> getSimplexPlugins() {
|
public Collection<SimplexPlugin> getSimplexPlugins() {
|
||||||
return Collections.unmodifiableList(simplexPlugins);
|
return new ArrayList<SimplexPlugin>(simplexPlugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<DuplexPlugin> getDuplexPlugins() {
|
public Collection<DuplexPlugin> getDuplexPlugins() {
|
||||||
return Collections.unmodifiableList(duplexPlugins);
|
return new ArrayList<DuplexPlugin>(duplexPlugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -169,7 +169,7 @@ class PluginManagerImpl implements PluginManager, Service {
|
|||||||
List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>();
|
List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>();
|
||||||
for (DuplexPlugin d : duplexPlugins)
|
for (DuplexPlugin d : duplexPlugins)
|
||||||
if (d.supportsInvitations()) supported.add(d);
|
if (d.supportsInvitations()) supported.add(d);
|
||||||
return Collections.unmodifiableList(supported);
|
return supported;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -177,7 +177,7 @@ class PluginManagerImpl implements PluginManager, Service {
|
|||||||
List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>();
|
List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>();
|
||||||
for (DuplexPlugin d : duplexPlugins)
|
for (DuplexPlugin d : duplexPlugins)
|
||||||
if (d.supportsKeyAgreement()) supported.add(d);
|
if (d.supportsKeyAgreement()) supported.add(d);
|
||||||
return Collections.unmodifiableList(supported);
|
return supported;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PluginStarter implements Runnable {
|
private class PluginStarter implements Runnable {
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import org.briarproject.api.sync.Message;
|
|||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.api.sync.MessageId;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -101,7 +100,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
} finally {
|
} finally {
|
||||||
db.endTransaction(txn);
|
db.endTransaction(txn);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableMap(local);
|
return local;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -176,7 +175,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
} finally {
|
} finally {
|
||||||
db.endTransaction(txn);
|
db.endTransaction(txn);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableMap(remote);
|
return remote;
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ import java.security.SecureRandom;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -443,7 +442,8 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<SharingInvitationItem> getInvitations() throws DbException {
|
public Collection<SharingInvitationItem> getInvitations() throws DbException {
|
||||||
List<SharingInvitationItem> invitations = new ArrayList<SharingInvitationItem>();
|
List<SharingInvitationItem> invitations =
|
||||||
|
new ArrayList<SharingInvitationItem>();
|
||||||
Transaction txn = db.startTransaction(true);
|
Transaction txn = db.startTransaction(true);
|
||||||
try {
|
try {
|
||||||
Set<S> shareables = new HashSet<S>();
|
Set<S> shareables = new HashSet<S>();
|
||||||
@@ -474,7 +474,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
|
|||||||
invitations.add(invitation);
|
invitations.add(invitation);
|
||||||
}
|
}
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
return Collections.unmodifiableCollection(invitations);
|
return invitations;
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -523,7 +523,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
|
|||||||
} finally {
|
} finally {
|
||||||
db.endTransaction(txn);
|
db.endTransaction(txn);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(subscribers);
|
return subscribers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Contact> getSharedBy(Transaction txn, GroupId g)
|
private List<Contact> getSharedBy(Transaction txn, GroupId g)
|
||||||
@@ -556,7 +556,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
|
|||||||
} finally {
|
} finally {
|
||||||
db.endTransaction(txn);
|
db.endTransaction(txn);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(shared);
|
return shared;
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import org.briarproject.util.ByteUtils;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.briarproject.api.sync.PacketTypes.ACK;
|
import static org.briarproject.api.sync.PacketTypes.ACK;
|
||||||
@@ -74,19 +73,22 @@ class PacketReaderImpl implements PacketReader {
|
|||||||
state = State.BUFFER_FULL;
|
state = State.BUFFER_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean eof() throws IOException {
|
public boolean eof() throws IOException {
|
||||||
if (state == State.BUFFER_EMPTY) readPacket();
|
if (state == State.BUFFER_EMPTY) readPacket();
|
||||||
if (state == State.BUFFER_EMPTY) throw new IllegalStateException();
|
if (state == State.BUFFER_EMPTY) throw new IllegalStateException();
|
||||||
return state == State.EOF;
|
return state == State.EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasAck() throws IOException {
|
public boolean hasAck() throws IOException {
|
||||||
return !eof() && header[1] == ACK;
|
return !eof() && header[1] == ACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Ack readAck() throws IOException {
|
public Ack readAck() throws IOException {
|
||||||
if (!hasAck()) throw new FormatException();
|
if (!hasAck()) throw new FormatException();
|
||||||
return new Ack(Collections.unmodifiableList(readMessageIds()));
|
return new Ack(readMessageIds());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MessageId> readMessageIds() throws IOException {
|
private List<MessageId> readMessageIds() throws IOException {
|
||||||
@@ -102,10 +104,12 @@ class PacketReaderImpl implements PacketReader {
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasMessage() throws IOException {
|
public boolean hasMessage() throws IOException {
|
||||||
return !eof() && header[1] == MESSAGE;
|
return !eof() && header[1] == MESSAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Message readMessage() throws IOException {
|
public Message readMessage() throws IOException {
|
||||||
if (!hasMessage()) throw new FormatException();
|
if (!hasMessage()) throw new FormatException();
|
||||||
if (payloadLength <= MESSAGE_HEADER_LENGTH) throw new FormatException();
|
if (payloadLength <= MESSAGE_HEADER_LENGTH) throw new FormatException();
|
||||||
@@ -125,21 +129,25 @@ class PacketReaderImpl implements PacketReader {
|
|||||||
return new Message(messageId, groupId, timestamp, raw);
|
return new Message(messageId, groupId, timestamp, raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasOffer() throws IOException {
|
public boolean hasOffer() throws IOException {
|
||||||
return !eof() && header[1] == OFFER;
|
return !eof() && header[1] == OFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Offer readOffer() throws IOException {
|
public Offer readOffer() throws IOException {
|
||||||
if (!hasOffer()) throw new FormatException();
|
if (!hasOffer()) throw new FormatException();
|
||||||
return new Offer(Collections.unmodifiableList(readMessageIds()));
|
return new Offer(readMessageIds());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasRequest() throws IOException {
|
public boolean hasRequest() throws IOException {
|
||||||
return !eof() && header[1] == REQUEST;
|
return !eof() && header[1] == REQUEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Request readRequest() throws IOException {
|
public Request readRequest() throws IOException {
|
||||||
if (!hasRequest()) throw new FormatException();
|
if (!hasRequest()) throw new FormatException();
|
||||||
return new Request(Collections.unmodifiableList(readMessageIds()));
|
return new Request(readMessageIds());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,5 @@
|
|||||||
package org.briarproject.lifecycle;
|
package org.briarproject.lifecycle;
|
||||||
|
|
||||||
import static com.sun.jna.Library.OPTION_FUNCTION_MAPPER;
|
|
||||||
import static com.sun.jna.Library.OPTION_TYPE_MAPPER;
|
|
||||||
import static java.util.logging.Level.WARNING;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.locks.Lock;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.briarproject.util.OsUtils;
|
|
||||||
|
|
||||||
import com.sun.jna.Native;
|
import com.sun.jna.Native;
|
||||||
import com.sun.jna.Pointer;
|
import com.sun.jna.Pointer;
|
||||||
import com.sun.jna.platform.win32.WinDef.HINSTANCE;
|
import com.sun.jna.platform.win32.WinDef.HINSTANCE;
|
||||||
@@ -28,6 +14,20 @@ import com.sun.jna.win32.StdCallLibrary.StdCallCallback;
|
|||||||
import com.sun.jna.win32.W32APIFunctionMapper;
|
import com.sun.jna.win32.W32APIFunctionMapper;
|
||||||
import com.sun.jna.win32.W32APITypeMapper;
|
import com.sun.jna.win32.W32APITypeMapper;
|
||||||
|
|
||||||
|
import org.briarproject.util.OsUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static com.sun.jna.Library.OPTION_FUNCTION_MAPPER;
|
||||||
|
import static com.sun.jna.Library.OPTION_TYPE_MAPPER;
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
|
||||||
class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
@@ -44,7 +44,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
|
|
||||||
WindowsShutdownManagerImpl() {
|
WindowsShutdownManagerImpl() {
|
||||||
// Use the Unicode versions of Win32 API calls
|
// Use the Unicode versions of Win32 API calls
|
||||||
Map<String, Object> m = new HashMap<String, Object>();
|
Map<String, Object> m = new HashMap<>();
|
||||||
m.put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
|
m.put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
|
||||||
m.put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
|
m.put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
|
||||||
options = Collections.unmodifiableMap(m);
|
options = Collections.unmodifiableMap(m);
|
||||||
@@ -112,6 +112,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
User32.class, options);
|
User32.class, options);
|
||||||
// Create a callback to handle the WM_QUERYENDSESSION message
|
// Create a callback to handle the WM_QUERYENDSESSION message
|
||||||
WindowProc proc = new WindowProc() {
|
WindowProc proc = new WindowProc() {
|
||||||
|
@Override
|
||||||
public LRESULT callback(HWND hwnd, int msg, WPARAM wp,
|
public LRESULT callback(HWND hwnd, int msg, WPARAM wp,
|
||||||
LPARAM lp) {
|
LPARAM lp) {
|
||||||
if (msg == WM_QUERYENDSESSION) {
|
if (msg == WM_QUERYENDSESSION) {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -114,7 +113,7 @@ implements RemovableDriveMonitor.Callback {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(matches);
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.briarproject.plugins.file;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
@@ -13,8 +12,9 @@ abstract class UnixRemovableDriveFinder implements RemovableDriveFinder {
|
|||||||
protected abstract String parseMountPoint(String line);
|
protected abstract String parseMountPoint(String line);
|
||||||
protected abstract boolean isRemovableDriveMountPoint(String path);
|
protected abstract boolean isRemovableDriveMountPoint(String path);
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<File> findRemovableDrives() throws IOException {
|
public List<File> findRemovableDrives() throws IOException {
|
||||||
List<File> drives = new ArrayList<File>();
|
List<File> drives = new ArrayList<>();
|
||||||
Process p = new ProcessBuilder(getMountCommand()).start();
|
Process p = new ProcessBuilder(getMountCommand()).start();
|
||||||
Scanner s = new Scanner(p.getInputStream(), "UTF-8");
|
Scanner s = new Scanner(p.getInputStream(), "UTF-8");
|
||||||
try {
|
try {
|
||||||
@@ -35,6 +35,6 @@ abstract class UnixRemovableDriveFinder implements RemovableDriveFinder {
|
|||||||
} finally {
|
} finally {
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(drives);
|
return drives;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
package org.briarproject.plugins.file;
|
package org.briarproject.plugins.file;
|
||||||
|
|
||||||
|
import com.sun.jna.platform.win32.Kernel32;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.sun.jna.platform.win32.Kernel32;
|
|
||||||
|
|
||||||
class WindowsRemovableDriveFinder implements RemovableDriveFinder {
|
class WindowsRemovableDriveFinder implements RemovableDriveFinder {
|
||||||
|
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa364939.aspx
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa364939.aspx
|
||||||
private static final int DRIVE_REMOVABLE = 2;
|
private static final int DRIVE_REMOVABLE = 2;
|
||||||
|
|
||||||
|
@Override
|
||||||
public Collection<File> findRemovableDrives() throws IOException {
|
public Collection<File> findRemovableDrives() throws IOException {
|
||||||
File[] roots = File.listRoots();
|
File[] roots = File.listRoots();
|
||||||
if (roots == null) throw new IOException();
|
if (roots == null) throw new IOException();
|
||||||
List<File> drives = new ArrayList<File>();
|
List<File> drives = new ArrayList<>();
|
||||||
for (File root : roots) {
|
for (File root : roots) {
|
||||||
try {
|
try {
|
||||||
int type = Kernel32.INSTANCE.GetDriveType(root.getPath());
|
int type = Kernel32.INSTANCE.GetDriveType(root.getPath());
|
||||||
@@ -26,6 +26,6 @@ class WindowsRemovableDriveFinder implements RemovableDriveFinder {
|
|||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(drives);
|
return drives;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user