001// SPDX-License-Identifier: GPL-3.0-or-later 002// Copyright © 2026 Aurélien Pierre 003 004package com.aurelienpierre.sioul; 005 006import android.content.Context; 007import android.provider.Telephony; 008 009import org.json.JSONException; 010import org.json.JSONObject; 011 012/** 013 * What the listener says of a notification for your computers, beside what 014 * decides its time (AppNotes, describe; crates/sioul-core/src/phonemsgs.rs, 015 * `Extra`): whether its app keeps it secret, when it was sent and posted, 016 * whether it shows a picture; and of each message, when it was sent and 017 * whether it is a picture. Never the picture itself: its address stays on 018 * the phone. Rust decides what of it, if anything, leaves the phone, and 019 * writes it (docs/android.md, "Messages on your computers"). 020 */ 021final class PhoneMessages 022{ 023 private PhoneMessages() 024 { 025 } 026 027 /** A notification's own: Notification.visibility (-1 secret), Notification.when, its post time, a picture of its own. */ 028 static JSONObject notice(JSONObject out, int visibility, long when, long posted, boolean picture) throws JSONException 029 { 030 return out.put("visibility", visibility).put("when", when).put("posted", posted).put("picture", picture); 031 } 032 033 /** The phone's default SMS app, for the tab ({@link StepService#call}, "sms-app"); "" when none, or no telephony. */ 034 static String smsApp(Context context) 035 { 036 try { 037 String found = Telephony.Sms.getDefaultSmsPackage(context); 038 return found == null ? "" : found; 039 } catch (RuntimeException e) { 040 return ""; 041 } 042 } 043 044 /** A message's own: when it was sent, and whether its data is a picture, by its type. */ 045 static JSONObject message(JSONObject one, long at, String type) throws JSONException 046 { 047 return one.put("at", at).put("picture", type != null && type.startsWith("image/")); 048 } 049}