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

Add App class, webconsole lint, ignore folders at IDE #72

Closed
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ obj
ant.properties
local.properties
build.sh
android.iml
build
*.iml
*.local
*.jks
tmp*
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ android {
targetSdkVersion 33
// TODO: 24?
minSdkVersion 16
versionCode 2510000
versionName "2.51.0"
archivesBaseName += "-$versionName"
//Required for app version retrieval to work as of Android Studio 4.1.0: https://issuetracker.google.com/issues/158695880
buildConfigField 'int', 'VERSION_CODE', "${project.android_version_code}"
buildConfigField 'String', 'VERSION_NAME', "\"${project.android_version_name}\""
archivesBaseName += "-${project.android_version_name}"
ndkVersion "23.2.8568313"

ndk {
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:name=".appscope.App"
android:allowBackup="true"
android:icon="@mipmap/logo"
android:label="@string/app_name"
Expand All @@ -36,7 +37,7 @@

<receiver
android:enabled="true"
android:name="org.purplei2p.i2pd.receivers.BootUpReceiver"
android:name=".appscope.receivers.BootUpReceiver"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
Expand All @@ -52,7 +53,7 @@
<activity android:name=".SettingsActivity" />

<receiver
android:name=".NetworkStateChangeReceiver"
android:name=".appscope.receivers.NetworkStateChangeReceiver"
android:label="NetworkChangeReceiver"
android:exported="true" >
<intent-filter>
Expand All @@ -74,7 +75,7 @@
android:name=".I2PDActivity" />

<service
android:name=".ForegroundService"
android:name=".appscope.ForegroundService"
android:exported="false"
android:stopWithTask="false"
android:enabled="true" />
Expand Down
86 changes: 6 additions & 80 deletions app/src/main/java/org/purplei2p/i2pd/I2PDActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Build;
import android.os.Environment;
import android.os.IBinder;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.provider.Settings;
Expand All @@ -38,6 +33,9 @@

import static android.provider.Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS;

import org.purplei2p.i2pd.appscope.App;
import org.purplei2p.i2pd.appscope.DaemonWrapper;

public class I2PDActivity extends Activity {
private static final String TAG = "i2pdActvt";
private static final int MY_PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
Expand All @@ -51,8 +49,7 @@ public class I2PDActivity extends Activity {
private CheckBox SAMState;
private CheckBox I2CPState;


private static volatile DaemonWrapper daemon;
private DaemonWrapper daemon = App.getDaemonWrapper();

private final DaemonWrapper.StateUpdateListener daemonStateUpdatedListener = new DaemonWrapper.StateUpdateListener() {
@Override
Expand Down Expand Up @@ -111,22 +108,14 @@ public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startService(new Intent(this, ForegroundService.class));
textView = (TextView) findViewById(R.id.appStatusText);
HTTPProxyState = (CheckBox) findViewById(R.id.service_httpproxy_box);
SOCKSProxyState = (CheckBox) findViewById(R.id.service_socksproxy_box);
BOBState = (CheckBox) findViewById(R.id.service_bob_box);
SAMState = (CheckBox) findViewById(R.id.service_sam_box);
I2CPState = (CheckBox) findViewById(R.id.service_i2cp_box);

if (daemon == null) {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
daemon = new DaemonWrapper(getAssets(), connectivityManager);
}
ForegroundService.init(daemon);

daemon.addStateChangeListener(daemonStateUpdatedListener);
daemonStateUpdatedListener.daemonStateUpdate(DaemonWrapper.State.uninitialized, daemon.getState());

// request permissions
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Expand All @@ -142,8 +131,6 @@ public void onCreate(Bundle savedInstanceState) {
}
}

doBindService();

final Timer gracefulQuitTimer = getGracefulQuitTimer();
if (gracefulQuitTimer != null) {
long gracefulStopAtMillis;
Expand All @@ -154,25 +141,16 @@ public void onCreate(Bundle savedInstanceState) {
}

openBatteryOptimizationDialogIfNeeded();

updateStatusText();
}

@Override
protected void onDestroy() {
super.onDestroy();
textView = null;
ForegroundService.deinit();
daemon.removeStateChangeListener(daemonStateUpdatedListener);
//cancelGracefulStop0();
try {
doUnbindService();
} catch (IllegalArgumentException ex) {
Log.e(TAG, "throwable caught and ignored", ex);
if (ex.getMessage().startsWith("Service not registered: " + org.purplei2p.i2pd.I2PDActivity.class.getName())) {
Log.i(TAG, "Service not registered exception seems to be normal, not a bug it seems.");
}
} catch (Throwable tr) {
Log.e(TAG, "throwable caught and ignored", tr);
}
}

@Override
Expand Down Expand Up @@ -204,58 +182,6 @@ private CharSequence throwableToString(Throwable tr) {
return sw.toString();
}

// private LocalService mBoundService;

private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
/* This is called when the connection with the service has been
established, giving us the service object we can use to
interact with the service. Because we have bound to a explicit
service that we know is running in our own process, we can
cast its IBinder to a concrete class and directly access it. */
// mBoundService = ((LocalService.LocalBinder)service).getService();

/* Tell the user about this for our demo. */
// Toast.makeText(Binding.this, R.string.local_service_connected,
// Toast.LENGTH_SHORT).show();
}

public void onServiceDisconnected(ComponentName className) {
/* This is called when the connection with the service has been
unexpectedly disconnected -- that is, its process crashed.
Because it is running in our same process, we should never
see this happen. */
// mBoundService = null;
// Toast.makeText(Binding.this, R.string.local_service_disconnected,
// Toast.LENGTH_SHORT).show();
}
};

private static volatile boolean mIsBound;

private void doBindService() {
synchronized (I2PDActivity.class) {
if (mIsBound)
return;
// Establish a connection with the service. We use an explicit
// class name because we want a specific service implementation that
// we know will be running in our own process (and thus won't be
// supporting component replacement by other applications).
bindService(new Intent(this, ForegroundService.class), mConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
}
}

private void doUnbindService() {
synchronized (I2PDActivity.class) {
if (mIsBound) {
// Detach our existing connection.
unbindService(mConnection);
mIsBound = false;
}
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
Expand Down
65 changes: 39 additions & 26 deletions app/src/main/java/org/purplei2p/i2pd/WebConsoleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,67 @@
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import java.util.Objects;

public class WebConsoleActivity extends Activity {
public static final String TAG = "webconsole";
private WebView webView;
private SwipeRefreshLayout swipeRefreshLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_console);
try {
setContentView(R.layout.activity_web_console);

Objects.requireNonNull(getActionBar()).setDisplayHomeAsUpEnabled(true);
Objects.requireNonNull(getActionBar()).setDisplayHomeAsUpEnabled(true);

webView = (WebView) findViewById(R.id.webconsole);
webView.setWebViewClient(new WebViewClient());
webView = findViewById(R.id.webconsole);
webView.setWebViewClient(new WebViewClient());

final WebSettings webSettings = webView.getSettings();
webSettings.setBuiltInZoomControls(true);
webSettings.setJavaScriptEnabled(false);
webView.loadUrl(I2PD_JNI.getWebConsAddr());
final WebSettings webSettings = webView.getSettings();
webSettings.setBuiltInZoomControls(true);
webSettings.setJavaScriptEnabled(false);
webView.loadUrl(I2PD_JNI.getWebConsAddr());

swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
swipeRefreshLayout.setRefreshing(true);
new Handler().post(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
webView.reload();
}
});
}
});
swipeRefreshLayout = findViewById(R.id.swipe);
swipeRefreshLayout.setOnRefreshListener(() -> {
try {
swipeRefreshLayout.setRefreshing(true);
new Handler().post(() -> {
try {
webView.reload();
swipeRefreshLayout.setRefreshing(false);
}catch(Throwable tr){
Log.e(TAG,"", tr);
}
});
}catch(Throwable tr){
Log.e(TAG,"", tr);
}
});
}catch(Throwable tr){
Log.e(TAG,"", tr);
}
}

@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
try {
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}catch(Throwable tr){
Log.e(TAG,"", tr);
}
}

Expand Down
Loading