Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lint warnings #337

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions exampleapp/src/main/java/org/matomo/demo/DemoApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import timber.log.Timber;

public class DemoApp extends MatomoApplication {
private DimensionQueue mDimensionQueue;

@Override
public TrackerBuilder onCreateTrackerConfig() {
Expand Down Expand Up @@ -55,7 +54,7 @@ private void onInitTracker() {
// i.e. "http://org.matomo.demo:1/com.android.vending"
// getTracker().download();

mDimensionQueue = new DimensionQueue(getTracker());
DimensionQueue mDimensionQueue = new DimensionQueue(getTracker());

// This will be send the next time something is tracked.
mDimensionQueue.add(0, "test");
Expand Down
10 changes: 5 additions & 5 deletions exampleapp/src/main/java/org/matomo/demo/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SettingsActivity extends Activity {

private void refreshUI(final Activity settingsActivity) {
// auto track button
Button button = (Button) findViewById(R.id.bindtoapp);
Button button = findViewById(R.id.bindtoapp);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -39,7 +39,7 @@ public void onClick(View v) {
});

// Dry run
CheckBox dryRun = (CheckBox) findViewById(R.id.dryRunCheckbox);
CheckBox dryRun = findViewById(R.id.dryRunCheckbox);
dryRun.setChecked(((MatomoApplication) getApplication()).getTracker().getDryRunTarget() != null);
dryRun.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -49,7 +49,7 @@ public void onClick(View v) {
});

// out out
CheckBox optOut = (CheckBox) findViewById(R.id.optOutCheckbox);
CheckBox optOut = findViewById(R.id.optOutCheckbox);
optOut.setChecked(((MatomoApplication) getApplication()).getTracker().isOptOut());
optOut.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -59,7 +59,7 @@ public void onClick(View v) {
});

// dispatch interval
EditText input = (EditText) findViewById(R.id.dispatchIntervallInput);
EditText input = findViewById(R.id.dispatchIntervallInput);
input.setText(Long.toString(
((MatomoApplication) getApplication()).getTracker().getDispatchInterval()
));
Expand Down Expand Up @@ -88,7 +88,7 @@ public void afterTextChanged(Editable editable) {
);

//session Timeout Input
input = (EditText) findViewById(R.id.sessionTimeoutInput);
input = findViewById(R.id.sessionTimeoutInput);
input.setText(Long.toString(
(((MatomoApplication) getApplication()).getTracker().getSessionTimeout() / 60000)
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.SharedPreferences;
import androidx.annotation.NonNull;

import java.util.Iterator;
import java.util.Map;
import java.util.UUID;

Expand Down Expand Up @@ -57,9 +56,7 @@ public void port(Tracker tracker) {
).apply();
mLegacyPrefs.edit().remove(LEGACY_PREF_PREV_VISIT).apply();
}
final Iterator<? extends Map.Entry<String, ?>> it = mLegacyPrefs.getAll().entrySet().iterator();
while (it.hasNext()) {
final Map.Entry<String, ?> oldEntry = it.next();
for (Map.Entry<String, ?> oldEntry : mLegacyPrefs.getAll().entrySet()) {
if (oldEntry.getKey().startsWith("downloaded:")) {
newSettings.edit().putBoolean(oldEntry.getKey(), true).apply();
mLegacyPrefs.edit().remove(oldEntry.getKey()).apply();
Expand Down
2 changes: 1 addition & 1 deletion tracker/src/main/java/org/matomo/sdk/Matomo.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Matomo {
private static final String TAG = Matomo.tag(Matomo.class);
private static final String BASE_PREFERENCE_FILE = "org.matomo.sdk";

@SuppressLint("StaticFieldLeak") private static Matomo sInstance;
@SuppressLint("StaticFieldLeak") private static volatile Matomo sInstance;
d4rken marked this conversation as resolved.
Show resolved Hide resolved

private final Map<Tracker, SharedPreferences> mPreferenceMap = new HashMap<>();
private final Context mContext;
Expand Down
4 changes: 2 additions & 2 deletions tracker/src/main/java/org/matomo/sdk/TrackerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* Configuration details for a {@link Tracker}
*/
public class TrackerBuilder {
private String mApiUrl;
private int mSiteId;
private final String mApiUrl;
private final int mSiteId;
private String mTrackerName;
private String mApplicationBaseUrl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPOutputStream;

import timber.log.Timber;
Expand Down Expand Up @@ -46,15 +46,11 @@ public boolean send(Packet packet) {
urlConnection.addRequestProperty("Content-Encoding", "gzip");
ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();

GZIPOutputStream gzipStream = null;
try {
gzipStream = new GZIPOutputStream(byteArrayOS);
gzipStream.write(toPost.getBytes(Charset.forName("UTF8")));
} finally {
// If closing fails we assume the written data to be invalid.
// Don't catch the exception and let it abort the `send(Packet)` call.
if (gzipStream != null) gzipStream.close();
try (GZIPOutputStream gzipStream = new GZIPOutputStream(byteArrayOS)) {
gzipStream.write(toPost.getBytes(StandardCharsets.UTF_8));
}
// If closing fails we assume the written data to be invalid.
// Don't catch the exception and let it abort the `send(Packet)` call.

OutputStream outputStream = null;
try {
Expand All @@ -75,7 +71,7 @@ public boolean send(Packet packet) {

BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(urlConnection.getOutputStream(), "UTF-8"));
writer = new BufferedWriter(new OutputStreamWriter(urlConnection.getOutputStream(), StandardCharsets.UTF_8));
writer.write(toPost);
} finally {
if (writer != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void checkCacheLimits() {
long timestamp;
try {
final String[] split = head.getName().split("_");
timestamp = Long.valueOf(split[1]);
timestamp = Long.parseLong(split[1]);
} catch (Exception e) {
Timber.tag(TAG).e(e);
timestamp = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class DownloadTracker {
private final Object mTrackOnceLock = new Object();
private final PackageManager mPackMan;
private final SharedPreferences mPreferences;
private final Context mContext;
private final boolean mInternalTracking;
private String mVersion;
private final PackageInfo mPkgInfo;
Expand Down Expand Up @@ -69,8 +68,6 @@ public ApkChecksum(Context context) {
}
}

public ApkChecksum(PackageInfo packageInfo) {mPackageInfo = packageInfo;}

@Override
public boolean isIntensiveWork() {
return true;
Expand Down Expand Up @@ -128,7 +125,7 @@ private static PackageInfo getOurPackageInfo(Context context) {

public DownloadTracker(Tracker tracker, @NonNull PackageInfo packageInfo) {
mTracker = tracker;
mContext = tracker.getMatomo().getContext();
Context mContext = tracker.getMatomo().getContext();
mPreferences = tracker.getPreferences();
mPackMan = tracker.getMatomo().getContext().getPackageManager();
mPkgInfo = packageInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Thread.UncaughtExceptionHandler getDefaultExceptionHandler() {
}

@Override
public void uncaughtException(Thread thread, Throwable ex) {
public void uncaughtException(@NonNull Thread thread, @NonNull Throwable ex) {
try {
String excInfo = ex.getMessage();

Expand Down
2 changes: 1 addition & 1 deletion tracker/src/main/java/org/matomo/sdk/tools/Checksum.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static String getHex(byte[] raw) {
public static String getMD5Checksum(String string) throws Exception {
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(string.getBytes());
byte messageDigest[] = digest.digest();
byte[] messageDigest = digest.digest();
return getHex(messageDigest);
}

Expand Down
8 changes: 0 additions & 8 deletions tracker/src/main/java/org/matomo/sdk/tools/Objects.java

This file was deleted.

10 changes: 0 additions & 10 deletions tracker/src/test/java/testhelpers/FullEnvTestLifeCycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,4 @@
* Tries to emulate a full app environment to satisfy more in-depth tests
*/
public class FullEnvTestLifeCycle extends DefaultTestLifecycle {
// @Override
// public Application createApplication(Method method, AndroidManifest appManifest, Config config) {
// // FIXME If a future version of Robolectric implements "setInstallerPackageName", remove this.
// RobolectricPackageManager oldManager = Robolectric.packageManager;
// RobolectricPackageManager newManager = new FullEnvPackageManager();
// for (PackageInfo pkg : oldManager.getInstalledPackages(0))
// newManager.addPackage(pkg);
// Robolectric.packageManager = newManager;
// return new MatomoTestApplication();
// }
}
1 change: 1 addition & 0 deletions tracker/src/test/java/testhelpers/FullEnvTestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/**
* Tries to emulate a full app environment to satisfy more in-depth tests
*/
@SuppressWarnings("unused")
public class FullEnvTestRunner extends RobolectricTestRunner {
public FullEnvTestRunner(Class<?> testClass) throws InitializationError {
super(testClass);
Expand Down
4 changes: 0 additions & 4 deletions tracker/src/test/java/testhelpers/JUnitTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public JUnitTree() {
minlogLevel = Log.VERBOSE;
}

public JUnitTree(int minlogLevel) {
this.minlogLevel = minlogLevel;
}

private static String priorityToString(int priority) {
switch (priority) {
case Log.ERROR:
Expand Down
3 changes: 0 additions & 3 deletions tracker/src/test/java/testhelpers/QueryHashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@ public String get(QueryParams key) {
return get(key.toString());
}

public boolean containsKey(QueryParams key) {
return super.containsKey(key.toString());
}
}