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

Commit 665189f9 authored by Chris Tate's avatar Chris Tate Committed by Android (Google) Code Review
Browse files

Merge "Don't back up wallpapers that we've been told not to" into nyc-dev

parents 129c01af d7faf536
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -43,7 +43,8 @@ interface IWallpaperManager {
     * new wallpaper content is ready to display.
     * new wallpaper content is ready to display.
     */
     */
    ParcelFileDescriptor setWallpaper(String name, in String callingPackage,
    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.
     * Set the live wallpaper. This only affects the system wallpaper.
@@ -124,6 +125,11 @@ interface IWallpaperManager {
     */
     */
    boolean isWallpaperSettingAllowed(in String callingPackage);
    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
     * Keyguard: register a callback for being notified that lock-state relevant
     * wallpaper content has changed.
     * wallpaper content has changed.
+25 −4
Original line number Original line 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");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with 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 */
            /* Set the wallpaper to the default values */
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(
                    "res:" + resources.getResourceName(resid),
                    "res:" + resources.getResourceName(resid),
                    mContext.getOpPackageName(), null, result, which, completion);
                    mContext.getOpPackageName(), null, false, result, which, completion);
            if (fd != null) {
            if (fd != null) {
                FileOutputStream fos = null;
                FileOutputStream fos = null;
                boolean ok = false;
                boolean ok = false;
@@ -985,7 +985,8 @@ public class WallpaperManager {
        final WallpaperSetCompletion completion = new WallpaperSetCompletion();
        final WallpaperSetCompletion completion = new WallpaperSetCompletion();
        try {
        try {
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null,
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null,
                    mContext.getOpPackageName(), visibleCropHint, result, which, completion);
                    mContext.getOpPackageName(), visibleCropHint, allowBackup,
                    result, which, completion);
            if (fd != null) {
            if (fd != null) {
                FileOutputStream fos = null;
                FileOutputStream fos = null;
                try {
                try {
@@ -1102,7 +1103,8 @@ public class WallpaperManager {
        final WallpaperSetCompletion completion = new WallpaperSetCompletion();
        final WallpaperSetCompletion completion = new WallpaperSetCompletion();
        try {
        try {
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null,
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null,
                    mContext.getOpPackageName(), visibleCropHint, result, which, completion);
                    mContext.getOpPackageName(), visibleCropHint, allowBackup,
                    result, which, completion);
            if (fd != null) {
            if (fd != null) {
                FileOutputStream fos = null;
                FileOutputStream fos = null;
                try {
                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 completion callback for setWallpaper() synchronization
    private class WallpaperSetCompletion extends IWallpaperManagerCallback.Stub {
    private class WallpaperSetCompletion extends IWallpaperManagerCallback.Stub {
        final CountDownLatch mLatch;
        final CountDownLatch mLatch;
+4 −34
Original line number Original line Diff line number Diff line
@@ -76,26 +76,6 @@ public class SystemBackupAgent extends BackupAgentHelper {
    @Override
    @Override
    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
            ParcelFileDescriptor newState) throws IOException {
            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(SYNC_SETTINGS_HELPER, new AccountSyncSettingsBackupHelper(this));
        addHelper(PREFERRED_HELPER, new PreferredActivityBackupHelper());
        addHelper(PREFERRED_HELPER, new PreferredActivityBackupHelper());
        addHelper(NOTIFICATION_HELPER, new NotificationBackupHelper(this));
        addHelper(NOTIFICATION_HELPER, new NotificationBackupHelper(this));
@@ -107,30 +87,20 @@ public class SystemBackupAgent extends BackupAgentHelper {


    @Override
    @Override
    public void onFullBackup(FullBackupDataOutput data) throws IOException {
    public void onFullBackup(FullBackupDataOutput data) throws IOException {
        // At present we back up only the wallpaper
        // At present we don't back up anything
        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);
    }
    }


    @Override
    @Override
    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
            throws IOException {
            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,
        mWallpaperHelper = new WallpaperBackupHelper(this,
                new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO },
                new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO },
                new String[] { WALLPAPER_IMAGE_KEY, WALLPAPER_INFO_KEY} );
                new String[] { WALLPAPER_IMAGE_KEY, WALLPAPER_INFO_KEY} );
        addHelper(WALLPAPER_HELPER, mWallpaperHelper);
        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,
        addHelper("system_files", new WallpaperBackupHelper(this,
                new String[] { WALLPAPER_IMAGE },
                new String[] { WALLPAPER_IMAGE },
                new String[] { WALLPAPER_IMAGE_KEY} ));
                new String[] { WALLPAPER_IMAGE_KEY} ));
+34 −0
Original line number Original line 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 Original line 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