diff options
Diffstat (limited to '')
-rw-r--r-- | src/main/AndroidManifest.xml | 1 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ConversationActivity.java | 52 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/XmppActivity.java | 1 | ||||
-rw-r--r-- | src/main/res/values/strings.xml | 4 |
4 files changed, 58 insertions, 0 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index d4d0d91b7..b05b31976 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -18,6 +18,7 @@ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="com.android.alarm.permission.SET_ALARM" /> + <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" /> 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"; diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 04c94db8b..930625abb 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -541,6 +541,9 @@ <string name="battery_optimizations_enabled">Battery optimizations enabled</string> <string name="battery_optimizations_enabled_explained">Your device is doing some heavy battery optimizations on Pix-Art Messenger that might lead to delayed notifications or even message loss.\nIt is recommended to disable those.</string> <string name="battery_optimizations_enabled_dialog">Your device is doing some heavy battery optimizations on Pix-Art Messenger that might lead to delayed notifications or even message loss.\n\nYou will now be asked to disable those.</string> + <string name="install_from_unknown_sources_disabled">Install from unknown sources disabled</string> + <string name="install_from_unknown_sources_disabled_explained">Your device is configured to not allow app installs from unknown sources, which causes problems with the in app updater.\nIt is recommended to allow installs from unknown sources.</string> + <string name="install_from_unknown_sources_disabled_dialog">Your device is configured to not allow app installs from unknown sources except from Google PlayStore. This will cause problems with the in app updater.\n\nYou will now be asked to allow app installs from unknown sources.</string> <string name="disable">Disable</string> <string name="selection_too_large">The selected area is too large</string> <string name="cancel_update">Cancel update?</string> @@ -577,6 +580,7 @@ <string name="presence_dnd">Busy</string> <string name="secure_password_generated">A secure password has been generated</string> <string name="device_does_not_support_battery_op">Your device does not support opting out of battery optimization</string> + <string name="device_does_not_support_unknown_source_op">Your device does not support allowing app installs from unknown source</string> <string name="share">Share</string> <string name="share_location">Share location</string> <string name="location_sharing_disabled">Location sharing is disabled in settings</string> |