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

Commit 5662dd83 authored by Felipe Leme's avatar Felipe Leme Committed by Android (Google) Code Review
Browse files

Merge "Refactoring: pulled ServiceHandler methods to its parent class."

parents 34e284ac 923afa9f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -39,4 +39,7 @@
    <!-- Toast message sent when the bugreport file could be read. -->
    <string name="bugreport_unreadable_text">Bug report file could not be read</string>

    <!-- Title for bug reports received from dumpstate without a name. [CHAR LIMIT=30]-->
    <string name="bugreport_unnamed">unnamed</string>

</resources>
+163 −153
Original line number Diff line number Diff line
@@ -180,13 +180,13 @@ public class BugreportProgressService extends Service {
    private final class ServiceHandler extends Handler {
        public ServiceHandler(Looper looper) {
            super(looper);
            pollProgress();
            poll();
        }

        @Override
        public void handleMessage(Message msg) {
            if (msg.what == MSG_POLL) {
                pollProgress();
                poll();
                return;
            }

@@ -243,6 +243,14 @@ public class BugreportProgressService extends Service {

        }

        private void poll() {
            if (pollProgress()) {
                // Keep polling...
                sendEmptyMessageDelayed(MSG_POLL, POLLING_FREQUENCY);
            }
        }
    }

    /**
     * Creates the {@link BugreportInfo} for a process and issue a system notification to
     * indicate its progress.
@@ -252,7 +260,6 @@ public class BugreportProgressService extends Service {
    private boolean startProgress(String name, int pid, int max) {
        if (name == null) {
            Log.w(TAG, "Missing " + EXTRA_NAME + " on start intent");
                name = "N/A";
        }
        if (pid == -1) {
            Log.e(TAG, "Missing " + EXTRA_PID + " on start intent");
@@ -279,7 +286,7 @@ public class BugreportProgressService extends Service {
     * Updates the system notification for a given bug report.
     */
    private void updateProgress(BugreportInfo info) {
            if (info.max <= 0 || info.progress < 0 || info.name == null) {
        if (info.max <= 0 || info.progress < 0) {
            Log.e(TAG, "Invalid progress values for " + info);
            return;
        }
@@ -299,11 +306,14 @@ public class BugreportProgressService extends Service {
                        PendingIntent.FLAG_CANCEL_CURRENT)).build();

        final String title = context.getString(R.string.bugreport_in_progress_title);
        final String name =
                info.name != null ? info.name : context.getString(R.string.bugreport_unnamed);

        final Notification notification = new Notification.Builder(context)
                .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb)
                .setContentTitle(title)
                .setTicker(title)
                    .setContentText(info.name)
                .setContentText(name)
                .setContentInfo(percentText)
                .setProgress(info.max, info.progress, false)
                .setOngoing(true)
@@ -348,8 +358,10 @@ public class BugreportProgressService extends Service {

    /**
     * Poll {@link SystemProperties} to get the progress on each monitored process.
     *
     * @return whether it should keep polling.
     */
        private void pollProgress() {
    private boolean pollProgress() {
        synchronized (mProcesses) {
            if (mProcesses.size() == 0) {
                Log.d(TAG, "No process to poll progress.");
@@ -389,8 +401,7 @@ public class BugreportProgressService extends Service {
                    }
                }
            }
                // Keep polling...
                sendEmptyMessageDelayed(MSG_POLL, POLLING_FREQUENCY);
            return true;
        }
    }

@@ -418,7 +429,6 @@ public class BugreportProgressService extends Service {
            triggerLocalNotification(context, pid, bugreportFile, screenshotFile);
        }
    }
    }

    /**
     * Responsible for triggering a notification that allows the user to start a "share" intent with