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

Commit 1c0c977c authored by Nadia Benbernou's avatar Nadia Benbernou
Browse files

Make SmsHelper local to Assistant rather than a singleton (I accidentally

forgot to include this piece in my previous CL it looks like).

Bug: 123365364
Test: Unit tests and manual testing.
Change-Id: I7c7096890c06d98f04e307f00f10c4138eee2868
parent affa55b4
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -105,6 +105,7 @@ public class Assistant extends NotificationAssistantService {
    protected AssistantSettings.Factory mSettingsFactory = AssistantSettings.FACTORY;
    @VisibleForTesting
    protected AssistantSettings mSettings;
    private SmsHelper mSmsHelper;

    public Assistant() {
    }
@@ -122,6 +123,18 @@ public class Assistant extends NotificationAssistantService {
        mAgingHelper = new AgingHelper(getContext(),
                mNotificationCategorizer,
                new AgingCallback());
        mSmsHelper = new SmsHelper(this);
        mSmsHelper.initialize();
    }

    @Override
    public void onDestroy() {
        // This null check is only for the unit tests as ServiceTestCase.tearDown calls onDestroy
        // without having first called onCreate.
        if (mSmsHelper != null) {
            mSmsHelper.destroy();
        }
        super.onDestroy();
    }

    private void loadFile() {
@@ -215,7 +228,7 @@ public class Assistant extends NotificationAssistantService {
            return null;
        }
        NotificationEntry entry =
                new NotificationEntry(mPackageManager, sbn, channel, SmsHelper.getInstance(this));
                new NotificationEntry(mPackageManager, sbn, channel, mSmsHelper);
        SmartActionsHelper.SmartSuggestions suggestions = mSmartActionsHelper.suggest(entry);
        return createEnqueuedNotificationAdjustment(
                entry, suggestions.actions, suggestions.replies);
@@ -262,7 +275,7 @@ public class Assistant extends NotificationAssistantService {
            Ranking ranking = getRanking(sbn.getKey(), rankingMap);
            if (ranking != null && ranking.getChannel() != null) {
                NotificationEntry entry = new NotificationEntry(mPackageManager,
                        sbn, ranking.getChannel(), SmsHelper.getInstance(this));
                        sbn, ranking.getChannel(), mSmsHelper);
                String key = getKey(
                        sbn.getPackageName(), sbn.getUserId(), ranking.getChannel().getId());
                ChannelImpressions ci = mkeyToImpressions.getOrDefault(key,
@@ -398,7 +411,6 @@ public class Assistant extends NotificationAssistantService {
    @Override
    public void onListenerConnected() {
        if (DEBUG) Log.i(TAG, "CONNECTED");
        SmsHelper.getInstance(this).initialize();
        try {
            mFile = new AtomicFile(new File(new File(
                    Environment.getDataUserCePackageDirectory(
@@ -415,7 +427,6 @@ public class Assistant extends NotificationAssistantService {

    @Override
    public void onListenerDisconnected() {
        SmsHelper.getInstance(this).destroy();
        if (mAgingHelper != null) {
            mAgingHelper.onDestroy();
        }
+1 −13
Original line number Diff line number Diff line
@@ -33,23 +33,11 @@ import com.android.internal.telephony.SmsApplication;
public class SmsHelper {
    private static final String TAG = "SmsHelper";

    private static SmsHelper sSmsHelper;
    private static final Object sLock = new Object();

    private final Context mContext;
    private ComponentName mDefaultSmsApplication;
    private BroadcastReceiver mBroadcastReceiver;

    static SmsHelper getInstance(Context context) {
        synchronized (sLock) {
            if (sSmsHelper == null) {
                sSmsHelper = new SmsHelper(context);
            }
            return sSmsHelper;
        }
    }

    private SmsHelper(Context context) {
    SmsHelper(Context context) {
        mContext = context.getApplicationContext();
    }