android: Cleanup classes
- Use final modifer wherever possible - Use try-with-resources for input/output streams Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
committed by
Jason A. Donenfeld
parent
4986d92f3d
commit
4671f59c67
@@ -22,7 +22,7 @@ public final class SharedLibraryLoader {
|
||||
private SharedLibraryLoader() {
|
||||
}
|
||||
|
||||
public static final void loadSharedLibrary(final Context context, final String libName) {
|
||||
public static void loadSharedLibrary(final Context context, final String libName) {
|
||||
Throwable noAbiException;
|
||||
try {
|
||||
System.loadLibrary(libName);
|
||||
@@ -35,12 +35,12 @@ public final class SharedLibraryLoader {
|
||||
final ZipFile zipFile;
|
||||
try {
|
||||
zipFile = new ZipFile(new File(context.getApplicationInfo().sourceDir), ZipFile.OPEN_READ);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
final String mappedLibName = System.mapLibraryName(libName);
|
||||
byte buffer[] = new byte[1024 * 32];
|
||||
final byte[] buffer = new byte[1024 * 32];
|
||||
for (final String abi : Build.SUPPORTED_ABIS) {
|
||||
final String libZipPath = "lib" + File.separatorChar + abi + File.separatorChar + mappedLibName;
|
||||
final ZipEntry zipEntry = zipFile.getEntry(libZipPath);
|
||||
@@ -50,13 +50,13 @@ public final class SharedLibraryLoader {
|
||||
try {
|
||||
f = File.createTempFile("lib", ".so", context.getCacheDir());
|
||||
Log.d(TAG, "Extracting apk:/" + libZipPath + " to " + f.getAbsolutePath() + " and loading");
|
||||
FileOutputStream out = new FileOutputStream(f);
|
||||
InputStream in = zipFile.getInputStream(zipEntry);
|
||||
int len;
|
||||
while ((len = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, len);
|
||||
try (final FileOutputStream out = new FileOutputStream(f);
|
||||
final InputStream in = zipFile.getInputStream(zipEntry)) {
|
||||
int len;
|
||||
while ((len = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, len);
|
||||
}
|
||||
}
|
||||
out.close();
|
||||
System.load(f.getAbsolutePath());
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
@@ -64,6 +64,7 @@ public final class SharedLibraryLoader {
|
||||
noAbiException = e;
|
||||
} finally {
|
||||
if (f != null)
|
||||
// noinspection ResultOfMethodCallIgnored
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public final class ToolsInstaller {
|
||||
|
||||
public CompletionStage<String> getVersion() {
|
||||
return Application.getComponent().getAsyncWorker().supplyAsync(() -> {
|
||||
final ArrayList<String> output = new ArrayList<>();
|
||||
final List<String> output = new ArrayList<>();
|
||||
if (rootShell.run(output, "cat /sys/module/wireguard/version") != 0 || output.isEmpty())
|
||||
throw new RuntimeException("Unable to determine kernel module version");
|
||||
return output.get(0);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Topic {
|
||||
subscribers = new SyncArrayList<>();
|
||||
}
|
||||
|
||||
public synchronized void subscribe(Subscriber sub) {
|
||||
public synchronized void subscribe(final Subscriber sub) {
|
||||
subscribers.add(new WeakReference<>(sub));
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ public class Topic {
|
||||
subscribers = new SyncArrayList<>();
|
||||
}
|
||||
|
||||
public synchronized void unsubscribe(Subscriber sub) {
|
||||
public synchronized void unsubscribe(final Subscriber sub) {
|
||||
List<WeakReference<Subscriber>> subs = subscribers;
|
||||
subscribers = new ArrayList<>();
|
||||
for (WeakReference<Subscriber> subscriber : subs) {
|
||||
for (final WeakReference<Subscriber> subscriber : subs) {
|
||||
if (subscriber.get() != null && subscriber.get() != sub)
|
||||
subscribers.add(subscriber);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class Topic {
|
||||
this.results = results;
|
||||
// Snapshot
|
||||
List<WeakReference<Subscriber>> subs = subscribers;
|
||||
for (WeakReference<Subscriber> subscriber : subs) {
|
||||
for (final WeakReference<Subscriber> subscriber : subs) {
|
||||
if (subscriber != null && subscriber.get() != null)
|
||||
subscriber.get().onTopicPublished(this);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class Topic {
|
||||
|
||||
public interface Subscriber {
|
||||
default void subscribeTopics() {
|
||||
for (Topic topic : getSubscription()) {
|
||||
for (final Topic topic : getSubscription()) {
|
||||
if (topic.isPublished()) {
|
||||
onTopicPublished(topic);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class Topic {
|
||||
}
|
||||
}
|
||||
default void unsubscribeTopics() {
|
||||
for (Topic event : getSubscription()) {
|
||||
for (final Topic event : getSubscription()) {
|
||||
event.unsubscribe(this);
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class Topic {
|
||||
|
||||
private static class SyncArrayList<E> extends ArrayList<E> {
|
||||
@Override
|
||||
public synchronized boolean add(E e) {
|
||||
public synchronized boolean add(final E e) {
|
||||
return super.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user