Skip to content

Commit

Permalink
* [Issue #1] Application crashes (immediately) after choosing ' View …
Browse files Browse the repository at this point in the history
…log' from the menu.

Dropped the use of the org.ocpsoft.prettytime:prettytime library: This fixes the crashes due to the library using unsupported language features on older platforms.
  • Loading branch information
amaa-99 committed Jul 29, 2023
1 parent 30bf035 commit c4732ab
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 88 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,6 @@ This project also uses some other open-source libraries such as:
<td>DBFlow</td>
<td>MIT</td>
<td>https://github.com/Raizlabs/DBFlow</td>
</tr>
<tr>
<td>Prettytime</td>
<td>Apache License 2.0</td>
<td>https://github.com/ocpsoft/prettytime</td>
</tr>
<tr>
<td>material-dialogs</td>
Expand Down
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ dependencies {
implementation 'io.reactivex.rxjava3:rxandroid:3.0.2'
implementation 'io.reactivex.rxjava3:rxjava:3.1.5'

implementation "org.ocpsoft.prettytime:prettytime:5.0.6.Final"
implementation "dnsjava:dnsjava:3.5.2"

}
1 change: 0 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-keepattributes
-keep class org.ocpsoft.prettytime.i18n.**
-keep class * extends com.raizlabs.android.dbflow.config.DatabaseHolder { *; }
-dontpreverify
-dontoptimize
Expand Down
23 changes: 0 additions & 23 deletions app/src/main/java/dev/ukanth/ufirewall/log/LogInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,9 @@
import android.util.Log;
import android.util.SparseArray;

import org.ocpsoft.prettytime.PrettyTime;
import org.ocpsoft.prettytime.TimeUnit;
import org.ocpsoft.prettytime.units.JustNow;

import java.net.InetAddress;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import dev.ukanth.ufirewall.Api;
import dev.ukanth.ufirewall.Api.PackageInfoData;
Expand All @@ -61,29 +55,12 @@ public class LogInfo {
public long timestamp;
int totalBlocked;

private static PrettyTime prettyTime;

public static String pretty(Date date) {
if (prettyTime == null) {
prettyTime = new PrettyTime(new Locale(G.locale()));
for (TimeUnit t : prettyTime.getUnits()) {
if (t instanceof JustNow) {
prettyTime.removeUnit(t);
break;
}
}
}
prettyTime.setReference(date);
return prettyTime.format(new Date(0));
}

private final HashMap<String, Integer> dstBlocked; // Number of packets blocked per destination IP address

public LogInfo() {
this.dstBlocked = new HashMap<String, Integer>();
}


public static String parseLog(Context ctx, List<LogData> listLogData) {

//final BufferedReader r = new BufferedReader(new StringReader(dmesg.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,24 @@

import androidx.recyclerview.widget.RecyclerView;

import org.ocpsoft.prettytime.PrettyTime;
import org.ocpsoft.prettytime.TimeUnit;
import org.ocpsoft.prettytime.units.JustNow;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import dev.ukanth.ufirewall.Api;
import dev.ukanth.ufirewall.R;
import dev.ukanth.ufirewall.util.G;

/**
* Created by ukanth on 25/7/16.
*/
public class LogRecyclerViewAdapter extends RecyclerView.Adapter<LogRecyclerViewAdapter.ViewHolder> {


private final List<LogData> logData;
private final Context context;
private LogData data;
private PackageInfo info;
private static PrettyTime prettyTime;
private final RecyclerItemClickListener recyclerItemClickListener;
private View mView;

Expand Down Expand Up @@ -137,12 +130,11 @@ public void onBindViewHolder(ViewHolder holder, int position) {
Log.e(TAG,e1.getMessage(),e1);
}
}


try {
//if(data.getTimestamp() != null && !data.getTimestamp().isEmpty()) {
holder.lastDenied.setText(pretty(new Date(System.currentTimeMillis() - data.getTimestamp())));
//}
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(data.getTimestamp());
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
holder.lastDenied.setText(dateFormat.format(calendar.getTime()));
} catch (Exception e) {
holder.lastDenied.setText("-");
}
Expand All @@ -155,26 +147,11 @@ public void onBindViewHolder(ViewHolder holder, int position) {
holder.icon.invalidate();
}

public static String pretty(Date date) {
if (prettyTime == null) {
prettyTime = new PrettyTime(new Locale(G.locale()));
for (TimeUnit t : prettyTime.getUnits()) {
if (t instanceof JustNow) {
prettyTime.removeUnit(t);
break;
}
}
}
prettyTime.setReference(date);
return prettyTime.format(new Date(0));
}

@Override
public int getItemCount() {
return logData.size();
}


public static class ViewHolder extends RecyclerView.ViewHolder {

final ImageView icon;
Expand Down
25 changes: 0 additions & 25 deletions app/src/main/java/dev/ukanth/ufirewall/service/LogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,7 @@
import com.topjohnwu.superuser.CallbackList;
import com.topjohnwu.superuser.Shell;

import org.ocpsoft.prettytime.PrettyTime;
import org.ocpsoft.prettytime.TimeUnit;
import org.ocpsoft.prettytime.units.JustNow;

import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

Expand Down Expand Up @@ -241,7 +235,6 @@ private void storeLogInfo(String line, Context context) {
}
}


private void checkBatteryOptimize() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final Intent doze = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
Expand All @@ -250,22 +243,6 @@ private void checkBatteryOptimize() {
}
}

private static PrettyTime prettyTime;

public static String pretty(Date date) {
if (prettyTime == null) {
prettyTime = new PrettyTime(new Locale(G.locale()));
for (TimeUnit t : prettyTime.getUnits()) {
if (t instanceof JustNow) {
prettyTime.removeUnit(t);
break;
}
}
}
prettyTime.setReference(date);
return prettyTime.format(new Date(0));
}

@SuppressLint("RestrictedApi")
private void showNotification(LogInfo logInfo) {
if(G.enableLogService()) {
Expand All @@ -279,8 +256,6 @@ private void showNotification(LogInfo logInfo) {
}
}



private static void store(final LogInfo logInfo, Context context) {
try {
if (logInfo != null) {
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/raw/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,6 @@
<td><a href="https://github.com/ReactiveX/RxJava">RxJava</a></td>
<td>Apache License 2.0</td>
</tr>
<tr>
<td><a href="https://github.com/ocpsoft/prettytime">PrettyTime</a></td>
<td>Apache License 2.0</td>
</tr>
</table>
</body>
</html>

0 comments on commit c4732ab

Please sign in to comment.