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

Commit d7faf536 authored by Christopher Tate's avatar Christopher Tate
Browse files

Don't back up wallpapers that we've been told not to

In addition, now that the full uncropped wallpaper image is being
backed up, we now handle that via the full-data backup path instead
of key/value.  Restore still knows about legacy data that gets
delivered via the older key/value mechanism.

This change also has the effect of removing the size limitations
around wallpaper restore acceptance.  Any size source imagery is
valid, as crop & scale are rerun in a device-appropriate way
after the restore.

Bug 25453848
Bug 25727875

Change-Id: Idc64a2eaab97a8ecc9d2b8ca5dc011f29cab324d
parent 66e640d8
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -43,7 +43,8 @@ interface IWallpaperManager {
     * new wallpaper content is ready to display.
     */
    ParcelFileDescriptor setWallpaper(String name, in String callingPackage,
            in Rect cropHint, out Bundle extras, int which, IWallpaperManagerCallback completion);
            in Rect cropHint, boolean allowBackup, out Bundle extras, int which,
            IWallpaperManagerCallback completion);

    /**
     * Set the live wallpaper. This only affects the system wallpaper.
@@ -124,6 +125,11 @@ interface IWallpaperManager {
     */
    boolean isWallpaperSettingAllowed(in String callingPackage);

    /*
     * Backup: is the current system wallpaper image eligible for off-device backup?
     */
    boolean isWallpaperBackupEligible(int userId);

    /*
     * Keyguard: register a callback for being notified that lock-state relevant
     * wallpaper content has changed.
+25 −4
Original line number Diff line number Diff line
/*
h * Copyright (C) 2009 The Android Open Source Project
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -875,7 +875,7 @@ public class WallpaperManager {
            /* Set the wallpaper to the default values */
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(
                    "res:" + resources.getResourceName(resid),
                    mContext.getOpPackageName(), null, result, which, completion);
                    mContext.getOpPackageName(), null, false, result, which, completion);
            if (fd != null) {
                FileOutputStream fos = null;
                boolean ok = false;
@@ -985,7 +985,8 @@ public class WallpaperManager {
        final WallpaperSetCompletion completion = new WallpaperSetCompletion();
        try {
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null,
                    mContext.getOpPackageName(), visibleCropHint, result, which, completion);
                    mContext.getOpPackageName(), visibleCropHint, allowBackup,
                    result, which, completion);
            if (fd != null) {
                FileOutputStream fos = null;
                try {
@@ -1102,7 +1103,8 @@ public class WallpaperManager {
        final WallpaperSetCompletion completion = new WallpaperSetCompletion();
        try {
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null,
                    mContext.getOpPackageName(), visibleCropHint, result, which, completion);
                    mContext.getOpPackageName(), visibleCropHint, allowBackup,
                    result, which, completion);
            if (fd != null) {
                FileOutputStream fos = null;
                try {
@@ -1565,6 +1567,25 @@ public class WallpaperManager {
        }
    }

    /**
     * Is the current system wallpaper eligible for backup?
     *
     * Only the OS itself may use this method.
     * @hide
     */
    public boolean isWallpaperBackupEligible() {
        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
            return false;
        }
        try {
            return sGlobals.mService.isWallpaperBackupEligible(mContext.getUserId());
        } catch (RemoteException e) {
            Log.e(TAG, "Exception querying wallpaper backup eligibility: " + e.getMessage());
        }
        return false;
    }

    // Private completion callback for setWallpaper() synchronization
    private class WallpaperSetCompletion extends IWallpaperManagerCallback.Stub {
        final CountDownLatch mLatch;
+4 −34
Original line number Diff line number Diff line
@@ -76,26 +76,6 @@ public class SystemBackupAgent extends BackupAgentHelper {
    @Override
    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
            ParcelFileDescriptor newState) throws IOException {
        // We only back up the data under the current "wallpaper" schema with metadata
        IWallpaperManager wallpaper = (IWallpaperManager)ServiceManager.getService(
                Context.WALLPAPER_SERVICE);
        String[] files = new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO };
        String[] keys = new String[] { WALLPAPER_IMAGE_KEY, WALLPAPER_INFO_KEY };
        if (wallpaper != null) {
            try {
                final String wallpaperName = wallpaper.getName();
                if (wallpaperName != null && wallpaperName.length() > 0) {
                    // When the wallpaper has a name, back up the info by itself.
                    // TODO: Don't rely on the innards of the service object like this!
                    // TODO: Send a delete for any stored wallpaper image in this case?
                    files = new String[] { WALLPAPER_INFO };
                    keys = new String[] { WALLPAPER_INFO_KEY };
                }
            } catch (RemoteException re) {
                Slog.e(TAG, "Couldn't get wallpaper name\n" + re);
            }
        }
        addHelper(WALLPAPER_HELPER, new WallpaperBackupHelper(this, files, keys));
        addHelper(SYNC_SETTINGS_HELPER, new AccountSyncSettingsBackupHelper(this));
        addHelper(PREFERRED_HELPER, new PreferredActivityBackupHelper());
        addHelper(NOTIFICATION_HELPER, new NotificationBackupHelper(this));
@@ -107,30 +87,20 @@ public class SystemBackupAgent extends BackupAgentHelper {

    @Override
    public void onFullBackup(FullBackupDataOutput data) throws IOException {
        // At present we back up only the wallpaper
        fullWallpaperBackup(data);
    }

    private void fullWallpaperBackup(FullBackupDataOutput output) {
        // Back up the data files directly.  We do them in this specific order --
        // info file followed by image -- because then we need take no special
        // steps during restore; the restore will happen properly when the individual
        // files are restored piecemeal.
        FullBackup.backupToTar(getPackageName(), FullBackup.ROOT_TREE_TOKEN, null,
                WALLPAPER_INFO_DIR, WALLPAPER_INFO, output);
        FullBackup.backupToTar(getPackageName(), FullBackup.ROOT_TREE_TOKEN, null,
                WALLPAPER_IMAGE_DIR, WALLPAPER_IMAGE, output);
        // At present we don't back up anything
    }

    @Override
    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
            throws IOException {
        // Slot in a restore helper for the older wallpaper backup schema to support restore
        // from devices still generating data in that format.
        mWallpaperHelper = new WallpaperBackupHelper(this,
                new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO },
                new String[] { WALLPAPER_IMAGE_KEY, WALLPAPER_INFO_KEY} );
        addHelper(WALLPAPER_HELPER, mWallpaperHelper);

        // On restore, we also support a previous data schema "system_files"
        // On restore, we also support a long-ago wallpaper data schema "system_files"
        addHelper("system_files", new WallpaperBackupHelper(this,
                new String[] { WALLPAPER_IMAGE },
                new String[] { WALLPAPER_IMAGE_KEY} ));
+34 −0
Original line number Diff line number Diff line
#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PROGUARD_FLAG_FILES := proguard.flags

LOCAL_PACKAGE_NAME := WallpaperBackup
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := false

include $(BUILD_PACKAGE)

########################
include $(call all-makefiles-under,$(LOCAL_PATH))
+30 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
 * Copyright (c) 2016 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.wallpaperbackup"
    android:sharedUserId="android.uid.system" >

    <application android:allowClearUserData="false"
                 android:process="system"
                 android:killAfterRestore="false"
                 android:allowBackup="true"
                 android:backupAgent=".WallpaperBackupAgent"
                 android:fullBackupOnly="true" >
    </application>
</manifest>
Loading