LeOS-Genesis/app/src/main/java/com/hiddenservices/onionservices/helperManager/helperMethod.java

992 lines
40 KiB
Java
Raw Normal View History

2022-03-29 21:55:20 +02:00
package com.hiddenservices.onionservices.helperManager;
2020-01-24 16:23:31 +01:00
import android.Manifest;
2020-10-20 16:55:08 +02:00
import android.annotation.SuppressLint;
2021-06-03 16:44:08 +02:00
import android.app.ActivityManager;
2020-01-24 16:23:31 +01:00
import android.app.DownloadManager;
2022-04-02 01:13:29 +02:00
import android.app.PendingIntent;
2021-03-06 19:55:24 +01:00
import android.content.ActivityNotFoundException;
2020-01-24 16:23:31 +01:00
import android.content.ClipData;
import android.content.ClipboardManager;
2022-04-18 21:00:09 +02:00
import android.content.ComponentName;
2021-04-24 23:26:22 +02:00
import android.content.ContentResolver;
2020-01-24 16:23:31 +01:00
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
2021-06-08 10:40:27 +02:00
import android.content.res.Configuration;
2020-01-24 16:23:31 +01:00
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Point;
2020-10-20 16:55:08 +02:00
import android.graphics.drawable.ColorDrawable;
2021-03-09 07:36:59 +01:00
import android.graphics.drawable.Drawable;
2021-04-05 21:07:02 +02:00
import android.graphics.drawable.TransitionDrawable;
2020-01-24 16:23:31 +01:00
import android.net.Uri;
2021-04-11 21:25:15 +02:00
import android.os.Build;
2021-05-14 14:43:40 +02:00
import android.os.Handler;
2020-01-24 16:23:31 +01:00
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.Display;
import android.view.Gravity;
2020-10-20 16:55:08 +02:00
import android.view.LayoutInflater;
2020-01-24 16:23:31 +01:00
import android.view.View;
2021-04-11 21:25:15 +02:00
import android.view.WindowManager;
2020-01-24 16:23:31 +01:00
import android.view.inputmethod.InputMethodManager;
2021-03-09 07:36:59 +01:00
import android.webkit.MimeTypeMap;
2020-10-20 16:55:08 +02:00
import android.widget.ActionMenuView;
2021-04-05 21:07:02 +02:00
import android.widget.ImageView;
2020-10-20 16:55:08 +02:00
import android.widget.PopupWindow;
2020-01-24 16:23:31 +01:00
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.app.ShareCompat;
import androidx.core.content.ContextCompat;
2021-03-06 19:55:24 +01:00
import androidx.core.content.FileProvider;
2021-03-04 11:09:23 +01:00
import androidx.core.graphics.ColorUtils;
2023-02-09 08:55:22 +01:00
import com.hiddenservices.onionservices.BuildConfig;
2022-04-18 21:00:09 +02:00
import com.hiddenservices.onionservices.appManager.activityContextManager;
2022-03-29 21:55:20 +02:00
import com.hiddenservices.onionservices.appManager.kotlinHelperLibraries.defaultBrowser;
2022-04-04 18:42:22 +02:00
import com.hiddenservices.onionservices.constants.constants;
2022-03-29 21:55:20 +02:00
import com.hiddenservices.onionservices.constants.enums;
import com.hiddenservices.onionservices.constants.keys;
2023-02-12 15:31:17 +01:00
import com.hiddenservices.onionservices.constants.status;
2022-04-04 18:42:22 +02:00
import com.hiddenservices.onionservices.libs.trueTime.trueTimeEncryption;
2022-03-29 21:55:20 +02:00
import com.hiddenservices.onionservices.pluginManager.pluginController;
2023-02-09 08:55:22 +01:00
import com.hiddenservices.onionservices.R;
2022-04-02 01:13:29 +02:00
import java.io.BufferedReader;
import java.io.BufferedWriter;
2021-03-06 19:55:24 +01:00
import java.io.File;
2022-04-02 01:13:29 +02:00
import java.io.FileOutputStream;
import java.io.FileReader;
2020-01-24 16:23:31 +01:00
import java.io.IOException;
2023-02-12 15:31:17 +01:00
import java.io.InputStream;
2022-04-02 01:13:29 +02:00
import java.io.OutputStreamWriter;
import java.io.Writer;
2021-01-18 11:07:12 +01:00
import java.lang.reflect.Field;
2022-04-03 14:15:23 +02:00
import java.net.DatagramSocket;
2020-01-24 16:23:31 +01:00
import java.net.MalformedURLException;
2022-04-03 14:15:23 +02:00
import java.net.ServerSocket;
2020-01-24 16:23:31 +01:00
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
2022-04-02 01:13:29 +02:00
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
2020-11-27 12:40:46 +01:00
import java.text.SimpleDateFormat;
2020-01-24 16:23:31 +01:00
import java.util.ArrayList;
2020-11-27 12:40:46 +01:00
import java.util.Calendar;
2021-08-19 22:17:54 +02:00
import java.util.Collections;
2020-11-27 12:40:46 +01:00
import java.util.Date;
2020-01-24 16:23:31 +01:00
import java.util.List;
2021-03-06 19:55:24 +01:00
import java.util.Locale;
2020-12-11 08:05:08 +01:00
import java.util.UUID;
2021-05-14 14:43:40 +02:00
import java.util.concurrent.Callable;
2021-03-14 18:59:37 +01:00
import java.util.regex.Matcher;
import java.util.regex.Pattern;
2020-01-24 16:23:31 +01:00
import javax.net.ssl.HttpsURLConnection;
2020-10-20 16:55:08 +02:00
import static android.content.Context.LAYOUT_INFLATER_SERVICE;
2020-01-24 16:23:31 +01:00
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
2022-03-29 21:55:20 +02:00
import static com.hiddenservices.onionservices.constants.constants.CONST_LIST_EXTERNAL_SHORTCUT;
import static com.hiddenservices.onionservices.constants.constants.CONST_PLAYSTORE_URL;
import static com.hiddenservices.onionservices.constants.keys.M_ACTIVITY_NAVIGATION_BUNDLE_KEY;
2022-04-18 21:00:09 +02:00
import static com.hiddenservices.onionservices.constants.keys.M_RESTART_APP_KEY;
2022-03-29 21:55:20 +02:00
import static com.hiddenservices.onionservices.pluginManager.pluginEnums.eMessageManager.M_OPEN_ACTIVITY_FAILED;
2020-01-24 16:23:31 +01:00
2023-02-12 15:31:17 +01:00
import org.torproject.android.service.wrapper.orbotLocalConstants;
2022-05-02 18:26:09 +02:00
public class helperMethod {
2020-01-24 16:23:31 +01:00
/*Helper Methods General*/
2022-04-02 01:13:29 +02:00
public static String getFileSizeBadge(long size) {
if (size <= 0)
return "0";
2022-05-02 18:26:09 +02:00
final String[] units = new String[]{"B Downloaded", "KB ⇣", "MB ⇣", "GB ⇣", "TB ⇣"};
2022-04-02 01:13:29 +02:00
int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
@SuppressLint({"UnspecifiedImmutableFlag", "LaunchActivityFromNotification"})
2022-05-02 18:26:09 +02:00
public static PendingIntent onCreateActionIntent(Context pContext, Class<?> pBroadcastReciever, int pNotificationID, String pTitle, int pCommandID) {
2022-04-02 01:13:29 +02:00
PendingIntent pendingIntent;
Intent pendingIntentTrigger = new Intent(pContext, pBroadcastReciever);
pendingIntentTrigger.setAction(pTitle);
pendingIntentTrigger.putExtra("N_ID", pNotificationID);
pendingIntentTrigger.putExtra("N_COMMAND", pCommandID);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
pendingIntent = PendingIntent.getBroadcast(pContext, pNotificationID, pendingIntentTrigger, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
2022-05-02 18:26:09 +02:00
} else {
2022-04-02 01:13:29 +02:00
pendingIntent = PendingIntent.getBroadcast(pContext, pNotificationID, pendingIntentTrigger, PendingIntent.FLAG_UPDATE_CURRENT);
}
return pendingIntent;
}
2023-02-12 15:31:17 +01:00
public static String getAssetsCacheFile(Context context, String fileName) {
File cacheFile = new File(context.getCacheDir(), fileName);
try {
try (InputStream inputStream = context.getAssets().open(fileName)) {
try (FileOutputStream outputStream = new FileOutputStream(cacheFile)) {
byte[] buf = new byte[1024];
int len;
while ((len = inputStream.read(buf)) > 0) {
outputStream.write(buf, 0, len);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
String mYAML = helperMethod.readFromFile(cacheFile.getPath());
if (status.sTorBrowsing) {
mYAML = mYAML.replace("# network.proxy.socks: \"127.0.0.1\"", "network.proxy.socks: \"127.0.0.1\"");
mYAML = mYAML.replace("# network.proxy.socks_port: 9050", "network.proxy.socks_port: 9050");
mYAML = mYAML.replace("browser.cache.memory.enable: true", "browser.cache.memory.enable: false");
StringBuilder buf = new StringBuilder(mYAML);
int portIndex = mYAML.indexOf("network.proxy.socks_port");
int breakIndex = mYAML.indexOf("\n", portIndex);
mYAML = buf.replace(portIndex, breakIndex, "network.proxy.socks_port: " + orbotLocalConstants.mSOCKSPort).toString();
helperMethod.writeToFile(cacheFile.getPath(), mYAML);
} else {
mYAML = mYAML.replace("browser.cache.memory.enable: true", "browser.cache.memory.enable: false");
helperMethod.writeToFile(cacheFile.getPath(), mYAML);
}
return cacheFile.getAbsolutePath();
}
2022-05-02 18:26:09 +02:00
public static String setGenesisVerificationToken(String pString) {
try {
if (pString.contains("?")) {
pString += "&" + constants.CONST_GENESIS_GMT_TIME_GET_KEY + "=" + trueTimeEncryption.getInstance().getSecretToken();
} else {
pString += "?" + constants.CONST_GENESIS_GMT_TIME_GET_KEY + "=" + trueTimeEncryption.getInstance().getSecretToken();
2022-04-04 18:42:22 +02:00
}
return pString;
2022-05-02 18:26:09 +02:00
} catch (Exception ex) {
2022-04-04 18:42:22 +02:00
return pString;
}
}
2021-01-18 11:07:12 +01:00
public static int getResId(String resName, Class<?> c) {
try {
Field idField = c.getDeclaredField(resName);
return idField.getInt(idField);
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
2021-06-03 16:44:08 +02:00
public static boolean isAppRunning(final Context context, final String packageName) {
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
2022-05-02 18:26:09 +02:00
if (procInfos != null) {
2021-06-03 16:44:08 +02:00
for (final ActivityManager.RunningAppProcessInfo processInfo : procInfos) {
if (processInfo.processName.equals(packageName)) {
return true;
}
}
}
return false;
}
2021-05-14 14:43:40 +02:00
public static void onDelayHandler(AppCompatActivity pActivity, int pTime, Callable<Void> pMethodParam) {
final Handler handler = new Handler();
handler.postDelayed(() ->
{
try {
pMethodParam.call();
} catch (Exception e) {
e.printStackTrace();
}
}, pTime);
}
2022-05-02 18:26:09 +02:00
public static void writeToFile(String pFilePath, String content) {
2022-04-02 01:13:29 +02:00
Writer writer;
try {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(pFilePath), StandardCharsets.UTF_8));
writer.write(content);
writer.close();
} catch (Exception ex) {
}
}
2022-05-02 18:26:09 +02:00
public static String readFromFile(String pFilePath) {
2022-04-02 01:13:29 +02:00
File file = new File(pFilePath);
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
return text.toString();
2022-05-02 18:26:09 +02:00
} catch (IOException e) {
2022-04-02 01:13:29 +02:00
return "";
}
}
2022-04-03 14:15:23 +02:00
public static boolean availablePort(int port) {
ServerSocket ss = null;
DatagramSocket ds = null;
try {
ss = new ServerSocket(port);
ss.setReuseAddress(true);
ds = new DatagramSocket(port);
ds.setReuseAddress(true);
return true;
} catch (IOException e) {
} finally {
if (ds != null) {
ds.close();
}
if (ss != null) {
try {
ss.close();
} catch (IOException e) {
/* should not be thrown */
}
}
}
return false;
}
2022-05-02 18:26:09 +02:00
public static String completeURL(String pURL) {
if (pURL.equals("about:blank") || pURL.equals("about:config") || pURL.startsWith("resource://")) {
2020-11-11 13:11:13 +01:00
return pURL;
}
2020-12-11 08:05:08 +01:00
URL weburl;
2022-05-02 18:26:09 +02:00
try {
2020-11-11 13:11:13 +01:00
weburl = new URL(pURL);
2020-01-24 16:23:31 +01:00
URLConnection result = weburl.openConnection();
if (result instanceof HttpsURLConnection) {
}
2022-05-02 18:26:09 +02:00
} catch (IOException e) {
2020-01-24 16:23:31 +01:00
e.printStackTrace();
}
2022-05-02 18:26:09 +02:00
if (!pURL.startsWith("www.") && !pURL.startsWith("http://") && !pURL.startsWith("https://")) {
pURL = "" + pURL;
2020-01-24 16:23:31 +01:00
}
2022-05-02 18:26:09 +02:00
if (!pURL.startsWith("http://") && !pURL.startsWith("https://")) {
if (pURL.startsWith("www")) {
pURL = "http://" + pURL;
} else {
pURL = "http://" + pURL;
2021-01-18 11:07:12 +01:00
}
2022-05-02 18:26:09 +02:00
} else {
if (pURL.startsWith("https://")) {
2022-02-16 13:40:39 +01:00
return pURL;
}
2022-05-02 18:26:09 +02:00
pURL = pURL.replace("https://", "").replace("http://", "");
if (pURL.startsWith("www")) {
pURL = "http://" + pURL;
} else {
pURL = "http://" + pURL;
2021-01-18 11:07:12 +01:00
}
2020-01-24 16:23:31 +01:00
}
2020-11-11 13:11:13 +01:00
return pURL;
2020-01-24 16:23:31 +01:00
}
2022-05-02 18:26:09 +02:00
public static String createRandomID() {
2020-12-11 08:05:08 +01:00
return UUID.randomUUID().toString();
}
2022-05-02 18:26:09 +02:00
public static int createUniqueNotificationID() {
2021-03-06 19:55:24 +01:00
Date now = new Date();
2022-05-02 18:26:09 +02:00
int id = Integer.parseInt(new SimpleDateFormat("ddHHmmss", Locale.US).format(now));
2021-03-06 19:55:24 +01:00
return id;
}
2020-12-11 08:05:08 +01:00
public static int getScreenHeight(AppCompatActivity context) {
Display display = context.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getRealSize(size);
return size.y;
}
2021-02-07 18:40:35 +01:00
public static int getScreenWidth(AppCompatActivity context) {
Display display = context.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getRealSize(size);
return size.x;
}
2023-02-04 10:46:32 +01:00
public static SpannableString urlDesigner(boolean protocol, String url, Context pContext, int pDefColor, int pTheme, boolean sTorBrowsing) {
2021-01-18 11:07:12 +01:00
2023-02-12 15:31:17 +01:00
int mColor;
2022-05-02 18:26:09 +02:00
if (pTheme == enums.Theme.THEME_DARK) {
2021-01-18 11:07:12 +01:00
mColor = Color.argb(255, 0, 204, 71);
2022-05-02 18:26:09 +02:00
} else {
2021-01-18 11:07:12 +01:00
mColor = Color.argb(255, 0, 153, 54);
}
2023-02-12 15:31:17 +01:00
if(url.equals("about:blank")){
SpannableString span = new SpannableString(url);
span.setSpan(new ForegroundColorSpan(Color.BLACK), getHost(url).length()+7, url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return span;
}
2020-01-24 16:23:31 +01:00
2023-02-04 10:46:32 +01:00
if (url.startsWith("https://") || url.startsWith("http://")) {
if(url.startsWith("https://")){
2023-02-12 15:31:17 +01:00
SpannableString span = new SpannableString(url);
span.setSpan(new ForegroundColorSpan(mColor), 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new ForegroundColorSpan(Color.GRAY), 5, 8, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
2023-02-04 10:46:32 +01:00
if(pTheme != enums.Theme.THEME_DARK){
2023-02-12 15:31:17 +01:00
span.setSpan(new ForegroundColorSpan(Color.BLACK), getHost(url).length()+8, url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
2023-02-04 10:46:32 +01:00
}else {
2023-02-12 15:31:17 +01:00
span.setSpan(new ForegroundColorSpan(Color.WHITE), getHost(url).length()+8, url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
2023-02-04 10:46:32 +01:00
}
2023-02-12 15:31:17 +01:00
return span;
2023-01-25 08:13:53 +01:00
}else {
2023-02-12 15:31:17 +01:00
SpannableString span = new SpannableString(url);
2023-02-04 10:46:32 +01:00
if(sTorBrowsing){
2023-02-12 15:31:17 +01:00
span.setSpan(new ForegroundColorSpan(mColor), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
2023-02-04 10:46:32 +01:00
}else {
2023-02-12 15:31:17 +01:00
span.setSpan(new ForegroundColorSpan(Color.RED), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
2023-02-04 10:46:32 +01:00
}
2023-02-12 15:31:17 +01:00
span.setSpan(new ForegroundColorSpan(Color.GRAY), 4, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new ForegroundColorSpan(Color.BLACK), getHost(url).length()+7, url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
2023-02-04 10:46:32 +01:00
if(pTheme != enums.Theme.THEME_DARK){
2023-02-12 15:31:17 +01:00
span.setSpan(new ForegroundColorSpan(Color.BLACK), getHost(url).length()+7, url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
2023-02-04 10:46:32 +01:00
}else {
2023-02-12 15:31:17 +01:00
span.setSpan(new ForegroundColorSpan(Color.WHITE), getHost(url).length()+7, url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
2023-02-04 10:46:32 +01:00
}
2023-02-12 15:31:17 +01:00
return span;
2023-01-25 08:13:53 +01:00
}
2022-05-02 18:26:09 +02:00
} else {
2020-01-24 16:23:31 +01:00
SpannableString ss = new SpannableString(url);
2023-02-04 10:46:32 +01:00
if(pTheme != enums.Theme.THEME_DARK){
ss.setSpan(new ForegroundColorSpan(Color.LTGRAY), getHost("http://"+url).length(), url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}else {
ss.setSpan(new ForegroundColorSpan(Color.GRAY), getHost("http://"+url).length(), url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
2020-01-24 16:23:31 +01:00
return ss;
}
}
2022-05-02 18:26:09 +02:00
public static void sendIssueEmail(Context context) {
2021-01-18 11:07:12 +01:00
Intent selectorIntent = new Intent(Intent.ACTION_SENDTO);
selectorIntent.setData(Uri.parse("mailto:"));
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
2022-04-24 18:29:32 +02:00
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"orionhiddentechnologies@gmail.com"});
2021-01-18 11:07:12 +01:00
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Issue Report");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Write Message Here....");
2022-05-02 18:26:09 +02:00
emailIntent.setSelector(selectorIntent);
2021-01-18 11:07:12 +01:00
context.startActivity(Intent.createChooser(emailIntent, "Send email..."));
2020-01-24 16:23:31 +01:00
}
2022-05-02 18:26:09 +02:00
public static void sendCustomMail(Context context, String pURL) {
2021-02-25 15:26:43 +01:00
String mail = pURL.replaceFirst("mailto:", "");
Intent selectorIntent = new Intent(Intent.ACTION_SENDTO);
selectorIntent.setData(Uri.parse("mailto:"));
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{mail});
2021-04-05 21:07:02 +02:00
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "get transport obfs4");
emailIntent.putExtra(Intent.EXTRA_TEXT, "get transport obfs4");
2022-05-02 18:26:09 +02:00
emailIntent.setSelector(selectorIntent);
2021-04-05 21:07:02 +02:00
context.startActivity(Intent.createChooser(emailIntent, "get transport obfs4"));
2021-02-25 15:26:43 +01:00
}
2022-05-02 18:26:09 +02:00
public static void sendBridgeEmail(Context context) {
2021-02-03 11:54:19 +01:00
Intent selectorIntent = new Intent(Intent.ACTION_SENDTO);
selectorIntent.setData(Uri.parse("mailto:"));
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"bridges@torproject.org"});
2021-04-05 21:07:02 +02:00
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "get transport obfs4");
emailIntent.putExtra(Intent.EXTRA_TEXT, "get transport obfs4");
2022-05-02 18:26:09 +02:00
emailIntent.setSelector(selectorIntent);
2021-04-05 21:07:02 +02:00
context.startActivity(Intent.createChooser(emailIntent, "get transport obfs4"));
2021-02-03 11:54:19 +01:00
}
2021-04-05 21:07:02 +02:00
2021-04-26 23:25:23 +02:00
public static String getMimeType(Context context, Uri uri) {
String extension;
if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
final MimeTypeMap mime = MimeTypeMap.getSingleton();
extension = mime.getExtensionFromMimeType(context.getContentResolver().getType(uri));
} else {
extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString());
}
return extension;
}
2020-01-24 16:23:31 +01:00
public static void hideKeyboard(AppCompatActivity context) {
2022-05-02 18:26:09 +02:00
if (context != null) {
2021-06-29 08:42:33 +02:00
View view = context.findViewById(android.R.id.content);
2022-05-02 18:26:09 +02:00
if (view != null) {
2021-06-29 08:42:33 +02:00
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null;
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
2020-01-24 16:23:31 +01:00
}
}
public static void shareApp(AppCompatActivity context) {
ShareCompat.IntentBuilder.from(context)
.setType("text/plain")
.setChooserTitle("Hi! Check out this Awesome App")
.setSubject("Hi! Check out this Awesome App")
2022-04-24 14:29:45 +02:00
.setText("Orion | Onion Search | " + CONST_PLAYSTORE_URL)
2020-01-24 16:23:31 +01:00
.startChooser();
}
2021-01-18 11:07:12 +01:00
public static int invertedShadeColor(int pColor, float pPercent) {
int mColor = pColor;
2022-05-02 18:26:09 +02:00
if (ColorUtils.calculateLuminance(pColor) <= 0.5) {
if (ColorUtils.calculateLuminance(pColor) == 1) {
2021-01-18 11:07:12 +01:00
return Color.DKGRAY;
}
int a = Color.alpha(mColor);
int r = Math.round(Color.red(mColor) / pPercent);
int g = Math.round(Color.green(mColor) / pPercent);
int b = Math.round(Color.blue(mColor) / pPercent);
2022-05-02 18:26:09 +02:00
return Color.argb(a, Math.min(r, 255), Math.min(g, 255), Math.min(b, 255));
} else {
2021-01-18 11:07:12 +01:00
pPercent = pPercent + 0.05f;
int a = (pColor >> 24) & 0xFF;
int r = (int) (((pColor >> 16) & 0xFF) * pPercent);
int g = (int) (((pColor >> 8) & 0xFF) * pPercent);
int b = (int) ((pColor & 0xFF) * pPercent);
return (a << 24) | (r << 16) | (g << 8) | b;
}
}
public static int invertedGrayColor(int pColor) {
2022-05-02 18:26:09 +02:00
if (ColorUtils.calculateLuminance(pColor) <= 0.5) {
2021-01-18 11:07:12 +01:00
return Color.WHITE;
2022-05-02 18:26:09 +02:00
} else {
2021-01-18 11:07:12 +01:00
return Color.BLACK;
}
}
public static boolean isColorDark(int pColor) {
2022-05-02 18:26:09 +02:00
if (ColorUtils.calculateLuminance(pColor) > 0.5) {
2021-01-18 11:07:12 +01:00
return true;
2022-05-02 18:26:09 +02:00
} else {
2021-01-18 11:07:12 +01:00
return false;
}
}
2021-03-14 18:59:37 +01:00
public static double getColorDensity(int pColor) {
return ColorUtils.calculateLuminance(pColor);
}
2020-10-05 13:12:00 +02:00
public static void shareApp(AppCompatActivity context, String p_share, String p_title) {
ShareCompat.IntentBuilder.from(context)
.setType("text/plain")
.setChooserTitle("Hi! Check out this Awesome URL | " + p_title)
.setSubject("Hi! Check out this Awesome URL | " + p_title)
.setText("Website URL | " + p_share)
.startChooser();
}
public static void shareURL(AppCompatActivity context, String p_share) {
ShareCompat.IntentBuilder.from(context)
.setType("text/plain")
.setChooserTitle("Hi! Check out these Awesome URLS")
.setSubject("Hi! Check out these Awesome URL")
.setText("Website URL | " + p_share)
.startChooser();
}
2022-05-02 18:26:09 +02:00
public static void openDownloadFolder(AppCompatActivity context) {
2020-01-24 16:23:31 +01:00
Intent intent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
2022-05-02 18:26:09 +02:00
if (intent.resolveActivity(context.getPackageManager()) != null) {
2020-01-24 16:23:31 +01:00
context.startActivity(intent);
2022-05-02 18:26:09 +02:00
} else {
helperMethod.showToastMessage("Download Folder Not Found", context);
2020-01-24 16:23:31 +01:00
}
}
2022-02-14 18:57:59 +01:00
public static String normalize(String url) {
2022-05-02 18:26:09 +02:00
try {
2022-02-14 18:57:59 +01:00
String pathSeparator = "/";
2022-02-12 11:16:57 +01:00
2022-02-14 18:57:59 +01:00
URI uri = new URI(url);
uri = uri.normalize();
2022-02-12 11:16:57 +01:00
2022-02-14 18:57:59 +01:00
String path = uri.getPath();
2022-02-12 11:16:57 +01:00
2022-02-14 18:57:59 +01:00
if (!path.startsWith(pathSeparator)) {
path = pathSeparator + path;
}
2022-02-12 11:16:57 +01:00
2022-02-14 18:57:59 +01:00
if (path.endsWith(pathSeparator)) {
path = path.substring(0, path.length() - 1);
}
2022-02-12 11:16:57 +01:00
2022-02-14 18:57:59 +01:00
String urlStr = uri.getScheme() + "://" + uri.getHost();
int port = uri.getPort();
2022-02-12 11:16:57 +01:00
2022-02-14 18:57:59 +01:00
if (port != -1) {
urlStr = urlStr + ":" + port;
}
2022-02-12 11:16:57 +01:00
2022-02-14 18:57:59 +01:00
urlStr = urlStr + path;
2022-02-12 11:16:57 +01:00
2022-02-14 18:57:59 +01:00
return urlStr;
2022-05-02 18:26:09 +02:00
} catch (Exception ex) {
2022-02-14 18:57:59 +01:00
return null;
}
2022-02-12 11:16:57 +01:00
}
2022-05-02 18:26:09 +02:00
static public String getHost(String link) {
2020-01-24 16:23:31 +01:00
URL url;
2022-05-02 18:26:09 +02:00
try {
2020-01-24 16:23:31 +01:00
url = new URL(link);
return url.getHost();
2022-05-02 18:26:09 +02:00
} catch (MalformedURLException e) {
2020-01-24 16:23:31 +01:00
e.printStackTrace();
return "";
}
}
2021-01-28 11:22:41 +01:00
public static String langaugeWithoutTranslation(String pLangauge) {
switch (pLangauge) {
case "en_US":
return "English (United States)";
case "de_DE":
return "German (Deutsche)";
case "ca_ES":
return "Catalan (Català)";
case "zh_CN":
return "Chinese (中文-中国)";
case "ch_CZ":
return "Czech čeština";
case "nl_NL":
return "Dutch Netherland";
case "fr_FR":
return "French francaise";
case "el_GR":
return "Greek (Ελληνικά)";
case "hu_HU":
return "Hungarian Magyar";
case "in_ID":
return "Indonesian bahasa";
case "it_IT":
return "Italian Italiana";
case "ja_JP":
return "Japanese (日本人)";
case "ko_KR":
return "Korean (韓国語)";
case "pt_PT":
return "Portuguese Português";
case "ro_RO":
return "Romanian Română";
case "ru_RU":
return "Russian (русский)";
case "th_TH":
return "Thai (ไทย)";
case "tr_TR":
return "Turkish Türk";
case "uk_UA":
return "Ukrainian (Український)";
case "vi_VN":
return "Vietnamese Tiếng Việt";
}
return "Not Defined";
}
2022-05-02 18:26:09 +02:00
public static Boolean isValidURL(String url) {
2021-03-14 18:59:37 +01:00
Pattern p = Pattern.compile("((http|https)://)(www.)?[a-zA-Z0-9@:%._\\+~#?&//=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%._\\+~#?&//=]*)");
Matcher m;
2022-05-02 18:26:09 +02:00
m = p.matcher(url);
2021-03-14 18:59:37 +01:00
return m.matches();
}
2021-01-28 11:22:41 +01:00
2022-05-02 18:26:09 +02:00
public static String removeLastSlash(String url) {
if (url.length() > 2) {
if (url.charAt(url.length() - 1) == '/') {
return url.substring(0, url.length() - 1);
2020-02-28 19:10:00 +01:00
}
}
return url;
}
2022-05-02 18:26:09 +02:00
public static String urlWithoutPrefix(String url) {
try {
url = url.substring(url.indexOf(getHost(url))).replace("www.", "").replace("m.", "");
2020-02-28 19:10:00 +01:00
return url;
2022-05-02 18:26:09 +02:00
} catch (Exception ex) {
2020-02-28 19:10:00 +01:00
return url;
}
}
2021-04-11 21:25:15 +02:00
public static Point getNavigationBarSize(Context context) {
Point appUsableSize = getAppUsableScreenSize(context);
Point realScreenSize = getRealScreenSize(context);
// navigation bar on the side
if (appUsableSize.x < realScreenSize.x) {
return new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y);
}
// navigation bar at the bottom
if (appUsableSize.y < realScreenSize.y) {
return new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y);
}
// navigation bar is not present
return new Point();
}
public static Point getAppUsableScreenSize(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
return size;
}
public static Point getRealScreenSize(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size = new Point();
display.getRealSize(size);
return size;
}
2022-05-02 18:26:09 +02:00
public static void openDefaultBrowser(AppCompatActivity mContext) {
2021-06-08 10:40:27 +02:00
defaultBrowser mIconManager = new defaultBrowser();
mIconManager.openSetDefaultBrowserOption(mContext);
}
2022-05-02 18:26:09 +02:00
public static boolean isDefaultBrowserSet(AppCompatActivity mContext) {
2021-06-08 10:40:27 +02:00
defaultBrowser mIconManager = new defaultBrowser();
return mIconManager.getabcEnabledValue(mContext);
}
public static void updateResources(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
configuration.locale = locale;
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
}
2022-05-02 18:26:09 +02:00
public static void openActivity(Class<?> cls, int type, AppCompatActivity context, boolean animation) {
2020-01-24 16:23:31 +01:00
Intent myIntent = new Intent(context, cls);
2020-10-20 16:55:08 +02:00
myIntent.putExtra(keys.PROXY_LIST_TYPE, type);
2022-05-02 18:26:09 +02:00
if (!animation) {
2020-01-24 16:23:31 +01:00
myIntent.addFlags(FLAG_ACTIVITY_NO_ANIMATION);
}
context.startActivity(myIntent);
}
2022-05-02 18:26:09 +02:00
public static void openIntent(Intent pIntent, AppCompatActivity pContext, int pType) {
if (pType == CONST_LIST_EXTERNAL_SHORTCUT) {
2021-08-01 11:47:13 +02:00
pIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
pIntent.putExtra(M_ACTIVITY_NAVIGATION_BUNDLE_KEY, pType);
pContext.startActivity(pIntent);
pContext.overridePendingTransition(R.anim.fade_in_lang, R.anim.fade_out_lang);
}
}
2022-05-02 18:26:09 +02:00
public static void restartActivity(Intent pIntent, AppCompatActivity pContext) {
2020-11-11 13:11:13 +01:00
pContext.finish();
pContext.startActivity(pIntent);
}
2022-05-02 18:26:09 +02:00
public static void onMinimizeApp(AppCompatActivity context) {
2020-01-24 16:23:31 +01:00
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startMain);
}
2022-05-02 18:26:09 +02:00
public static int screenWidth() {
2020-01-24 16:23:31 +01:00
return (Resources.getSystem().getDisplayMetrics().widthPixels);
}
2022-05-02 18:26:09 +02:00
public static void openNotification(AppCompatActivity pContext) {
2020-11-11 13:11:13 +01:00
Intent intent = new Intent();
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
intent.putExtra("android.provider.extra.APP_PACKAGE", pContext.getPackageName());
pContext.startActivity(intent);
}
2022-05-02 18:26:09 +02:00
public static boolean isDayMode(AppCompatActivity pContext) {
if (pContext.getResources().getString(R.string.mode).equals("Day")) {
2021-03-14 18:59:37 +01:00
return true;
2022-05-02 18:26:09 +02:00
} else {
2021-03-14 18:59:37 +01:00
return false;
}
}
2022-05-02 18:26:09 +02:00
public static String getDomainName(String url) {
try {
2020-01-24 16:23:31 +01:00
URI uri = new URI(url);
String domain = uri.getHost();
return domain.startsWith("www.") ? domain.substring(4) : domain;
2022-05-02 18:26:09 +02:00
} catch (Exception ex) {
2020-01-24 16:23:31 +01:00
return url;
}
}
2022-05-02 18:26:09 +02:00
public static void openPlayStore(String packageName, AppCompatActivity context) {
2020-01-24 16:23:31 +01:00
Intent intent = new Intent(Intent.ACTION_VIEW);
2022-05-02 18:26:09 +02:00
intent.setData(Uri.parse("market://details?id=" + packageName));
2020-01-24 16:23:31 +01:00
2022-05-02 18:26:09 +02:00
if (intent.resolveActivity(context.getPackageManager()) != null) {
2020-01-24 16:23:31 +01:00
context.startActivity(intent);
2022-05-02 18:26:09 +02:00
} else {
helperMethod.showToastMessage("Playstore Not Found", context);
2020-01-24 16:23:31 +01:00
}
}
public static int dpFromPx(final Context context, final float px) {
2022-05-02 18:26:09 +02:00
return (int) (px / context.getResources().getDisplayMetrics().density);
2020-01-24 16:23:31 +01:00
}
2022-05-02 18:26:09 +02:00
public static int pxFromDp(float dp) {
return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
2020-01-24 16:23:31 +01:00
}
2021-04-05 21:07:02 +02:00
public static void setImageDrawableWithAnimation(ImageView imageView, Drawable drawable, int duration) {
Drawable currentDrawable = imageView.getDrawable();
if (currentDrawable == null) {
imageView.setImageDrawable(drawable);
return;
}
2022-05-02 18:26:09 +02:00
TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[]{
2021-04-05 21:07:02 +02:00
currentDrawable,
drawable
});
imageView.setImageDrawable(transitionDrawable);
transitionDrawable.startTransition(duration);
}
2021-04-24 23:26:22 +02:00
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());
2021-03-09 07:36:59 +01:00
}
2021-04-24 23:26:22 +02:00
return mimeType;
2021-03-09 07:36:59 +01:00
}
2021-03-06 19:55:24 +01:00
public static void openFile(File url, Context context) {
2022-05-02 18:26:09 +02:00
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
2021-05-05 15:37:08 +02:00
try {
2022-04-02 01:13:29 +02:00
Uri uri = FileProvider.getUriForFile(context, "com.hiddenservices.onionservices.provider", url);
2022-05-02 18:26:09 +02:00
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString()));
2021-05-05 15:37:08 +02:00
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(uri, Uri.parse(url.toString()).getScheme());
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
2021-08-19 22:17:54 +02:00
pluginController.getInstance().onMessageManagerInvoke(Collections.singletonList(context), M_OPEN_ACTIVITY_FAILED);
2021-05-05 15:37:08 +02:00
}
2022-05-02 18:26:09 +02:00
} else {
2021-04-24 23:26:22 +02:00
try {
2022-04-02 01:13:29 +02:00
Uri uri = FileProvider.getUriForFile(context, "com.hiddenservices.onionservices.provider", url);
2022-05-02 18:26:09 +02:00
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString()));
2021-04-24 23:26:22 +02:00
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2022-05-02 18:26:09 +02:00
intent.setDataAndType(Uri.fromFile(url), getMimeType(uri.toString(), context));
2021-04-24 23:26:22 +02:00
context.startActivity(intent);
} catch (ActivityNotFoundException ex) {
2021-08-19 22:17:54 +02:00
pluginController.getInstance().onMessageManagerInvoke(Collections.singletonList(context), M_OPEN_ACTIVITY_FAILED);
2021-04-24 23:26:22 +02:00
}
2021-03-06 19:55:24 +01:00
}
}
2022-05-02 18:26:09 +02:00
public static void copyURL(String url, Context context) {
2020-02-28 19:10:00 +01:00
2020-01-24 16:23:31 +01:00
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("link", url);
clipboard.setPrimaryClip(clip);
}
2022-05-02 18:26:09 +02:00
public static void showToastMessage(String message, Context context) {
if (context != null) {
2023-01-25 08:13:53 +01:00
Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
2022-05-02 18:26:09 +02:00
toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0);
2021-06-29 08:42:33 +02:00
toast.show();
}
2020-01-24 16:23:31 +01:00
}
public static boolean checkPermissions(AppCompatActivity context) {
2023-01-04 09:50:41 +01:00
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.O_MR1){
return true;
}
2020-01-24 16:23:31 +01:00
String[] permissions = new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE,
2023-01-04 09:50:41 +01:00
Manifest.permission.READ_EXTERNAL_STORAGE
2020-01-24 16:23:31 +01:00
};
int result;
List<String> listPermissionsNeeded = new ArrayList<>();
for (String p : permissions) {
result = ContextCompat.checkSelfPermission(context, p);
if (result != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(p);
}
}
if (!listPermissionsNeeded.isEmpty()) {
2023-01-04 09:50:41 +01:00
ActivityCompat.requestPermissions(context, listPermissionsNeeded.toArray(new String[0]), 1050);
2020-01-24 16:23:31 +01:00
return false;
}
return true;
}
2022-05-02 18:26:09 +02:00
public static String getCurrentDate() {
2020-12-11 08:05:08 +01:00
@SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
2020-11-27 12:40:46 +01:00
Date date = new Date();
sdf.applyPattern("E | MMM dd,yyyy");
return sdf.format(date);
}
2022-05-02 18:26:09 +02:00
public static Drawable getDrawableXML(Context pContext, int pSrc) {
2021-08-19 22:17:54 +02:00
try {
Drawable mDrawable;
Resources res = pContext.getResources();
mDrawable = Drawable.createFromXml(res, res.getXml(pSrc));
return mDrawable;
2022-05-02 18:26:09 +02:00
} catch (Exception ex) {
2021-08-19 22:17:54 +02:00
return null;
}
2021-03-09 07:36:59 +01:00
}
2021-03-23 12:52:22 +01:00
2022-05-02 18:26:09 +02:00
public static String getCurrentTime() {
2020-11-27 12:40:46 +01:00
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH) + 1; // Note: zero based!
int day = now.get(Calendar.DAY_OF_MONTH);
int hour = now.get(Calendar.HOUR_OF_DAY);
int minute = now.get(Calendar.MINUTE);
int second = now.get(Calendar.SECOND);
int millis = now.get(Calendar.MILLISECOND);
System.out.printf("%d-%02d-%02d %02d:%02d:%02d.%03d", year, month, day, hour, minute, second, millis);
2023-02-19 11:32:46 +01:00
return day + "/" + month + "/" + year + " | " + hour + ":" + minute + ":" + second;
2020-11-27 12:40:46 +01:00
}
2021-05-24 17:06:43 +02:00
public static PopupWindow onCreateMenu(View p_view, int p_layout, String pSettingLanguageRegion) {
2020-12-11 08:05:08 +01:00
PopupWindow popupWindow;
2020-10-20 16:55:08 +02:00
LayoutInflater layoutInflater
= (LayoutInflater) p_view.getContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
@SuppressLint("InflateParams") final View popupView = layoutInflater.inflate(p_layout, null);
popupWindow = new PopupWindow(
popupView,
ActionMenuView.LayoutParams.WRAP_CONTENT,
ActionMenuView.LayoutParams.WRAP_CONTENT, true);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
popupWindow.setAnimationStyle(R.style.popup_window_animation);
2021-02-15 21:26:33 +01:00
2022-05-02 18:26:09 +02:00
if (pSettingLanguageRegion.equals("Ur")) {
popupWindow.showAtLocation(p_view, Gravity.TOP | Gravity.START, 0, 0);
} else {
popupWindow.showAtLocation(p_view, Gravity.TOP | Gravity.END, 0, 0);
2021-02-15 21:26:33 +01:00
}
2020-10-20 16:55:08 +02:00
popupWindow.setElevation(7);
return popupWindow;
}
2022-04-23 23:14:37 +02:00
public static void restart(boolean pOpenOnRestart, Context pContext) {
ActivityManager manager = (ActivityManager) pContext.getSystemService(Context.ACTIVITY_SERVICE);
2022-04-18 21:00:09 +02:00
List<ActivityManager.RunningAppProcessInfo> runningProcesses = manager
.getRunningAppProcesses();
if (runningProcesses != null) {
for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
if (!BuildConfig.APPLICATION_ID.equalsIgnoreCase(processInfo.processName)) {
android.os.Process.killProcess(processInfo.pid);
}
}
}
2022-04-23 23:14:37 +02:00
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
super.run();
PackageManager packageManager = pContext.getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(pContext.getPackageName());
ComponentName componentName = intent.getComponent();
Intent mainIntent = Intent.makeRestartActivityTask(componentName);
mainIntent.putExtra(M_RESTART_APP_KEY, pOpenOnRestart);
2023-01-25 08:13:53 +01:00
pContext.startActivity(mainIntent);
2022-04-23 23:14:37 +02:00
}
});
Runtime.getRuntime().exit(0);
System.exit(1);
}
public static void restartAndOpen(boolean pOpenOnRestart) {
ActivityManager manager = (ActivityManager) activityContextManager.getInstance().getHomeController().getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningProcesses = manager.getRunningAppProcesses();
if (runningProcesses != null) {
for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
if (!BuildConfig.APPLICATION_ID.equalsIgnoreCase(processInfo.processName)) {
android.os.Process.killProcess(processInfo.pid);
}
}
}
2022-04-18 21:00:09 +02:00
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
super.run();
PackageManager packageManager = activityContextManager.getInstance().getHomeController().getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(activityContextManager.getInstance().getHomeController().getPackageName());
ComponentName componentName = intent.getComponent();
Intent mainIntent = Intent.makeRestartActivityTask(componentName);
mainIntent.putExtra(M_RESTART_APP_KEY, pOpenOnRestart);
2023-01-25 08:13:53 +01:00
activityContextManager.getInstance().getHomeController().startActivity(mainIntent);
2022-04-23 06:04:52 +02:00
activityContextManager.getInstance().getHomeController().overridePendingTransition(R.anim.popup_scale_in, R.anim.popup_scale_out);
2022-04-18 21:00:09 +02:00
}
});
2023-01-01 12:53:56 +01:00
2022-04-18 21:00:09 +02:00
Runtime.getRuntime().exit(0);
2022-04-23 23:14:37 +02:00
System.exit(1);
2022-04-18 21:00:09 +02:00
}
2020-01-24 16:23:31 +01:00
}