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

Commit 7bb802a4 authored by d34d's avatar d34d Committed by Clark Scheff
Browse files

Themes: Build icon cache when applying icons

The theme service will schedule building of the icon cache when
an icon pack is applied.  This will allow the icon cache to be
populated immediately after icons are applied rather than build
it up as icons are requested.

Change-Id: I453eda5f6298ff79e22827c622a0eddcab9c721d
parent b23bebcf
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.app.WallpaperManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
@@ -106,6 +107,7 @@ public class ThemeService extends IThemeService.Stub {
    private class ThemeWorkerHandler extends Handler {
        private static final int MESSAGE_CHANGE_THEME = 1;
        private static final int MESSAGE_APPLY_DEFAULT_THEME = 2;
        private static final int MESSAGE_BUILD_ICON_CACHE = 3;

        public ThemeWorkerHandler(Looper looper) {
            super(looper);
@@ -121,6 +123,9 @@ public class ThemeService extends IThemeService.Stub {
                case MESSAGE_APPLY_DEFAULT_THEME:
                    doApplyDefaultTheme();
                    break;
                case MESSAGE_BUILD_ICON_CACHE:
                    doBuildIconCache();
                    break;
                default:
                    Log.w(TAG, "Unknown message " + msg.what);
                    break;
@@ -266,6 +271,7 @@ public class ThemeService extends IThemeService.Stub {
            pm.updateIconMaps(null);
        } else {
            pm.updateIconMaps(pkgName);
            mHandler.sendEmptyMessage(ThemeWorkerHandler.MESSAGE_BUILD_ICON_CACHE);
        }
    }

@@ -863,4 +869,20 @@ public class ThemeService extends IThemeService.Stub {
            return (int) (lhs.lastModified() - rhs.lastModified());
        }
    };

    private void doBuildIconCache() {
        PackageManager pm = mContext.getPackageManager();
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        List<ResolveInfo> infos = pm.queryIntentActivities(mainIntent, 0);
        for(ResolveInfo info : infos) {
            try {
                pm.getActivityIcon(new ComponentName(info.activityInfo.packageName,
                        info.activityInfo.name));
            } catch (Exception e) {
                Log.w(TAG, "Unable to fetch icon for " + info, e);
            }
        }
    }
}