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

Commit 29e8a852 authored by Hakjun Choi's avatar Hakjun Choi
Browse files

Amend the way to invoke message application for the the first time satellite connected notification

It was finalized to invoke the home screen of default message app instead of invoking 'What to expect' dialog, as OEM's message app may be default.

Bug: 322733285
Test: manually tested with below scenario
      1. Google message is the default app.
      2. Playstore downloaded app is the default app.
      3. No default app is decided.
Change-Id: I9b0b69c1682ea8b3a97ed1704d254d05320bc9f2
parent 7b4a7557
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;
@@ -4229,13 +4232,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();