Skip to content

Commit

Permalink
removed a lot of lintable warnings, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bitmold committed Feb 17, 2022
1 parent e4454a6 commit aa575d5
Show file tree
Hide file tree
Showing 21 changed files with 34 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,12 @@ public View getView(int position, View convertView, ViewGroup parent) {
convertView.setFocusable(true);
convertView.setFocusableInTouchMode(true);

convertView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {

if (hasFocus)
v.setBackgroundColor(getResources().getColor(R.color.dark_purple));
else
{
v.setBackgroundColor(getResources().getColor(android.R.color.transparent));
}
convertView.setOnFocusChangeListener((v, hasFocus) -> {
if (hasFocus)
v.setBackgroundColor(getResources().getColor(R.color.dark_purple));
else
{
v.setBackgroundColor(getResources().getColor(android.R.color.transparent));
}
});

Expand Down Expand Up @@ -253,11 +249,7 @@ public ArrayList<TorifiedApp> getApps(SharedPreferences prefs) {


// check if this application is allowed
if (Arrays.binarySearch(tordApps, app.getPackageName()) >= 0) {
app.setTorified(true);
} else {
app.setTorified(false);
}
app.setTorified(Arrays.binarySearch(tordApps, app.getPackageName()) >= 0);

}

Expand Down Expand Up @@ -308,7 +300,7 @@ else if (v.getTag() instanceof CheckBox)

private static class ReloadAppsAsyncTask extends AsyncTask<Void, Void, Void> {

private WeakReference<AppManagerActivity> activity;
private final WeakReference<AppManagerActivity> activity;

ReloadAppsAsyncTask(AppManagerActivity activity) {
this.activity = new WeakReference<>(activity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.btnSnowflakeAmp).setVisibility(View.GONE);
}
else {
findViewById(R.id.btnMoat).setOnClickListener(v -> {
startActivityForResult(new Intent(BridgeWizardActivity.this, MoatActivity.class), MOAT_REQUEST_CODE);
});
findViewById(R.id.btnMoat).setOnClickListener(v -> startActivityForResult(new Intent(BridgeWizardActivity.this, MoatActivity.class), MOAT_REQUEST_CODE));
}

mBtDirect = findViewById(R.id.btnBridgesDirect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.torproject.android.R;
import org.torproject.android.core.ClipboardUtils;
import org.torproject.android.service.OrbotService;
import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.service.util.Prefs;

import java.io.UnsupportedEncodingException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.HurlStack;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ public class ProxiedHurlStack extends HurlStack {
private final String mUsername;
private final String mPassword;

public ProxiedHurlStack(String host, int port) {
super();

mHost = host;
mPort = port;
mUsername = null;
mPassword = null;
}

public ProxiedHurlStack(String host, int port, String username, String password) {
super();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}

private void attemptToWriteBackup(Uri outputFile) {
String port = getArguments().getString(OnionServiceActivity.BUNDLE_KEY_PORT);
String relativePath = getArguments().getString(OnionServiceActivity.BUNDLE_KEY_PATH);
V3BackupUtils v3BackupUtils = new V3BackupUtils(getContext());
String backup = v3BackupUtils.createV3ZipBackup(port, relativePath, outputFile);
String backup = v3BackupUtils.createV3ZipBackup(relativePath, outputFile);
Toast.makeText(getContext(), backup != null ? R.string.backup_saved_at_external_storage : R.string.error, Toast.LENGTH_LONG).show();
dismiss();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import androidx.coordinatorlayout.widget.CoordinatorLayout;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import org.torproject.android.R;
import org.torproject.android.core.DiskUtils;
Expand Down Expand Up @@ -55,7 +54,7 @@ public void onCreate(Bundle bundle) {
fab.setOnClickListener(v -> new OnionServiceCreateDialogFragment().show(getSupportFragmentManager(), OnionServiceCreateDialogFragment.class.getSimpleName()));

mContentResolver = getContentResolver();
mAdapter = new OnionV3ListAdapter(this, mContentResolver.query(OnionServiceContentProvider.CONTENT_URI, OnionServiceContentProvider.PROJECTION, BASE_WHERE_SELECTION_CLAUSE + '1', null, null), 0);
mAdapter = new OnionV3ListAdapter(this, mContentResolver.query(OnionServiceContentProvider.CONTENT_URI, OnionServiceContentProvider.PROJECTION, BASE_WHERE_SELECTION_CLAUSE + '1', null, null));
mContentResolver.registerContentObserver(OnionServiceContentProvider.CONTENT_URI, true, new OnionServiceObserver(new Handler()));

ListView onionList = findViewById(R.id.onion_list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class OnionV3ListAdapter extends CursorAdapter {

private final LayoutInflater mLayoutInflater;

OnionV3ListAdapter(Context context, Cursor cursor, int flags) {
super(context, cursor, flags);
OnionV3ListAdapter(Context context, Cursor cursor) {
super(context, cursor, 0);
mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public V3BackupUtils(Context context) {
mResolver = mContext.getContentResolver();
}

public String createV3ZipBackup(String port, String relativePath, Uri zipFile) {
public String createV3ZipBackup(String relativePath, Uri zipFile) {
String[] files = createFilesForZippingV3(relativePath);
ZipUtilities zip = new ZipUtilities(files, zipFile, mResolver);
if (!zip.zip()) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

mResolver = getContentResolver();
mAdapter = new ClientAuthListAdapter(this, mResolver.query(ClientAuthContentProvider.CONTENT_URI, ClientAuthContentProvider.PROJECTION, null, null, null), 0);
mAdapter = new ClientAuthListAdapter(this, mResolver.query(ClientAuthContentProvider.CONTENT_URI, ClientAuthContentProvider.PROJECTION, null, null, null));
mResolver.registerContentObserver(ClientAuthContentProvider.CONTENT_URI, true, new V3ClientAuthContentObserver(new Handler()));

findViewById(R.id.fab).setOnClickListener(v ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
public class ClientAuthListAdapter extends CursorAdapter {
private final LayoutInflater mLayoutInflator;

ClientAuthListAdapter(Context context, Cursor cursor, int flags) {
super(context, cursor, flags);
ClientAuthListAdapter(Context context, Cursor cursor) {
super(context, cursor, 0);
mLayoutInflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_v3auth.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="org.torproject.android.ui.hiddenservices.ClientCookiesActivity">
tools:context="org.torproject.android.ui.v3onionservice.clientauth.ClientAuthActivity">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public static class ExitNode {
ExitNode(String fingerPrint) {
this.fingerPrint = fingerPrint;
}
public String fingerPrint;
public final String fingerPrint;
public String country;
public String ipAddress;
boolean querying = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
public static File appCacheHome;
private final ExecutorService mExecutor = Executors.newCachedThreadPool();
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.LOLLIPOP)
boolean mIsLollipop = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
final boolean mIsLollipop = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
OrbotRawEventListener mOrbotRawEventListener;
OrbotVpnManager mVpnManager;
Handler mHandler;
//we should randomly sort alBridges so we don't have the same bridge order each time
Random bridgeSelectRandom = new Random(System.nanoTime());
final Random bridgeSelectRandom = new Random(System.nanoTime());
ActionBroadcastReceiver mActionBroadcastReceiver;
private String mCurrentStatus = STATUS_OFF;
TorControlConnection conn = null;
Expand Down Expand Up @@ -716,13 +716,6 @@ private void startTor() {
mNotifyBuilder.setProgress(100, 0, false);
showToolbarNotification("", NOTIFY_ID, R.drawable.ic_stat_tor);

ArrayList<String> customEnv = new ArrayList<>();

if (Prefs.bridgesEnabled())
if (Prefs.useVpn() && !mIsLollipop) {
customEnv.add("TOR_PT_PROXY=socks5://" + OrbotVpnManager.sSocksProxyLocalhost + ":" + OrbotVpnManager.sSocksProxyServerPort);
}

startTorService();

if (Prefs.hostOnionServicesEnabled()) {
Expand Down Expand Up @@ -1431,7 +1424,7 @@ static class Bridge {
}

private class IncomingIntentRouter implements Runnable {
Intent mIntent;
final Intent mIntent;

public IncomingIntentRouter(Intent intent) {
mIntent = intent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public interface TorServiceConstants {
/**
* The user has disabled the ability for background starts triggered by
* apps. Fallback to the old {@link Intent} action that brings up Orbot:
* {@link org.torproject.android.OrbotMainActivity#INTENT_ACTION_REQUEST_START_TOR}
* {@link #ACTION_START}
*/
String STATUS_STARTS_DISABLED = "STARTS_DISABLED";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class CustomTorResourceInstaller {
Expand All @@ -25,7 +24,7 @@ public CustomTorResourceInstaller(Context context, File installFolder) {
/*
* Write the inputstream contents to the file
*/
private static boolean streamToFile(InputStream stm, File outFile, boolean append, boolean zip) throws IOException {
private static void streamToFile(InputStream stm, File outFile, boolean append, boolean zip) throws IOException {
byte[] buffer = new byte[1024];

int bytecount;
Expand All @@ -35,7 +34,7 @@ private static boolean streamToFile(InputStream stm, File outFile, boolean appen

if (zip) {
zis = new ZipInputStream(stm);
ZipEntry ze = zis.getNextEntry();
zis.getNextEntry();
stm = zis;
}

Expand All @@ -48,9 +47,6 @@ private static boolean streamToFile(InputStream stm, File outFile, boolean appen

if (zis != null)
zis.close();


return true;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ public static String getExitNodes() {
return prefs.getString(PREF_EXIT_NODES, "");
}

public static void setExitNodes(String exits) {
putString(PREF_EXIT_NODES, exits);
}

public static SharedPreferences getSharedPrefs(Context context) {
return context.getSharedPreferences(OrbotConstants.PREF_TOR_SHARED_PREFS, Context.MODE_MULTI_PROCESS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public static String getIPAddress(boolean useIPv4) throws SocketException {
return sAddr;
} else {
if (!isIPv4) {
if (sAddr.startsWith("fe80") || sAddr.startsWith("FE80")) // skipping link-local addresses
if (sAddr.startsWith("FE80")) // skipping link-local addresses
continue;

int delim = sAddr.indexOf('%'); // drop ip6 port suffix
Expand Down Expand Up @@ -260,9 +260,9 @@ public static void setCheckConnectedIfaces(boolean value) {
*/
public static class AppDescriptor {

private String packageName;
private String version;
private int uid;
private final String packageName;
private final String version;
private final int uid;

public AppDescriptor(int uid, String pName, String ver) {
this.uid = uid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.zip.ZipEntry;
Expand All @@ -27,9 +26,6 @@ public static boolean isPortOpen(final String ip, final int port, final int time
socket.connect(new InetSocketAddress(ip, port), timeout);
socket.close();
return true;
} catch (ConnectException ce) {
//ce.printStackTrace();
return false;
} catch (Exception ex) {
//ex.printStackTrace();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@

public class RequestPacketHandler implements Runnable {

IpPacket packet;
PacketFlow pFlow;
DNSResolver mDnsResolver;
final IpPacket packet;
final PacketFlow pFlow;
final DNSResolver mDnsResolver;

public RequestPacketHandler (IpPacket packet, PacketFlow pFLow, DNSResolver dnsResolver)
{
public RequestPacketHandler (IpPacket packet, PacketFlow pFLow, DNSResolver dnsResolver) {
this.packet = packet;
this.pFlow = pFLow;
this.mDnsResolver = dnsResolver;
}
public void run() {


try {
UdpPacket udpPacket = (UdpPacket) packet.getPayload();

Expand All @@ -36,8 +33,6 @@ public void run() {
if (dnsResp != null) {

DnsPacket dnsRequest = (DnsPacket) udpPacket.getPayload();


DnsPacket dnsResponse = DnsPacket.newPacket(dnsResp, 0, dnsResp.length);

DnsPacket.Builder dnsBuilder = new DnsPacket.Builder();
Expand Down Expand Up @@ -105,7 +100,5 @@ else if (packet instanceof IpV6Packet)
} catch (Exception ioe) {
Log.e("DNS", "could not parse DNS packet: " + ioe);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ public static ArrayList<TorifiedApp> getApps(Context context, SharedPreferences
//app.setIcon(pMgr.getApplicationIcon(aInfo));

// check if this application is allowed
if (Arrays.binarySearch(tordApps, app.getPackageName()) >= 0) {
app.setTorified(true);
} else {
app.setTorified(false);
}
app.setTorified(Arrays.binarySearch(tordApps, app.getPackageName()) >= 0);
}

Collections.sort(apps);
Expand Down

0 comments on commit aa575d5

Please sign in to comment.