Bug Fixes

Bug Fixes
master
Abdul Mannan Saeed 2023-02-26 21:39:28 +05:00
parent 7be82ffbdb
commit cb9df8c06b
6 changed files with 194 additions and 144 deletions

View File

@ -17,6 +17,8 @@ import org.torproject.android.service.wrapper.orbotLocalConstants;
import static com.hiddenservices.onionservices.constants.constants.CONST_EXTERNAL_SHORTCUT_COMMAND_ERASE;
import static com.hiddenservices.onionservices.constants.keys.EXTERNAL_SHORTCUT_COMMAND;
import java.util.concurrent.Callable;
public class externalShortcutController extends AppCompatActivity {
/* Initialize */
@ -42,7 +44,7 @@ public class externalShortcutController extends AppCompatActivity {
setContentView(R.layout.popup_data_cleared_shortcut);
panicExitInvoked();
helperMethod.onDelayHandler(this, 3000, () -> {
finishAndRemoveTask();
externalShortcutController.this.finishAndRemoveTask();
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
return null;

View File

@ -15,6 +15,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.dataModel.geckoDataModel;
import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.downloadManager.geckoDownloadManager;
import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.geckoSession;
import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.helperClasses.permissionHandler;
import com.hiddenservices.onionservices.appManager.homeManager.homeController.homeEnums;
import com.hiddenservices.onionservices.constants.status;
import com.hiddenservices.onionservices.constants.strings;
@ -32,6 +33,7 @@ import org.mozilla.geckoview.WebResponse;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
public class contentDelegate implements GeckoSession.ContentDelegate {
@ -103,23 +105,7 @@ public class contentDelegate implements GeckoSession.ContentDelegate {
@UiThread
@Override
public void onExternalResponse(@NonNull GeckoSession session, @NonNull WebResponse response) {
Dexter.withContext(mContext.get())
.withPermissions(
Manifest.permission.CAMERA,
Manifest.permission.READ_CONTACTS,
Manifest.permission.MEDIA_CONTENT_CONTROL,
Manifest.permission.MANAGE_MEDIA,
Manifest.permission.ACCESS_MEDIA_LOCATION,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_VIDEO,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.MANAGE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO
).withListener(new MultiplePermissionsListener() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport multiplePermissionsReport) {
permissionHandler.getInstance().checkPermission((Callable<Void>) () -> {
try {
if (response.headers.containsKey("Content-Disposition")) {
mDownloadManager.downloadFile(response, mGeckoSession, mContext.get(), mEvent);
@ -130,13 +116,8 @@ public class contentDelegate implements GeckoSession.ContentDelegate {
mEvent.invokeObserver(Arrays.asList(response, mGeckoDataModel.mSessionID), homeEnums.eGeckoCallback.ON_HANDLE_EXTERNAL_INTENT);
mGeckoSession.stop();
}
}
@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> list, PermissionToken permissionToken) {
}
}).check();
return null;
});
}
@UiThread

View File

@ -0,0 +1,102 @@
package com.hiddenservices.onionservices.appManager.homeManager.geckoManager.helperClasses;
import static com.hiddenservices.onionservices.pluginManager.pluginEnums.eMessageManager.M_OPEN_CICADA;
import android.Manifest;
import android.os.Build;
import androidx.appcompat.app.AppCompatActivity;
import com.hiddenservices.onionservices.pluginManager.pluginController;
import com.karumi.dexter.Dexter;
import com.karumi.dexter.DexterBuilder;
import com.karumi.dexter.MultiplePermissionsReport;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.multi.MultiplePermissionsListener;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
public class permissionHandler {
private WeakReference<AppCompatActivity> mContext;
public static permissionHandler ourInstance = new permissionHandler();
/*Initializations*/
public static permissionHandler getInstance() {
return ourInstance;
}
public void onInitPermissionHandler(WeakReference<AppCompatActivity> pContext){
mContext = pContext;
}
public void checkPermission(Callable<Void> pMethodParam){
DexterBuilder.Permission mPermission = Dexter.withContext(mContext.get());
DexterBuilder.MultiPermissionListener mListener;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
mListener = mPermission.withPermissions(
Manifest.permission.CAMERA,
Manifest.permission.READ_CONTACTS,
Manifest.permission.MEDIA_CONTENT_CONTROL,
Manifest.permission.MANAGE_MEDIA,
Manifest.permission.ACCESS_MEDIA_LOCATION,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_VIDEO,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.MANAGE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO);
}
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
mListener = mPermission.withPermissions(
Manifest.permission.CAMERA,
Manifest.permission.READ_CONTACTS,
Manifest.permission.MEDIA_CONTENT_CONTROL,
Manifest.permission.MANAGE_MEDIA,
Manifest.permission.ACCESS_MEDIA_LOCATION,
Manifest.permission.MANAGE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO);
}
else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
mListener = mPermission.withPermissions(
Manifest.permission.CAMERA,
Manifest.permission.READ_CONTACTS,
Manifest.permission.MEDIA_CONTENT_CONTROL,
Manifest.permission.ACCESS_MEDIA_LOCATION,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO
);
}else {
mListener = mPermission.withPermissions(
Manifest.permission.CAMERA,
Manifest.permission.READ_CONTACTS,
Manifest.permission.MEDIA_CONTENT_CONTROL,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO
);
}
mListener.withListener(new MultiplePermissionsListener() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport multiplePermissionsReport) {
try {
pMethodParam.call();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> list, PermissionToken permissionToken) {
pluginController.getInstance().onMessageManagerInvoke(Collections.singletonList(this), M_OPEN_CICADA);
}
}).check();
}
}

View File

@ -61,6 +61,7 @@ import androidx.lifecycle.OnLifecycleEvent;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.hiddenservices.onionservices.appManager.activityContextManager;
import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.helperClasses.permissionHandler;
import com.hiddenservices.onionservices.appManager.unproxiedConnectionManager.unproxiedConnectionController;
import com.hiddenservices.onionservices.appManager.bookmarkManager.bookmarkSettings.bookmarkSettingController;
import com.hiddenservices.onionservices.appManager.bookmarkManager.bookmarkHome.bookmarkController;
@ -263,6 +264,7 @@ public class homeController extends AppCompatActivity implements ComponentCallba
status.sSettingIsAppRunning = true;
initPreFixes();
initBundle();
permissionHandler.getInstance().onInitPermissionHandler(new WeakReference(this));
if(!status.mThemeApplying){
initTor();
}
@ -2131,31 +2133,13 @@ public class homeController extends AppCompatActivity implements ComponentCallba
handler.postDelayed(() -> mGeckoView.clearFocus(), 500);
}
} else if (requestCode == 115) {
Dexter.withContext(this)
.withPermissions(
Manifest.permission.CAMERA,
Manifest.permission.READ_CONTACTS,
Manifest.permission.MEDIA_CONTENT_CONTROL,
Manifest.permission.MANAGE_MEDIA,
Manifest.permission.ACCESS_MEDIA_LOCATION,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_VIDEO,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.MANAGE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO
).withListener(new MultiplePermissionsListener() {
permissionHandler.getInstance().checkPermission(new Callable<Void>() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport multiplePermissionsReport) {
public Void call() throws Exception {
mGeckoClient.onUploadRequest(resultCode, data);
return null;
}
@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> list, PermissionToken permissionToken) {
}
}).check();
});
} else {
super.onActivityResult(requestCode, resultCode, data);
}
@ -2477,6 +2461,7 @@ public class homeController extends AppCompatActivity implements ComponentCallba
}
} else if (menuId == R.id.menu29) {
pluginController.getInstance().onMessageManagerInvoke(Collections.singletonList(this), pluginEnums.eMessageManager.M_TOR_SWITCH);
pluginController.getInstance().onMessageManagerInvoke(Collections.singletonList(this), pluginEnums.eMessageManager.M_TOR_SWITCH);
} else if (menuId == R.id.menuItem25) {
String mFileName = DownloadUtils.guessFileName(null, "", mGeckoClient.getSession().getCurrentURL(), null);

View File

@ -66,7 +66,13 @@ public class downloadReciever extends AsyncTask<String, Integer, String> {
this.mContext = new WeakReference(pContext);
this.mEvent = pEvent;
this.mFileName = pFileName;
if(pFileName.contains("/")){
pFileName = pFileName.substring(pFileName.lastIndexOf("/")+1);
}
if(pFileName.contains("?")){
pFileName = pFileName.substring(0, pFileName.lastIndexOf("?"));
}
this.mFileName = helperMethod.createRandomID().substring(0,5) + pFileName;
this.mURL = pURL;
this.mNotificationID = pNotificationID;
this.mBroadcastReciever = pBroadcastReciever;
@ -122,12 +128,17 @@ public class downloadReciever extends AsyncTask<String, Integer, String> {
}
boolean mRequestRunning = false;
@Override
protected String doInBackground(String... f_url) {
int mRequestCode = 0;
OutputStream mOutputStream;
InputStream mInputStream;
if(!mRequestRunning){
mRequestRunning = true;
}else {
return "";
}
try {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
String fURL = f_url[0];
@ -135,14 +146,10 @@ public class downloadReciever extends AsyncTask<String, Integer, String> {
HttpURLConnection conection;
Proxy proxy;
if (helperMethod.getDomainName(fURL).contains(".onion")) {
if (orbotLocalConstants.mSOCKSPort == -1) {
proxy = new Proxy(Proxy.Type.SOCKS, InetSocketAddress.createUnresolved("localhost", orbotLocalConstants.mSOCKSPort));
conection = (HttpURLConnection) url.openConnection(proxy);
} else {
conection = (HttpURLConnection) url.openConnection();
}
} else {
if (orbotLocalConstants.mSOCKSPort == -1) {
if (status.sTorBrowsing) {
Proxy mProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", orbotLocalConstants.mHTTPPort));
URLConnection mURLConnection = new URI(fURL).toURL().openConnection(mProxy);
conection = (HttpURLConnection) mURLConnection;
@ -167,12 +174,8 @@ public class downloadReciever extends AsyncTask<String, Integer, String> {
StrongHttpsClient httpclient = new StrongHttpsClient(mContext.get());
if (helperMethod.getDomainName(f_url[0]).contains(".onion")) {
if(status.sTorBrowsing){
httpclient.useProxy(true, "SOCKS", "127.0.0.1", orbotLocalConstants.mSOCKSPort);
} else {
httpclient.useProxy(false, "SOCKS", "127.0.0.1", orbotLocalConstants.mSOCKSPort);
}
HttpGet httpget = new HttpGet(urlEncoded);
HttpResponse response = httpclient.execute(httpget);
mInputStream = response.getEntity().getContent();
@ -180,6 +183,22 @@ public class downloadReciever extends AsyncTask<String, Integer, String> {
mOutputStream = new FileOutputStream(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/" + mFileName);
float lenghtOfFile = response.getEntity().getContentLength();
readStream(mInputStream, mOutputStream, lenghtOfFile);
}else {
HttpURLConnection conection;
String fURL = f_url[0];
URLConnection mURLConnection = new URI(fURL).toURL().openConnection();
conection = (HttpURLConnection) mURLConnection;
conection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0");
conection.setRequestProperty("Accept", "*/*");
conection.connect();
mRequestCode = conection.getResponseCode();
mInputStream = conection.getInputStream();
mOutputStream = new FileOutputStream(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/" + mFileName);
int lenghtOfFile = conection.getContentLength();
readStream(mInputStream, mOutputStream, lenghtOfFile);
}
}
} catch (Exception ex) {
if (mRequestCode != 200 && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
@ -188,6 +207,7 @@ public class downloadReciever extends AsyncTask<String, Integer, String> {
onBackgroundException(mRequestCode);
}
mRequestRunning = false;
return null;
}
@ -215,30 +235,6 @@ public class downloadReciever extends AsyncTask<String, Integer, String> {
mNotificationBuilder.setPriority(Notification.PRIORITY_LOW);
mNotifyManager.notify(mNotificationID, mNotificationBuilder.build());
DownloadManager dm = (DownloadManager) mContext.get().getSystemService(Context.DOWNLOAD_SERVICE);
String mPath = (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + File.separator + mFileName).replace("File//", "content://");
File mFile = new File(mPath);
/* Create Dwonload Complete Destination */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Uri uri = FileProvider.getUriForFile(mContext.get(), "com.hiddenservices.onionservices.provider", mFile);
ContentValues contentValues = new ContentValues();
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(), mContext.get()));
contentValues.put(MediaStore.Downloads.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS + File.separator + mFileName + "_" + helperMethod.createRandomID().substring(0, 5));
ContentResolver database = mContext.get().getContentResolver();
database.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues);
} else {
Uri uri = FileProvider.getUriForFile(mContext.get(), "com.hiddenservices.onionservices.provider", mFile);
String mime = helperMethod.getMimeType(uri.toString(), mContext.get());
if (mime != null) {
dm.addCompletedDownload(mFileName, mURL, false, mime, mFile.getAbsolutePath(), mFile.length(), false);
}
}
}
@ -300,6 +296,7 @@ public class downloadReciever extends AsyncTask<String, Integer, String> {
pOutputStream.write(mData, 0, mCurrentReadCount);
}
mNotifyManager.cancel(mNotificationID);
onPostExecute("");
return true;
}

View File

@ -1,6 +1,7 @@
package com.hiddenservices.onionservices.pluginManager;
import android.Manifest;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
@ -8,6 +9,8 @@ import android.view.WindowManager;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import com.hiddenservices.onionservices.appManager.activityContextManager;
import com.hiddenservices.onionservices.appManager.homeManager.geckoManager.helperClasses.permissionHandler;
import com.hiddenservices.onionservices.appManager.homeManager.homeController.homeEnums;
import com.hiddenservices.onionservices.appManager.unproxiedConnectionManager.unproxiedConnectionController;
import com.hiddenservices.onionservices.appManager.homeManager.homeController.homeController;
import com.hiddenservices.onionservices.appManager.orbotLogManager.orbotLogController;
@ -36,6 +39,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Callable;
import static com.hiddenservices.onionservices.constants.constants.CONST_BRIDGES;
import static com.hiddenservices.onionservices.pluginManager.pluginEnums.eAdManagerCallbacks.M_ON_AD_CLICKED;
@ -233,23 +237,7 @@ public class pluginController {
return null;
});
} else if (pEventType.equals(M_DOWNLOAD_SINGLE) || pEventType.equals(M_DOWNLOAD_FILE) || pEventType.equals(M_DOWNLOAD_FILE_MANUAL)) {
Dexter.withContext(mHomeController.get())
.withPermissions(
Manifest.permission.CAMERA,
Manifest.permission.READ_CONTACTS,
Manifest.permission.MEDIA_CONTENT_CONTROL,
Manifest.permission.MANAGE_MEDIA,
Manifest.permission.ACCESS_MEDIA_LOCATION,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_VIDEO,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.MANAGE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO
).withListener(new MultiplePermissionsListener() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport multiplePermissionsReport) {
permissionHandler.getInstance().checkPermission((Callable<Void>) () -> {
if(pEventType.equals(M_DOWNLOAD_SINGLE)){
if (pData != null) {
if (pData.size() < 3) {
@ -269,13 +257,8 @@ public class pluginController {
if(pEventType.equals(M_DOWNLOAD_FILE_MANUAL)){
((homeController) mHomeController.get()).onManualDownload(pData.get(0).toString());
}
}
@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> list, PermissionToken permissionToken) {
onMessageManagerInvoke(Collections.singletonList(this), M_OPEN_CICADA);
}
}).check();
return null;
});
} else if (pEventType.equals(M_CANCEL_WELCOME)) {
status.sSettingIsWelcomeEnabled = false;