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

Commit a8118d9f authored by Peter Kalauskas's avatar Peter Kalauskas
Browse files

Move receiver registration to background thread

 - Use dependency injection for StorageNotification

 - In StorageNotification, register broadcast receivers on background
   thread

Test: SystemUITests
Bug: 200831506
Bug: 247839538
Change-Id: Id009bb3ce5945d41f1794f776d34894e3495c559
parent 00773c6a
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.dagger;

import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.app.AlarmManager;
@@ -68,6 +69,7 @@ import android.os.PowerManager;
import android.os.ServiceManager;
import android.os.UserManager;
import android.os.Vibrator;
import android.os.storage.StorageManager;
import android.permission.PermissionManager;
import android.safetycenter.SafetyCenterManager;
import android.service.dreams.DreamService;
@@ -109,6 +111,7 @@ import dagger.Provides;
/**
 * Provides Non-SystemUI, Framework-Owned instances to the dependency graph.
 */
@SuppressLint("NonInjectedService")
@Module
public class FrameworkServicesModule {
    @Provides
@@ -462,7 +465,13 @@ public class FrameworkServicesModule {

    @Provides
    @Singleton
    static SubscriptionManager provideSubcriptionManager(Context context) {
    static StorageManager provideStorageManager(Context context) {
        return context.getSystemService(StorageManager.class);
    }

    @Provides
    @Singleton
    static SubscriptionManager provideSubscriptionManager(Context context) {
        return context.getSystemService(SubscriptionManager.class);
    }

+27 −12
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.internal.R;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.systemui.CoreStartable;
import com.android.systemui.SystemUIApplication;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.util.NotificationChannels;

@@ -61,15 +62,24 @@ public class StorageNotification implements CoreStartable {
    private static final String ACTION_SNOOZE_VOLUME = "com.android.systemui.action.SNOOZE_VOLUME";
    private static final String ACTION_FINISH_WIZARD = "com.android.systemui.action.FINISH_WIZARD";
    private final Context mContext;
    private final BroadcastDispatcher mBroadcastDispatcher;

    // TODO: delay some notifications to avoid bumpy fast operations

    private NotificationManager mNotificationManager;
    private StorageManager mStorageManager;
    private final NotificationManager mNotificationManager;
    private final StorageManager mStorageManager;

    @Inject
    public StorageNotification(Context context) {
    public StorageNotification(
            Context context,
            BroadcastDispatcher broadcastDispatcher,
            NotificationManager notificationManager,
            StorageManager storageManager
    ) {
        mContext = context;
        mBroadcastDispatcher = broadcastDispatcher;
        mNotificationManager = notificationManager;
        mStorageManager = storageManager;
    }

    private static class MoveInfo {
@@ -168,17 +178,22 @@ public class StorageNotification implements CoreStartable {

    @Override
    public void start() {
        mNotificationManager = mContext.getSystemService(NotificationManager.class);

        mStorageManager = mContext.getSystemService(StorageManager.class);
        mStorageManager.registerListener(mListener);

        mContext.registerReceiver(mSnoozeReceiver, new IntentFilter(ACTION_SNOOZE_VOLUME),
                android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, null,
                Context.RECEIVER_EXPORTED_UNAUDITED);
        mContext.registerReceiver(mFinishReceiver, new IntentFilter(ACTION_FINISH_WIZARD),
                android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS, null,
                Context.RECEIVER_EXPORTED_UNAUDITED);
        mBroadcastDispatcher.registerReceiver(
                mSnoozeReceiver,
                new IntentFilter(ACTION_SNOOZE_VOLUME),
                null,
                null,
                Context.RECEIVER_EXPORTED_UNAUDITED,
                android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
        mBroadcastDispatcher.registerReceiver(
                mFinishReceiver,
                new IntentFilter(ACTION_FINISH_WIZARD),
                null,
                null,
                Context.RECEIVER_EXPORTED_UNAUDITED,
                android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);

        // Kick current state into place
        final List<DiskInfo> disks = mStorageManager.getDisks();