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 Psiphon countries and various bug fixes #185

Merged
merged 10 commits into from
May 18, 2024
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
5 changes: 2 additions & 3 deletions app/src/main/java/org/bepass/oblivion/BugActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
public class BugActivity extends AppCompatActivity {

private final Handler handler = new Handler(Looper.getMainLooper());
private ImageView back;
private TextView logs;
private ScrollView logScrollView;
private boolean isUserScrollingUp = false;
Expand All @@ -28,12 +27,12 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bug);

back = findViewById(R.id.back);
ImageView back = findViewById(R.id.back);
logs = findViewById(R.id.logs);
logScrollView = findViewById(R.id.logScrollView);

setupScrollListener();
back.setOnClickListener(v -> onBackPressed());
back.setOnClickListener(v -> getOnBackPressedDispatcher().onBackPressed());
logUpdater = new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import java.util.concurrent.Executors;

public class BypassListAppsAdapter extends RecyclerView.Adapter<BypassListAppsAdapter.ViewHolder> {

private static final String TAG = "InstalledAppsAdapter";

private final ExecutorService executor = Executors.newSingleThreadExecutor();
private final Handler handler = new Handler(Looper.getMainLooper());
private final FileManager fm;
Expand Down Expand Up @@ -156,7 +153,7 @@ public static class AppInfo {
IconLoader iconLoader;
boolean isSelected;

public AppInfo(String name, IconLoader iconLoader, String packageName, boolean isSelected) {
AppInfo(String name, IconLoader iconLoader, String packageName, boolean isSelected) {
this.appName = name;
this.packageName = packageName;
this.iconLoader = iconLoader;
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/org/bepass/oblivion/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Set;

public class FileManager {
public static String currentLog;
private static FileManager instance;
private final SharedPreferences sharedPreferences;

Expand Down
20 changes: 7 additions & 13 deletions app/src/main/java/org/bepass/oblivion/InfoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,15 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info);

init();

github.setOnClickListener(v -> openURL("https://github.com/bepass-org/oblivion"));

back.setOnClickListener(v -> onBackPressed());
}

private void init() {
back = findViewById(R.id.back);
github = findViewById(R.id.github_layout);
}

protected void openURL(String url) {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
github.setOnClickListener(v -> {
Uri uri = Uri.parse("https://github.com/bepass-org/oblivion");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
});

back.setOnClickListener(v -> getOnBackPressedDispatcher().onBackPressed());
}
}
138 changes: 84 additions & 54 deletions app/src/main/java/org/bepass/oblivion/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
Expand All @@ -16,82 +17,55 @@
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;

public class MainActivity extends ConnectionAwareBaseActivity {
// Views
ImageView infoIcon, bugIcon, settingsIcon;
TouchAwareSwitch switchButton;
TextView stateText, publicIP;
ProgressBar ipProgressBar;
FileManager fileManager;
PublicIPUtils pIPUtils;
private ActivityResultLauncher<String> pushNotificationPermissionLauncher;
private ActivityResultLauncher<Intent> vpnPermissionLauncher;
import java.util.HashSet;
import java.util.Set;

public class MainActivity extends StateAwareBaseActivity {
private TouchAwareSwitch switchButton;
private TextView stateText, publicIP;
private ProgressBar ipProgressBar;
private PublicIPUtils pIPUtils;
private long backPressedTime;
private Toast backToast;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
// Custom back pressed logic here
if (backPressedTime + 2000 > System.currentTimeMillis()) {
if (backToast != null) backToast.cancel();
finish(); // or super.handleOnBackPressed() if you want to keep default behavior alongside
} else {
if (backToast != null)
backToast.cancel(); // Cancel the existing toast to avoid stacking
backToast = Toast.makeText(MainActivity.this, "برای خروج، دوباره بازگشت را فشار دهید.", Toast.LENGTH_SHORT);
backToast.show();
}
backPressedTime = System.currentTimeMillis();
}
});
pushNotificationPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
if (!isGranted) {
Toast.makeText(this, "Permission denied", Toast.LENGTH_LONG).show();
}
});
vpnPermissionLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (result.getResultCode() != RESULT_OK) {
Toast.makeText(this, "Really!?", Toast.LENGTH_LONG).show();
}
switchButton.setChecked(false);
});

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
pushNotificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS);
}
cleanOrMigrateSettings();

fileManager = FileManager.getInstance(getApplicationContext());
// Get the global PublicIPUtils instance
pIPUtils = PublicIPUtils.getInstance(getApplicationContext());

infoIcon = findViewById(R.id.info_icon);
bugIcon = findViewById(R.id.bug_icon);
settingsIcon = findViewById(R.id.setting_icon);
// Set the layout of the main activity
setContentView(R.layout.activity_main);

// Views
ImageView infoIcon = findViewById(R.id.info_icon);
ImageView bugIcon = findViewById(R.id.bug_icon);
ImageView settingsIcon = findViewById(R.id.setting_icon);

FrameLayout switchButtonFrame = findViewById(R.id.switch_button_frame);
switchButton = findViewById(R.id.switch_button);
stateText = findViewById(R.id.state_text);
publicIP = findViewById(R.id.publicIP);
ipProgressBar = (ProgressBar) findViewById(R.id.ipProgressBar);
ipProgressBar = findViewById(R.id.ipProgressBar);

// Set listeners
infoIcon.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, InfoActivity.class)));
bugIcon.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, BugActivity.class)));
settingsIcon.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, SettingsActivity.class)));
switchButtonFrame.setOnClickListener(v -> switchButton.toggle());

if (!fileManager.getBoolean("isFirstValueInit")) {
fileManager.set("USERSETTING_endpoint", "engage.cloudflareclient.com:2408");
fileManager.set("USERSETTING_port", "8086");
fileManager.set("USERSETTING_gool", false);
fileManager.set("USERSETTING_psiphon", false);
fileManager.set("USERSETTING_lan", false);
fileManager.set("isFirstValueInit", true);
}
// Request for VPN creation
ActivityResultLauncher<Intent> vpnPermissionLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (result.getResultCode() != RESULT_OK) {
Toast.makeText(this, "Really!?", Toast.LENGTH_LONG).show();
}
switchButton.setChecked(false);
});

// Listener for toggle switch
switchButton.setOnCheckedChangeListener((view, isChecked) -> {
if (!isChecked) {
if (!lastKnownConnectionState.isDisconnected()) {
Expand All @@ -108,6 +82,62 @@ public void handleOnBackPressed() {
OblivionVpnService.startVpnService(this);
}
});

// Request permission to create push notifications
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
ActivityResultLauncher<String> pushNotificationPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
if (!isGranted) {
Toast.makeText(this, "Permission denied", Toast.LENGTH_LONG).show();
}
});
pushNotificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS);
}

// Set the behaviour of the back button
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
// Custom back pressed logic here
if (backPressedTime + 2000 > System.currentTimeMillis()) {
if (backToast != null) backToast.cancel();
finish(); // or super.handleOnBackPressed() if you want to keep default behavior alongside
} else {
if (backToast != null)
backToast.cancel(); // Cancel the existing toast to avoid stacking
backToast = Toast.makeText(MainActivity.this, "برای خروج، دوباره بازگشت را فشار دهید.", Toast.LENGTH_SHORT);
backToast.show();
}
backPressedTime = System.currentTimeMillis();
}
});
}

protected void cleanOrMigrateSettings() {
// Get the global FileManager instance
FileManager fileManager = FileManager.getInstance(getApplicationContext());

if (!fileManager.getBoolean("isFirstValueInit")) {
fileManager.set("USERSETTING_endpoint", "engage.cloudflareclient.com:2408");
fileManager.set("USERSETTING_port", "8086");
fileManager.set("USERSETTING_gool", false);
fileManager.set("USERSETTING_psiphon", false);
fileManager.set("USERSETTING_lan", false);
fileManager.set("isFirstValueInit", true);
}

// Check which split mode apps have been uninstalled and remove them from the list in settings
Set<String> splitApps = fileManager.getStringSet("splitTunnelApps", new HashSet<>());
Set<String> shouldKeep = new HashSet<>();
final PackageManager pm = getApplicationContext().getPackageManager();
for (String packageName : splitApps) {
try {
pm.getPackageInfo(packageName, PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException ignored) {
continue;
}
shouldKeep.add(packageName);
}
fileManager.set("splitTunnelApps", shouldKeep);
}

@NonNull
Expand Down
Loading
Loading