Loading packages/Shell/src/com/android/shell/BugreportProgressService.java +23 −9 Original line number Diff line number Diff line Loading @@ -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"; Loading Loading @@ -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> Loading Loading @@ -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); Loading Loading @@ -990,7 +988,7 @@ public class BugreportProgressService extends Service { Log.d(TAG, "stopProgress(" + id + "): cancel notification"); NotificationManager.from(mContext).cancel(id); cancelNotification(id); stopSelfWhenDoneLocked(); } Loading Loading @@ -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; } Loading Loading @@ -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); Loading Loading @@ -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); } /** Loading Loading @@ -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()); } /** Loading @@ -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()) { Loading packages/Shell/tests/src/com/android/shell/BugreportProgressServiceTest.java +64 −68 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
packages/Shell/src/com/android/shell/BugreportProgressService.java +23 −9 Original line number Diff line number Diff line Loading @@ -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"; Loading Loading @@ -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> Loading Loading @@ -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); Loading Loading @@ -990,7 +988,7 @@ public class BugreportProgressService extends Service { Log.d(TAG, "stopProgress(" + id + "): cancel notification"); NotificationManager.from(mContext).cancel(id); cancelNotification(id); stopSelfWhenDoneLocked(); } Loading Loading @@ -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; } Loading Loading @@ -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); Loading Loading @@ -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); } /** Loading Loading @@ -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()); } /** Loading @@ -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()) { Loading
packages/Shell/tests/src/com/android/shell/BugreportProgressServiceTest.java +64 −68 File changed.Preview size limit exceeded, changes collapsed. Show changes