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

Commit d02623bf authored by Felipe Leme's avatar Felipe Leme
Browse files

Minor improvements on BugreportProgressService.

Such as:

- Include userId on notification log statements
- Made classes final
- Removed unused constant
- Reused notification code
- Change unit test to use mockito rule
- Other cosmetics changes in the test (like removing m prefix on
  public attributes)

Bug: 423702145
Test: atest BugreportProgressServiceTest
Test: manual verification
Flag: EXEMPT logging and tests changes only

Change-Id: Ib8d85fc3d445797f839ebbb5f888dc2a59c44d13
parent e7ebff9d
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ import java.util.zip.ZipOutputStream;
 * bugreport artifacts.
 * </ol>
 */
public class BugreportProgressService extends Service {
public final class BugreportProgressService extends Service {
    private static final String TAG = "BugreportProgressService";
    private static final boolean DEBUG = false;
    private static final String WRITE_AND_APPEND_MODE = "wa";
@@ -217,8 +217,6 @@ public class BugreportProgressService extends Service {
    /** System property where dumpstate stores last triggered bugreport id */
    static final String PROPERTY_LAST_ID = "dumpstate.last_id";

    private static final String BUGREPORT_SERVICE = "bugreport";

    /**
     * Directory on Shell's data storage where screenshots will be stored.
     * <p>
@@ -937,7 +935,7 @@ public class BugreportProgressService extends Service {
    private void sendForegroundabledNotification(int id, Notification notification) {
        if (mForegroundId >= 0) {
            if (DEBUG) Log.d(TAG, "Already running as foreground service");
            NotificationManager.from(mContext).notify(id, notification);
            sendNotification(id, notification);
        } else {
            mForegroundId = id;
            Log.d(TAG, "Start running as foreground service on id " + mForegroundId);
@@ -990,7 +988,7 @@ public class BugreportProgressService extends Service {


        Log.d(TAG, "stopProgress(" + id + "): cancel notification");
        NotificationManager.from(mContext).cancel(id);
        cancelNotification(id);

        stopSelfWhenDoneLocked();
    }
@@ -1031,7 +1029,7 @@ public class BugreportProgressService extends Service {
            Log.w(TAG, "launchBugreportInfoDialog(): canceling notification because id " + id
                    + " was not found");
            // TODO: add test case to make sure notification is canceled.
            NotificationManager.from(mContext).cancel(id);
            cancelNotification(id);
            return;
        }

@@ -1068,7 +1066,7 @@ public class BugreportProgressService extends Service {
            Log.w(TAG, "takeScreenshot(): canceling notification because id " + id
                    + " was not found");
            // TODO: add test case to make sure notification is canceled.
            NotificationManager.from(mContext).cancel(id);
            cancelNotification(id);
            return;
        }
        setTakingScreenshot(true);
@@ -1364,7 +1362,7 @@ public class BugreportProgressService extends Service {
            warningIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(warningIntent);
        }
        NotificationManager.from(mContext).cancel(id);
        cancelNotification(id);
    }

    /**
@@ -1513,7 +1511,7 @@ public class BugreportProgressService extends Service {
        }

        Log.d(TAG, "Sending 'Share' notification for ID " + info.id + ": " + title);
        NotificationManager.from(mContext).notify(info.id, builder.build());
        sendNotification(info.id, builder.build());
    }

    /**
@@ -1531,6 +1529,22 @@ public class BugreportProgressService extends Service {
        sendForegroundabledNotification(id, builder.build());
    }

    private void cancelNotification(int id) {
        if (DEBUG) {
            Log.v(TAG, "Calling NotificationManager.cancel(" + id + ") on user "
                    + mContext.getUser());
        }
        NotificationManager.from(mContext).cancel(id);
    }

    private void sendNotification(int id, Notification notification) {
        if (DEBUG) {
            Log.v(TAG, "Calling NotificationManager.notify(" + id + ", " + notification
                    + ") on user " + mContext.getUser());
        }
        NotificationManager.from(mContext).notify(id, notification);
    }

    private static Notification.Builder newBaseNotification(Context context) {
        synchronized (sNotificationBundle) {
            if (sNotificationBundle.isEmpty()) {
+64 −68

File changed.

Preview size limit exceeded, changes collapsed.