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

Commit 0f77a1a0 authored by Ching-Sung Li's avatar Ching-Sung Li Committed by Ching Sung Li
Browse files

Load default wallpaper by device's CMF color

Load default wallpaper by device's CMF color in WallpaperManager. The
fallback is to use default wallpaper if no matching wallpaper with
corresponding CMF color.

Bug: 178161042
Test: Build ROM and manual test
Change-Id: Iea818784f05f730e3cde79e95771a84db1b39225
parent e32f0d1c
Loading
Loading
Loading
Loading
+28 −11
Original line number Original line Diff line number Diff line
@@ -57,6 +57,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Build;
import android.os.Bundle;
import android.os.Bundle;
import android.os.DeadSystemException;
import android.os.DeadSystemException;
import android.os.Environment;
import android.os.FileUtils;
import android.os.FileUtils;
import android.os.Handler;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
@@ -120,6 +121,8 @@ public class WallpaperManager {
    /** {@hide} */
    /** {@hide} */
    private static final String VALUE_CMF_COLOR =
    private static final String VALUE_CMF_COLOR =
            android.os.SystemProperties.get("ro.boot.hardware.color");
            android.os.SystemProperties.get("ro.boot.hardware.color");
    /** {@hide} */
    private static final String WALLPAPER_CMF_PATH = "/wallpaper/image/";


    /**
    /**
     * Activity Action: Show settings for choosing wallpaper. Do not use directly to construct
     * Activity Action: Show settings for choosing wallpaper. Do not use directly to construct
@@ -2066,31 +2069,45 @@ public class WallpaperManager {
            return null;
            return null;
        } else {
        } else {
            whichProp = PROP_WALLPAPER;
            whichProp = PROP_WALLPAPER;
            final int defaultColorResId = context.getResources().getIdentifier(
            defaultResId = com.android.internal.R.drawable.default_wallpaper;
                    "default_wallpaper_" + VALUE_CMF_COLOR, "drawable", "android");
            defaultResId =
                    defaultColorResId == 0 ? com.android.internal.R.drawable.default_wallpaper
                            : defaultColorResId;
        }
        }
        final String path = SystemProperties.get(whichProp);
        final String path = SystemProperties.get(whichProp);
        final InputStream wallpaperInputStream = getWallpaperInputStream(path);
        if (wallpaperInputStream != null) {
            return wallpaperInputStream;
        }
        final String cmfPath = getCmfWallpaperPath();
        final InputStream cmfWallpaperInputStream = getWallpaperInputStream(cmfPath);
        if (cmfWallpaperInputStream != null) {
            return cmfWallpaperInputStream;
        }
        try {
            return context.getResources().openRawResource(defaultResId);
        } catch (NotFoundException e) {
            // no default defined for this device; this is not a failure
        }
        return null;
    }

    private static InputStream getWallpaperInputStream(String path) {
        if (!TextUtils.isEmpty(path)) {
        if (!TextUtils.isEmpty(path)) {
            final File file = new File(path);
            final File file = new File(path);
            if (file.exists()) {
            if (file.exists()) {
                try {
                try {
                    return new FileInputStream(file);
                    return new FileInputStream(file);
                } catch (IOException e) {
                } catch (IOException e) {
                    // Ignored, fall back to platform default below
                    // Ignored, fall back to platform default
                }
                }
            }
            }
        }
        }
        try {
            return context.getResources().openRawResource(defaultResId);
        } catch (NotFoundException e) {
            // no default defined for this device; this is not a failure
        }
        return null;
        return null;
    }
    }


    private static String getCmfWallpaperPath() {
        return Environment.getProductDirectory() + WALLPAPER_CMF_PATH + "default_wallpaper_"
                + VALUE_CMF_COLOR;
    }

    /**
    /**
     * Return {@link ComponentName} of the default live wallpaper, or
     * Return {@link ComponentName} of the default live wallpaper, or
     * {@code null} if none is defined.
     * {@code null} if none is defined.