add start/install orbot to error notification if applicable. fixes #3846
This commit is contained in:
parent
70c10fd0de
commit
f3362ebde5
|
@ -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<Account> 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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 666 B |
Binary file not shown.
After Width: | Height: | Size: 464 B |
Binary file not shown.
After Width: | Height: | Size: 883 B |
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
Loading…
Reference in New Issue