From dce1daf69b807e9b7f593c68593d9b2add6fa7b5 Mon Sep 17 00:00:00 2001 From: msmannan00 Date: Sun, 25 Apr 2021 02:26:22 +0500 Subject: [PATCH] Bug Fixes Bug Fixes --- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 23 ++-- .../historyManager/historyRowModel.java | 1 + .../geckoManager/geckoSession.java | 2 +- .../homeManager/hintManager/hintAdapter.java | 99 ++++++++++++--- .../homeController/homeController.java | 12 +- .../clientauth/ClientAuthContentProvider.java | 104 ++++++++++++++++ .../clientauth/ClientAuthDatabase.java | 30 +++++ .../dataManager/suggestionDataModel.java | 3 + .../helperManager/ProxySettings.java | 2 +- .../helperManager/downloadNotification.java | 2 +- .../helperManager/helperMethod.java | 28 +++-- .../helperManager/localFileDownloader.java | 115 ++++++++++++++---- .../res/custom-xml/generic/xml/file_path.xml | 4 + .../android/proxy/OrbotService.java | 29 ++--- 15 files changed, 367 insertions(+), 88 deletions(-) create mode 100644 app/src/main/java/com/darkweb/genesissearchengine/clientauth/ClientAuthContentProvider.java create mode 100644 app/src/main/java/com/darkweb/genesissearchengine/clientauth/ClientAuthDatabase.java create mode 100644 app/src/main/res/custom-xml/generic/xml/file_path.xml diff --git a/app/build.gradle b/app/build.gradle index 90051e41..d46f3ae3 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -97,6 +97,7 @@ dependencies { implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0' implementation 'com.google.firebase:firebase-messaging:21.1.0' + implementation 'com.android.support:support-core-utils:28.0.0' /* Default Libraries */ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6bed4757..e2e3d053 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,6 +14,7 @@ + - - - - - + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/darkweb/genesissearchengine/appManager/historyManager/historyRowModel.java b/app/src/main/java/com/darkweb/genesissearchengine/appManager/historyManager/historyRowModel.java index 384a5285..67fb06a7 100755 --- a/app/src/main/java/com/darkweb/genesissearchengine/appManager/historyManager/historyRowModel.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/appManager/historyManager/historyRowModel.java @@ -1,5 +1,6 @@ package com.darkweb.genesissearchengine.appManager.historyManager; +import android.os.Handler; import android.widget.ImageView; import java.util.Calendar; import java.util.Date; diff --git a/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/geckoManager/geckoSession.java b/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/geckoManager/geckoSession.java index 57cea63e..67754ebe 100644 --- a/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/geckoManager/geckoSession.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/geckoManager/geckoSession.java @@ -760,7 +760,7 @@ public class geckoSession extends GeckoSession implements GeckoSession.MediaDele PendingIntent pIntent = PendingIntent.getActivity(mContext.get().getApplicationContext(), 0, intent, 0); String channel_id = createNotificationChannel(mContext.get().getApplicationContext()); - assert channel_id != null; + NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mContext.get().getApplicationContext(), channel_id) .setSmallIcon(R.drawable.ic_download) .setContentTitle(filename) diff --git a/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/hintManager/hintAdapter.java b/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/hintManager/hintAdapter.java index 86500968..78dcbc66 100644 --- a/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/hintManager/hintAdapter.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/hintManager/hintAdapter.java @@ -5,6 +5,7 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; +import android.os.Handler; import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -22,7 +23,10 @@ import androidx.room.Ignore; import com.darkweb.genesissearchengine.appManager.historyManager.historyRowModel; import com.darkweb.genesissearchengine.appManager.tabManager.tabEnums; import com.darkweb.genesissearchengine.constants.enums; +import com.darkweb.genesissearchengine.constants.status; import com.darkweb.genesissearchengine.constants.strings; +import com.darkweb.genesissearchengine.dataManager.dataController; +import com.darkweb.genesissearchengine.dataManager.dataEnums; import com.darkweb.genesissearchengine.helperManager.eventObserver; import com.darkweb.genesissearchengine.helperManager.helperMethod; import com.example.myapplication.R; @@ -43,6 +47,10 @@ public class hintAdapter extends RecyclerView.Adapter mWebIcon = new HashMap<>(); + private ArrayList mKeys = new ArrayList<>(); + private Map mHandlers = new HashMap<>(); + private Map mPastWebIcon = new HashMap<>(); + private Map mPastIconFlicker = new HashMap<>(); public hintAdapter(ArrayList pHintList, eventObserver.eventListener pEvent, AppCompatActivity pContext, String pSearch) { this.mHintList = new ArrayList(); @@ -62,7 +70,9 @@ public class hintAdapter extends RecyclerView.Adapter6){ @@ -199,18 +227,49 @@ public class hintAdapter extends RecyclerView.Adapter { - mHintWebIcon.setColorFilter(null); - mHintWebIcon.clearColorFilter(); - mHintWebIcon.setImageTintList(null); - mHintWebIcon.setClipToOutline(true); mWebIcon.put(mURLLink,mHindTypeIconTemp.getDrawable()); + mKeys.add(mURLLink); + + if(mKeys.size()>5){ + mWebIcon.remove(mKeys.get(0)); + mKeys.remove(0); + } + if(mHindTypeIconTemp.getDrawable() != null){ - mHintWebIcon.setImageDrawable(mHindTypeIconTemp.getDrawable()); + if(mHandlers.containsKey(getLayoutPosition())){ + mHandlers.get(getLayoutPosition()).removeCallbacksAndMessages(null); + if(getLayoutPosition()==1){ + Log.i("SUPERFUCK1","SUPERFUCK1"); + } + }else { + mHandlers.put(getLayoutPosition(), new Handler()); + } + + if(mURLPast.equals(mPastIconFlicker.get(getLayoutPosition()))){ + Runnable mRunnable = () -> { + mHintWebIcon.setColorFilter(null); + mHintWebIcon.clearColorFilter(); + mHintWebIcon.setImageTintList(null); + mHintWebIcon.setClipToOutline(true); + mHintWebIcon.setImageDrawable(mHindTypeIconTemp.getDrawable()); + mPastWebIcon.put(getLayoutPosition(),mHindTypeIconTemp.getDrawable()); + + if(getLayoutPosition() == 1){ + Log.i("FUSSSS1111","FUSSSS1111"); + } + + }; + mHandlers.get(getLayoutPosition()).postDelayed(mRunnable, 200); + } + }else { - Resources res = itemView.getContext().getResources(); - try { - mHintWebIcon.setImageDrawable(Drawable.createFromXml(res, res.getXml(R.xml.ic_baseline_browser))); - } catch (Exception ignored) { + if(mURLPast.equals(mPastIconFlicker.get(getLayoutPosition()))){ + Resources res = itemView.getContext().getResources(); + try { + Log.i("FUSSSS1111","FUSSSS2222"); + mHintWebIcon.setImageDrawable(Drawable.createFromXml(res, res.getXml(R.xml.ic_baseline_browser))); + } catch (Exception ignored) { + } } } diff --git a/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeController/homeController.java b/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeController/homeController.java index 39aad603..3b1dcf07 100644 --- a/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeController/homeController.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeController/homeController.java @@ -108,7 +108,6 @@ import static com.darkweb.genesissearchengine.pluginManager.pluginEnums.eMessage import static com.darkweb.genesissearchengine.pluginManager.pluginEnums.eMessageManagerCallbacks.M_RATE_APPLICATION; import static java.lang.Character.isLetter; import static org.mozilla.geckoview.ContentBlocking.CookieBehavior.ACCEPT_FIRST_PARTY; -import static org.torproject.android.proxy.TorServiceConstants.REQUEST_VPN; public class homeController extends AppCompatActivity implements ComponentCallbacks2 { @@ -964,6 +963,7 @@ public class homeController extends AppCompatActivity implements ComponentCallba if ((scrollY >= (v.getChildAt(v.getChildCount() - 1).getMeasuredHeight() - v.getMeasuredHeight())) && scrollY > oldScrollY) { } } + onInvokePixelGenerator(); }); } @@ -1323,6 +1323,8 @@ public class homeController extends AppCompatActivity implements ComponentCallba mHomeViewController.onClearSelections(true); } pluginController.getInstance().onLanguageInvoke(Collections.singletonList(this), pluginEnums.eLangManager.M_RESUME); + mHomeViewController.onClearSelections(true); + mHomeViewController.onUpdateSearchBar(mGeckoClient.getSession().getCurrentURL(),false,true, true); } @Override @@ -1383,6 +1385,10 @@ public class homeController extends AppCompatActivity implements ComponentCallba } } + if(status.sSettingIsAppStarted){ + mHomeViewController.onClearSelections(isKeyboardOpened); + } + if(mAppBar!=null){ mHomeViewController.expandTopBar(); @@ -2055,10 +2061,10 @@ public class homeController extends AppCompatActivity implements ComponentCallba dataController.getInstance().invokeTab(dataEnums.eTabCommands.M_UPDATE_PIXEL, Arrays.asList(mGeckoClient.getSession().getSessionID(), mRenderedBitmap, null, mGeckoView, true)); } } - }, 150); + }, 400); }; - mScrollHandler.postDelayed(mScrollRunnable, 250); + mScrollHandler.postDelayed(mScrollRunnable, 450); } public class geckoViewCallback implements eventObserver.eventListener{ diff --git a/app/src/main/java/com/darkweb/genesissearchengine/clientauth/ClientAuthContentProvider.java b/app/src/main/java/com/darkweb/genesissearchengine/clientauth/ClientAuthContentProvider.java new file mode 100644 index 00000000..67af8eb4 --- /dev/null +++ b/app/src/main/java/com/darkweb/genesissearchengine/clientauth/ClientAuthContentProvider.java @@ -0,0 +1,104 @@ +package com.darkweb.genesissearchengine.clientauth; + +import android.content.ContentProvider; +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.UriMatcher; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.net.Uri; +import android.provider.BaseColumns; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public class ClientAuthContentProvider extends ContentProvider { + public static final String[] PROJECTION = { + V3ClientAuth._ID, + V3ClientAuth.DOMAIN, + V3ClientAuth.HASH, + V3ClientAuth.ENABLED, + }; + private static final String AUTH = "com.darkweb.genesissearchengine.clientauth.ClientAuthContentProvider"; + public static final Uri CONTENT_URI = Uri.parse("content://" + AUTH + "/v3auth"); + private static final int V3AUTHS = 1, V3AUTH_ID = 2; + + private static final UriMatcher uriMatcher; + + static { + uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + uriMatcher.addURI(AUTH, "v3auth", V3AUTHS); + uriMatcher.addURI(AUTH, "v3auth/#", V3AUTH_ID); + } + + private ClientAuthDatabase mDatabase; + + @Override + public boolean onCreate() { + mDatabase = new ClientAuthDatabase(getContext()); + return true; + } + + @Nullable + @Override + public String getType(@NonNull Uri uri) { + int match = uriMatcher.match(uri); + switch (match) { + case V3AUTHS: + return "vnd.android.cursor.dir/vnd.torproject.v3auths"; + case V3AUTH_ID: + return "vnd.android.cursor.item/vnd.torproject.v3auth"; + default: + return null; + } + } + + @Nullable + @Override + public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) { + if (uriMatcher.match(uri) == V3AUTH_ID) + selection = "_id=" + uri.getLastPathSegment(); + SQLiteDatabase db = mDatabase.getReadableDatabase(); + return db.query(ClientAuthDatabase.DATABASE_NAME, projection, selection, selectionArgs, null, null, sortOrder); + } + + @Nullable + @Override + public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) { + SQLiteDatabase db = mDatabase.getWritableDatabase(); + long regId = db.insert(ClientAuthDatabase.DATABASE_NAME, null, values); + getContext().getContentResolver().notifyChange(CONTENT_URI, null); + return ContentUris.withAppendedId(CONTENT_URI, regId); + } + + @Override + public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) { + if (uriMatcher.match(uri) == V3AUTH_ID) + selection = "_id=" + uri.getLastPathSegment(); + SQLiteDatabase db = mDatabase.getWritableDatabase(); + int rows = db.delete(ClientAuthDatabase.DATABASE_NAME, selection, selectionArgs); + getContext().getContentResolver().notifyChange(CONTENT_URI, null); + return rows; + } + + @Override + public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs) { + SQLiteDatabase db = mDatabase.getWritableDatabase(); + if (uriMatcher.match(uri) == V3AUTH_ID) + selection = "id_=" + uri.getLastPathSegment(); + int rows = db.update(ClientAuthDatabase.DATABASE_NAME, values, selection, null); + getContext().getContentResolver().notifyChange(CONTENT_URI, null); + return rows; + } + + public static final class V3ClientAuth implements BaseColumns { + private V3ClientAuth() { + } // no-op + + public static final String + DOMAIN = "domain", + HASH = "hash", + ENABLED = "enabled"; + } + +} diff --git a/app/src/main/java/com/darkweb/genesissearchengine/clientauth/ClientAuthDatabase.java b/app/src/main/java/com/darkweb/genesissearchengine/clientauth/ClientAuthDatabase.java new file mode 100644 index 00000000..4dfda1a8 --- /dev/null +++ b/app/src/main/java/com/darkweb/genesissearchengine/clientauth/ClientAuthDatabase.java @@ -0,0 +1,30 @@ +package com.darkweb.genesissearchengine.clientauth; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +public class ClientAuthDatabase extends SQLiteOpenHelper { + static final String DATABASE_NAME = "v3_client_auths"; + private static final int DATABASE_VERSION = 1; + + private static final String V3_AUTHS_CREATE_SQL = + "CREATE TABLE " + DATABASE_NAME + " (" + + "_id INTEGER PRIMARY KEY AUTOINCREMENT, " + + "domain TEXT, " + + "hash TEXT, " + + "enabled INTEGER DEFAULT 1);"; + + ClientAuthDatabase(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL(V3_AUTHS_CREATE_SQL); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + } +} diff --git a/app/src/main/java/com/darkweb/genesissearchengine/dataManager/suggestionDataModel.java b/app/src/main/java/com/darkweb/genesissearchengine/dataManager/suggestionDataModel.java index 12d3d29a..2a06442e 100644 --- a/app/src/main/java/com/darkweb/genesissearchengine/dataManager/suggestionDataModel.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/dataManager/suggestionDataModel.java @@ -37,6 +37,9 @@ public class suggestionDataModel implements SpellCheckerSession.SpellCheckerSess private ArrayList getDefaultSuggestionsOnStart(String pQuery, int mSize, ArrayList mDuplicationHandler, boolean pDefaultHostChaned){ + if(pQuery.equals(strings.GENERIC_EMPTY_STR)){ + pQuery = "hidden web"; + } mCurrentList.clear(); if(!pQuery.equals(strings.GENERIC_EMPTY_STR) && !pQuery.equals("about:blank") && !pQuery.contains("?") && !pQuery.contains("/") && !pQuery.contains(" ") && !pQuery.contains(" ") && !pQuery.contains("\n")){ mCurrentList.size(); diff --git a/app/src/main/java/com/darkweb/genesissearchengine/helperManager/ProxySettings.java b/app/src/main/java/com/darkweb/genesissearchengine/helperManager/ProxySettings.java index 2b50c847..abbfdee7 100644 --- a/app/src/main/java/com/darkweb/genesissearchengine/helperManager/ProxySettings.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/helperManager/ProxySettings.java @@ -7,7 +7,7 @@ import ch.boye.httpclientandroidlib.HttpHost; public class ProxySettings { private static final String TOR_PROXY_ADDRESS = "127.0.0.1"; - private static final int TOR_PROXY_PORT = 1080; + private static final int TOR_PROXY_PORT = 8118; public static Proxy getProxy() { // TODO make configurable diff --git a/app/src/main/java/com/darkweb/genesissearchengine/helperManager/downloadNotification.java b/app/src/main/java/com/darkweb/genesissearchengine/helperManager/downloadNotification.java index 8cbe9ff9..c9263734 100644 --- a/app/src/main/java/com/darkweb/genesissearchengine/helperManager/downloadNotification.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/helperManager/downloadNotification.java @@ -12,7 +12,7 @@ public class downloadNotification extends BroadcastReceiver { int mCommand = intent.getExtras().getInt("N_COMMAND"); if(mCommand==1){ pluginController.getInstance().onDownloadInvoke(Collections.singletonList(intent.getExtras().getInt("N_ID")), pluginEnums.eDownloadManager.M_TRIGGER); - }else if(mCommand==0) { + }else if(mCommand==0 || mCommand==2) { pluginController.getInstance().onDownloadInvoke(Collections.singletonList(intent.getExtras().getInt("N_ID")), pluginEnums.eDownloadManager.M_CANCEL); } } diff --git a/app/src/main/java/com/darkweb/genesissearchengine/helperManager/helperMethod.java b/app/src/main/java/com/darkweb/genesissearchengine/helperManager/helperMethod.java index 73a84aee..9e6a76c9 100755 --- a/app/src/main/java/com/darkweb/genesissearchengine/helperManager/helperMethod.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/helperManager/helperMethod.java @@ -9,6 +9,7 @@ import android.content.ActivityNotFoundException; import android.content.ClipData; import android.content.ClipboardManager; import android.content.ComponentName; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -632,13 +633,17 @@ public class helperMethod transitionDrawable.startTransition(duration); } - public static String getMimeType(String url) { - String type = null; - String extension = MimeTypeMap.getFileExtensionFromUrl(url); - if (extension != null) { - type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); + public static String getMimeType(String url, Context pContext) { + String mimeType; + Uri myUri = Uri.parse(url); + if (ContentResolver.SCHEME_CONTENT.equals(myUri.getScheme())) { + ContentResolver cr = pContext.getContentResolver(); + mimeType = cr.getType(myUri); + } else { + String fileExtension = MimeTypeMap.getFileExtensionFromUrl(myUri.toString()); + mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension.toLowerCase()); } - return type; + return mimeType; } public static void openFile(File url, Context context) { @@ -650,7 +655,16 @@ public class helperMethod intent.setDataAndType(uri, Uri.parse(url.toString()).getScheme()); context.startActivity(intent); } catch (ActivityNotFoundException e) { - Toast.makeText(context, "No application found which can open the file", Toast.LENGTH_SHORT).show(); + try { + Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", url); + Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url.toString())); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.setDataAndType(Uri.fromFile(url), getMimeType(uri.toString(),context)); + context.startActivity(intent); + } catch (ActivityNotFoundException ex) { + Toast.makeText(context, "No application found which can open the file", Toast.LENGTH_SHORT).show(); + } } } public static void copyURL(String url,Context context){ diff --git a/app/src/main/java/com/darkweb/genesissearchengine/helperManager/localFileDownloader.java b/app/src/main/java/com/darkweb/genesissearchengine/helperManager/localFileDownloader.java index 7413b74c..f278bb09 100644 --- a/app/src/main/java/com/darkweb/genesissearchengine/helperManager/localFileDownloader.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/helperManager/localFileDownloader.java @@ -15,30 +15,34 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Environment; +import android.os.Handler; import android.os.StrictMode; import android.provider.MediaStore; +import android.widget.Toast; + import androidx.core.app.NotificationCompat; import androidx.core.content.FileProvider; import com.darkweb.genesissearchengine.netcipher.client.StrongHttpsClient; import com.example.myapplication.R; import org.mozilla.thirdparty.com.google.android.exoplayer2.util.Log; import org.torproject.android.proxy.util.Prefs; - -import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStream; +import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URI; import java.net.URL; import java.net.URLConnection; -import java.net.URLEncoder; +import java.text.DecimalFormat; +import ch.boye.httpclientandroidlib.HttpHost; import ch.boye.httpclientandroidlib.HttpResponse; import ch.boye.httpclientandroidlib.client.methods.HttpGet; +import ch.boye.httpclientandroidlib.conn.params.ConnRoutePNames; + import static java.lang.Thread.sleep; @@ -50,6 +54,7 @@ public class localFileDownloader extends AsyncTask { private NotificationCompat.Builder build; private OutputStream output; private InputStream mStream; + private Boolean mIsCanceled = false; private String PROXY_ADDRESS = "localhost"; private int PROXY_PORT = 9050; @@ -117,21 +122,39 @@ public class localFileDownloader extends AsyncTask { mNotifyManager.notify(mID, build.build()); } + public static String getFileSize(long size) { + if (size <= 0) + return "0"; + + final String[] units = new String[] { "B Downloaded", "KB ⇣", "MB ⇣", "GB ⇣", "TB ⇣" }; + int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); + + return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; + } + + @Override protected String doInBackground(String... f_url) { int count; + int mRequestCode = 0; if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { try { URL url = new URL(f_url[0]); - Proxy proxy = new Proxy(Proxy.Type.SOCKS, InetSocketAddress.createUnresolved(PROXY_ADDRESS, PROXY_PORT)); - URLConnection conection; + HttpURLConnection conection; + Proxy proxy; + if(helperMethod.getDomainName(f_url[0]).contains(".onion")){ + proxy = new Proxy(Proxy.Type.SOCKS, InetSocketAddress.createUnresolved(PROXY_ADDRESS, 9050)); + conection = (HttpURLConnection) url.openConnection(proxy); + }else { + conection = (HttpURLConnection) ProxySelector.openConnectionWithProxy(new URI(f_url[0]));; + } - conection = url.openConnection(proxy); - //conection = (HttpsURLConnection)ProxySelector.openConnectionWithProxy(new URI(f_url[0])); + conection.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0"); + conection.setRequestProperty("Accept","*/*"); conection.connect(); int lenghtOfFile = conection.getContentLength(); - + mRequestCode = conection.getResponseCode(); mStream = conection.getInputStream(); // Output stream output = new FileOutputStream(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString()+"/"+mFileName)); @@ -143,7 +166,12 @@ public class localFileDownloader extends AsyncTask { while ((count = mStream.read(data)) != -1) { total += count; int cur = (int) ((total * 100) / lenghtOfFile); - mDownloadByte = cur; + if(lenghtOfFile<0){ + cur = (int)total; + mDownloadByte = cur * -1; + }else { + mDownloadByte = cur; + } publishProgress(Math.min(cur, 100)); if (Math.min(cur, 100) > 98) { sleep(500); @@ -163,6 +191,10 @@ public class localFileDownloader extends AsyncTask { mStream.close(); } catch (Exception ex) { + Log.i("FIZZAHFUCK", ex.getMessage()); + if(mRequestCode>300){ + //Toast.makeText(context,"Request Forbidden Error Code : ",mRequestCode).show(); + } onCancel(); } }else { @@ -172,7 +204,11 @@ public class localFileDownloader extends AsyncTask { StrongHttpsClient httpclient = new StrongHttpsClient(context); - httpclient.useProxy(true, "SOCKS", "127.0.0.1", 9050); + if(helperMethod.getDomainName(f_url[0]).contains(".onion")){ + httpclient.useProxy(true, "SOCKS", "127.0.0.1", 9050); + }else { + httpclient.useProxy(true, "SOCKS", "127.0.0.1", 9050); + } HttpGet httpget = new HttpGet(urlEncoded); HttpResponse response = httpclient.execute(httpget); @@ -182,17 +218,26 @@ public class localFileDownloader extends AsyncTask { InputStream mStream = response.getEntity().getContent(); + mRequestCode = response.getStatusLine().getStatusCode(); output = new FileOutputStream(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString()+"/"+mFileName)); byte[] data = new byte[100000]; long total = 0; - mTotalByte = response.getEntity().getContentLength(); + float lenghtOfFile = response.getEntity().getContentLength(); + mTotalByte = lenghtOfFile; int read; while ((read = mStream.read(data)) != -1) { total += read; int cur = (int) ((total * 100) / response.getEntity().getContentLength()); mDownloadByte = cur; + if(lenghtOfFile<0){ + cur = (int)total; + mDownloadByte = total * -1; + }else { + mDownloadByte = cur; + } + publishProgress(Math.min(cur, 100)); if (Math.min(cur, 100) > 98) { sleep(500); @@ -210,19 +255,24 @@ public class localFileDownloader extends AsyncTask { output.close(); mStream.close(); }catch (Exception ex){ - Log.d("sda", "dsa"); + if(mRequestCode>300){ + //Toast.makeText(context,"Request Forbidden Error Code : ",mRequestCode).show(); + } + onCancel(); } } return null; } protected void onProgressUpdate(Integer... progress) { - build.setProgress(100, progress[0], false); int mPercentage = (int)(mDownloadByte); if(mPercentage<0){ - mPercentage = 0; + build.setProgress(100, progress[0], true); + build.setContentText(getFileSize(mPercentage * -1)); + }else { + build.setProgress(100, progress[0], false); + build.setContentText(mPercentage+"%"); } - build.setContentText(mPercentage+"%"); mNotifyManager.notify(mID, build.build()); super.onProgressUpdate(progress); } @@ -230,19 +280,27 @@ public class localFileDownloader extends AsyncTask { @Override protected void onPostExecute(String file_url) { Intent snoozeIntentPost = new Intent(context, downloadNotification.class); - snoozeIntentPost.setAction("Download_Cancelled"); + snoozeIntentPost.setAction("Download_Open"); snoozeIntentPost.putExtra("N_ID", mID); snoozeIntentPost.putExtra("N_COMMAND", 1); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, mID, snoozeIntentPost, PendingIntent.FLAG_UPDATE_CURRENT); + Intent snoozeIntentPost1 = new Intent(context, downloadNotification.class); + snoozeIntentPost1.setAction("Download_Cancelled"); + snoozeIntentPost1.putExtra("N_ID", mID); + snoozeIntentPost1.putExtra("N_COMMAND", 2); + PendingIntent pendingIntent1 = PendingIntent.getBroadcast(context, mID, snoozeIntentPost1, PendingIntent.FLAG_UPDATE_CURRENT); + + build.addAction(0, null, null); build.setContentIntent(pendingIntent); - build.addAction(android.R.drawable.stat_sys_download, "Open",pendingIntent); build.setContentText("Download complete"); build.setSmallIcon(R.xml.ic_check); + build.setColor(Color.parseColor("#84989f")); build.setProgress(0, 0, false); build.setAutoCancel(true); - build.setColor(Color.parseColor("#212d45")); build.setOngoing(false); + build.addAction(android.R.drawable.stat_sys_download, "Open",pendingIntent); + build.addAction(R.drawable.ic_download, "Cancel",pendingIntent1); build.setPriority(Notification.PRIORITY_LOW); mNotifyManager.notify(mID, build.build()); @@ -258,7 +316,7 @@ public class localFileDownloader extends AsyncTask { contentValues.put(MediaStore.Downloads.TITLE, mFileName); contentValues.put(MediaStore.Downloads.DISPLAY_NAME, mFileName); contentValues.put(MediaStore.Downloads.SIZE, mDownloadByte); - contentValues.put(MediaStore.Downloads.MIME_TYPE, helperMethod.getMimeType(uri.toString())); + contentValues.put(MediaStore.Downloads.MIME_TYPE, helperMethod.getMimeType(uri.toString(), context)); contentValues.put(MediaStore.Downloads.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS + File.separator + "Temp"); @@ -266,21 +324,28 @@ public class localFileDownloader extends AsyncTask { database.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues); } else { Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", mFile); - dm.addCompletedDownload(mFileName, mURL, false, helperMethod.getMimeType(uri.toString()), mFile.getAbsolutePath(), mFile.length(), false); + String mime = helperMethod.getMimeType(uri.toString(), context); + if(mime!=null){ + dm.addCompletedDownload(mFileName, mURL, false, mime, mFile.getAbsolutePath(), mFile.length(), false); + } } } public void onCancel(){ + mIsCanceled = true; mNotifyManager.cancel(mID); cancel(true); } public void onTrigger(){ - mNotifyManager.cancel(mID); - String mPath = (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + File.separator + mFileName).replace("File//","content://"); - File mFile = new File(mPath); - helperMethod.openFile(mFile, context); + if(!mIsCanceled){ + mNotifyManager.cancel(mID); + String mPath = (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + File.separator + mFileName).replace("File//","content://"); + File mFile = new File(mPath); + + new Handler().postDelayed(() -> helperMethod.openFile(mFile, context), 500); + } } } diff --git a/app/src/main/res/custom-xml/generic/xml/file_path.xml b/app/src/main/res/custom-xml/generic/xml/file_path.xml new file mode 100644 index 00000000..01038999 --- /dev/null +++ b/app/src/main/res/custom-xml/generic/xml/file_path.xml @@ -0,0 +1,4 @@ + + + + diff --git a/orbotservice/src/main/java/org/torproject/android/proxy/OrbotService.java b/orbotservice/src/main/java/org/torproject/android/proxy/OrbotService.java index 541bd5b1..73dce933 100644 --- a/orbotservice/src/main/java/org/torproject/android/proxy/OrbotService.java +++ b/orbotservice/src/main/java/org/torproject/android/proxy/OrbotService.java @@ -73,8 +73,6 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; -import java.io.Reader; -import java.io.StringReader; import java.net.Socket; import java.util.ArrayList; import java.util.Arrays; @@ -93,22 +91,21 @@ import java.util.concurrent.TimeoutException; import IPtProxy.IPtProxy; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; -import static org.torproject.android.proxy.wrapper.orbotLocalConstants.mBridgesDefault; public class OrbotService extends VpnService implements TorServiceConstants, OrbotConstants { public final static String BINARY_TOR_VERSION = org.torproject.android.binary.TorServiceConstants.BINARY_TOR_VERSION; - static final int NOTIFY_ID = 11; + static final int NOTIFY_ID = 1; private final static int CONTROL_SOCKET_TIMEOUT = 60000; private boolean mConnectivity = true; - private static final int ERROR_NOTIFY_ID = 31; - private static final int HS_NOTIFY_ID = 41; + private static final int ERROR_NOTIFY_ID = 3; + private static final int HS_NOTIFY_ID = 4; private Notification mNotification; private static final Uri V2_HS_CONTENT_URI = Uri.parse("content://org.torproject.android.ui.hiddenservices.providers/hs"); private static final Uri V3_ONION_SERVICES_CONTENT_URI = Uri.parse("content://org.torproject.android.ui.v3onionservice/v3"); private static final Uri COOKIE_CONTENT_URI = Uri.parse("content://org.torproject.android.ui.hiddenservices.providers.cookie/cookie"); - private static final Uri V3_CLIENT_AUTH_URI = Uri.parse("content://org.torproject.android.ui.v3onionservice.clientauth/v3auth"); - private final static String NOTIFICATION_CHANNEL_ID = "genesis_channel_1"; + private static final Uri V3_CLIENT_AUTH_URI = Uri.parse("content://com.darkweb.genesissearchengine.clientauth.ClientAuthContentProvider/v3auth"); + private final static String NOTIFICATION_CHANNEL_ID = "orbot_channel_1"; private static final String[] LEGACY_V2_ONION_SERVICE_PROJECTION = new String[]{ OnionService._ID, OnionService.NAME, @@ -237,9 +234,6 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb @RequiresApi(api = Build.VERSION_CODES.O) private void createNotificationChannel() { - if(1==1){ - return; - } if(orbotLocalConstants.mNotificationStatus==1) { NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); @@ -258,9 +252,6 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb @SuppressLint({"NewApi", "RestrictedApi"}) protected void showToolbarNotification(String notifyMsg, int notifyType, int icon) { - if(1==1){ - return; - } //if(orbotLocalConstants.mNotificationStatus==1){ PackageManager pm = getPackageManager(); Intent intent = pm.getLaunchIntentForPackage(getPackageName()); @@ -981,12 +972,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb } protected void exec(Runnable runn) { - try { - new Thread(runn).start(); - }catch (Exception ex){ - ex.printStackTrace(); - Log.i("",""); - } + mExecutor.execute(runn); } private int exec(String cmd, boolean wait) throws Exception { @@ -1635,8 +1621,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb alBridges = new ArrayList<>(); try { - Reader inputString = new StringReader(mBridgesDefault); - BufferedReader in = new BufferedReader(inputString); + BufferedReader in = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.bridges), "UTF-8")); String str; while ((str = in.readLine()) != null) {