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

Commit 64348cc4 authored by d34d's avatar d34d
Browse files

CM11 Themes: Clear wallpaper mixnmatch entry on external change

If a wallpaper is applied from a theme and the wallpaper is changed
from an external source, the theme is still shown to have its
wallpaper applied.  This patch will clear this value out when a
wallpaper change is detected that is not from the ThemeService.

Change-Id: I3d32bb3c0ac96db3f940989bc7ad4eda5e4a71f7
parent 8fe25d01
Loading
Loading
Loading
Loading
+26 −4
Original line number Diff line number Diff line
@@ -20,10 +20,12 @@ import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.app.WallpaperManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@@ -79,6 +81,7 @@ public class ThemeService extends IThemeService.Stub {
    private Context mContext;
    private String mPkgName;
    private int mProgress;
    private boolean mWallpaperChangedByUs = false;

    private final RemoteCallbackList<IThemeChangeListener> mClients =
            new RemoteCallbackList<IThemeChangeListener>();
@@ -131,6 +134,9 @@ public class ThemeService extends IThemeService.Stub {
    }

    public void systemRunning() {
        // listen for wallpaper changes
        IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
        mContext.registerReceiver(mWallpaperChangeReceiver, filter);
    }

    private void doApplyTheme(String pkgName, List<String> components) {
@@ -149,7 +155,7 @@ public class ThemeService extends IThemeService.Stub {
        // TODO: provide progress updates that reflect the time needed for each component
        final int progressIncrement = 75 / components.size();

        updateProvider(components);
        updateProvider(components, mPkgName);

        if (components.contains(ThemesContract.ThemesColumns.MODIFIES_ICONS)) {
            updateIcons();
@@ -157,7 +163,9 @@ public class ThemeService extends IThemeService.Stub {
        }

        if (components.contains(ThemesContract.ThemesColumns.MODIFIES_LAUNCHER)) {
            updateWallpaper();
            if (updateWallpaper()) {
                mWallpaperChangedByUs = true;
            }
            incrementProgress(progressIncrement, pkgName);
        }

@@ -205,9 +213,9 @@ public class ThemeService extends IThemeService.Stub {
        postFinish(true, pkgName);
    }

    private void updateProvider(List<String> components) {
    private void updateProvider(List<String> components, String pkgName) {
        ContentValues values = new ContentValues();
        values.put(ThemesContract.MixnMatchColumns.COL_VALUE, mPkgName);
        values.put(ThemesContract.MixnMatchColumns.COL_VALUE, pkgName);

        for (String component : components) {
            String where = ThemesContract.MixnMatchColumns.COL_KEY + "=?";
@@ -698,4 +706,18 @@ public class ThemeService extends IThemeService.Stub {
            }
        }
    }

    private BroadcastReceiver mWallpaperChangeReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (!mWallpaperChangedByUs) {
                // In case the mixnmatch table has a mods_launcher entry, we'll clear it
                List<String> components = new ArrayList<String>(1);
                components.add(ThemesContract.ThemesColumns.MODIFIES_LAUNCHER);
                updateProvider(components, "");
            } else {
                mWallpaperChangedByUs = false;
            }
        }
    };
}