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

Commit f61bb7ed authored by d34d's avatar d34d Committed by Gerrit Code Review
Browse files

Merge "CM11 Themes: Clear wallpaper mixnmatch entry on external change" into cm-11.0

parents 5d1fc33f 64348cc4
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>();
@@ -135,6 +138,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) {
@@ -153,7 +159,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();
@@ -161,7 +167,9 @@ public class ThemeService extends IThemeService.Stub {
        }

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

@@ -245,9 +253,9 @@ public class ThemeService extends IThemeService.Stub {
        }
    }

    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 + "=?";
@@ -709,4 +717,18 @@ public class ThemeService extends IThemeService.Stub {
        if (anim.exists())
            anim.delete();
    }

    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;
            }
        }
    };
}