aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationActivity.java52
-rw-r--r--src/main/java/de/pixart/messenger/ui/XmppActivity.java1
2 files changed, 53 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
index 8904aedd6..81611343a 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
@@ -1422,6 +1422,9 @@ public class ConversationActivity extends XmppActivity
if (!ExceptionHelper.checkForCrash(this, this.xmppConnectionService) && !mRedirected.get()) {
openBatteryOptimizationDialogIfNeeded();
}
+ if (!installedFromFDroid()) {
+ openInstallFromUnknownSourcesDialogIfNeeded();
+ }
if (isConversationsOverviewVisable() && isConversationsOverviewHideable()) {
xmppConnectionService.getNotificationService().setOpenConversation(null);
} else {
@@ -1689,6 +1692,55 @@ public class ConversationActivity extends XmppActivity
}
}
+ private void openInstallFromUnknownSourcesDialogIfNeeded() {
+ final PackageManager packageManager = this.getPackageManager();
+ boolean installFromUnknownSource = false;
+ int isUnknownAllowed = 0;
+ if (Build.VERSION.SDK_INT >= 26) {
+ installFromUnknownSource = packageManager.canRequestPackageInstalls();
+ } else if (Build.VERSION.SDK_INT >= 17) {
+ try {
+ isUnknownAllowed = Settings.Global.getInt(this.getApplicationContext().getContentResolver(), Settings.Global.INSTALL_NON_MARKET_APPS);
+ } catch (Settings.SettingNotFoundException e) {
+ isUnknownAllowed = 0;
+ e.printStackTrace();
+ }
+ installFromUnknownSource = isUnknownAllowed == 1;
+ } else {
+ try {
+ isUnknownAllowed = Settings.Secure.getInt(this.getApplicationContext().getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS);
+ } catch (Settings.SettingNotFoundException e) {
+ isUnknownAllowed = 0;
+ e.printStackTrace();
+ }
+ installFromUnknownSource = isUnknownAllowed == 1;
+ }
+ Log.d(Config.LOGTAG, "Install from unknown sources for Android SDK " + Build.VERSION.SDK_INT + " allowd: " + installFromUnknownSource);
+
+ if (!installFromUnknownSource) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.install_from_unknown_sources_disabled);
+ builder.setMessage(R.string.install_from_unknown_sources_disabled_dialog);
+ builder.setPositiveButton(R.string.next, (dialog, which) -> {
+ Intent intent = null;
+ if (android.os.Build.VERSION.SDK_INT >= 26) {
+ intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
+ Uri uri = Uri.parse("package:" + getPackageName());
+ intent.setData(uri);
+ } else {
+ intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
+ }
+ Log.d(Config.LOGTAG, "Allow install from unknown sources for Android SDK " + Build.VERSION.SDK_INT + " intent " + intent.toString());
+ try {
+ startActivityForResult(intent, REQUEST_UNKNOWN_SOURCE_OP);
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(ConversationActivity.this, R.string.device_does_not_support_battery_op, Toast.LENGTH_SHORT).show();
+ }
+ });
+ builder.create().show();
+ }
+ }
+
private boolean hasAccountWithoutPush() {
for (Account account : xmppConnectionService.getAccounts()) {
if (account.getStatus() == Account.State.ONLINE && !xmppConnectionService.getPushManagementService().available(account)) {
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
index 7aca6a708..e14efd734 100644
--- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
@@ -88,6 +88,7 @@ public abstract class XmppActivity extends Activity {
protected static final int REQUEST_INVITE_TO_CONVERSATION = 0x0102;
protected static final int REQUEST_CHOOSE_PGP_ID = 0x0103;
protected static final int REQUEST_BATTERY_OP = 0x13849ff;
+ protected static final int REQUEST_UNKNOWN_SOURCE_OP = 0x14958ff;
public static final String EXTRA_ACCOUNT = "account";