File tree Expand file tree Collapse file tree
app/src/main/java/io/github/muntashirakon/AppManager Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5050import io .github .muntashirakon .AppManager .self .SelfPermissions ;
5151import io .github .muntashirakon .AppManager .utils .ContextUtils ;
5252import io .github .muntashirakon .AppManager .utils .ExUtils ;
53+ import io .github .muntashirakon .AppManager .utils .Utils ;
5354import io .github .muntashirakon .proc .ProcFs ;
5455import io .github .muntashirakon .proc .ProcUidNetStat ;
5556
@@ -319,6 +320,10 @@ private List<PackageUsageInfo> getUsageStatsInternal(@UsageUtils.IntervalType in
319320 for (UsageEvents .Event event : events ) {
320321 int eventType = event .getEventType ();
321322 String packageName = event .getPackageName ();
323+ if (packageName == null ) {
324+ Log .i (TAG , "Ignored event with empty package name: " + Utils .prettyPrintObject (event ));
325+ continue ;
326+ }
322327 // Queries are sorted in descending order, so a not-running activity should be paused or
323328 // stopped first and then resumed (i.e., reversed logic).
324329 if (eventType == UsageEvents .Event .DEVICE_SHUTDOWN ) {
Original file line number Diff line number Diff line change 3939
4040import org .jetbrains .annotations .Contract ;
4141
42+ import java .lang .reflect .Field ;
4243import java .nio .ByteBuffer ;
4344import java .nio .CharBuffer ;
4445import java .nio .charset .StandardCharsets ;
@@ -673,6 +674,34 @@ public static boolean isWifiActive(@NonNull Context context) {
673674 return info != null && info .getType () == ConnectivityManager .TYPE_WIFI ;
674675 }
675676
677+ @ NonNull
678+ public static <T > String prettyPrintObject (@ Nullable T obj ) {
679+ if (obj == null ) {
680+ return "null" ;
681+ }
682+ StringBuilder sb = new StringBuilder ();
683+ Class <?> clazz = obj .getClass ();
684+ sb .append (clazz .getSimpleName ()).append ("{" );
685+ Field [] fields = clazz .getDeclaredFields ();
686+ for (int i = 0 ; i < fields .length ; i ++) {
687+ Field field = fields [i ];
688+ field .setAccessible (true );
689+ sb .append (field .getName ()).append ("=" );
690+ try {
691+ Object value = field .get (obj );
692+ sb .append (value );
693+ } catch (IllegalAccessException e ) {
694+ sb .append ("N/A" );
695+ }
696+ if (i < fields .length - 1 ) {
697+ sb .append (", " );
698+ }
699+ }
700+ sb .append ("}" );
701+ return sb .toString ();
702+ }
703+
704+
676705 public static boolean isRoboUnitTest () {
677706 return "robolectric" .equals (Build .FINGERPRINT );
678707 }
You can’t perform that action at this time.
0 commit comments