/** * Remove a pre-loaded icon from the persistent icon cache. * * @param componentName the component that should own the icon */ public void deletePreloadedIcon(ComponentName componentName, UserHandleCompat user) { // We don't keep icons for other profiles in persistent cache. if (!user.equals(UserHandleCompat.myUserHandle()) || componentName == null) { return; } remove(componentName, user); boolean success = mContext.deleteFile(getResourceFilename(componentName)); if (DEBUG && success) Log.d(TAG, "removed pre-loaded icon from persistent cache"); }
private void pushSessionBadgeToLauncher(int sessionId) { SessionInfo session = mInstaller.getSessionInfo(sessionId); if (session != null) { addSessionInfoToCahce(session, UserHandleCompat.myUserHandle()); if (session.getAppPackageName() != null) { mPendingBadgeUpdates.add(session.getAppPackageName()); } mPendingReplays.put(sessionId, session); replayUpdates(null); } }
@Override public HashSet<String> updateAndGetActiveSessionCache() { HashSet<String> activePackages = new HashSet<String>(); UserHandleCompat user = UserHandleCompat.myUserHandle(); for (SessionInfo info : mInstaller.getAllSessions()) { addSessionInfoToCahce(info, user); if (info.getAppPackageName() != null) { activePackages.add(info.getAppPackageName()); } } return activePackages; }
public IconCache(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); mContext = context; mPackageManager = context.getPackageManager(); mUserManager = UserManagerCompat.getInstance(mContext); // mLauncherApps = LauncherAppsCompat.getInstance(mContext); mIconDpi = activityManager.getLauncherLargeIconDensity(); // need to set mIconDpi before getting default icon UserHandleCompat myUser = UserHandleCompat.myUserHandle(); mDefaultIcons.put(myUser, makeDefaultIcon(myUser)); }
/** * Read a pre-loaded icon from the persistent icon cache. * * @param componentName the component that should own the icon * @returns a bitmap if one is cached, or null. */ private Bitmap getPreloadedIcon(ComponentName componentName, UserHandleCompat user) { final String key = componentName.flattenToShortString(); // We don't keep icons for other profiles in persistent cache. if (!user.equals(UserHandleCompat.myUserHandle())) { return null; } if (DEBUG) Log.v(TAG, "looking for pre-load icon for " + key); Bitmap icon = null; FileInputStream resourceFile = null; try { resourceFile = mContext.openFileInput(getResourceFilename(componentName)); byte[] buffer = new byte[1024]; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); int bytesRead = 0; while (bytesRead >= 0) { bytes.write(buffer, 0, bytesRead); bytesRead = resourceFile.read(buffer, 0, buffer.length); } if (DEBUG) Log.d(TAG, "read " + bytes.size()); icon = BitmapFactory.decodeByteArray(bytes.toByteArray(), 0, bytes.size()); if (icon == null) { Log.w(TAG, "failed to decode pre-load icon for " + key); } } catch (FileNotFoundException e) { if (DEBUG) Log.d(TAG, "there is no restored icon for: " + key); } catch (IOException e) { Log.w(TAG, "failed to read pre-load icon for: " + key, e); } finally { if (resourceFile != null) { try { resourceFile.close(); } catch (IOException e) { Log.d(TAG, "failed to manage pre-load icon file: " + key, e); } } } return icon; }
public UserHandleCompat getUser() { return UserHandleCompat.myUserHandle(); }
public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); final UserHandleCompat user = UserHandleCompat.myUserHandle(); if (Intent.ACTION_PACKAGE_CHANGED.equals(action) || Intent.ACTION_PACKAGE_REMOVED.equals(action) || Intent.ACTION_PACKAGE_ADDED.equals(action)) { final String packageName = intent.getData().getSchemeSpecificPart(); final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); if (packageName == null || packageName.length() == 0) { // they sent us a bad intent return; } if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) { for (OnAppsChangedCallbackCompat callback : getCallbacks()) { callback.onPackageChanged(packageName, user); } } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) { if (!replacing) { for (OnAppsChangedCallbackCompat callback : getCallbacks()) { callback.onPackageRemoved(packageName, user); } } // else, we are replacing the package, so a PACKAGE_ADDED will be sent // later, we will update the package at this time } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) { if (!replacing) { for (OnAppsChangedCallbackCompat callback : getCallbacks()) { callback.onPackageAdded(packageName, user); } } else { for (OnAppsChangedCallbackCompat callback : getCallbacks()) { callback.onPackageChanged(packageName, user); } } } } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) { // EXTRA_REPLACING is available Kitkat onwards. For lower devices, it is broadcasted // when moving a package or mounting/un-mounting external storage. Assume that // it is a replacing operation. final boolean replacing = intent.getBooleanExtra( Intent.EXTRA_REPLACING, Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT); String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST); for (OnAppsChangedCallbackCompat callback : getCallbacks()) { callback.onPackagesAvailable(packages, user, replacing); } } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) { // This intent is broadcasted when moving a package or mounting/un-mounting // external storage. // However on Kitkat this is also sent when a package is being updated, and // contains an extra Intent.EXTRA_REPLACING=true for that case. // Using false as default for Intent.EXTRA_REPLACING gives correct value on // lower devices as the intent is not sent when the app is updating/replacing. final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST); for (OnAppsChangedCallbackCompat callback : getCallbacks()) { callback.onPackagesUnavailable(packages, user, replacing); } } }