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

Commit 3a287ad4 authored by Clark Scheff's avatar Clark Scheff Committed by Gerrit Code Review
Browse files

Themes: Update provider with components that were applied

There may be times when one or more components do not get applied
so we should remove them from the component map and then update
the provider after all changes have been made.

Change-Id: I75d2a674d84c6a0de3f0b613d1dfc50654c2d181
parent 12460844
Loading
Loading
Loading
Loading
+55 −24
Original line number Diff line number Diff line
@@ -173,52 +173,68 @@ public class ThemeService extends IThemeService.Stub {
        // TODO: provide progress updates that reflect the time needed for each component
        final int progressIncrement = 75 / componentMap.size();

        updateProvider(componentMap);

        if (componentMap.containsKey(ThemesColumns.MODIFIES_ICONS)) {
            updateIcons(componentMap.get(ThemesColumns.MODIFIES_ICONS));
            if (!updateIcons(componentMap.get(ThemesColumns.MODIFIES_ICONS))) {
                componentMap.remove(ThemesColumns.MODIFIES_ICONS);
            }
            incrementProgress(progressIncrement);
        }

        if (componentMap.containsKey(ThemesColumns.MODIFIES_LAUNCHER)) {
            if (updateWallpaper(componentMap.get(ThemesColumns.MODIFIES_LAUNCHER))) {
                mWallpaperChangedByUs = true;
            } else {
                componentMap.remove(ThemesColumns.MODIFIES_LAUNCHER);
            }
            incrementProgress(progressIncrement);
        }

        if (componentMap.containsKey(ThemesColumns.MODIFIES_LOCKSCREEN)) {
            updateLockscreen(componentMap.get(ThemesColumns.MODIFIES_LOCKSCREEN));
            if (!updateLockscreen(componentMap.get(ThemesColumns.MODIFIES_LOCKSCREEN))) {
                componentMap.remove(ThemesColumns.MODIFIES_LOCKSCREEN);
            }
            incrementProgress(progressIncrement);
        }

        if (componentMap.containsKey(ThemesColumns.MODIFIES_NOTIFICATIONS)) {
            updateNotifications(componentMap.get(ThemesColumns.MODIFIES_NOTIFICATIONS));
            if (!updateNotifications(componentMap.get(ThemesColumns.MODIFIES_NOTIFICATIONS))) {
                componentMap.remove(ThemesColumns.MODIFIES_NOTIFICATIONS);
            }
            incrementProgress(progressIncrement);
        }

        Environment.setUserRequired(false);
        if (componentMap.containsKey(ThemesColumns.MODIFIES_ALARMS)) {
            updateAlarms(componentMap.get(ThemesColumns.MODIFIES_ALARMS));
            if (!updateAlarms(componentMap.get(ThemesColumns.MODIFIES_ALARMS))) {
                componentMap.remove(ThemesColumns.MODIFIES_ALARMS);
            }
            incrementProgress(progressIncrement);
        }

        if (componentMap.containsKey(ThemesColumns.MODIFIES_RINGTONES)) {
            updateRingtones(componentMap.get(ThemesColumns.MODIFIES_RINGTONES));
            if (!updateRingtones(componentMap.get(ThemesColumns.MODIFIES_RINGTONES))) {
                componentMap.remove(ThemesColumns.MODIFIES_RINGTONES);
            }
            incrementProgress(progressIncrement);
        }

        if (componentMap.containsKey(ThemesColumns.MODIFIES_BOOT_ANIM)) {
            updateBootAnim(componentMap.get(ThemesColumns.MODIFIES_BOOT_ANIM));
            if (!updateBootAnim(componentMap.get(ThemesColumns.MODIFIES_BOOT_ANIM))) {
                componentMap.remove(ThemesColumns.MODIFIES_BOOT_ANIM);
            }
            incrementProgress(progressIncrement);
        }
        Environment.setUserRequired(true);

        if (componentMap.containsKey(ThemesColumns.MODIFIES_FONTS)) {
            updateFonts(componentMap.get(ThemesColumns.MODIFIES_FONTS));
            if (!updateFonts(componentMap.get(ThemesColumns.MODIFIES_FONTS))) {
                componentMap.remove(ThemesColumns.MODIFIES_FONTS);
            }
            incrementProgress(progressIncrement);
        }

        updateProvider(componentMap);

        updateConfiguration(componentMap);

        killLaunchers(componentMap);
@@ -268,7 +284,8 @@ public class ThemeService extends IThemeService.Stub {
        }
    }

    private void updateIcons(String pkgName) {
    private boolean updateIcons(String pkgName) {
        try {
            PackageManager pm = mContext.getPackageManager();
            if (pkgName.equals(HOLO_DEFAULT)) {
                pm.updateIconMaps(null);
@@ -276,6 +293,11 @@ public class ThemeService extends IThemeService.Stub {
                pm.updateIconMaps(pkgName);
                mHandler.sendEmptyMessage(ThemeWorkerHandler.MESSAGE_BUILD_ICON_CACHE);
            }
        } catch (Exception e) {
            Log.w(TAG, "Changing icons failed", e);
            return false;
        }
        return true;
    }

    private boolean updateFonts(String pkgName) {
@@ -325,9 +347,11 @@ public class ThemeService extends IThemeService.Stub {
        return true;
    }

    private void updateBootAnim(String pkgName) {
    private boolean updateBootAnim(String pkgName) {
        if (HOLO_DEFAULT.equals(pkgName)) {
            clearBootAnimation();
        if (HOLO_DEFAULT.equals(pkgName)) return;
            return true;
        }

        PackageManager pm = mContext.getPackageManager();
        try {
@@ -335,7 +359,9 @@ public class ThemeService extends IThemeService.Stub {
            applyBootAnimation(ai.sourceDir);
        } catch (PackageManager.NameNotFoundException e) {
            Log.w(TAG, "Changing boot animation failed", e);
            return false;
        }
        return true;
    }

    private boolean updateAlarms(String pkgName) {
@@ -465,7 +491,7 @@ public class ThemeService extends IThemeService.Stub {
    }

    private boolean updateLockscreen(String pkgName) {
        boolean success = false;
        boolean success;
        success = setCustomLockScreenWallpaper(pkgName);

        if (success) {
@@ -507,9 +533,9 @@ public class ThemeService extends IThemeService.Stub {
    }

    private boolean updateWallpaper(String pkgName) {
        String selection = ThemesContract.ThemesColumns.PKG_NAME + "= ?";
        String selection = ThemesColumns.PKG_NAME + "= ?";
        String[] selectionArgs = { pkgName };
        Cursor c = mContext.getContentResolver().query(ThemesContract.MixnMatchColumns.CONTENT_URI,
        Cursor c = mContext.getContentResolver().query(ThemesColumns.CONTENT_URI,
                null, selection,
                selectionArgs, null);
        c.moveToFirst();
@@ -519,12 +545,16 @@ public class ThemeService extends IThemeService.Stub {
                wm.clear();
            } catch (IOException e) {
                return false;
            } finally {
                c.close();
            }
        } else if (TextUtils.isEmpty(pkgName)) {
            try {
                wm.clear(false);
            } catch (IOException e) {
                return false;
            } finally {
                c.close();
            }
        } else {
            InputStream in = null;
@@ -532,10 +562,10 @@ public class ThemeService extends IThemeService.Stub {
                Context themeContext = mContext.createPackageContext(pkgName,
                        Context.CONTEXT_IGNORE_SECURITY);
                boolean isLegacyTheme = c.getInt(
                        c.getColumnIndex(ThemesContract.ThemesColumns.IS_LEGACY_THEME)) == 1;
                        c.getColumnIndex(ThemesColumns.IS_LEGACY_THEME)) == 1;
                if (!isLegacyTheme) {
                    String wallpaper = c.getString(
                            c.getColumnIndex(ThemesContract.ThemesColumns.WALLPAPER_URI));
                                c.getColumnIndex(ThemesColumns.WALLPAPER_URI));
                    if (wallpaper != null) {
                        if (URLUtil.isAssetUrl(wallpaper)) {
                            in = ThemeUtils.getInputStreamFromAsset(themeContext, wallpaper);
@@ -573,6 +603,7 @@ public class ThemeService extends IThemeService.Stub {
                return false;
            } finally {
                ThemeUtils.closeQuietly(in);
                c.close();
            }
        }
        return true;