From 6bc71e7464b76d866e097b25f8df7f4c6324fc6f Mon Sep 17 00:00:00 2001 From: msmannan00 Date: Sat, 6 Apr 2019 18:44:27 +0500 Subject: [PATCH] bug fixes --- app/build.gradle | 2 +- .../example/myapplication/KeyboardUtils.java | 42 ++++ .../myapplication/application_controller.java | 187 +++++++++++++----- .../com/example/myapplication/constants.java | 2 +- .../myapplication/message_manager.java | 10 + .../myapplication/webRequestHandler.java | 32 ++- app/src/main/res/layout/application_view.xml | 4 +- 7 files changed, 222 insertions(+), 57 deletions(-) create mode 100644 app/src/main/java/com/example/myapplication/KeyboardUtils.java diff --git a/app/build.gradle b/app/build.gradle index acf110f1..9d798006 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'maven' ext { geckoviewChannel = "nightly" - geckoviewVersion = "64.0.20180927100037" + geckoviewVersion = "66.0.20181225095124" } android { compileSdkVersion 28 diff --git a/app/src/main/java/com/example/myapplication/KeyboardUtils.java b/app/src/main/java/com/example/myapplication/KeyboardUtils.java new file mode 100644 index 00000000..98e8c95d --- /dev/null +++ b/app/src/main/java/com/example/myapplication/KeyboardUtils.java @@ -0,0 +1,42 @@ +package com.example.myapplication; + +import android.app.Activity; +import android.content.Context; +import android.graphics.Rect; +import android.view.View; +import android.view.inputmethod.InputMethodManager; + +public class KeyboardUtils { + + public static void hideKeyboard(Activity activity) { + View view = activity.findViewById(android.R.id.content); + if (view != null) { + InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } + + public static void showKeyboard(Activity activity) { + InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); + inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } + + public static void addKeyboardVisibilityListener(View rootLayout, OnKeyboardVisibiltyListener onKeyboardVisibiltyListener) { + rootLayout.getViewTreeObserver().addOnGlobalLayoutListener(() -> { + Rect r = new Rect(); + rootLayout.getWindowVisibleDisplayFrame(r); + int screenHeight = rootLayout.getRootView().getHeight(); + + // r.bottom is the position above soft keypad or device button. + // if keypad is shown, the r.bottom is smaller than that before. + int keypadHeight = screenHeight - r.bottom; + + boolean isVisible = keypadHeight > screenHeight * 0.15; // 0.15 ratio is perhaps enough to determine keypad height. + onKeyboardVisibiltyListener.onVisibilityChange(isVisible); + }); + } + + public interface OnKeyboardVisibiltyListener { + void onVisibilityChange(boolean isVisible); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/application_controller.java b/app/src/main/java/com/example/myapplication/application_controller.java index e0f81061..9d8926d8 100644 --- a/app/src/main/java/com/example/myapplication/application_controller.java +++ b/app/src/main/java/com/example/myapplication/application_controller.java @@ -4,9 +4,11 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.graphics.Color; +import android.os.Handler; import android.support.constraint.ConstraintLayout; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.util.Log; import android.util.Patterns; import android.view.KeyEvent; import android.view.View; @@ -22,6 +24,7 @@ import java.util.Stack; import info.guardianproject.netcipher.proxy.OrbotHelper; import org.mozilla.gecko.PrefsHelper; +import org.mozilla.geckoview.GeckoDisplay; import org.mozilla.geckoview.GeckoRuntime; import org.mozilla.geckoview.GeckoSession; import org.mozilla.geckoview.GeckoView; @@ -46,6 +49,10 @@ public class application_controller extends AppCompatActivity private GeckoSession session1; private GeckoRuntime runtime1; private String version_code = "1.0"; + private boolean wasBackPressed = false; + private boolean isLoadedUrlSet = false; + private boolean isOnnionUrlHalted = false; + Handler handler = null; /*helper Variables*/ Stack traceUrlList = new Stack(); @@ -71,10 +78,7 @@ public class application_controller extends AppCompatActivity { message_manager.getInstance().versionWarning(this); } - if(version.equals("none")) - { - webRequestHandler.getInstance().getVersion(this); - } + webRequestHandler.getInstance().getVersion(this); } public void initializeAds() @@ -90,8 +94,7 @@ public class application_controller extends AppCompatActivity PrefsHelper.setPref("network.proxy.socks_version",5); //manual proxy settings PrefsHelper.setPref("network.proxy.socks_remote_dns",true); //manual proxy settings PrefsHelper.setPref("browser.cache.disk.enable",false); - PrefsHelper.setPref("browser.cache.memory.enable",true); - PrefsHelper.setPref("browser.cache.disk.capacity",0); + PrefsHelper.setPref("browser.cache.memory.enable",false); PrefsHelper.setPref("general.useragent.override", "Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0"); PrefsHelper.setPref("privacy.donottrackheader.enabled",false); PrefsHelper.setPref("privacy.donottrackheader.value",1); @@ -173,7 +176,14 @@ public class application_controller extends AppCompatActivity @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { + if(url.equals(searchbar.getText().toString())) + { + view.stopLoading(); + return true; + } + searchbar.setText(url.replaceAll("boogle.store","genesis.onion")); + KeyboardUtils.hideKeyboard(application_controller.this); if(!url.toString().contains("boogle")) { @@ -182,11 +192,17 @@ public class application_controller extends AppCompatActivity boolean init_status=orbot_manager.getInstance().reinitOrbot(application_controller.this); if(!init_status) { + progressBar.setAlpha(0); + progressBar.setVisibility(View.VISIBLE); + progressBar.animate().setDuration(300).alpha(1f); + + isOnnionUrlHalted = false; + session1.stop(); session1.close(); + webLoader.releaseSession(); session1 = new GeckoSession(); session1.open(runtime1); session1.setProgressDelegate(new progressDelegate()); - webLoader.releaseSession(); webLoader.setSession(session1); session1.loadUri(url); @@ -200,7 +216,7 @@ public class application_controller extends AppCompatActivity traceUrlList.add(status.currentURL); status.currentURL = url; } - + Log.i("WOW1",url); loadURLAnimate(url); return true; } @@ -210,6 +226,8 @@ public class application_controller extends AppCompatActivity { super.onPageFinished(view, url); + webView1.stopLoading(); + webView2.stopLoading(); webView1.animate().setDuration(250).alpha(1f); webView2.animate().setDuration(250).alpha(1f).withEndAction((() -> { datamodel.getInstance().setIsLoadingURL(false); @@ -241,7 +259,8 @@ public class application_controller extends AppCompatActivity @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { - System.out.println("SUP2"); + Log.i("SUP2",errorCode+""); + System.out.println("SUP2 : " + errorCode); requestFailure.setVisibility(View.VISIBLE); requestFailure.animate().alpha(1.0f); loadErrorPage(); @@ -273,14 +292,21 @@ class progressDelegate implements GeckoSession.ProgressDelegate @Override public void onPageStart(GeckoSession session, String url) { + if(isOnnionUrlHalted) + { + return; + } + + isLoadedUrlSet = false; + KeyboardUtils.hideKeyboard(application_controller.this); try { URL host = new URL(url); if(!host.getHost().contains("onion")) { session1.stop(); - session1.close(); - session1.stop(); + //session1.close(); + //session1.stop(); message_manager.getInstance().baseURLError(application_controller.this); } } @@ -293,10 +319,9 @@ class progressDelegate implements GeckoSession.ProgressDelegate boolean isBlackPage = url.equals("about:blank"); if(!isBlackPage) { - traceUrlList.add(status.currentURL); - status.currentURL = url; + searchbar.setText(url); } - if(!isBlackPage) + if(!isBlackPage && progressBar.getVisibility() == View.INVISIBLE) { progressBar.setAlpha(0); progressBar.setVisibility(View.VISIBLE); @@ -306,20 +331,51 @@ class progressDelegate implements GeckoSession.ProgressDelegate @Override public void onPageStop(GeckoSession session, boolean success) { - progressBar.animate().alpha(0f); - datamodel.getInstance().setIsLoadingURL(false); + handler = new Handler(); + handler.postDelayed(new Runnable() { + @Override + public void run() { + progressBar.animate().alpha(0f).withEndAction((() -> progressBar.setVisibility(View.INVISIBLE)));; + datamodel.getInstance().setIsLoadingURL(false); + message_manager.getInstance().URLNotFoundError(application_controller.this); + } + }, 10000); } @Override public void onProgressChange(GeckoSession session, int progress) { - if(progress>=50 && webLoader.getVisibility()==View.INVISIBLE) + if(progress>=100) { - webLoader.bringToFront(); - webLoader.animate().setDuration(100).alpha(1); - webLoader.setVisibility(View.VISIBLE); + if(!isLoadedUrlSet &&!isOnnionUrlHalted) + { + webLoader.bringToFront(); + webLoader.animate().setDuration(100).alpha(1); + webLoader.setVisibility(View.VISIBLE); + requestFailure.animate().alpha(0f).setDuration(300).withEndAction((() -> requestFailure.setVisibility(View.INVISIBLE)));; - requestFailure.animate().alpha(0f).setDuration(300).withEndAction((() -> requestFailure.setVisibility(View.INVISIBLE)));; + String url = searchbar.getText().toString(); + boolean isBlackPage = url.equals("about:blank"); + if(!isBlackPage && !wasBackPressed) + { + Log.i("SHIT1 : ",status.currentURL); + traceUrlList.add(status.currentURL); + searchbar.setText(url); + status.currentURL = url; + } + } + isLoadedUrlSet = true; + } + if(progress>=100) + { + progressBar.animate().alpha(0f).withEndAction((() -> progressBar.setVisibility(View.INVISIBLE)));; + datamodel.getInstance().setIsLoadingURL(false); + } + + if(handler!=null) + { + handler.removeCallbacksAndMessages(null); + handler= null; } } @@ -346,13 +402,25 @@ class progressDelegate implements GeckoSession.ProgressDelegate public void onHomeButtonPressed(View view) { - session1.stop(); - session1.close(); - session1.stop(); + webRequestHandler.getInstance().isUrlStoped=true; + status.currentURL="https://boogle.store/"; + searchbar.setText("https://boogle.store/"); + //webLoader.releaseSession(); + //session1 = new GeckoSession(); + //session1.open(runtime1); + //session1.setProgressDelegate(new progressDelegate()); + //webLoader.setSession(session1); progressBar.animate().alpha(0f); progressBar.setVisibility(View.VISIBLE); progressBar.animate().setDuration(300).alpha(1f); - loadURLAnimate("http://boogle.store/"); + webView1.stopLoading(); + webView2.stopLoading(); + loadURLAnimate("https://boogle.store/"); + session1.close(); + isOnnionUrlHalted = true; + wasBackPressed = false; + KeyboardUtils.hideKeyboard(application_controller.this); + webRequestHandler.getInstance().isUrlStoped=false; } public void onReloadButtonPressed(View view) @@ -366,6 +434,7 @@ class progressDelegate implements GeckoSession.ProgressDelegate @Override public void onBackPressed() { + session1.stop(); orbot_manager.getInstance().reinitOrbot(this); if(traceUrlList.size()>0) { @@ -374,17 +443,26 @@ class progressDelegate implements GeckoSession.ProgressDelegate { if(!status.currentURL.contains("boogle.store")) { + Log.i("FITS4 : " , ""); + isOnnionUrlHalted=true; + session1.stop(); + session1.close(); + webLoader.releaseSession(); status.currentURL = traceUrlList.pop().toString(); - progressBar.animate().alpha(0f); - webLoader.animate().setDuration(250).alpha(0); - webLoader.setVisibility(View.INVISIBLE); + progressBar.animate().alpha(0f).withEndAction((() -> progressBar.setVisibility(View.INVISIBLE)));; + webLoader.animate().alpha(0f).withEndAction((() -> webLoader.setVisibility(View.INVISIBLE)));; + isOnnionUrlHalted = true; + wasBackPressed = false; + KeyboardUtils.hideKeyboard(application_controller.this); } else { + session1.close(); + Log.i("FITS3 : " , ""); loadURLAnimate(traceUrlList.pop().toString()); if(traceUrlList.size()<=0) { - status.currentURL = "http://boogle.store/"; + status.currentURL = "https://boogle.store/"; } else { @@ -396,33 +474,49 @@ class progressDelegate implements GeckoSession.ProgressDelegate { if(traceUrlList.size()<=0 || traceUrlList.peek().toString().contains("boogle.store")) { - status.currentURL = "http://boogle.store/"; + Log.i("FITS2 : " , ""); + status.currentURL = "https://boogle.store/"; webLoader.animate().setDuration(250).alpha(0); + traceUrlList.pop(); + wasBackPressed = false; + session1.close(); } else { webLoader.animate().setDuration(250).alpha(1); status.currentURL = traceUrlList.peek().toString(); + String prevURL = traceUrlList.pop().toString(); + Log.i("FITS : " , prevURL); + session1.goBack(); + wasBackPressed = true; } - traceUrlList.pop(); - session1.stop(); - session1.close(); - session1.stop(); - session1.goBack(); } if(traceUrlList.size()==0) { - searchbar.setText("http://genesis.onion/"); + searchbar.setText("https://genesis.onion/"); } } } + public void loadGeckoUrl(String url) + { + session1.close(); + session1 = new GeckoSession(); + session1.open(runtime1); + session1.setProgressDelegate(new application_controller.progressDelegate()); + webLoader.releaseSession(); + webLoader.setSession(session1); + session1.loadUri(url); + } + public boolean onEditorClicked(TextView v, int actionId, KeyEvent event) { try { session1.stop(); - session1.close(); + webView1.stopLoading(); + webView2.stopLoading(); + //session1.close(); String url = v.getText().toString(); if(!url.startsWith("www.")&& !url.startsWith("http://")&& !url.startsWith("https://")){ url = "www."+url; @@ -444,15 +538,9 @@ class progressDelegate implements GeckoSession.ProgressDelegate } else if(host.getHost().contains(constants.allowedHost)) { - if(!orbot_manager.getInstance().reinitOrbot(this.getApplicationContext())) + if(!orbot_manager.getInstance().reinitOrbot(this)) { - session1.close(); - session1 = new GeckoSession(); - session1.open(runtime1); - session1.setProgressDelegate(new application_controller.progressDelegate()); - webLoader.releaseSession(); - webLoader.setSession(session1); - + session1.stop(); session1.loadUri(url); } return true; @@ -465,17 +553,20 @@ class progressDelegate implements GeckoSession.ProgressDelegate } else { - loadURLAnimate("http://boogle.store/search?q="+v.getText().toString().replaceAll(" ","+")+"&p_num=1&s_type=all"); + loadURLAnimate("https://boogle.store/search?q="+v.getText().toString().replaceAll(" ","+")+"&p_num=1&s_type=all"); } - orbot_manager.getInstance().reinitOrbot(this.getApplicationContext()); + orbot_manager.getInstance().reinitOrbot(this); } catch (IOException e) { - loadURLAnimate("http://boogle.store/search?q="+v.getText().toString().replaceAll(" ","+")+"&p_num=1&s_type=all"); + loadURLAnimate("https://boogle.store/search?q="+v.getText().toString().replaceAll(" ","+")+"&p_num=1&s_type=all"); e.printStackTrace(); } return false; } + + } + diff --git a/app/src/main/java/com/example/myapplication/constants.java b/app/src/main/java/com/example/myapplication/constants.java index c3876d39..e4d8de44 100644 --- a/app/src/main/java/com/example/myapplication/constants.java +++ b/app/src/main/java/com/example/myapplication/constants.java @@ -2,7 +2,7 @@ package com.example.myapplication; public class constants { - public static String backendUrl = "http://boogle.store"; + public static String backendUrl = "https://boogle.store"; public static String backendUrlHost = "boogle.store"; public static String frontEndUrlHost = "genesis.store"; public static String allowedHost = ".onion"; diff --git a/app/src/main/java/com/example/myapplication/message_manager.java b/app/src/main/java/com/example/myapplication/message_manager.java index f380fa88..962a9b8c 100644 --- a/app/src/main/java/com/example/myapplication/message_manager.java +++ b/app/src/main/java/com/example/myapplication/message_manager.java @@ -27,6 +27,16 @@ public class message_manager { .show(); } + public void URLNotFoundError(Context application_context) + { + new LovelyInfoDialog(application_context) + .setTopColorRes(R.color.header) + .setIcon(R.drawable.logo) + .setTitle("URL Temporarily Unavailable") + .setMessage("Site is Down or temporarily Unavailabe. Try again after a while") + .show(); + } + public void startingOrbotInfo(Context application_context) { new LovelyInfoDialog(application_context) diff --git a/app/src/main/java/com/example/myapplication/webRequestHandler.java b/app/src/main/java/com/example/myapplication/webRequestHandler.java index 6c306dd0..45725b99 100644 --- a/app/src/main/java/com/example/myapplication/webRequestHandler.java +++ b/app/src/main/java/com/example/myapplication/webRequestHandler.java @@ -4,6 +4,7 @@ import android.annotation.SuppressLint; import android.content.Context; import android.os.Message; import android.support.constraint.ConstraintLayout; +import android.util.Log; import android.view.View; import android.webkit.WebView; import android.widget.EditText; @@ -39,9 +40,11 @@ public class webRequestHandler implements StrongBuilder.Callback private int currentViewIndex = 0; private String html = ""; private String baseURL = ""; - private Thread clientThread = null; + public Thread clientThread = null; HttpGet request = null; private Handler updateUIHandler = null; + public boolean isUrlStoped = false; + private String currenturl = ""; private final static int MESSAGE_UPDATE_TEXT_CHILD_THREAD =1; private final static int INTERNET_ERROR =2; @@ -70,7 +73,18 @@ public class webRequestHandler implements StrongBuilder.Callback try { - preInitialization(url); + if(!currenturl.equals(url)) + { + currenturl = url; + preInitialization(url); + } + else + { + //progressBar.animate().setDuration(0).alpha(0f).withEndAction((() -> { + // progressBar.setVisibility(View.INVISIBLE); + //})); + return; + } } catch (Exception e) { @@ -80,6 +94,7 @@ public class webRequestHandler implements StrongBuilder.Callback clientThread = new Thread(() -> { try { + currenturl = url; if(url.contains("boogle.store")) { nonProxyConnection(url); @@ -91,8 +106,12 @@ public class webRequestHandler implements StrongBuilder.Callback } catch (Exception e) { - onError(); - e.printStackTrace(); + if(!isUrlStoped) + { + Log.i("SUP3",e.getMessage()+""); + //onError(); + e.printStackTrace(); + } } }); clientThread.start(); @@ -120,6 +139,8 @@ public class webRequestHandler implements StrongBuilder.Callback } public void nonProxyConnection(String url) throws IOException { + url = url.replace("http://boogle","https://boogle"); + HttpClient client = new DefaultHttpClient(); request = new HttpGet(url); baseURL = url; @@ -139,6 +160,7 @@ public class webRequestHandler implements StrongBuilder.Callback Message message = new Message(); message.what = MESSAGE_UPDATE_TEXT_CHILD_THREAD; updateUIHandler.sendMessage(message); + } public void proxyConnection(String url) throws Exception { @@ -241,7 +263,7 @@ public class webRequestHandler implements StrongBuilder.Callback { try { - String webPage = "http://boogle.store/version"; + String webPage = "https://boogle.store/version"; URL url = new URL(webPage); URLConnection urlConnection = null; urlConnection = url.openConnection(); diff --git a/app/src/main/res/layout/application_view.xml b/app/src/main/res/layout/application_view.xml index 99a17fad..8f9b3158 100644 --- a/app/src/main/res/layout/application_view.xml +++ b/app/src/main/res/layout/application_view.xml @@ -135,13 +135,13 @@ android:background="@drawable/searchbar" android:textCursorDrawable="@drawable/cursorcolor" android:hint="Search or type web address" - android:text="http://genesis.onion" + android:text="https://genesis.onion" android:ems="10" android:layout_marginTop="8dp" + android:inputType="textNoSuggestions" android:layout_marginBottom="8dp" android:layout_marginRight="10dp" android:layout_marginLeft="5dp" - android:inputType="text" android:maxLines="1" android:id="@+id/search" android:layout_weight="1"/>