diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-08-03 23:00:06 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-08-03 23:00:06 +0200 |
commit | 71aa88f3702aa293b35832956f9d38481deff47c (patch) | |
tree | ef775b2d66fc1a92c08c89bb63b40d88f8e077f2 /src/main/java | |
parent | 316b0203f8b68242ccd19bbf4f31e776fad5875a (diff) |
some changes in Updater
Diffstat (limited to '')
4 files changed, 43 insertions, 29 deletions
diff --git a/src/main/java/de/pixart/messenger/services/UpdateService.java b/src/main/java/de/pixart/messenger/services/UpdateService.java index 7e636b8e6..3b3829290 100644 --- a/src/main/java/de/pixart/messenger/services/UpdateService.java +++ b/src/main/java/de/pixart/messenger/services/UpdateService.java @@ -32,13 +32,13 @@ import static de.pixart.messenger.services.NotificationService.UPDATE_NOTIFICATI public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapper> { private boolean mUseTor; private Context context; - private boolean playstore; + private String store; public UpdateService() { } - public UpdateService(Context context, boolean PlayStore, XmppConnectionService mXmppConnectionService) { + public UpdateService(Context context, String Store, XmppConnectionService mXmppConnectionService) { this.context = context; - this.playstore = PlayStore; + this.store = Store; this.mUseTor = mXmppConnectionService.useTorToConnect(); } @@ -94,7 +94,7 @@ public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapp if (checkVersion(version, ownVersion) >= 1) { Log.d(Config.LOGTAG, "AppUpdater: Version " + ownVersion + " should be updated to " + version); UpdateAvailable = true; - showNotification(url, changelog, version, filesize, playstore); + showNotification(url, changelog, version, filesize, store); } else { Log.d(Config.LOGTAG, "AppUpdater: Version " + ownVersion + " is up to date"); UpdateAvailable = false; @@ -138,12 +138,12 @@ public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapp }); } - private void showNotification(String url, String changelog, String version, String filesize, boolean playstore) { + private void showNotification(String url, String changelog, String version, String filesize, String store) { Intent intent = new Intent(context, UpdaterActivity.class); intent.putExtra("update", "PixArtMessenger_UpdateService"); intent.putExtra("url", url); intent.putExtra("changelog", changelog); - intent.putExtra("playstore", playstore); + intent.putExtra("store", store); PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 068384a60..e50f0d9e2 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -169,6 +169,9 @@ public class XmppConnectionService extends Service { public static final String ACTION_FCM_MESSAGE_RECEIVED = "fcm_message_received"; private static final String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts"; private static final String SETTING_LAST_ACTIVITY_TS = "last_activity_timestamp"; + public static final String FDroid = "org.fdroid.fdroid"; + public static final String PlayStore = "com.android.vending"; + public static final String Yalp = "com.github.yeriomin.yalpstore"; static { URL.setURLStreamHandlerFactory(new CustomURLStreamHandlerFactory()); @@ -4307,20 +4310,16 @@ public class XmppConnectionService extends Service { } } - public boolean installedFromFDroid() { + public String installedFrom() { final PackageManager packageManager = this.getPackageManager(); final String packageID = BuildConfig.APPLICATION_ID; final String installedFrom = packageManager.getInstallerPackageName(packageID); Log.d(Config.LOGTAG, "Messenger installed from " + installedFrom); - return installedFrom != null && installedFrom.contains("org.fdroid.fdroid"); - } - - public boolean installedFromPlayStore() { - final PackageManager packageManager = this.getPackageManager(); - final String packageID = BuildConfig.APPLICATION_ID; - final String installedFrom = packageManager.getInstallerPackageName(packageID); - Log.d(Config.LOGTAG, "Messenger installed from " + installedFrom); - return installedFrom != null && (installedFrom.contains("com.android.vending") || installedFrom.contains("com.github.yeriomin.yalpstore")); + if (installedFrom != null) { + return installedFrom; + } else { + return null; + } } public ShortcutService getShortcutService() { diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java index 67618dc65..f2e4dc2b6 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java @@ -93,6 +93,7 @@ import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xmpp.OnUpdateBlocklist; import de.pixart.messenger.xmpp.chatstate.ChatState; +import static de.pixart.messenger.services.XmppConnectionService.PlayStore; import static de.pixart.messenger.ui.ConversationFragment.REQUEST_DECRYPT_PGP; import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS; @@ -193,9 +194,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio if (xmppConnectionService.getAccounts().size() != 0) { if (xmppConnectionService.hasInternetConnection()) { if (xmppConnectionService.isWIFI() || (xmppConnectionService.isMobile() && !xmppConnectionService.isMobileRoaming())) { - if (!xmppConnectionService.installedFromFDroid()) { - AppUpdate(xmppConnectionService.installedFromPlayStore()); - } + AppUpdate(xmppConnectionService.installedFrom()); } } } @@ -559,10 +558,10 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio return true; case R.id.action_check_updates: if (xmppConnectionService.hasInternetConnection()) { - if (!installFromUnknownSourceAllowed() && !xmppConnectionService.installedFromPlayStore()) { + if (!installFromUnknownSourceAllowed() && !xmppConnectionService.installedFrom().equals(PlayStore)) { openInstallFromUnknownSourcesDialogIfNeeded(); } else { - UpdateService task = new UpdateService(this, xmppConnectionService.installedFromPlayStore(), xmppConnectionService); + UpdateService task = new UpdateService(this, xmppConnectionService.installedFrom(), xmppConnectionService); task.executeOnExecutor(UpdateService.THREAD_POOL_EXECUTOR, "true"); Log.d(Config.LOGTAG, "AppUpdater started"); } @@ -940,8 +939,8 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio runOnUiThread(() -> Toast.makeText(this, resId, Toast.LENGTH_SHORT).show()); } - protected void AppUpdate(boolean PlayStore) { - if (PlayStore) { + protected void AppUpdate(String Store) { + if (Store == null) { return; } String PREFS_NAME = "UpdateTimeStamp"; @@ -954,10 +953,10 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio editor.putLong("lastUpdateTime", lastUpdateTime); editor.apply(); Log.d(Config.LOGTAG, "AppUpdater: CurrentTime: " + lastUpdateTime); - if (!installFromUnknownSourceAllowed() && !PlayStore) { + if (!installFromUnknownSourceAllowed() && !Store.equals(PlayStore)) { openInstallFromUnknownSourcesDialogIfNeeded(); } else { - UpdateService task = new UpdateService(this, PlayStore, xmppConnectionService); + UpdateService task = new UpdateService(this, Store, xmppConnectionService); task.executeOnExecutor(UpdateService.THREAD_POOL_EXECUTOR, "false"); Log.d(Config.LOGTAG, "AppUpdater started"); } diff --git a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java index 4832dc466..0c59b06c6 100644 --- a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java +++ b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java @@ -37,13 +37,15 @@ import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.utils.WakeLockHelper; import static de.pixart.messenger.http.HttpConnectionManager.getProxy; +import static de.pixart.messenger.services.XmppConnectionService.FDroid; +import static de.pixart.messenger.services.XmppConnectionService.PlayStore; public class UpdaterActivity extends XmppActivity { static final private String FileName = "update.apk"; String appURI = ""; String changelog = ""; Integer filesize = 0; - boolean playstore = false; + String store; ProgressDialog mProgressDialog; DownloadTask downloadTask; XmppConnectionService mXmppConnectionService; @@ -104,9 +106,9 @@ public class UpdaterActivity extends XmppActivity { UpdaterActivity.this.finish(); } try { - playstore = getIntent().getBooleanExtra("playstore", false); + store = getIntent().getStringExtra("store"); } catch (Exception e) { - playstore = false; + store = null; } //delete old downloaded localVersion files File dir = new File(FileBackend.getConversationsDirectory("Update", false)); @@ -129,7 +131,7 @@ public class UpdaterActivity extends XmppActivity { //ask for permissions on devices >= SDK 23 if (isStoragePermissionGranted() && isNetworkAvailable(getApplicationContext())) { //start downloading the file using the download manager - if (playstore) { + if (store.equals(PlayStore)) { Uri uri = Uri.parse("market://details?id=de.pixart.messenger"); Intent marketIntent = new Intent(Intent.ACTION_VIEW, uri); PackageManager manager = getApplicationContext().getPackageManager(); @@ -143,6 +145,20 @@ public class UpdaterActivity extends XmppActivity { startActivity(browserIntent); overridePendingTransition(R.animator.fade_in, R.animator.fade_out); } + } else if (store.equals(FDroid)) { + Uri uri = Uri.parse("https://f-droid.org/de/packages/de.pixart.messenger/"); + Intent marketIntent = new Intent(Intent.ACTION_VIEW, uri); + PackageManager manager = getApplicationContext().getPackageManager(); + List<ResolveInfo> infos = manager.queryIntentActivities(marketIntent, 0); + if (infos.size() > 0) { + startActivity(marketIntent); + overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + } else { + uri = Uri.parse("https://f-droid.org/de/packages/de.pixart.messenger/"); + Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(browserIntent); + overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + } } else { Toast.makeText(getApplicationContext(), getText(R.string.download_started), Toast.LENGTH_LONG).show(); downloadTask = new DownloadTask(UpdaterActivity.this) { |