From cb9df8c06b875f0ace840388808e591c48d253d0 Mon Sep 17 00:00:00 2001 From: Abdul Mannan Saeed <111820160@umt.edu.pk> Date: Sun, 26 Feb 2023 21:39:28 +0500 Subject: [PATCH] Bug Fixes Bug Fixes --- .../externalShortcutController.java | 4 +- .../delegateModel/contentDelegate.java | 49 +++------ .../helperClasses/permissionHandler.java | 102 ++++++++++++++++++ .../homeController/homeController.java | 35 ++---- .../downloadReciever.java | 83 +++++++------- .../pluginManager/pluginController.java | 65 +++++------ 6 files changed, 194 insertions(+), 144 deletions(-) create mode 100644 app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/permissionHandler.java diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/externalCommandManager/externalShortcutController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/externalCommandManager/externalShortcutController.java index 84e0f012..aa05e3e5 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/externalCommandManager/externalShortcutController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/externalCommandManager/externalShortcutController.java @@ -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; diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/contentDelegate.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/contentDelegate.java index 87a34200..f2906edd 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/contentDelegate.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/delegateModel/contentDelegate.java @@ -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,40 +105,19 @@ 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) { - try { - if (response.headers.containsKey("Content-Disposition")) { - mDownloadManager.downloadFile(response, mGeckoSession, mContext.get(), mEvent); - } else if (response.headers.containsKey("Content-Type")) { - mDownloadManager.downloadFile(response, mGeckoSession, mContext.get(), mEvent); - } - } catch (ActivityNotFoundException e) { - mEvent.invokeObserver(Arrays.asList(response, mGeckoDataModel.mSessionID), homeEnums.eGeckoCallback.ON_HANDLE_EXTERNAL_INTENT); - mGeckoSession.stop(); - } - } - - @Override - public void onPermissionRationaleShouldBeShown(List list, PermissionToken permissionToken) { - - } - }).check(); + permissionHandler.getInstance().checkPermission((Callable) () -> { + try { + if (response.headers.containsKey("Content-Disposition")) { + mDownloadManager.downloadFile(response, mGeckoSession, mContext.get(), mEvent); + } else if (response.headers.containsKey("Content-Type")) { + mDownloadManager.downloadFile(response, mGeckoSession, mContext.get(), mEvent); + } + } catch (ActivityNotFoundException e) { + mEvent.invokeObserver(Arrays.asList(response, mGeckoDataModel.mSessionID), homeEnums.eGeckoCallback.ON_HANDLE_EXTERNAL_INTENT); + mGeckoSession.stop(); + } + return null; + }); } @UiThread diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/permissionHandler.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/permissionHandler.java new file mode 100644 index 00000000..a6723f38 --- /dev/null +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/geckoManager/helperClasses/permissionHandler.java @@ -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 mContext; + public static permissionHandler ourInstance = new permissionHandler(); + + /*Initializations*/ + public static permissionHandler getInstance() { + return ourInstance; + } + + public void onInitPermissionHandler(WeakReference pContext){ + mContext = pContext; + } + + public void checkPermission(Callable 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 list, PermissionToken permissionToken) { + pluginController.getInstance().onMessageManagerInvoke(Collections.singletonList(this), M_OPEN_CICADA); + } + }).check(); + } + +} diff --git a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/homeController/homeController.java b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/homeController/homeController.java index f6454c15..a1e6d7dc 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/homeController/homeController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/appManager/homeManager/homeController/homeController.java @@ -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() { - @Override - public void onPermissionsChecked(MultiplePermissionsReport multiplePermissionsReport) { - mGeckoClient.onUploadRequest(resultCode, data); - } - - @Override - public void onPermissionRationaleShouldBeShown(List list, PermissionToken permissionToken) { - - } - }).check(); + permissionHandler.getInstance().checkPermission(new Callable() { + @Override + public Void call() throws Exception { + mGeckoClient.onUploadRequest(resultCode, data); + return null; + } + }); } 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); diff --git a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/downloadPluginManager/downloadReciever.java b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/downloadPluginManager/downloadReciever.java index d2e1975d..a11af636 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/downloadPluginManager/downloadReciever.java +++ b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/downloadPluginManager/downloadReciever.java @@ -66,7 +66,13 @@ public class downloadReciever extends AsyncTask { 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 { } + 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 { 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(); - } + proxy = new Proxy(Proxy.Type.SOCKS, InetSocketAddress.createUnresolved("localhost", orbotLocalConstants.mSOCKSPort)); + conection = (HttpURLConnection) url.openConnection(proxy); } 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,19 +174,31 @@ public class downloadReciever extends AsyncTask { 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(); + mRequestCode = response.getStatusLine().getStatusCode(); + 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); } - HttpGet httpget = new HttpGet(urlEncoded); - HttpResponse response = httpclient.execute(httpget); - mInputStream = response.getEntity().getContent(); - mRequestCode = response.getStatusLine().getStatusCode(); - mOutputStream = new FileOutputStream(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/" + mFileName); - float lenghtOfFile = response.getEntity().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 { onBackgroundException(mRequestCode); } + mRequestRunning = false; return null; } @@ -215,30 +235,6 @@ public class downloadReciever extends AsyncTask { 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 { pOutputStream.write(mData, 0, mCurrentReadCount); } + mNotifyManager.cancel(mNotificationID); onPostExecute(""); return true; } diff --git a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/pluginController.java b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/pluginController.java index 82cce25c..74574e09 100644 --- a/app/src/main/java/com/hiddenservices/onionservices/pluginManager/pluginController.java +++ b/app/src/main/java/com/hiddenservices/onionservices/pluginManager/pluginController.java @@ -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,49 +237,28 @@ 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) { - if(pEventType.equals(M_DOWNLOAD_SINGLE)){ - if (pData != null) { - if (pData.size() < 3) { - ((homeController) mHomeController.get()).onManualDownload(pData.get(0).toString()); - } else { - if (pData.get(2).toString().startsWith("https://data") || pData.get(2).toString().startsWith("http://data")) { - ((homeController) mHomeController.get()).onManualDownload(pData.get(2).toString().replace("https://", "").replace("http://", "")); - } else { - ((homeController) mHomeController.get()).onManualDownloadFileName(pData.get(2).toString(), (String) pData.get(0)); - } - } - } - } - if(pEventType.equals(M_DOWNLOAD_FILE)){ - ((homeController) mHomeController.get()).onDownloadFile(); - } - if(pEventType.equals(M_DOWNLOAD_FILE_MANUAL)){ - ((homeController) mHomeController.get()).onManualDownload(pData.get(0).toString()); + permissionHandler.getInstance().checkPermission((Callable) () -> { + if(pEventType.equals(M_DOWNLOAD_SINGLE)){ + if (pData != null) { + if (pData.size() < 3) { + ((homeController) mHomeController.get()).onManualDownload(pData.get(0).toString()); + } else { + if (pData.get(2).toString().startsWith("https://data") || pData.get(2).toString().startsWith("http://data")) { + ((homeController) mHomeController.get()).onManualDownload(pData.get(2).toString().replace("https://", "").replace("http://", "")); + } else { + ((homeController) mHomeController.get()).onManualDownloadFileName(pData.get(2).toString(), (String) pData.get(0)); } } - - @Override - public void onPermissionRationaleShouldBeShown(List list, PermissionToken permissionToken) { - onMessageManagerInvoke(Collections.singletonList(this), M_OPEN_CICADA); - } - }).check(); + } + } + if(pEventType.equals(M_DOWNLOAD_FILE)){ + ((homeController) mHomeController.get()).onDownloadFile(); + } + if(pEventType.equals(M_DOWNLOAD_FILE_MANUAL)){ + ((homeController) mHomeController.get()).onManualDownload(pData.get(0).toString()); + } + return null; + }); } else if (pEventType.equals(M_CANCEL_WELCOME)) { status.sSettingIsWelcomeEnabled = false;