From f3362ebde51ba85082c2a006ca25484889f1ef61 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 19 Aug 2020 15:29:25 +0200 Subject: [PATCH] add start/install orbot to error notification if applicable. fixes #3846 --- .../services/NotificationService.java | 21 +++++++++++++++++- .../conversations/utils/TorServiceUtils.java | 10 ++++----- .../ic_play_circle_filled_white_48dp.png | Bin 0 -> 666 bytes .../ic_play_circle_filled_white_48dp.png | Bin 0 -> 464 bytes .../ic_play_circle_filled_white_48dp.png | Bin 0 -> 883 bytes .../ic_play_circle_filled_white_48dp.png | Bin 0 -> 1331 bytes .../ic_play_circle_filled_white_48dp.png | Bin 0 -> 1826 bytes 7 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 src/main/res/drawable-hdpi/ic_play_circle_filled_white_48dp.png create mode 100644 src/main/res/drawable-mdpi/ic_play_circle_filled_white_48dp.png create mode 100644 src/main/res/drawable-xhdpi/ic_play_circle_filled_white_48dp.png create mode 100644 src/main/res/drawable-xxhdpi/ic_play_circle_filled_white_48dp.png create mode 100644 src/main/res/drawable-xxxhdpi/ic_play_circle_filled_white_48dp.png diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index 2e64815f5..a77b923f2 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -61,6 +61,7 @@ import eu.siacs.conversations.ui.TimePreference; import eu.siacs.conversations.utils.AccountUtils; import eu.siacs.conversations.utils.Compatibility; import eu.siacs.conversations.utils.GeoHelper; +import eu.siacs.conversations.utils.TorServiceUtils; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xmpp.XmppConnection; import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection; @@ -1092,9 +1093,11 @@ public class NotificationService { } final boolean showAllErrors = QuickConversationsService.isConversations(); final List errors = new ArrayList<>(); + boolean torNotAvailable = false; for (final Account account : mXmppConnectionService.getAccounts()) { if (account.hasErrorStatus() && account.showErrorNotification() && (showAllErrors || account.getLastErrorStatus() == Account.State.UNAUTHORIZED)) { errors.add(account); + torNotAvailable |= account.getStatus() == Account.State.TOR_NOT_AVAILABLE; } } if (mXmppConnectionService.foregroundNotificationNeedsUpdatingWhenErrorStateChanges()) { @@ -1113,7 +1116,23 @@ public class NotificationService { } mBuilder.addAction(R.drawable.ic_autorenew_white_24dp, mXmppConnectionService.getString(R.string.try_again), - createTryAgainIntent()); + createTryAgainIntent() + ); + if (torNotAvailable) { + if (TorServiceUtils.isOrbotInstalled(mXmppConnectionService)) { + mBuilder.addAction( + R.drawable.ic_play_circle_filled_white_48dp, + mXmppConnectionService.getString(R.string.start_orbot), + PendingIntent.getActivity(mXmppConnectionService, 147, TorServiceUtils.LAUNCH_INTENT, 0) + ); + } else { + mBuilder.addAction( + R.drawable.ic_file_download_white_24dp, + mXmppConnectionService.getString(R.string.install_orbot), + PendingIntent.getActivity(mXmppConnectionService, 146, TorServiceUtils.INSTALL_INTENT, 0) + ); + } + } mBuilder.setDeleteIntent(createDismissErrorIntent()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBuilder.setVisibility(Notification.VISIBILITY_PRIVATE); diff --git a/src/main/java/eu/siacs/conversations/utils/TorServiceUtils.java b/src/main/java/eu/siacs/conversations/utils/TorServiceUtils.java index c3f6fd3c6..9fc9f5082 100644 --- a/src/main/java/eu/siacs/conversations/utils/TorServiceUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/TorServiceUtils.java @@ -16,6 +16,9 @@ public class TorServiceUtils { private static final Uri ORBOT_PLAYSTORE_URI = Uri.parse("market://details?id=" + URI_ORBOT); private final static String ACTION_START_TOR = "org.torproject.android.START_TOR"; + public static final Intent INSTALL_INTENT = new Intent(Intent.ACTION_VIEW, ORBOT_PLAYSTORE_URI); + public static final Intent LAUNCH_INTENT = new Intent(ACTION_START_TOR); + public final static String ACTION_STATUS = "org.torproject.android.intent.action.STATUS"; public final static String EXTRA_STATUS = "org.torproject.android.intent.extra.STATUS"; @@ -30,17 +33,14 @@ public class TorServiceUtils { public static void downloadOrbot(Activity activity, int requestCode) { - final Intent intent = new Intent(Intent.ACTION_VIEW, ORBOT_PLAYSTORE_URI); try { - activity.startActivityForResult(intent, requestCode); + activity.startActivityForResult(INSTALL_INTENT, requestCode); } catch (ActivityNotFoundException e) { ToastCompat.makeText(activity, R.string.no_market_app_installed, ToastCompat.LENGTH_SHORT).show(); } } public static void startOrbot(Activity activity, int requestCode) { - final Intent launchIntent = new Intent(URI_ORBOT); - launchIntent.setAction(ACTION_START_TOR); - activity.startActivityForResult(launchIntent, requestCode); + activity.startActivityForResult(LAUNCH_INTENT, requestCode); } } diff --git a/src/main/res/drawable-hdpi/ic_play_circle_filled_white_48dp.png b/src/main/res/drawable-hdpi/ic_play_circle_filled_white_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..30330cfad6fc31d88d473c30deb4f1b101e70b23 GIT binary patch literal 666 zcmV;L0%iS)P)KoJ$#a2BE&B1G5KtV4`9-@U>Xiu8Z3hhnNLqTEHU_CFi{b5EA+5lUSV03GGP|Y4B7~O#$)UXE$ zMt7_Swe3NI(Y5rTdwY;zbX`5DZx0fTuBQh@b|B&Ch7$_%Ke9#n$R_TWdgA`<8zjnL zR3;rw+N)z<4_f~(FV|Ok(5&eAvFQHzp}0-`fEJEFG47^*gx!uiHcc`SG9GCd&J5$L)iUJ*c^n<+pYN6wSQ0WbcEP)8qwL)}Di@L#=vc2@L4ggOYl3qLMETUUz&Y@xg0B7)Z;_5v!psA;D{ljZ5) zc#?BoPeMz<=Us&de(}5?&XfNETsn+db08ohBH+N95p7%?Q<;9yV8)pwPJEzlFQ~F4 z!bFHq#YWKQ2T}rhj|mEV;Zb}%si4RX8@3cBf&x2i+2WZ6pGkvn67)&SJDs4)PttOu zoGe(91&bs>L;I}W^9vavFY$sIIvn2c4H?rofy)^k_ZRXN2}g3Opo1RgUc#tas$eV= z2%{RRg0)N_jB2F{4l;o-s=X=*WCCGSS5*+n1j4AozbLSe=q>Vyvj52c;BPuYixQ2V zfhuTc+A5l=z~z)#v-=*`>>NI#;~tHSN&GyhXEbnrQ%f3|K3OnNp2-yg(sH4sTU&ah zrE6NeeA4jAyxDndv1LPEw*1;DHoTIq?;gHIIQhp8kRCUrTVtW-#)^unfcGG6`1cl!3TbBCbQR4az#Z&MMXt1K#o;*Iio^@SKfK& zl?D|~*ndW&kOE z<`WV$Xn z5mr^ck_L=(N0{9*CJ7kj4j^R0h!o&UYM7`>p9CPm1*SSD?jP_QCfoK4Sip4iegMNX zG2Js6?|>6*sN@wehb`s308-pwOLda&0Y70=Kez>S^B>;&o)+?bB<&7Rz-x+cC?nsJ z8^9OTd;k9y{0}cfM@>AN^1*G{b0Fa;33rRh|EQkQ)r!=hx z*b)NBPiaFBP!$5mPw8(RzyOE=JFu=%`1 z-tU2@ZA|tH$}b?!Ii~uPPX7Q!A5~0rNsrXA%Moq~yBji+2VciRCj86S(npU+xC(JR znIH~-_j4Z7pKec3$M56p5Of=K273Wwo@avUk$f0eP%@MPdgmDo?-Ed+I+9)UA?#~d zNq*!b5;Z80Fmn+u%@SAmsmdZL(^nC*?DK-#n(Xl{9kyHsO)|{}|DaQab*8jOBM)$R z@ta_UBFB`ur^Op@w793t5t|gq(rf-YuK6bdM1Tko0V06Z^FN`6oF-LpM=}5a002ov JPDHLkV1l`OfX)B_ literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xxhdpi/ic_play_circle_filled_white_48dp.png b/src/main/res/drawable-xxhdpi/ic_play_circle_filled_white_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..1d73fb5f49686ad8aa5535da4db8ecb0e9267b15 GIT binary patch literal 1331 zcmV-31DT6gOANX9Tzo7>imQ=8r z~zxRBUuaffld_JGg z=kxh|K5FQopR3$qnnhN~@_{mCK9FUFMILdREA(@e8kE#gBz>wl%n*~T5Ts=$8KRvk zmx1;$z@HR|Ql3dJ@}+A)yBOdx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OCyG59ERT`48zT_|5F4XSo0X002ovPDHLkV1hwJYjywt literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xxxhdpi/ic_play_circle_filled_white_48dp.png b/src/main/res/drawable-xxxhdpi/ic_play_circle_filled_white_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..166f5c5ce313a782e713ff9a5704902fb6a639bf GIT binary patch literal 1826 zcmZ{lX*?A8AIE<)gBjP1V+flWwY3@#ie4cr6$^DyD>OcC(KTIj(>~Nc`$cKIMVpcZN6lVXh$|tWX zqf1PpZBDiTV@=RDdu23*KR-b{a)zR^DNW6C#X$bF z53Cj-Z9}OA`O{sl-;AE6uz`q9Mo+_7DV)}|OMjL0E+>MfC+Yb&)YJp=WWz9S$&RN9 zC3Gppg?Vsy>938k*JK(!ZV z@qxr|WanZcuf&nD`sf(~9yr%2SzADLinTj$WP0*XE=OfzCj7cA<8)AT#TU5KSStrnYBc8Bzk#0wlK>6D?ZbmX8$Y zIa=#wK9XbZEWp&WI#CT98G-BQS)CmNwKOwY5sr6Z9jJeSh&YUftb+|6NU2#0ehFHM zSk5?FR8@Gb#*Fq5XY#uy=Sm_7bQ>p2_zBDZN5O%YfpQtj?;-=K0@rCk`9(6gHb_4o zEN2!yV=v^VpKC^YhWj{jM}!l7s9k2HQ{d*Mry-`%TB zfSi?df2?ahSi5+DIB8>$Ec@|5{QeX#ds5SO`<(cG@cCV{Y}A_hMery7?X8B&;$(&B z0?+L;dHdzp3XLDh-9kBkc~IRQGSYFonv$`)1v*cLNGHc{7L)Qov;FSwV9WlOm|wyM z0O4nmvSJoCB)suJQnk=zmmmxLhxfBL(NC|d@ULOwdrC3&!>aH#_8vA&WAn{BfZwSU zn()rxz612oM~u^^Cf=kxKBKwp`;?y^2SKj#V0R`csua-nTg8A=_M+X03<%sGY2SjO z;eH(Kxt3eJe7IOcxpU_7=!&q4DD7+};i+fGk(ZETO+mABGrYa*)fhl$^|NKhDu0x> z5iWDuMj3gAWYsT25cy%ro!z#Q^!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