public void onPackagesChanged(boolean queryReplace, String[] pkgList) {
    if (DEBUG)
      Slog.d(
          TAG,
          "onPackagesChanged queryReplace="
              + queryReplace
              + " pkgList="
              + (pkgList == null ? null : Arrays.asList(pkgList))
              + " mEnabledServicesPackageNames="
              + mEnabledServicesPackageNames);
    boolean anyServicesInvolved = false;
    if (pkgList != null && (pkgList.length > 0)) {
      for (String pkgName : pkgList) {
        if (mEnabledServicesPackageNames.contains(pkgName)) {
          anyServicesInvolved = true;
        }
      }
    }

    if (anyServicesInvolved) {
      // if we're not replacing a package, clean up orphaned bits
      if (!queryReplace) {
        disableNonexistentServices();
      }
      // make sure we're still bound to any of our services who may have just upgraded
      rebindServices();
    }
  }
  /** Called by the Binder stub. */
  void dump(String[] args, PrintWriter pw) {
    synchronized (mLock) {
      final long screenOnTime = getScreenOnTimeLocked(checkAndGetTimeLocked());
      IndentingPrintWriter idpw = new IndentingPrintWriter(pw, "  ");
      ArraySet<String> argSet = new ArraySet<>();
      argSet.addAll(Arrays.asList(args));

      final int userCount = mUserState.size();
      for (int i = 0; i < userCount; i++) {
        idpw.printPair("user", mUserState.keyAt(i));
        idpw.println();
        idpw.increaseIndent();
        if (argSet.contains("--checkin")) {
          mUserState.valueAt(i).checkin(idpw, screenOnTime);
        } else {
          mUserState.valueAt(i).dump(idpw, screenOnTime);
          idpw.println();
          if (args.length > 0 && "history".equals(args[0])) {
            mAppIdleHistory.dump(idpw, mUserState.keyAt(i));
          }
        }
        idpw.decreaseIndent();
      }
      pw.write("Screen On Timebase:" + mScreenOnTime + "\n");
    }
  }
 private void performDexOptLibsLI(
     ArrayList<String> libs,
     String[] instructionSets,
     boolean forceDex,
     boolean defer,
     ArraySet<String> done) {
   for (String libName : libs) {
     PackageParser.Package libPkg = mPackageManagerService.findSharedNonSystemLibrary(libName);
     if (libPkg != null && !done.contains(libName)) {
       performDexOptLI(libPkg, instructionSets, forceDex, defer, done);
     }
   }
 }
 public void addSystemIcon(String slot, int index, int viewIndex, StatusBarIcon icon) {
   boolean blocked = mIconBlacklist.contains(slot);
   StatusBarIconView view = new StatusBarIconView(mContext, slot, null, blocked);
   view.set(icon);
   mStatusIcons.addView(
       view,
       viewIndex,
       new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, mIconSize));
   view = new StatusBarIconView(mContext, slot, null, blocked);
   view.set(icon);
   mStatusIconsKeyguard.addView(
       view,
       viewIndex,
       new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, mIconSize));
   applyIconTint();
 }
 void handleShowAppErrorUi(Message msg) {
   AppErrorDialog.Data data = (AppErrorDialog.Data) msg.obj;
   boolean showBackground =
       Settings.Secure.getInt(
               mContext.getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0)
           != 0;
   synchronized (mService) {
     ProcessRecord proc = data.proc;
     AppErrorResult res = data.result;
     if (proc != null && proc.crashDialog != null) {
       Slog.e(TAG, "App already has crash dialog: " + proc);
       if (res != null) {
         res.set(AppErrorDialog.ALREADY_SHOWING);
       }
       return;
     }
     boolean isBackground =
         (UserHandle.getAppId(proc.uid) >= Process.FIRST_APPLICATION_UID && proc.pid != MY_PID);
     for (int userId : mService.mUserController.getCurrentProfileIdsLocked()) {
       isBackground &= (proc.userId != userId);
     }
     if (isBackground && !showBackground) {
       Slog.w(TAG, "Skipping crash dialog of " + proc + ": background");
       if (res != null) {
         res.set(AppErrorDialog.BACKGROUND_USER);
       }
       return;
     }
     final boolean crashSilenced =
         mAppsNotReportingCrashes != null
             && mAppsNotReportingCrashes.contains(proc.info.packageName);
     if (mService.canShowErrorDialogs() && !crashSilenced) {
       proc.crashDialog = new AppErrorDialog(mContext, mService, data);
     } else {
       // The device is asleep, so just pretend that the user
       // saw a crash dialog and hit "force quit".
       if (res != null) {
         res.set(AppErrorDialog.CANT_SHOW);
       }
     }
   }
   // If we've created a crash dialog, show it without the lock held
   if (data.proc.crashDialog != null) {
     data.proc.crashDialog.show();
   }
 }
 public CheckEventResult checkEvent(EventInfo filter, long time) {
   final Uri.Builder uriBuilder = Instances.CONTENT_URI.buildUpon();
   ContentUris.appendId(uriBuilder, time);
   ContentUris.appendId(uriBuilder, time + EVENT_CHECK_LOOKAHEAD);
   final Uri uri = uriBuilder.build();
   final Cursor cursor =
       mUserContext
           .getContentResolver()
           .query(uri, INSTANCE_PROJECTION, null, null, INSTANCE_ORDER_BY);
   final CheckEventResult result = new CheckEventResult();
   result.recheckAt = time + EVENT_CHECK_LOOKAHEAD;
   try {
     final ArraySet<Long> primaryCalendars = getPrimaryCalendars();
     while (cursor != null && cursor.moveToNext()) {
       final long begin = cursor.getLong(0);
       final long end = cursor.getLong(1);
       final String title = cursor.getString(2);
       final boolean calendarVisible = cursor.getInt(3) == 1;
       final int eventId = cursor.getInt(4);
       final String owner = cursor.getString(5);
       final long calendarId = cursor.getLong(6);
       final int availability = cursor.getInt(7);
       final boolean calendarPrimary = primaryCalendars.contains(calendarId);
       if (DEBUG)
         Log.d(
             TAG,
             String.format(
                 "%s %s-%s v=%s a=%s eid=%s o=%s cid=%s p=%s",
                 title,
                 new Date(begin),
                 new Date(end),
                 calendarVisible,
                 availabilityToString(availability),
                 eventId,
                 owner,
                 calendarId,
                 calendarPrimary));
       final boolean meetsTime = time >= begin && time < end;
       final boolean meetsCalendar =
           calendarVisible
               && calendarPrimary
               && (filter.calendar == null || Objects.equals(filter.calendar, owner));
       final boolean meetsAvailability = availability != Instances.AVAILABILITY_FREE;
       if (meetsCalendar && meetsAvailability) {
         if (DEBUG) Log.d(TAG, "  MEETS CALENDAR & AVAILABILITY");
         final boolean meetsAttendee = meetsAttendee(filter, eventId, owner);
         if (meetsAttendee) {
           if (DEBUG) Log.d(TAG, "    MEETS ATTENDEE");
           if (meetsTime) {
             if (DEBUG) Log.d(TAG, "      MEETS TIME");
             result.inEvent = true;
           }
           if (begin > time && begin < result.recheckAt) {
             result.recheckAt = begin;
           } else if (end > time && end < result.recheckAt) {
             result.recheckAt = end;
           }
         }
       }
     }
   } finally {
     if (cursor != null) {
       cursor.close();
     }
   }
   return result;
 }