Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package org.iiab.controller.feedback.data;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.LabeledIntent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.widget.Toast;

import org.iiab.controller.R;
import org.iiab.controller.feedback.domain.EmailContent;

import java.io.File;
import java.util.List;
import java.util.Locale;

/**
* ADFA-5130: shares a feedback report so the text is never lost — text is prioritised over the
* screenshot.
*
* <p>Every receiver gets the rich intent (screenshot + text): email, WhatsApp, Telegram and Signal
* all keep both. Slack is the lone exception — it drops {@code EXTRA_TEXT} whenever an image stream
* is attached — so Slack alone is handed a text-only intent (no stream, so it keeps the full
* report). This is done entirely through the native share sheet (no custom picker): Slack's rich
* entry is removed with {@code EXTRA_EXCLUDE_COMPONENTS} and a text-only one is added with
* {@code EXTRA_INITIAL_INTENTS}. See {@link #addSlackTextOnlyOverride}.
*
* <p><b>Accepted trade-off:</b> excluding Slack's component also removes its Direct Share targets
* (the conversation shortcuts), so from Slack the user picks the recipient inside the app. We take
* that over losing the text: the report text is the accessible, machine-usable part; the screenshot
* is supplementary. The Android share sheet offers no way to keep Direct Share and override the
* payload at the same time.
*
* <p><b>Only Slack is special-cased</b> (matched by package name). If another receiver ever turns
* out to have the same defect, add its package to the match — the mechanism generalises without new
* code. If Slack is renamed or absent the override simply does not apply, Slack falls back to the
* rich intent, and the report text is on the clipboard as a deterministic, accessible fallback.
*
* <p><b>Rejected alternatives:</b> baking the text into the image (destroys accessibility for screen
* readers); a custom picker or a per-app dictionary for every messaging app (maintenance sink); and
* an earlier wildcard-type + composite-{@code ClipData} "coercion" meant to make Slack keep the
* text — it did not change Slack's behaviour on a real device, so Slack now gets an explicit
* text-only intent instead.
*/
public final class HybridFeedbackSender {

/** Slack's Android package is {@code com.Slack}; matched case-insensitively as a substring so
* the exact casing does not matter and a minor rename still catches it. */
private static final String SLACK_HINT = "slack";

/** @return true if the share chooser was launched. */
public boolean send(Activity activity, EmailContent content) {
try {
String body = content.body();
boolean copied = copyTextToClipboard(activity, body);

Intent rich = buildRichIntent(activity, content, body);
Intent chooser = Intent.createChooser(rich, activity.getString(R.string.feedback_send));
addSlackTextOnlyOverride(activity, rich, chooser, body, content.subject());

if (copied) {
Toast.makeText(activity, R.string.feedback_share_copied, Toast.LENGTH_LONG).show();
}
activity.startActivity(chooser);
return true;
} catch (ActivityNotFoundException e) {
return false;
} catch (Throwable t) {
return false;
}
}

/** The default: text + screenshot, kept by email and standards-respecting messaging apps. */
private static Intent buildRichIntent(Activity activity, EmailContent content, String body) {
Intent rich = new Intent(Intent.ACTION_SEND);
// Broad type so the sheet lists email and every messaging app; each keeps image + text.
// This is NOT a Slack workaround — Slack is handled separately in addSlackTextOnlyOverride.
rich.setType("*/*");
rich.putExtra(Intent.EXTRA_TEXT, body);
rich.putExtra(Intent.EXTRA_SUBJECT, content.subject());
rich.putExtra(Intent.EXTRA_TITLE, content.subject()); // sharesheet preview title
if (content.recipient() != null) {
rich.putExtra(Intent.EXTRA_EMAIL, new String[]{content.recipient()});
}
if (content.attachmentPath() != null) {
Uri uri = androidx.core.content.FileProvider.getUriForFile(
activity, activity.getPackageName() + ".provider", new File(content.attachmentPath()));
rich.putExtra(Intent.EXTRA_STREAM, uri);
// ClipData carries the read grant to whichever app is chosen.
rich.setClipData(ClipData.newUri(activity.getContentResolver(), "screenshot", uri));
rich.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
return rich;
}

/**
* If Slack is installed, exclude its rich entry from the sheet and add a text-only one in its
* place, so Slack keeps the report text. targetSdk is 28, so package-visibility filtering (API
* 30+) does not apply and {@code queryIntentActivities} sees Slack directly — no {@code <queries>}
* declaration is needed.
*/
private static void addSlackTextOnlyOverride(Activity activity, Intent rich, Intent chooser,
String body, String subject) {
PackageManager pm = activity.getPackageManager();
ResolveInfo slack = null;
List<ResolveInfo> handlers = pm.queryIntentActivities(rich, 0);
for (ResolveInfo ri : handlers) {
if (ri.activityInfo != null && ri.activityInfo.packageName != null
&& ri.activityInfo.packageName.toLowerCase(Locale.US).contains(SLACK_HINT)) {
slack = ri;
break;
}
}
if (slack == null) {
return; // Slack not installed / not found -> rich intent + clipboard fallback stand
}
ComponentName comp = new ComponentName(slack.activityInfo.packageName, slack.activityInfo.name);

Intent textOnly = new Intent(Intent.ACTION_SEND);
textOnly.setType("text/plain"); // no stream -> Slack keeps the full text
textOnly.putExtra(Intent.EXTRA_TEXT, body);
textOnly.putExtra(Intent.EXTRA_SUBJECT, subject);
textOnly.setComponent(comp);

LabeledIntent labeled = new LabeledIntent(textOnly, slack.activityInfo.packageName,
slack.loadLabel(pm).toString(), slack.getIconResource());

// Exclude Slack's rich entry (this also drops its Direct Share targets — accepted, see the
// class doc) and add the text-only one in its place, so Slack keeps the text.
chooser.putExtra(Intent.EXTRA_EXCLUDE_COMPONENTS, new ComponentName[]{comp});
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{labeled});
}

/** Best-effort: put the report text on the clipboard. Never throws. */
private static boolean copyTextToClipboard(Context ctx, String text) {
try {
ClipboardManager cm = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
if (cm == null) {
return false;
}
cm.setPrimaryClip(ClipData.newPlainText("K2Go feedback", text));
return true;
} catch (Throwable t) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ public static void installOn(android.app.Activity activity, String screenTag, in
attach(fab, () -> sendFeedback(activity, screenTag));
}

/** ADFA-4538/4932: capture a screenshot, build the diagnostics payload, and hand it to the
* configured transport (mailto -> mail chooser). Shared by MainActivity and the redesign. */
/** ADFA-4538/4932: capture a screenshot, build the diagnostics payload, and hand it off.
* ADFA-5130: routing is delegated to {@link FeedbackShareRouter} (email vs share-to-app).
* Shared by MainActivity and the redesign. */
public static void sendFeedback(android.app.Activity activity, String screen) {
org.iiab.controller.feedback.data.FeedbackScreenshot.capture(activity, path -> {
if (activity.isFinishing() || activity.isDestroyed()) {
Expand All @@ -179,14 +180,11 @@ public static void sendFeedback(android.app.Activity activity, String screen) {
.screen(screen)
.screenshot(path)
.build();
boolean ok = org.iiab.controller.feedback.data.FeedbackConfig.create(activity)
.send(activity, payload);
if (ok) {
org.iiab.controller.analytics.AnalyticsClient.with(activity).logFeedbackSent();
} else {
android.widget.Toast.makeText(activity, org.iiab.controller.R.string.feedback_no_email_app,
android.widget.Toast.LENGTH_LONG).show();
}
// ADFA-5130: route by channel (email keeps the attachment; messaging gets text + the
// screenshot on the clipboard) instead of always building the single mail chooser, so
// sharing to Slack/WhatsApp no longer drops the report text. Reporting/analytics move
// into the router so both channels are handled in one place.
FeedbackShareRouter.share(activity, payload);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.iiab.controller.feedback.presentation;

import android.app.Activity;
import android.content.Context;
import android.widget.Toast;

import org.iiab.controller.R;
import org.iiab.controller.analytics.AnalyticsClient;
import org.iiab.controller.feedback.data.FeedbackConfig;
import org.iiab.controller.feedback.data.HybridFeedbackSender;
import org.iiab.controller.feedback.data.MailtoFeedbackTransport;
import org.iiab.controller.feedback.data.WorkerFeedbackTransport;
import org.iiab.controller.feedback.domain.EmailContent;
import org.iiab.controller.feedback.domain.FeedbackPayload;
import org.iiab.controller.feedback.domain.FeedbackRenderer;

/**
* ADFA-5130: hands a feedback report to the right sender.
*
* <p>With a screenshot it goes through {@link HybridFeedbackSender} — a single native share that
* carries text + image so it works across email and messaging in one send (and coaxes even Slack
* into keeping the text, with a clipboard-text fallback). With no screenshot there is nothing an
* image-only receiver could strip, so the plain mail path is used (unchanged). The worker transport,
* when enabled, POSTs and shows no chooser.
*
* <p>The UI is entirely native (the system share sheet); there is no custom app picker and no
* per-app branching.
*/
public final class FeedbackShareRouter {

private FeedbackShareRouter() {
}

public static void share(Activity activity, FeedbackPayload payload) {
if (FeedbackConfig.WORKER.equals(FeedbackConfig.transport(activity))) {
report(activity, new WorkerFeedbackTransport().send(activity, payload));
return;
}
EmailContent content = new FeedbackRenderer().render(payload);
if (content.attachmentPath() == null) {
report(activity, new MailtoFeedbackTransport().send(activity, payload));
return;
}
report(activity, new HybridFeedbackSender().send(activity, content));
}

private static void report(Context ctx, boolean ok) {
if (ok) {
// ADFA-4466 Phase 2: feedback-channel adoption (no content; no-op unless opted in).
AnalyticsClient.with(ctx).logFeedbackSent();
} else {
Toast.makeText(ctx, R.string.feedback_no_email_app, Toast.LENGTH_LONG).show();
}
}
}
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,5 @@
<string name="install_error_verify">فشلت ملفات النظام التي تم تنزيلها في فحص السلامة (غير مكتملة أو تالفة). يرجى محاولة التثبيت مرة أخرى.</string>
<string name="install_btn_select_content">اختيار المحتوى</string>
<string name="feedback_force_crash">فرض تعطل تجريبي (debug)</string>
<string name="feedback_share_copied">تم نسخ نص التقرير — الصقه إذا لم يصل</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-az/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -532,4 +532,5 @@
<string name="feedback_force_crash">Sınaq çökməsini məcbur et (debug)</string>
<!-- ADFA-4795: arch technical labels l10n. review — machine, verify. -->
<!-- ADFA-4795: Lottie sign OPEN/CLOSED l10n. review — machine, verify. -->
<string name="feedback_share_copied">Hesabat mətni kopyalandı — çatmadısa yapışdırın</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,5 @@
<string name="install_error_verify">Изтеглените системни файлове не преминаха проверката за цялост (непълни или повредени). Опитайте да инсталирате отново.</string>
<string name="install_btn_select_content">Избор на съдържание</string>
<string name="feedback_force_crash">Принудително тестово сривване (debug)</string>
<string name="feedback_share_copied">Текстът на отчета е копиран — поставете го, ако не е пристигнал</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-bn/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -525,4 +525,5 @@
<string name="feedback_force_crash">পরীক্ষামূলক ক্র্যাশ বাধ্য করুন (debug)</string>
<!-- ADFA-4795: arch technical labels l10n. review — machine, verify. -->
<!-- ADFA-4795: Lottie sign OPEN/CLOSED l10n. review — machine, verify. -->
<string name="feedback_share_copied">রিপোর্টের লেখা কপি করা হয়েছে — না এলে পেস্ট করুন</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,5 @@
<string name="install_error_verify">Stažené systémové soubory neprošly kontrolou integrity (neúplné nebo poškozené). Zkuste instalaci znovu.</string>
<string name="install_btn_select_content">Vybrat obsah</string>
<string name="feedback_force_crash">Vynutit testovací pád (debug)</string>
<string name="feedback_share_copied">Text hlášení zkopírován — vložte jej, pokud nedorazil</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,5 @@
<string name="install_error_verify">Die heruntergeladenen Systemdateien haben die Integritätsprüfung nicht bestanden (unvollständig oder beschädigt). Bitte versuchen Sie die Installation erneut.</string>
<string name="install_btn_select_content">Inhalt auswählen</string>
<string name="feedback_force_crash">Testabsturz erzwingen (debug)</string>
<string name="feedback_share_copied">Berichtstext kopiert — füge ihn ein, falls er nicht ankam</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,5 @@
<string name="install_error_verify">Τα ληφθέντα αρχεία συστήματος απέτυχαν στον έλεγχο ακεραιότητας (ελλιπή ή κατεστραμμένα). Δοκιμάστε ξανά την εγκατάσταση.</string>
<string name="install_btn_select_content">Επιλογή περιεχομένου</string>
<string name="feedback_force_crash">Εξαναγκασμός δοκιμαστικής κατάρρευσης (debug)</string>
<string name="feedback_share_copied">Το κείμενο της αναφοράς αντιγράφηκε — επικολλήστε το αν δεν έφτασε</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -588,4 +588,5 @@
<string name="install_error_verify">Los archivos del sistema descargados no superaron la verificación de integridad (incompletos o dañados). Vuelve a intentar la instalación.</string>
<string name="install_btn_select_content">Seleccionar contenido</string>
<string name="feedback_force_crash">Forzar fallo de prueba (debug)</string>
<string name="feedback_share_copied">Texto del reporte copiado — pégalo si no llegó</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,5 @@
<string name="install_error_verify">فایل‌های سیستمی دانلودشده در بررسی یکپارچگی ناموفق بودند (ناقص یا خراب). لطفاً نصب را دوباره امتحان کنید.</string>
<string name="install_btn_select_content">انتخاب محتوا</string>
<string name="feedback_force_crash">اجبار به خرابی آزمایشی (debug)</string>
<string name="feedback_share_copied">متن گزارش کپی شد — اگر نرسید آن را بچسبانید</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -589,4 +589,5 @@
<string name="install_error_verify">Les fichiers système téléchargés ont échoué à la vérification d\'intégrité (incomplets ou corrompus). Veuillez réessayer l\'installation.</string>
<string name="install_btn_select_content">Choisir le contenu</string>
<string name="feedback_force_crash">Forcer un plantage de test (debug)</string>
<string name="feedback_share_copied">Texte du rapport copié — collez-le s’il n’est pas arrivé</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-gu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -525,4 +525,5 @@
<string name="feedback_force_crash">પરીક્ષણ ક્રેશ ફરજ પાડો (debug)</string>
<!-- ADFA-4795: arch technical labels l10n. review — machine, verify. -->
<!-- ADFA-4795: Lottie sign OPEN/CLOSED l10n. review — machine, verify. -->
<string name="feedback_share_copied">રિપોર્ટનો ટેક્સ્ટ કૉપિ થયો — ન પહોંચ્યો હોય તો પેસ્ટ કરો</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -589,4 +589,5 @@
<string name="install_error_verify">डाउनलोड की गई सिस्टम फ़ाइलें अखंडता जाँच में विफल रहीं (अपूर्ण या दूषित)। कृपया पुनः इंस्टॉल करने का प्रयास करें।</string>
<string name="install_btn_select_content">सामग्री चुनें</string>
<string name="feedback_force_crash">परीक्षण क्रैश बाध्य करें (debug)</string>
<string name="feedback_share_copied">रिपोर्ट का टेक्स्ट कॉपी हो गया — न पहुँचे तो पेस्ट करें</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,5 @@
<string name="install_error_verify">A letöltött rendszerfájlok nem mentek át az integritásellenőrzésen (hiányosak vagy sérültek). Kérjük, próbálja meg újra a telepítést.</string>
<string name="install_btn_select_content">Tartalom kiválasztása</string>
<string name="feedback_force_crash">Teszt-összeomlás kényszerítése (debug)</string>
<string name="feedback_share_copied">A jelentés szövege másolva — illessze be, ha nem érkezett meg</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,5 @@
<string name="install_error_verify">Berkas sistem yang diunduh gagal pemeriksaan integritas (tidak lengkap atau rusak). Silakan coba pasang lagi.</string>
<string name="install_btn_select_content">Pilih konten</string>
<string name="feedback_force_crash">Paksa crash uji (debug)</string>
<string name="feedback_share_copied">Teks laporan disalin — tempel jika tidak terkirim</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,5 @@
<string name="install_error_verify">I file di sistema scaricati non hanno superato il controllo di integrità (incompleti o corrotti). Riprova l\'installazione.</string>
<string name="install_btn_select_content">Seleziona contenuti</string>
<string name="feedback_force_crash">Forza crash di prova (debug)</string>
<string name="feedback_share_copied">Testo del report copiato — incollalo se non è arrivato</string>
</resources>
Loading
Loading