Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 473f734d authored by Hakjun Choi's avatar Hakjun Choi Committed by Android (Google) Code Review
Browse files

Merge "Amend the way to invoke message application for the the first time...

Merge "Amend the way to invoke message application for the the first time satellite connected notification" into 24D1-dev
parents d5337747 29e8a852
Loading
Loading
Loading
Loading
+26 −6
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.net.Uri;
@@ -77,6 +78,7 @@ import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Telephony;
import android.telephony.CarrierConfigManager;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.Rlog;
@@ -126,6 +128,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
@@ -4255,13 +4258,30 @@ public class SatelliteController extends Handler {
                        com.android.internal.R.color.system_notification_accent_color))
                .setVisibility(Notification.VISIBILITY_PUBLIC);

        // Add action to invoke `What to expect` dialog of Messaging application.
        Intent intentOpenMessage = new Intent(Intent.ACTION_VIEW);
        intentOpenMessage.setData(Uri.parse("sms:"));
        // TODO : b/322733285 add putExtra to invoke "What to expect" dialog.
        PendingIntent pendingIntentOpenMessage = PendingIntent.getActivity(mContext, 0,
                intentOpenMessage, PendingIntent.FLAG_IMMUTABLE);
        // Add action to invoke message application.
        // getDefaultSmsPackage and getLaunchIntentForPackage are nullable.
        Optional<Intent> nullableIntent = Optional.ofNullable(
                        Telephony.Sms.getDefaultSmsPackage(mContext))
                .flatMap(packageName -> {
                    PackageManager pm = mContext.getPackageManager();
                    return Optional.ofNullable(pm.getLaunchIntentForPackage(packageName));
                });
        // If nullableIntent is null, create new Intent for most common way to invoke message app.
        Intent finalIntent = nullableIntent.map(intent -> {
            // Invoke the home screen of default message application.
            intent.setAction(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_HOME);
            return intent;
        }).orElseGet(() -> {
            loge("showSatelliteSystemNotification: no default sms package name, Invoke "
                    + "default sms compose window instead");
            Intent newIntent = new Intent(Intent.ACTION_VIEW);
            newIntent.setData(Uri.parse("sms:"));
            return newIntent;
        });

        PendingIntent pendingIntentOpenMessage = PendingIntent.getActivity(mContext, 0,
                finalIntent, PendingIntent.FLAG_IMMUTABLE);
        Notification.Action actionOpenMessage = new Notification.Action.Builder(0,
                mContext.getResources().getString(R.string.satellite_notification_open_message),
                pendingIntentOpenMessage).build();