2009-03-03 19:31:44 -08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.server;
|
|
|
|
|
|
|
|
import static android.os.ParcelFileDescriptor.*;
|
2009-06-24 17:29:38 -07:00
|
|
|
|
2012-09-15 19:33:48 -07:00
|
|
|
import android.app.ActivityManagerNative;
|
2012-08-28 22:17:23 -07:00
|
|
|
import android.app.AppGlobals;
|
2012-09-15 19:33:48 -07:00
|
|
|
import android.app.IUserSwitchObserver;
|
2009-08-05 21:29:42 -07:00
|
|
|
import android.app.IWallpaperManager;
|
|
|
|
import android.app.IWallpaperManagerCallback;
|
2009-09-03 00:18:47 -07:00
|
|
|
import android.app.PendingIntent;
|
2009-09-07 00:49:58 -07:00
|
|
|
import android.app.WallpaperInfo;
|
2010-03-05 15:46:30 -08:00
|
|
|
import android.app.backup.BackupManager;
|
2012-02-06 12:04:42 -08:00
|
|
|
import android.app.backup.WallpaperBackupHelper;
|
2012-03-22 16:16:17 -07:00
|
|
|
import android.content.BroadcastReceiver;
|
2009-08-08 20:40:27 -07:00
|
|
|
import android.content.ComponentName;
|
2009-03-03 19:31:44 -08:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2012-03-22 16:16:17 -07:00
|
|
|
import android.content.IntentFilter;
|
2009-08-08 20:40:27 -07:00
|
|
|
import android.content.ServiceConnection;
|
2012-08-28 22:17:23 -07:00
|
|
|
import android.content.pm.IPackageManager;
|
2009-03-03 19:31:44 -08:00
|
|
|
import android.content.pm.PackageManager;
|
2009-08-08 20:40:27 -07:00
|
|
|
import android.content.pm.ResolveInfo;
|
|
|
|
import android.content.pm.ServiceInfo;
|
2009-07-28 18:24:51 -07:00
|
|
|
import android.content.pm.PackageManager.NameNotFoundException;
|
2012-10-04 14:55:42 -07:00
|
|
|
import android.content.pm.UserInfo;
|
2009-07-28 18:24:51 -07:00
|
|
|
import android.content.res.Resources;
|
2009-03-03 19:31:44 -08:00
|
|
|
import android.os.Binder;
|
2009-08-28 10:34:25 -07:00
|
|
|
import android.os.Bundle;
|
2012-03-22 16:16:17 -07:00
|
|
|
import android.os.Environment;
|
2010-10-15 12:54:40 -07:00
|
|
|
import android.os.FileUtils;
|
2009-08-08 20:40:27 -07:00
|
|
|
import android.os.IBinder;
|
2012-09-15 19:33:48 -07:00
|
|
|
import android.os.IRemoteCallback;
|
2009-03-03 19:31:44 -08:00
|
|
|
import android.os.RemoteException;
|
|
|
|
import android.os.FileObserver;
|
|
|
|
import android.os.ParcelFileDescriptor;
|
|
|
|
import android.os.RemoteCallbackList;
|
2012-07-05 06:41:43 -04:00
|
|
|
import android.os.SELinux;
|
2009-08-08 20:40:27 -07:00
|
|
|
import android.os.ServiceManager;
|
2009-08-13 18:51:59 -07:00
|
|
|
import android.os.SystemClock;
|
2012-08-16 10:48:27 -07:00
|
|
|
import android.os.UserHandle;
|
2012-10-04 14:55:42 -07:00
|
|
|
import android.os.UserManager;
|
2009-08-08 20:40:27 -07:00
|
|
|
import android.service.wallpaper.IWallpaperConnection;
|
|
|
|
import android.service.wallpaper.IWallpaperEngine;
|
|
|
|
import android.service.wallpaper.IWallpaperService;
|
|
|
|
import android.service.wallpaper.WallpaperService;
|
2010-02-26 18:56:32 -08:00
|
|
|
import android.util.Slog;
|
2012-02-06 12:04:42 -08:00
|
|
|
import android.util.SparseArray;
|
2009-07-28 18:24:51 -07:00
|
|
|
import android.util.Xml;
|
2011-04-20 18:18:51 -07:00
|
|
|
import android.view.Display;
|
2009-08-08 20:40:27 -07:00
|
|
|
import android.view.IWindowManager;
|
|
|
|
import android.view.WindowManager;
|
2009-03-03 19:31:44 -08:00
|
|
|
|
2009-09-07 00:49:58 -07:00
|
|
|
import java.io.FileDescriptor;
|
2009-07-28 18:24:51 -07:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2009-03-03 19:31:44 -08:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileNotFoundException;
|
2009-07-28 18:24:51 -07:00
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileOutputStream;
|
2009-09-07 00:49:58 -07:00
|
|
|
import java.io.PrintWriter;
|
2009-08-08 20:40:27 -07:00
|
|
|
import java.util.List;
|
2009-07-28 18:24:51 -07:00
|
|
|
|
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
|
|
import org.xmlpull.v1.XmlSerializer;
|
|
|
|
|
2010-02-19 17:02:21 -08:00
|
|
|
import com.android.internal.content.PackageMonitor;
|
2010-02-24 19:54:22 -08:00
|
|
|
import com.android.internal.util.FastXmlSerializer;
|
2010-03-18 22:47:17 -07:00
|
|
|
import com.android.internal.util.JournaledFile;
|
2009-03-03 19:31:44 -08:00
|
|
|
|
2009-08-05 21:29:42 -07:00
|
|
|
class WallpaperManagerService extends IWallpaperManager.Stub {
|
2009-08-08 20:40:27 -07:00
|
|
|
static final String TAG = "WallpaperService";
|
2009-08-18 18:29:09 -07:00
|
|
|
static final boolean DEBUG = false;
|
2009-07-28 18:24:51 -07:00
|
|
|
|
2011-08-24 17:06:58 -07:00
|
|
|
final Object mLock = new Object[0];
|
2009-03-03 19:31:44 -08:00
|
|
|
|
2009-08-13 18:51:59 -07:00
|
|
|
/**
|
|
|
|
* Minimum time between crashes of a wallpaper service for us to consider
|
|
|
|
* restarting it vs. just reverting to the static wallpaper.
|
|
|
|
*/
|
|
|
|
static final long MIN_WALLPAPER_CRASH_TIME = 10000;
|
|
|
|
static final String WALLPAPER = "wallpaper";
|
2012-02-06 12:04:42 -08:00
|
|
|
static final String WALLPAPER_INFO = "wallpaper_info.xml";
|
2009-07-28 18:24:51 -07:00
|
|
|
|
2012-10-05 11:06:53 -07:00
|
|
|
/**
|
|
|
|
* Name of the component used to display bitmap wallpapers from either the gallery or
|
|
|
|
* built-in wallpapers.
|
|
|
|
*/
|
|
|
|
static final ComponentName IMAGE_WALLPAPER = new ComponentName("com.android.systemui",
|
|
|
|
"com.android.systemui.ImageWallpaper");
|
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
/**
|
|
|
|
* Observes the wallpaper for changes and notifies all IWallpaperServiceCallbacks
|
|
|
|
* that the wallpaper has changed. The CREATE is triggered when there is no
|
|
|
|
* wallpaper set and is created for the first time. The CLOSE_WRITE is triggered
|
|
|
|
* everytime the wallpaper is changed.
|
|
|
|
*/
|
2012-02-06 12:04:42 -08:00
|
|
|
private class WallpaperObserver extends FileObserver {
|
|
|
|
|
|
|
|
final WallpaperData mWallpaper;
|
|
|
|
final File mWallpaperDir;
|
|
|
|
final File mWallpaperFile;
|
|
|
|
|
|
|
|
public WallpaperObserver(WallpaperData wallpaper) {
|
|
|
|
super(getWallpaperDir(wallpaper.userId).getAbsolutePath(),
|
|
|
|
CLOSE_WRITE | DELETE | DELETE_SELF);
|
|
|
|
mWallpaperDir = getWallpaperDir(wallpaper.userId);
|
|
|
|
mWallpaper = wallpaper;
|
|
|
|
mWallpaperFile = new File(mWallpaperDir, WALLPAPER);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEvent(int event, String path) {
|
|
|
|
if (path == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
synchronized (mLock) {
|
|
|
|
// changing the wallpaper means we'll need to back up the new one
|
|
|
|
long origId = Binder.clearCallingIdentity();
|
|
|
|
BackupManager bm = new BackupManager(mContext);
|
|
|
|
bm.dataChanged();
|
|
|
|
Binder.restoreCallingIdentity(origId);
|
|
|
|
|
|
|
|
File changedFile = new File(mWallpaperDir, path);
|
|
|
|
if (mWallpaperFile.equals(changedFile)) {
|
|
|
|
notifyCallbacksLocked(mWallpaper);
|
|
|
|
if (mWallpaper.wallpaperComponent == null || event != CLOSE_WRITE
|
|
|
|
|| mWallpaper.imageWallpaperPending) {
|
|
|
|
if (event == CLOSE_WRITE) {
|
|
|
|
mWallpaper.imageWallpaperPending = false;
|
2009-07-28 18:24:51 -07:00
|
|
|
}
|
2012-10-05 11:06:53 -07:00
|
|
|
bindWallpaperComponentLocked(IMAGE_WALLPAPER, true,
|
2012-09-15 19:33:48 -07:00
|
|
|
false, mWallpaper, null);
|
2012-02-06 12:04:42 -08:00
|
|
|
saveSettingsLocked(mWallpaper);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-08 20:40:27 -07:00
|
|
|
final Context mContext;
|
|
|
|
final IWindowManager mIWindowManager;
|
2012-08-28 22:17:23 -07:00
|
|
|
final IPackageManager mIPackageManager;
|
2010-02-19 17:02:21 -08:00
|
|
|
final MyPackageMonitor mMonitor;
|
2012-02-06 12:04:42 -08:00
|
|
|
WallpaperData mLastWallpaper;
|
2009-03-03 19:31:44 -08:00
|
|
|
|
2012-02-06 12:04:42 -08:00
|
|
|
SparseArray<WallpaperData> mWallpaperMap = new SparseArray<WallpaperData>();
|
2011-08-24 20:05:39 -07:00
|
|
|
|
2012-02-06 12:04:42 -08:00
|
|
|
int mCurrentUserId;
|
|
|
|
|
|
|
|
static class WallpaperData {
|
|
|
|
|
|
|
|
int userId;
|
|
|
|
|
|
|
|
File wallpaperFile;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client is currently writing a new image wallpaper.
|
|
|
|
*/
|
|
|
|
boolean imageWallpaperPending;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resource name if using a picture from the wallpaper gallery
|
|
|
|
*/
|
|
|
|
String name = "";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The component name of the currently set live wallpaper.
|
|
|
|
*/
|
|
|
|
ComponentName wallpaperComponent;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The component name of the wallpaper that should be set next.
|
|
|
|
*/
|
|
|
|
ComponentName nextWallpaperComponent;
|
|
|
|
|
|
|
|
WallpaperConnection connection;
|
|
|
|
long lastDiedTime;
|
|
|
|
boolean wallpaperUpdating;
|
|
|
|
WallpaperObserver wallpaperObserver;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of callbacks registered they should each be notified when the wallpaper is changed.
|
|
|
|
*/
|
|
|
|
private RemoteCallbackList<IWallpaperManagerCallback> callbacks
|
|
|
|
= new RemoteCallbackList<IWallpaperManagerCallback>();
|
|
|
|
|
|
|
|
int width = -1;
|
|
|
|
int height = -1;
|
|
|
|
|
|
|
|
WallpaperData(int userId) {
|
|
|
|
this.userId = userId;
|
|
|
|
wallpaperFile = new File(getWallpaperDir(userId), WALLPAPER);
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 20:05:39 -07:00
|
|
|
|
2009-08-08 20:40:27 -07:00
|
|
|
class WallpaperConnection extends IWallpaperConnection.Stub
|
|
|
|
implements ServiceConnection {
|
2009-09-07 00:49:58 -07:00
|
|
|
final WallpaperInfo mInfo;
|
2009-08-08 20:40:27 -07:00
|
|
|
final Binder mToken = new Binder();
|
|
|
|
IWallpaperService mService;
|
|
|
|
IWallpaperEngine mEngine;
|
2012-02-06 12:04:42 -08:00
|
|
|
WallpaperData mWallpaper;
|
2012-09-15 19:33:48 -07:00
|
|
|
IRemoteCallback mReply;
|
2009-08-08 20:40:27 -07:00
|
|
|
|
2012-02-06 12:04:42 -08:00
|
|
|
public WallpaperConnection(WallpaperInfo info, WallpaperData wallpaper) {
|
2009-09-07 00:49:58 -07:00
|
|
|
mInfo = info;
|
2012-02-06 12:04:42 -08:00
|
|
|
mWallpaper = wallpaper;
|
2009-09-07 00:49:58 -07:00
|
|
|
}
|
2012-09-15 19:33:48 -07:00
|
|
|
|
|
|
|
@Override
|
2009-08-08 20:40:27 -07:00
|
|
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
|
|
|
synchronized (mLock) {
|
2012-02-06 12:04:42 -08:00
|
|
|
if (mWallpaper.connection == this) {
|
|
|
|
mWallpaper.lastDiedTime = SystemClock.uptimeMillis();
|
2009-08-08 20:40:27 -07:00
|
|
|
mService = IWallpaperService.Stub.asInterface(service);
|
2012-02-06 12:04:42 -08:00
|
|
|
attachServiceLocked(this, mWallpaper);
|
2009-09-07 00:49:58 -07:00
|
|
|
// XXX should probably do saveSettingsLocked() later
|
|
|
|
// when we have an engine, but I'm not sure about
|
|
|
|
// locking there and anyway we always need to be able to
|
|
|
|
// recover if there is something wrong.
|
2012-02-06 12:04:42 -08:00
|
|
|
saveSettingsLocked(mWallpaper);
|
2009-08-08 20:40:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-03 19:31:44 -08:00
|
|
|
|
2012-09-15 19:33:48 -07:00
|
|
|
@Override
|
2009-08-08 20:40:27 -07:00
|
|
|
public void onServiceDisconnected(ComponentName name) {
|
|
|
|
synchronized (mLock) {
|
|
|
|
mService = null;
|
|
|
|
mEngine = null;
|
2012-02-06 12:04:42 -08:00
|
|
|
if (mWallpaper.connection == this) {
|
|
|
|
Slog.w(TAG, "Wallpaper service gone: " + mWallpaper.wallpaperComponent);
|
|
|
|
if (!mWallpaper.wallpaperUpdating
|
|
|
|
&& (mWallpaper.lastDiedTime + MIN_WALLPAPER_CRASH_TIME)
|
|
|
|
> SystemClock.uptimeMillis()
|
|
|
|
&& mWallpaper.userId == mCurrentUserId) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.w(TAG, "Reverting to built-in wallpaper!");
|
2012-09-15 19:33:48 -07:00
|
|
|
clearWallpaperLocked(true, mWallpaper.userId, null);
|
2009-08-13 18:51:59 -07:00
|
|
|
}
|
|
|
|
}
|
2009-08-08 20:40:27 -07:00
|
|
|
}
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
|
2012-09-15 19:33:48 -07:00
|
|
|
@Override
|
2009-08-08 20:40:27 -07:00
|
|
|
public void attachEngine(IWallpaperEngine engine) {
|
2012-09-15 19:33:48 -07:00
|
|
|
synchronized (mLock) {
|
|
|
|
mEngine = engine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void engineShown(IWallpaperEngine engine) {
|
|
|
|
synchronized (mLock) {
|
|
|
|
if (mReply != null) {
|
|
|
|
long ident = Binder.clearCallingIdentity();
|
|
|
|
try {
|
|
|
|
mReply.sendResult(null);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
Binder.restoreCallingIdentity(ident);
|
|
|
|
}
|
|
|
|
mReply = null;
|
|
|
|
}
|
|
|
|
}
|
2009-08-08 20:40:27 -07:00
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
|
2012-09-15 19:33:48 -07:00
|
|
|
@Override
|
2009-08-08 20:40:27 -07:00
|
|
|
public ParcelFileDescriptor setWallpaper(String name) {
|
|
|
|
synchronized (mLock) {
|
2012-02-06 12:04:42 -08:00
|
|
|
if (mWallpaper.connection == this) {
|
|
|
|
return updateWallpaperBitmapLocked(name, mWallpaper);
|
2009-08-08 20:40:27 -07:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
|
2010-02-19 17:02:21 -08:00
|
|
|
class MyPackageMonitor extends PackageMonitor {
|
|
|
|
@Override
|
|
|
|
public void onPackageUpdateFinished(String packageName, int uid) {
|
|
|
|
synchronized (mLock) {
|
2012-09-20 13:12:03 -07:00
|
|
|
if (mCurrentUserId != getChangingUserId()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
|
|
|
|
if (wallpaper != null) {
|
2012-02-06 12:04:42 -08:00
|
|
|
if (wallpaper.wallpaperComponent != null
|
|
|
|
&& wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
|
|
|
|
wallpaper.wallpaperUpdating = false;
|
|
|
|
ComponentName comp = wallpaper.wallpaperComponent;
|
|
|
|
clearWallpaperComponentLocked(wallpaper);
|
2012-09-20 13:12:03 -07:00
|
|
|
if (!bindWallpaperComponentLocked(comp, false, false,
|
|
|
|
wallpaper, null)) {
|
2012-02-06 12:04:42 -08:00
|
|
|
Slog.w(TAG, "Wallpaper no longer available; reverting to default");
|
2012-09-15 19:33:48 -07:00
|
|
|
clearWallpaperLocked(false, wallpaper.userId, null);
|
2012-02-06 12:04:42 -08:00
|
|
|
}
|
2011-09-15 15:15:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPackageModified(String packageName) {
|
|
|
|
synchronized (mLock) {
|
2012-09-20 13:12:03 -07:00
|
|
|
if (mCurrentUserId != getChangingUserId()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
|
|
|
|
if (wallpaper != null) {
|
2012-02-06 12:04:42 -08:00
|
|
|
if (wallpaper.wallpaperComponent == null
|
|
|
|
|| !wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
|
2012-09-20 13:12:03 -07:00
|
|
|
return;
|
2012-02-06 12:04:42 -08:00
|
|
|
}
|
2012-04-19 23:12:09 -07:00
|
|
|
doPackagesChangedLocked(true, wallpaper);
|
2010-02-19 17:02:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPackageUpdateStarted(String packageName, int uid) {
|
|
|
|
synchronized (mLock) {
|
2012-09-20 13:12:03 -07:00
|
|
|
if (mCurrentUserId != getChangingUserId()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
|
|
|
|
if (wallpaper != null) {
|
2012-02-06 12:04:42 -08:00
|
|
|
if (wallpaper.wallpaperComponent != null
|
|
|
|
&& wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
|
|
|
|
wallpaper.wallpaperUpdating = true;
|
|
|
|
}
|
2010-02-19 17:02:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
|
2012-04-19 23:12:09 -07:00
|
|
|
synchronized (mLock) {
|
|
|
|
boolean changed = false;
|
2012-09-20 13:12:03 -07:00
|
|
|
if (mCurrentUserId != getChangingUserId()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
|
|
|
|
if (wallpaper != null) {
|
2012-04-19 23:12:09 -07:00
|
|
|
boolean res = doPackagesChangedLocked(doit, wallpaper);
|
|
|
|
changed |= res;
|
|
|
|
}
|
|
|
|
return changed;
|
2012-02-06 12:04:42 -08:00
|
|
|
}
|
2010-02-19 17:02:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSomePackagesChanged() {
|
2012-04-19 23:12:09 -07:00
|
|
|
synchronized (mLock) {
|
2012-09-20 13:12:03 -07:00
|
|
|
if (mCurrentUserId != getChangingUserId()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
|
|
|
|
if (wallpaper != null) {
|
2012-04-19 23:12:09 -07:00
|
|
|
doPackagesChangedLocked(true, wallpaper);
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
}
|
2010-02-19 17:02:21 -08:00
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
|
2012-04-19 23:12:09 -07:00
|
|
|
boolean doPackagesChangedLocked(boolean doit, WallpaperData wallpaper) {
|
2010-02-19 17:02:21 -08:00
|
|
|
boolean changed = false;
|
2012-04-19 23:12:09 -07:00
|
|
|
if (wallpaper.wallpaperComponent != null) {
|
|
|
|
int change = isPackageDisappearing(wallpaper.wallpaperComponent
|
|
|
|
.getPackageName());
|
|
|
|
if (change == PACKAGE_PERMANENT_CHANGE
|
|
|
|
|| change == PACKAGE_TEMPORARY_CHANGE) {
|
|
|
|
changed = true;
|
|
|
|
if (doit) {
|
|
|
|
Slog.w(TAG, "Wallpaper uninstalled, removing: "
|
2012-02-06 12:04:42 -08:00
|
|
|
+ wallpaper.wallpaperComponent);
|
2012-09-15 19:33:48 -07:00
|
|
|
clearWallpaperLocked(false, wallpaper.userId, null);
|
2010-02-19 17:02:21 -08:00
|
|
|
}
|
|
|
|
}
|
2012-04-19 23:12:09 -07:00
|
|
|
}
|
|
|
|
if (wallpaper.nextWallpaperComponent != null) {
|
|
|
|
int change = isPackageDisappearing(wallpaper.nextWallpaperComponent
|
|
|
|
.getPackageName());
|
|
|
|
if (change == PACKAGE_PERMANENT_CHANGE
|
|
|
|
|| change == PACKAGE_TEMPORARY_CHANGE) {
|
|
|
|
wallpaper.nextWallpaperComponent = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wallpaper.wallpaperComponent != null
|
|
|
|
&& isPackageModified(wallpaper.wallpaperComponent.getPackageName())) {
|
|
|
|
try {
|
|
|
|
mContext.getPackageManager().getServiceInfo(
|
|
|
|
wallpaper.wallpaperComponent, 0);
|
|
|
|
} catch (NameNotFoundException e) {
|
|
|
|
Slog.w(TAG, "Wallpaper component gone, removing: "
|
|
|
|
+ wallpaper.wallpaperComponent);
|
2012-09-15 19:33:48 -07:00
|
|
|
clearWallpaperLocked(false, wallpaper.userId, null);
|
2012-04-19 23:12:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wallpaper.nextWallpaperComponent != null
|
|
|
|
&& isPackageModified(wallpaper.nextWallpaperComponent.getPackageName())) {
|
|
|
|
try {
|
|
|
|
mContext.getPackageManager().getServiceInfo(
|
|
|
|
wallpaper.nextWallpaperComponent, 0);
|
|
|
|
} catch (NameNotFoundException e) {
|
|
|
|
wallpaper.nextWallpaperComponent = null;
|
2010-02-19 17:02:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-05 21:29:42 -07:00
|
|
|
public WallpaperManagerService(Context context) {
|
2010-02-26 18:56:32 -08:00
|
|
|
if (DEBUG) Slog.v(TAG, "WallpaperService startup");
|
2009-03-03 19:31:44 -08:00
|
|
|
mContext = context;
|
2009-08-08 20:40:27 -07:00
|
|
|
mIWindowManager = IWindowManager.Stub.asInterface(
|
|
|
|
ServiceManager.getService(Context.WINDOW_SERVICE));
|
2012-08-28 22:17:23 -07:00
|
|
|
mIPackageManager = AppGlobals.getPackageManager();
|
2010-02-19 17:02:21 -08:00
|
|
|
mMonitor = new MyPackageMonitor();
|
2012-09-20 13:12:03 -07:00
|
|
|
mMonitor.register(context, null, UserHandle.ALL, true);
|
2012-08-31 12:12:28 -07:00
|
|
|
getWallpaperDir(UserHandle.USER_OWNER).mkdirs();
|
|
|
|
loadSettingsLocked(UserHandle.USER_OWNER);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
2012-02-06 12:04:42 -08:00
|
|
|
private static File getWallpaperDir(int userId) {
|
2012-08-31 12:12:28 -07:00
|
|
|
return Environment.getUserSystemDirectory(userId);
|
2012-02-06 12:04:42 -08:00
|
|
|
}
|
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
@Override
|
|
|
|
protected void finalize() throws Throwable {
|
|
|
|
super.finalize();
|
2012-02-06 12:04:42 -08:00
|
|
|
for (int i = 0; i < mWallpaperMap.size(); i++) {
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.valueAt(i);
|
|
|
|
wallpaper.wallpaperObserver.stopWatching();
|
|
|
|
}
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
2012-03-22 16:16:17 -07:00
|
|
|
|
2013-06-25 14:59:53 -07:00
|
|
|
public void systemRunning() {
|
2010-02-26 18:56:32 -08:00
|
|
|
if (DEBUG) Slog.v(TAG, "systemReady");
|
2012-08-31 12:12:28 -07:00
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(UserHandle.USER_OWNER);
|
2012-09-15 19:33:48 -07:00
|
|
|
switchWallpaper(wallpaper, null);
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.wallpaperObserver = new WallpaperObserver(wallpaper);
|
|
|
|
wallpaper.wallpaperObserver.startWatching();
|
|
|
|
|
2012-03-22 16:16:17 -07:00
|
|
|
IntentFilter userFilter = new IntentFilter();
|
|
|
|
userFilter.addAction(Intent.ACTION_USER_REMOVED);
|
2012-10-12 12:30:07 -07:00
|
|
|
userFilter.addAction(Intent.ACTION_USER_STOPPING);
|
2012-03-22 16:16:17 -07:00
|
|
|
mContext.registerReceiver(new BroadcastReceiver() {
|
2012-02-06 12:04:42 -08:00
|
|
|
@Override
|
2012-03-22 16:16:17 -07:00
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String action = intent.getAction();
|
2012-09-15 19:33:48 -07:00
|
|
|
if (Intent.ACTION_USER_REMOVED.equals(action)) {
|
2012-10-12 12:30:07 -07:00
|
|
|
onRemoveUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
|
|
|
|
UserHandle.USER_NULL));
|
2012-03-22 16:16:17 -07:00
|
|
|
}
|
2012-10-30 12:23:52 -07:00
|
|
|
// TODO: Race condition causing problems when cleaning up on stopping a user.
|
|
|
|
// Comment this out for now.
|
|
|
|
// else if (Intent.ACTION_USER_STOPPING.equals(action)) {
|
|
|
|
// onStoppingUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
|
|
|
|
// UserHandle.USER_NULL));
|
|
|
|
// }
|
2012-02-06 12:04:42 -08:00
|
|
|
}
|
2012-03-22 16:16:17 -07:00
|
|
|
}, userFilter);
|
2012-10-12 12:30:07 -07:00
|
|
|
|
2012-09-15 19:33:48 -07:00
|
|
|
try {
|
|
|
|
ActivityManagerNative.getDefault().registerUserSwitchObserver(
|
|
|
|
new IUserSwitchObserver.Stub() {
|
|
|
|
@Override
|
|
|
|
public void onUserSwitching(int newUserId, IRemoteCallback reply) {
|
|
|
|
switchUser(newUserId, reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUserSwitchComplete(int newUserId) throws RemoteException {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
String getName() {
|
2012-09-15 19:33:48 -07:00
|
|
|
synchronized (mLock) {
|
|
|
|
return mWallpaperMap.get(0).name;
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
}
|
|
|
|
|
2012-10-12 12:30:07 -07:00
|
|
|
void onStoppingUser(int userId) {
|
|
|
|
if (userId < 1) return;
|
2012-03-22 16:16:17 -07:00
|
|
|
synchronized (mLock) {
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(userId);
|
|
|
|
if (wallpaper != null) {
|
2012-10-12 12:30:07 -07:00
|
|
|
if (wallpaper.wallpaperObserver != null) {
|
|
|
|
wallpaper.wallpaperObserver.stopWatching();
|
|
|
|
wallpaper.wallpaperObserver = null;
|
|
|
|
}
|
2012-03-22 16:16:17 -07:00
|
|
|
mWallpaperMap.remove(userId);
|
|
|
|
}
|
2012-10-12 12:30:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onRemoveUser(int userId) {
|
|
|
|
if (userId < 1) return;
|
|
|
|
synchronized (mLock) {
|
|
|
|
onStoppingUser(userId);
|
2012-03-22 16:16:17 -07:00
|
|
|
File wallpaperFile = new File(getWallpaperDir(userId), WALLPAPER);
|
|
|
|
wallpaperFile.delete();
|
|
|
|
File wallpaperInfoFile = new File(getWallpaperDir(userId), WALLPAPER_INFO);
|
|
|
|
wallpaperInfoFile.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-15 19:33:48 -07:00
|
|
|
void switchUser(int userId, IRemoteCallback reply) {
|
2012-02-06 12:04:42 -08:00
|
|
|
synchronized (mLock) {
|
|
|
|
mCurrentUserId = userId;
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(userId);
|
|
|
|
if (wallpaper == null) {
|
|
|
|
wallpaper = new WallpaperData(userId);
|
|
|
|
mWallpaperMap.put(userId, wallpaper);
|
|
|
|
loadSettingsLocked(userId);
|
2012-10-04 14:55:42 -07:00
|
|
|
}
|
|
|
|
// Not started watching yet, in case wallpaper data was loaded for other reasons.
|
|
|
|
if (wallpaper.wallpaperObserver == null) {
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.wallpaperObserver = new WallpaperObserver(wallpaper);
|
|
|
|
wallpaper.wallpaperObserver.startWatching();
|
|
|
|
}
|
2012-09-15 19:33:48 -07:00
|
|
|
switchWallpaper(wallpaper, reply);
|
2012-02-06 12:04:42 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-15 19:33:48 -07:00
|
|
|
void switchWallpaper(WallpaperData wallpaper, IRemoteCallback reply) {
|
2009-08-13 10:20:21 -07:00
|
|
|
synchronized (mLock) {
|
2011-09-15 15:15:27 -07:00
|
|
|
RuntimeException e = null;
|
2009-08-13 10:20:21 -07:00
|
|
|
try {
|
2012-02-06 12:04:42 -08:00
|
|
|
ComponentName cname = wallpaper.wallpaperComponent != null ?
|
|
|
|
wallpaper.wallpaperComponent : wallpaper.nextWallpaperComponent;
|
2012-09-15 19:33:48 -07:00
|
|
|
if (bindWallpaperComponentLocked(cname, true, false, wallpaper, reply)) {
|
2011-09-15 15:15:27 -07:00
|
|
|
return;
|
2009-08-13 10:20:21 -07:00
|
|
|
}
|
2011-09-15 15:15:27 -07:00
|
|
|
} catch (RuntimeException e1) {
|
|
|
|
e = e1;
|
2009-08-13 10:20:21 -07:00
|
|
|
}
|
2011-09-15 15:15:27 -07:00
|
|
|
Slog.w(TAG, "Failure starting previous wallpaper", e);
|
2012-09-15 19:33:48 -07:00
|
|
|
clearWallpaperLocked(false, wallpaper.userId, reply);
|
2009-08-13 10:20:21 -07:00
|
|
|
}
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
public void clearWallpaper() {
|
2010-02-26 18:56:32 -08:00
|
|
|
if (DEBUG) Slog.v(TAG, "clearWallpaper");
|
2009-07-28 18:24:51 -07:00
|
|
|
synchronized (mLock) {
|
2012-09-15 19:33:48 -07:00
|
|
|
clearWallpaperLocked(false, UserHandle.getCallingUserId(), null);
|
2010-02-19 17:02:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-15 19:33:48 -07:00
|
|
|
void clearWallpaperLocked(boolean defaultFailed, int userId, IRemoteCallback reply) {
|
2012-02-06 12:04:42 -08:00
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(userId);
|
|
|
|
File f = new File(getWallpaperDir(userId), WALLPAPER);
|
2010-02-19 17:02:21 -08:00
|
|
|
if (f.exists()) {
|
|
|
|
f.delete();
|
|
|
|
}
|
|
|
|
final long ident = Binder.clearCallingIdentity();
|
2011-09-15 15:15:27 -07:00
|
|
|
RuntimeException e = null;
|
2010-02-19 17:02:21 -08:00
|
|
|
try {
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.imageWallpaperPending = false;
|
|
|
|
if (userId != mCurrentUserId) return;
|
2011-09-15 15:15:27 -07:00
|
|
|
if (bindWallpaperComponentLocked(defaultFailed
|
2012-10-05 11:06:53 -07:00
|
|
|
? IMAGE_WALLPAPER
|
2012-09-15 19:33:48 -07:00
|
|
|
: null, true, false, wallpaper, reply)) {
|
2011-09-15 15:15:27 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (IllegalArgumentException e1) {
|
|
|
|
e = e1;
|
2010-02-19 17:02:21 -08:00
|
|
|
} finally {
|
|
|
|
Binder.restoreCallingIdentity(ident);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
2011-09-15 15:15:27 -07:00
|
|
|
|
|
|
|
// This can happen if the default wallpaper component doesn't
|
|
|
|
// exist. This should be a system configuration problem, but
|
|
|
|
// let's not let it crash the system and just live with no
|
|
|
|
// wallpaper.
|
|
|
|
Slog.e(TAG, "Default wallpaper component not found!", e);
|
2012-02-06 12:04:42 -08:00
|
|
|
clearWallpaperComponentLocked(wallpaper);
|
2012-09-15 19:33:48 -07:00
|
|
|
if (reply != null) {
|
|
|
|
try {
|
|
|
|
reply.sendResult(null);
|
|
|
|
} catch (RemoteException e1) {
|
|
|
|
}
|
|
|
|
}
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
2012-09-15 19:33:48 -07:00
|
|
|
public boolean hasNamedWallpaper(String name) {
|
|
|
|
synchronized (mLock) {
|
2012-10-04 14:55:42 -07:00
|
|
|
List<UserInfo> users;
|
|
|
|
long ident = Binder.clearCallingIdentity();
|
|
|
|
try {
|
|
|
|
users = ((UserManager) mContext.getSystemService(Context.USER_SERVICE)).getUsers();
|
|
|
|
} finally {
|
|
|
|
Binder.restoreCallingIdentity(ident);
|
|
|
|
}
|
|
|
|
for (UserInfo user: users) {
|
|
|
|
WallpaperData wd = mWallpaperMap.get(user.id);
|
|
|
|
if (wd == null) {
|
|
|
|
// User hasn't started yet, so load her settings to peek at the wallpaper
|
|
|
|
loadSettingsLocked(user.id);
|
|
|
|
wd = mWallpaperMap.get(user.id);
|
|
|
|
}
|
|
|
|
if (wd != null && name.equals(wd.name)) {
|
2012-09-15 19:33:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
2012-09-15 19:33:48 -07:00
|
|
|
return false;
|
|
|
|
}
|
2009-03-03 19:31:44 -08:00
|
|
|
|
2012-09-15 19:33:48 -07:00
|
|
|
public void setDimensionHints(int width, int height) throws RemoteException {
|
|
|
|
checkPermission(android.Manifest.permission.SET_WALLPAPER_HINTS);
|
2009-07-28 18:24:51 -07:00
|
|
|
synchronized (mLock) {
|
2012-09-15 19:33:48 -07:00
|
|
|
int userId = UserHandle.getCallingUserId();
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(userId);
|
|
|
|
if (wallpaper == null) {
|
|
|
|
throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
|
|
|
|
}
|
|
|
|
if (width <= 0 || height <= 0) {
|
|
|
|
throw new IllegalArgumentException("width and height must be > 0");
|
|
|
|
}
|
|
|
|
|
2012-02-06 12:04:42 -08:00
|
|
|
if (width != wallpaper.width || height != wallpaper.height) {
|
|
|
|
wallpaper.width = width;
|
|
|
|
wallpaper.height = height;
|
|
|
|
saveSettingsLocked(wallpaper);
|
|
|
|
if (mCurrentUserId != userId) return; // Don't change the properties now
|
|
|
|
if (wallpaper.connection != null) {
|
|
|
|
if (wallpaper.connection.mEngine != null) {
|
2009-08-28 10:34:25 -07:00
|
|
|
try {
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.connection.mEngine.setDesiredSize(
|
2009-08-28 10:34:25 -07:00
|
|
|
width, height);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
notifyCallbacksLocked(wallpaper);
|
2009-08-28 10:34:25 -07:00
|
|
|
}
|
|
|
|
}
|
2009-07-28 18:24:51 -07:00
|
|
|
}
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getWidthHint() throws RemoteException {
|
2009-07-28 18:24:51 -07:00
|
|
|
synchronized (mLock) {
|
2012-08-16 10:48:27 -07:00
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId());
|
2012-02-06 12:04:42 -08:00
|
|
|
return wallpaper.width;
|
2009-07-28 18:24:51 -07:00
|
|
|
}
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getHeightHint() throws RemoteException {
|
2009-07-28 18:24:51 -07:00
|
|
|
synchronized (mLock) {
|
2012-08-16 10:48:27 -07:00
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId());
|
2012-02-06 12:04:42 -08:00
|
|
|
return wallpaper.height;
|
2009-07-28 18:24:51 -07:00
|
|
|
}
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
2009-08-28 10:34:25 -07:00
|
|
|
public ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb,
|
|
|
|
Bundle outParams) {
|
2009-07-28 18:24:51 -07:00
|
|
|
synchronized (mLock) {
|
2012-02-06 12:04:42 -08:00
|
|
|
// This returns the current user's wallpaper, if called by a system service. Else it
|
|
|
|
// returns the wallpaper for the calling user.
|
|
|
|
int callingUid = Binder.getCallingUid();
|
|
|
|
int wallpaperUserId = 0;
|
|
|
|
if (callingUid == android.os.Process.SYSTEM_UID) {
|
|
|
|
wallpaperUserId = mCurrentUserId;
|
|
|
|
} else {
|
2012-08-16 10:48:27 -07:00
|
|
|
wallpaperUserId = UserHandle.getUserId(callingUid);
|
2012-02-06 12:04:42 -08:00
|
|
|
}
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(wallpaperUserId);
|
2009-07-28 18:24:51 -07:00
|
|
|
try {
|
2009-08-28 10:34:25 -07:00
|
|
|
if (outParams != null) {
|
2012-02-06 12:04:42 -08:00
|
|
|
outParams.putInt("width", wallpaper.width);
|
|
|
|
outParams.putInt("height", wallpaper.height);
|
2009-08-28 10:34:25 -07:00
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.callbacks.register(cb);
|
|
|
|
File f = new File(getWallpaperDir(wallpaperUserId), WALLPAPER);
|
2009-07-28 18:24:51 -07:00
|
|
|
if (!f.exists()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return ParcelFileDescriptor.open(f, MODE_READ_ONLY);
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
/* Shouldn't happen as we check to see if the file exists */
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.w(TAG, "Error getting wallpaper", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
2009-07-28 18:24:51 -07:00
|
|
|
return null;
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-07 00:49:58 -07:00
|
|
|
public WallpaperInfo getWallpaperInfo() {
|
2012-08-16 10:48:27 -07:00
|
|
|
int userId = UserHandle.getCallingUserId();
|
2009-09-07 00:49:58 -07:00
|
|
|
synchronized (mLock) {
|
2012-02-06 12:04:42 -08:00
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(userId);
|
|
|
|
if (wallpaper.connection != null) {
|
|
|
|
return wallpaper.connection.mInfo;
|
2009-09-07 00:49:58 -07:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
|
2009-07-28 18:24:51 -07:00
|
|
|
public ParcelFileDescriptor setWallpaper(String name) {
|
2009-03-03 19:31:44 -08:00
|
|
|
checkPermission(android.Manifest.permission.SET_WALLPAPER);
|
2009-07-28 18:24:51 -07:00
|
|
|
synchronized (mLock) {
|
2012-09-15 19:33:48 -07:00
|
|
|
if (DEBUG) Slog.v(TAG, "setWallpaper");
|
|
|
|
int userId = UserHandle.getCallingUserId();
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(userId);
|
|
|
|
if (wallpaper == null) {
|
|
|
|
throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
|
|
|
|
}
|
2009-08-13 18:51:59 -07:00
|
|
|
final long ident = Binder.clearCallingIdentity();
|
|
|
|
try {
|
2012-02-06 12:04:42 -08:00
|
|
|
ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name, wallpaper);
|
2009-08-13 18:51:59 -07:00
|
|
|
if (pfd != null) {
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.imageWallpaperPending = true;
|
2009-08-13 18:51:59 -07:00
|
|
|
}
|
|
|
|
return pfd;
|
|
|
|
} finally {
|
|
|
|
Binder.restoreCallingIdentity(ident);
|
2009-08-08 20:40:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-06 12:04:42 -08:00
|
|
|
ParcelFileDescriptor updateWallpaperBitmapLocked(String name, WallpaperData wallpaper) {
|
2009-08-08 20:40:27 -07:00
|
|
|
if (name == null) name = "";
|
|
|
|
try {
|
2012-02-06 12:04:42 -08:00
|
|
|
File dir = getWallpaperDir(wallpaper.userId);
|
|
|
|
if (!dir.exists()) {
|
|
|
|
dir.mkdir();
|
2011-11-29 18:01:50 -08:00
|
|
|
FileUtils.setPermissions(
|
2012-02-06 12:04:42 -08:00
|
|
|
dir.getPath(),
|
2011-11-29 18:01:50 -08:00
|
|
|
FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
|
|
|
|
-1, -1);
|
|
|
|
}
|
2012-07-05 06:41:43 -04:00
|
|
|
File file = new File(dir, WALLPAPER);
|
|
|
|
ParcelFileDescriptor fd = ParcelFileDescriptor.open(file,
|
2009-08-08 20:40:27 -07:00
|
|
|
MODE_CREATE|MODE_READ_WRITE);
|
2012-07-05 06:41:43 -04:00
|
|
|
if (!SELinux.restorecon(file)) {
|
|
|
|
return null;
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.name = name;
|
2009-08-08 20:40:27 -07:00
|
|
|
return fd;
|
|
|
|
} catch (FileNotFoundException e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.w(TAG, "Error setting wallpaper", e);
|
2009-08-08 20:40:27 -07:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setWallpaperComponent(ComponentName name) {
|
|
|
|
checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT);
|
|
|
|
synchronized (mLock) {
|
2012-09-15 19:33:48 -07:00
|
|
|
if (DEBUG) Slog.v(TAG, "setWallpaperComponent name=" + name);
|
|
|
|
int userId = UserHandle.getCallingUserId();
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(userId);
|
|
|
|
if (wallpaper == null) {
|
|
|
|
throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
|
|
|
|
}
|
2009-08-08 20:40:27 -07:00
|
|
|
final long ident = Binder.clearCallingIdentity();
|
2009-07-28 18:24:51 -07:00
|
|
|
try {
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.imageWallpaperPending = false;
|
2012-09-15 19:33:48 -07:00
|
|
|
bindWallpaperComponentLocked(name, false, true, wallpaper, null);
|
2009-08-13 10:20:21 -07:00
|
|
|
} finally {
|
|
|
|
Binder.restoreCallingIdentity(ident);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-06 12:04:42 -08:00
|
|
|
boolean bindWallpaperComponentLocked(ComponentName componentName, boolean force,
|
2012-09-15 19:33:48 -07:00
|
|
|
boolean fromUser, WallpaperData wallpaper, IRemoteCallback reply) {
|
2010-02-26 18:56:32 -08:00
|
|
|
if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName);
|
2009-08-13 10:20:21 -07:00
|
|
|
// Has the component changed?
|
2011-08-05 14:43:50 -07:00
|
|
|
if (!force) {
|
2012-02-06 12:04:42 -08:00
|
|
|
if (wallpaper.connection != null) {
|
|
|
|
if (wallpaper.wallpaperComponent == null) {
|
2011-08-05 14:43:50 -07:00
|
|
|
if (componentName == null) {
|
|
|
|
if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: still using default");
|
|
|
|
// Still using default wallpaper.
|
2011-09-15 15:15:27 -07:00
|
|
|
return true;
|
2011-08-05 14:43:50 -07:00
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
} else if (wallpaper.wallpaperComponent.equals(componentName)) {
|
2011-08-05 14:43:50 -07:00
|
|
|
// Changing to same wallpaper.
|
|
|
|
if (DEBUG) Slog.v(TAG, "same wallpaper");
|
2011-09-15 15:15:27 -07:00
|
|
|
return true;
|
2009-08-08 20:40:27 -07:00
|
|
|
}
|
2009-08-13 10:20:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2009-11-15 22:53:08 -08:00
|
|
|
if (componentName == null) {
|
2009-11-12 07:45:47 -08:00
|
|
|
String defaultComponent =
|
|
|
|
mContext.getString(com.android.internal.R.string.default_wallpaper_component);
|
2009-11-15 22:53:08 -08:00
|
|
|
if (defaultComponent != null) {
|
2009-11-12 07:45:47 -08:00
|
|
|
// See if there is a default wallpaper component specified
|
2009-11-15 22:53:08 -08:00
|
|
|
componentName = ComponentName.unflattenFromString(defaultComponent);
|
2010-02-26 18:56:32 -08:00
|
|
|
if (DEBUG) Slog.v(TAG, "Use default component wallpaper:" + componentName);
|
2009-11-12 07:45:47 -08:00
|
|
|
}
|
2009-11-15 22:53:08 -08:00
|
|
|
if (componentName == null) {
|
2009-11-12 07:45:47 -08:00
|
|
|
// Fall back to static image wallpaper
|
2012-10-05 11:06:53 -07:00
|
|
|
componentName = IMAGE_WALLPAPER;
|
2009-11-12 07:45:47 -08:00
|
|
|
//clearWallpaperComponentLocked();
|
|
|
|
//return;
|
2010-02-26 18:56:32 -08:00
|
|
|
if (DEBUG) Slog.v(TAG, "Using image wallpaper");
|
2009-11-12 07:45:47 -08:00
|
|
|
}
|
2009-08-13 10:20:21 -07:00
|
|
|
}
|
2012-08-28 22:17:23 -07:00
|
|
|
int serviceUserId = wallpaper.userId;
|
|
|
|
ServiceInfo si = mIPackageManager.getServiceInfo(componentName,
|
|
|
|
PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS, serviceUserId);
|
2013-09-08 13:01:28 -07:00
|
|
|
if (si == null) {
|
|
|
|
// The wallpaper component we're trying to use doesn't exist
|
|
|
|
Slog.w(TAG, "Attempted wallpaper " + componentName + " is unavailable");
|
|
|
|
return false;
|
|
|
|
}
|
2009-08-13 10:20:21 -07:00
|
|
|
if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) {
|
2011-09-15 15:15:27 -07:00
|
|
|
String msg = "Selected service does not require "
|
2009-08-13 10:20:21 -07:00
|
|
|
+ android.Manifest.permission.BIND_WALLPAPER
|
2011-09-15 15:15:27 -07:00
|
|
|
+ ": " + componentName;
|
|
|
|
if (fromUser) {
|
|
|
|
throw new SecurityException(msg);
|
|
|
|
}
|
|
|
|
Slog.w(TAG, msg);
|
|
|
|
return false;
|
2009-08-13 10:20:21 -07:00
|
|
|
}
|
|
|
|
|
2009-09-07 00:49:58 -07:00
|
|
|
WallpaperInfo wi = null;
|
|
|
|
|
2009-08-13 10:20:21 -07:00
|
|
|
Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
|
2012-10-05 11:06:53 -07:00
|
|
|
if (componentName != null && !componentName.equals(IMAGE_WALLPAPER)) {
|
2009-08-08 20:40:27 -07:00
|
|
|
// Make sure the selected service is actually a wallpaper service.
|
2012-08-28 22:17:23 -07:00
|
|
|
List<ResolveInfo> ris =
|
|
|
|
mIPackageManager.queryIntentServices(intent,
|
|
|
|
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
|
|
|
|
PackageManager.GET_META_DATA, serviceUserId);
|
2009-08-08 20:40:27 -07:00
|
|
|
for (int i=0; i<ris.size(); i++) {
|
|
|
|
ServiceInfo rsi = ris.get(i).serviceInfo;
|
|
|
|
if (rsi.name.equals(si.name) &&
|
|
|
|
rsi.packageName.equals(si.packageName)) {
|
2009-09-07 00:49:58 -07:00
|
|
|
try {
|
|
|
|
wi = new WallpaperInfo(mContext, ris.get(i));
|
|
|
|
} catch (XmlPullParserException e) {
|
2011-09-15 15:15:27 -07:00
|
|
|
if (fromUser) {
|
|
|
|
throw new IllegalArgumentException(e);
|
|
|
|
}
|
|
|
|
Slog.w(TAG, e);
|
|
|
|
return false;
|
2009-09-07 00:49:58 -07:00
|
|
|
} catch (IOException e) {
|
2011-09-15 15:15:27 -07:00
|
|
|
if (fromUser) {
|
|
|
|
throw new IllegalArgumentException(e);
|
|
|
|
}
|
|
|
|
Slog.w(TAG, e);
|
|
|
|
return false;
|
2009-09-07 00:49:58 -07:00
|
|
|
}
|
2009-08-08 20:40:27 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-09-07 00:49:58 -07:00
|
|
|
if (wi == null) {
|
2011-09-15 15:15:27 -07:00
|
|
|
String msg = "Selected service is not a wallpaper: "
|
|
|
|
+ componentName;
|
|
|
|
if (fromUser) {
|
|
|
|
throw new SecurityException(msg);
|
|
|
|
}
|
|
|
|
Slog.w(TAG, msg);
|
|
|
|
return false;
|
2009-08-08 20:40:27 -07:00
|
|
|
}
|
2009-07-28 18:24:51 -07:00
|
|
|
}
|
2009-08-13 10:20:21 -07:00
|
|
|
|
|
|
|
// Bind the service!
|
2010-02-26 18:56:32 -08:00
|
|
|
if (DEBUG) Slog.v(TAG, "Binding to:" + componentName);
|
2012-02-06 12:04:42 -08:00
|
|
|
WallpaperConnection newConn = new WallpaperConnection(wi, wallpaper);
|
2009-11-15 22:53:08 -08:00
|
|
|
intent.setComponent(componentName);
|
2009-09-03 00:18:47 -07:00
|
|
|
intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
|
|
|
|
com.android.internal.R.string.wallpaper_binding_label);
|
2012-08-31 14:05:51 -07:00
|
|
|
intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivityAsUser(
|
2009-09-07 00:49:58 -07:00
|
|
|
mContext, 0,
|
|
|
|
Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER),
|
|
|
|
mContext.getText(com.android.internal.R.string.chooser_wallpaper)),
|
2012-08-31 14:05:51 -07:00
|
|
|
0, null, new UserHandle(serviceUserId)));
|
Switch proc stats to use new process state constants.
These new constants are a better mapping to the kind of
information that procstats is wanting to collect about
processes. In doing this, the process states are tweaked
to have a bit more information that we care about for
procstats.
This changes the format of the data printed by procstats,
so the checkin version is bumped to 2. The structure is
the same, however the codes for process states have all
changed. The new codes are, in order of precedence:
p -- persistent system process.
t -- top activity; actually any visible activity.
f -- important foreground process (ime, wallpaper, etc).
b -- important background process
u -- performing backup operation.
w -- heavy-weight process (currently not used).
s -- background process running a service.
r -- process running a receiver.
h -- process hosting home/launcher app when not on top.
l -- process hosting the last app the user was in.
a -- cached process hosting a previous activity.
c -- cached process hosting a client activity.
e -- cached process that is empty.
In addition, we are now collecting uss along with pss
data for each process, so the pss checkin entries now
have three new values at the end of the min/avg/max uss
values of that process.
With this switch to using process state constants more
fundamentally, I realized that they could actually be
used by the core oom adj code to make it a lot cleaner.
So that change has been made, that code has changed quite
radically, and lost a lot of its secondary states and flags
that it used to use in its computation, now relying on
primarily the oom_adj and proc state values for the process.
This also cleaned up a few problems -- for example for
purposes of determing the memory level of the device, if a
long-running service dropped into the cached oom_adj level,
it would start being counted as a cached process and thus
make us think that the memory state is better than it is.
Now we do this based on the proc state, which always stays
as a service regardless of what is happening like this, giving
as a more consistent view of the memory state of the device.
Making proc state a more fundamentally part of the oom adj
computation means that the values can also be more carefully
tuned in semantic meaning so the value assigned to a process
doesn't tend to change unless the semantics of the process
has really significantly changed.
For example, a process will be assigned the service state
regardless of whether that services is executing operations
in the foreground, running normally, or has been dropped to
the lru list for pruning. The top state is used for everything
related to activities visible to the user: when actually on
top, visible but not on top, currently pausing, etc.
There is a new Context.BIND_SHOWING_UI added for when system
services bind to apps, to explicitly indicate that the app
is showing UI for the system. This gives us a better metric
to determine when it is showing UI, and thus when it needs
to do a memory trim when it is no longer in that state. Without
this, services could get in bad states of continually trimming.
Finally, more HashSet containers have been changed to ArraySet,
reducing the temporary iterators created for iterating over
them.
Change-Id: I1724113f42abe7862e8aecb6faae5a7620245e89
2013-07-13 21:32:12 -07:00
|
|
|
if (!mContext.bindServiceAsUser(intent, newConn,
|
|
|
|
Context.BIND_AUTO_CREATE | Context.BIND_SHOWING_UI,
|
2013-01-16 12:30:11 -08:00
|
|
|
new UserHandle(serviceUserId))) {
|
2011-09-15 15:15:27 -07:00
|
|
|
String msg = "Unable to bind service: "
|
|
|
|
+ componentName;
|
|
|
|
if (fromUser) {
|
|
|
|
throw new IllegalArgumentException(msg);
|
|
|
|
}
|
|
|
|
Slog.w(TAG, msg);
|
|
|
|
return false;
|
2009-08-13 10:20:21 -07:00
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
if (wallpaper.userId == mCurrentUserId && mLastWallpaper != null) {
|
|
|
|
detachWallpaperLocked(mLastWallpaper);
|
|
|
|
}
|
|
|
|
wallpaper.wallpaperComponent = componentName;
|
|
|
|
wallpaper.connection = newConn;
|
|
|
|
wallpaper.lastDiedTime = SystemClock.uptimeMillis();
|
2012-09-15 19:33:48 -07:00
|
|
|
newConn.mReply = reply;
|
2009-08-13 10:20:21 -07:00
|
|
|
try {
|
2012-02-06 12:04:42 -08:00
|
|
|
if (wallpaper.userId == mCurrentUserId) {
|
|
|
|
if (DEBUG)
|
|
|
|
Slog.v(TAG, "Adding window token: " + newConn.mToken);
|
|
|
|
mIWindowManager.addWindowToken(newConn.mToken,
|
|
|
|
WindowManager.LayoutParams.TYPE_WALLPAPER);
|
|
|
|
mLastWallpaper = wallpaper;
|
|
|
|
}
|
2009-08-13 10:20:21 -07:00
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
2012-08-28 22:17:23 -07:00
|
|
|
} catch (RemoteException e) {
|
|
|
|
String msg = "Remote exception for " + componentName + "\n" + e;
|
2011-09-15 15:15:27 -07:00
|
|
|
if (fromUser) {
|
|
|
|
throw new IllegalArgumentException(msg);
|
|
|
|
}
|
|
|
|
Slog.w(TAG, msg);
|
|
|
|
return false;
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
2011-09-15 15:15:27 -07:00
|
|
|
return true;
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
|
|
|
|
void detachWallpaperLocked(WallpaperData wallpaper) {
|
|
|
|
if (wallpaper.connection != null) {
|
2012-09-15 19:33:48 -07:00
|
|
|
if (wallpaper.connection.mReply != null) {
|
|
|
|
try {
|
|
|
|
wallpaper.connection.mReply.sendResult(null);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
|
|
|
wallpaper.connection.mReply = null;
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
if (wallpaper.connection.mEngine != null) {
|
2009-08-08 20:40:27 -07:00
|
|
|
try {
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.connection.mEngine.destroy();
|
2009-08-08 20:40:27 -07:00
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
mContext.unbindService(wallpaper.connection);
|
2009-08-18 15:08:22 -07:00
|
|
|
try {
|
2012-02-06 12:04:42 -08:00
|
|
|
if (DEBUG)
|
|
|
|
Slog.v(TAG, "Removing window token: " + wallpaper.connection.mToken);
|
|
|
|
mIWindowManager.removeWindowToken(wallpaper.connection.mToken);
|
2009-08-18 15:08:22 -07:00
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.connection.mService = null;
|
|
|
|
wallpaper.connection.mEngine = null;
|
|
|
|
wallpaper.connection = null;
|
2009-08-08 20:40:27 -07:00
|
|
|
}
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
|
|
|
|
void clearWallpaperComponentLocked(WallpaperData wallpaper) {
|
|
|
|
wallpaper.wallpaperComponent = null;
|
|
|
|
detachWallpaperLocked(wallpaper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void attachServiceLocked(WallpaperConnection conn, WallpaperData wallpaper) {
|
2009-08-08 20:40:27 -07:00
|
|
|
try {
|
2009-08-20 19:31:38 -07:00
|
|
|
conn.mService.attach(conn, conn.mToken,
|
|
|
|
WindowManager.LayoutParams.TYPE_WALLPAPER, false,
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.width, wallpaper.height);
|
2009-08-08 20:40:27 -07:00
|
|
|
} catch (RemoteException e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.w(TAG, "Failed attaching wallpaper; clearing", e);
|
2012-02-06 12:04:42 -08:00
|
|
|
if (!wallpaper.wallpaperUpdating) {
|
2012-09-15 19:33:48 -07:00
|
|
|
bindWallpaperComponentLocked(null, false, false, wallpaper, null);
|
2010-02-19 17:02:21 -08:00
|
|
|
}
|
2009-08-08 20:40:27 -07:00
|
|
|
}
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
|
|
|
|
private void notifyCallbacksLocked(WallpaperData wallpaper) {
|
|
|
|
final int n = wallpaper.callbacks.beginBroadcast();
|
2009-03-03 19:31:44 -08:00
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
try {
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.callbacks.getBroadcastItem(i).onWallpaperChanged();
|
2009-03-03 19:31:44 -08:00
|
|
|
} catch (RemoteException e) {
|
|
|
|
|
|
|
|
// The RemoteCallbackList will take care of removing
|
|
|
|
// the dead object for us.
|
|
|
|
}
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.callbacks.finishBroadcast();
|
2009-03-03 19:31:44 -08:00
|
|
|
final Intent intent = new Intent(Intent.ACTION_WALLPAPER_CHANGED);
|
2012-08-29 18:32:08 -07:00
|
|
|
mContext.sendBroadcastAsUser(intent, new UserHandle(mCurrentUserId));
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void checkPermission(String permission) {
|
2009-07-28 18:24:51 -07:00
|
|
|
if (PackageManager.PERMISSION_GRANTED!= mContext.checkCallingOrSelfPermission(permission)) {
|
2009-03-03 19:31:44 -08:00
|
|
|
throw new SecurityException("Access denied to process: " + Binder.getCallingPid()
|
|
|
|
+ ", must have permission " + permission);
|
|
|
|
}
|
|
|
|
}
|
2009-07-28 18:24:51 -07:00
|
|
|
|
2012-02-06 12:04:42 -08:00
|
|
|
private static JournaledFile makeJournaledFile(int userId) {
|
2012-08-31 12:12:28 -07:00
|
|
|
final String base = new File(getWallpaperDir(userId), WALLPAPER_INFO).getAbsolutePath();
|
2009-07-28 18:24:51 -07:00
|
|
|
return new JournaledFile(new File(base), new File(base + ".tmp"));
|
|
|
|
}
|
|
|
|
|
2012-02-06 12:04:42 -08:00
|
|
|
private void saveSettingsLocked(WallpaperData wallpaper) {
|
|
|
|
JournaledFile journal = makeJournaledFile(wallpaper.userId);
|
2009-07-28 18:24:51 -07:00
|
|
|
FileOutputStream stream = null;
|
|
|
|
try {
|
|
|
|
stream = new FileOutputStream(journal.chooseForWrite(), false);
|
|
|
|
XmlSerializer out = new FastXmlSerializer();
|
|
|
|
out.setOutput(stream, "utf-8");
|
|
|
|
out.startDocument(null, true);
|
|
|
|
|
|
|
|
out.startTag(null, "wp");
|
2012-02-06 12:04:42 -08:00
|
|
|
out.attribute(null, "width", Integer.toString(wallpaper.width));
|
|
|
|
out.attribute(null, "height", Integer.toString(wallpaper.height));
|
|
|
|
out.attribute(null, "name", wallpaper.name);
|
|
|
|
if (wallpaper.wallpaperComponent != null
|
2012-10-05 11:06:53 -07:00
|
|
|
&& !wallpaper.wallpaperComponent.equals(IMAGE_WALLPAPER)) {
|
2009-08-08 20:40:27 -07:00
|
|
|
out.attribute(null, "component",
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.wallpaperComponent.flattenToShortString());
|
2009-08-08 20:40:27 -07:00
|
|
|
}
|
2009-07-28 18:24:51 -07:00
|
|
|
out.endTag(null, "wp");
|
|
|
|
|
|
|
|
out.endDocument();
|
|
|
|
stream.close();
|
|
|
|
journal.commit();
|
|
|
|
} catch (IOException e) {
|
|
|
|
try {
|
|
|
|
if (stream != null) {
|
|
|
|
stream.close();
|
|
|
|
}
|
|
|
|
} catch (IOException ex) {
|
|
|
|
// Ignore
|
|
|
|
}
|
|
|
|
journal.rollback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-06 12:04:42 -08:00
|
|
|
private void migrateFromOld() {
|
|
|
|
File oldWallpaper = new File(WallpaperBackupHelper.WALLPAPER_IMAGE_KEY);
|
|
|
|
File oldInfo = new File(WallpaperBackupHelper.WALLPAPER_INFO_KEY);
|
|
|
|
if (oldWallpaper.exists()) {
|
|
|
|
File newWallpaper = new File(getWallpaperDir(0), WALLPAPER);
|
|
|
|
oldWallpaper.renameTo(newWallpaper);
|
|
|
|
}
|
|
|
|
if (oldInfo.exists()) {
|
|
|
|
File newInfo = new File(getWallpaperDir(0), WALLPAPER_INFO);
|
|
|
|
oldInfo.renameTo(newInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadSettingsLocked(int userId) {
|
2010-02-26 18:56:32 -08:00
|
|
|
if (DEBUG) Slog.v(TAG, "loadSettingsLocked");
|
2009-11-15 22:53:08 -08:00
|
|
|
|
2012-02-06 12:04:42 -08:00
|
|
|
JournaledFile journal = makeJournaledFile(userId);
|
2009-07-28 18:24:51 -07:00
|
|
|
FileInputStream stream = null;
|
|
|
|
File file = journal.chooseForRead();
|
2012-02-06 12:04:42 -08:00
|
|
|
if (!file.exists()) {
|
|
|
|
// This should only happen one time, when upgrading from a legacy system
|
|
|
|
migrateFromOld();
|
|
|
|
}
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.get(userId);
|
|
|
|
if (wallpaper == null) {
|
|
|
|
wallpaper = new WallpaperData(userId);
|
|
|
|
mWallpaperMap.put(userId, wallpaper);
|
|
|
|
}
|
2009-07-28 18:24:51 -07:00
|
|
|
boolean success = false;
|
|
|
|
try {
|
|
|
|
stream = new FileInputStream(file);
|
|
|
|
XmlPullParser parser = Xml.newPullParser();
|
|
|
|
parser.setInput(stream, null);
|
|
|
|
|
|
|
|
int type;
|
|
|
|
do {
|
|
|
|
type = parser.next();
|
|
|
|
if (type == XmlPullParser.START_TAG) {
|
|
|
|
String tag = parser.getName();
|
|
|
|
if ("wp".equals(tag)) {
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.width = Integer.parseInt(parser.getAttributeValue(null, "width"));
|
|
|
|
wallpaper.height = Integer.parseInt(parser
|
|
|
|
.getAttributeValue(null, "height"));
|
|
|
|
wallpaper.name = parser.getAttributeValue(null, "name");
|
2009-08-08 20:40:27 -07:00
|
|
|
String comp = parser.getAttributeValue(null, "component");
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.nextWallpaperComponent = comp != null
|
2009-08-08 20:40:27 -07:00
|
|
|
? ComponentName.unflattenFromString(comp)
|
|
|
|
: null;
|
2012-02-06 12:04:42 -08:00
|
|
|
if (wallpaper.nextWallpaperComponent == null
|
|
|
|
|| "android".equals(wallpaper.nextWallpaperComponent
|
|
|
|
.getPackageName())) {
|
2012-10-05 11:06:53 -07:00
|
|
|
wallpaper.nextWallpaperComponent = IMAGE_WALLPAPER;
|
2011-08-05 14:43:50 -07:00
|
|
|
}
|
2009-11-15 22:53:08 -08:00
|
|
|
|
|
|
|
if (DEBUG) {
|
2012-02-06 12:04:42 -08:00
|
|
|
Slog.v(TAG, "mWidth:" + wallpaper.width);
|
|
|
|
Slog.v(TAG, "mHeight:" + wallpaper.height);
|
|
|
|
Slog.v(TAG, "mName:" + wallpaper.name);
|
|
|
|
Slog.v(TAG, "mNextWallpaperComponent:"
|
|
|
|
+ wallpaper.nextWallpaperComponent);
|
2009-11-15 22:53:08 -08:00
|
|
|
}
|
2009-07-28 18:24:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (type != XmlPullParser.END_DOCUMENT);
|
|
|
|
success = true;
|
2012-11-28 18:05:36 -08:00
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
Slog.w(TAG, "no current wallpaper -- first boot?");
|
2009-07-28 18:24:51 -07:00
|
|
|
} catch (NullPointerException e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.w(TAG, "failed parsing " + file + " " + e);
|
2009-07-28 18:24:51 -07:00
|
|
|
} catch (NumberFormatException e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.w(TAG, "failed parsing " + file + " " + e);
|
2009-07-28 18:24:51 -07:00
|
|
|
} catch (XmlPullParserException e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.w(TAG, "failed parsing " + file + " " + e);
|
2009-07-28 18:24:51 -07:00
|
|
|
} catch (IOException e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.w(TAG, "failed parsing " + file + " " + e);
|
2009-07-28 18:24:51 -07:00
|
|
|
} catch (IndexOutOfBoundsException e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.w(TAG, "failed parsing " + file + " " + e);
|
2009-07-28 18:24:51 -07:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (stream != null) {
|
|
|
|
stream.close();
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
// Ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success) {
|
2012-02-06 12:04:42 -08:00
|
|
|
wallpaper.width = -1;
|
|
|
|
wallpaper.height = -1;
|
|
|
|
wallpaper.name = "";
|
2009-07-28 18:24:51 -07:00
|
|
|
}
|
2011-04-20 18:18:51 -07:00
|
|
|
|
|
|
|
// We always want to have some reasonable width hint.
|
|
|
|
WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
|
|
|
|
Display d = wm.getDefaultDisplay();
|
|
|
|
int baseSize = d.getMaximumSizeDimension();
|
2012-02-06 12:04:42 -08:00
|
|
|
if (wallpaper.width < baseSize) {
|
|
|
|
wallpaper.width = baseSize;
|
2011-04-20 18:18:51 -07:00
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
if (wallpaper.height < baseSize) {
|
|
|
|
wallpaper.height = baseSize;
|
2011-04-20 18:18:51 -07:00
|
|
|
}
|
2009-07-28 18:24:51 -07:00
|
|
|
}
|
|
|
|
|
2010-09-14 11:30:29 -07:00
|
|
|
// Called by SystemBackupAgent after files are restored to disk.
|
2009-07-28 18:24:51 -07:00
|
|
|
void settingsRestored() {
|
2012-02-06 12:04:42 -08:00
|
|
|
// TODO: If necessary, make it work for secondary users as well. This currently assumes
|
|
|
|
// restores only to the primary user
|
2010-02-26 18:56:32 -08:00
|
|
|
if (DEBUG) Slog.v(TAG, "settingsRestored");
|
2012-02-06 12:04:42 -08:00
|
|
|
WallpaperData wallpaper = null;
|
2009-07-28 18:24:51 -07:00
|
|
|
boolean success = false;
|
|
|
|
synchronized (mLock) {
|
2012-02-06 12:04:42 -08:00
|
|
|
loadSettingsLocked(0);
|
|
|
|
wallpaper = mWallpaperMap.get(0);
|
|
|
|
if (wallpaper.nextWallpaperComponent != null
|
2012-10-05 11:06:53 -07:00
|
|
|
&& !wallpaper.nextWallpaperComponent.equals(IMAGE_WALLPAPER)) {
|
2012-02-06 12:04:42 -08:00
|
|
|
if (!bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false,
|
2012-09-15 19:33:48 -07:00
|
|
|
wallpaper, null)) {
|
2009-12-16 14:03:31 -08:00
|
|
|
// No such live wallpaper or other failure; fall back to the default
|
|
|
|
// live wallpaper (since the profile being restored indicated that the
|
|
|
|
// user had selected a live rather than static one).
|
2012-09-15 19:33:48 -07:00
|
|
|
bindWallpaperComponentLocked(null, false, false, wallpaper, null);
|
2009-12-16 14:03:31 -08:00
|
|
|
}
|
2009-07-28 18:24:51 -07:00
|
|
|
success = true;
|
|
|
|
} else {
|
2009-11-15 22:53:08 -08:00
|
|
|
// If there's a wallpaper name, we use that. If that can't be loaded, then we
|
|
|
|
// use the default.
|
2012-02-06 12:04:42 -08:00
|
|
|
if ("".equals(wallpaper.name)) {
|
2010-02-26 18:56:32 -08:00
|
|
|
if (DEBUG) Slog.v(TAG, "settingsRestored: name is empty");
|
2009-11-15 22:53:08 -08:00
|
|
|
success = true;
|
|
|
|
} else {
|
2010-02-26 18:56:32 -08:00
|
|
|
if (DEBUG) Slog.v(TAG, "settingsRestored: attempting to restore named resource");
|
2012-02-06 12:04:42 -08:00
|
|
|
success = restoreNamedResourceLocked(wallpaper);
|
2009-11-15 22:53:08 -08:00
|
|
|
}
|
2010-02-26 18:56:32 -08:00
|
|
|
if (DEBUG) Slog.v(TAG, "settingsRestored: success=" + success);
|
2009-11-15 22:53:08 -08:00
|
|
|
if (success) {
|
2012-02-06 12:04:42 -08:00
|
|
|
bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false,
|
2012-09-15 19:33:48 -07:00
|
|
|
wallpaper, null);
|
2009-11-15 22:53:08 -08:00
|
|
|
}
|
2009-07-28 18:24:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success) {
|
2012-02-06 12:04:42 -08:00
|
|
|
Slog.e(TAG, "Failed to restore wallpaper: '" + wallpaper.name + "'");
|
|
|
|
wallpaper.name = "";
|
|
|
|
getWallpaperDir(0).delete();
|
2009-07-28 18:24:51 -07:00
|
|
|
}
|
2010-09-14 11:30:29 -07:00
|
|
|
|
|
|
|
synchronized (mLock) {
|
2012-02-06 12:04:42 -08:00
|
|
|
saveSettingsLocked(wallpaper);
|
2010-09-14 11:30:29 -07:00
|
|
|
}
|
2009-07-28 18:24:51 -07:00
|
|
|
}
|
|
|
|
|
2012-02-06 12:04:42 -08:00
|
|
|
boolean restoreNamedResourceLocked(WallpaperData wallpaper) {
|
|
|
|
if (wallpaper.name.length() > 4 && "res:".equals(wallpaper.name.substring(0, 4))) {
|
|
|
|
String resName = wallpaper.name.substring(4);
|
2009-07-28 18:24:51 -07:00
|
|
|
|
|
|
|
String pkg = null;
|
|
|
|
int colon = resName.indexOf(':');
|
|
|
|
if (colon > 0) {
|
|
|
|
pkg = resName.substring(0, colon);
|
|
|
|
}
|
|
|
|
|
|
|
|
String ident = null;
|
|
|
|
int slash = resName.lastIndexOf('/');
|
|
|
|
if (slash > 0) {
|
|
|
|
ident = resName.substring(slash+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
String type = null;
|
|
|
|
if (colon > 0 && slash > 0 && (slash-colon) > 1) {
|
|
|
|
type = resName.substring(colon+1, slash);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pkg != null && ident != null && type != null) {
|
|
|
|
int resId = -1;
|
|
|
|
InputStream res = null;
|
|
|
|
FileOutputStream fos = null;
|
|
|
|
try {
|
|
|
|
Context c = mContext.createPackageContext(pkg, Context.CONTEXT_RESTRICTED);
|
|
|
|
Resources r = c.getResources();
|
|
|
|
resId = r.getIdentifier(resName, null, null);
|
|
|
|
if (resId == 0) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "couldn't resolve identifier pkg=" + pkg + " type=" + type
|
2009-07-28 18:24:51 -07:00
|
|
|
+ " ident=" + ident);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = r.openRawResource(resId);
|
2012-02-06 12:04:42 -08:00
|
|
|
if (wallpaper.wallpaperFile.exists()) {
|
|
|
|
wallpaper.wallpaperFile.delete();
|
2010-03-18 22:47:17 -07:00
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
fos = new FileOutputStream(wallpaper.wallpaperFile);
|
2009-07-28 18:24:51 -07:00
|
|
|
|
|
|
|
byte[] buffer = new byte[32768];
|
|
|
|
int amt;
|
|
|
|
while ((amt=res.read(buffer)) > 0) {
|
|
|
|
fos.write(buffer, 0, amt);
|
|
|
|
}
|
|
|
|
// mWallpaperObserver will notice the close and send the change broadcast
|
|
|
|
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.v(TAG, "Restored wallpaper: " + resName);
|
2009-07-28 18:24:51 -07:00
|
|
|
return true;
|
|
|
|
} catch (NameNotFoundException e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Package name " + pkg + " not found");
|
2009-07-28 18:24:51 -07:00
|
|
|
} catch (Resources.NotFoundException e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Resource not found: " + resId);
|
2009-07-28 18:24:51 -07:00
|
|
|
} catch (IOException e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "IOException while restoring wallpaper ", e);
|
2009-07-28 18:24:51 -07:00
|
|
|
} finally {
|
|
|
|
if (res != null) {
|
|
|
|
try {
|
|
|
|
res.close();
|
|
|
|
} catch (IOException ex) {}
|
|
|
|
}
|
|
|
|
if (fos != null) {
|
2010-10-15 12:54:40 -07:00
|
|
|
FileUtils.sync(fos);
|
2009-07-28 18:24:51 -07:00
|
|
|
try {
|
|
|
|
fos.close();
|
|
|
|
} catch (IOException ex) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-02-06 12:04:42 -08:00
|
|
|
|
2009-09-07 00:49:58 -07:00
|
|
|
@Override
|
|
|
|
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
|
|
|
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
|
|
|
|
!= PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
|
|
|
pw.println("Permission Denial: can't dump wallpaper service from from pid="
|
|
|
|
+ Binder.getCallingPid()
|
|
|
|
+ ", uid=" + Binder.getCallingUid());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
synchronized (mLock) {
|
|
|
|
pw.println("Current Wallpaper Service state:");
|
2012-02-06 12:04:42 -08:00
|
|
|
for (int i = 0; i < mWallpaperMap.size(); i++) {
|
|
|
|
WallpaperData wallpaper = mWallpaperMap.valueAt(i);
|
|
|
|
pw.println(" User " + wallpaper.userId + ":");
|
|
|
|
pw.print(" mWidth=");
|
|
|
|
pw.print(wallpaper.width);
|
|
|
|
pw.print(" mHeight=");
|
|
|
|
pw.println(wallpaper.height);
|
|
|
|
pw.print(" mName=");
|
|
|
|
pw.println(wallpaper.name);
|
|
|
|
pw.print(" mWallpaperComponent=");
|
|
|
|
pw.println(wallpaper.wallpaperComponent);
|
|
|
|
if (wallpaper.connection != null) {
|
|
|
|
WallpaperConnection conn = wallpaper.connection;
|
|
|
|
pw.print(" Wallpaper connection ");
|
|
|
|
pw.print(conn);
|
|
|
|
pw.println(":");
|
|
|
|
if (conn.mInfo != null) {
|
|
|
|
pw.print(" mInfo.component=");
|
|
|
|
pw.println(conn.mInfo.getComponent());
|
|
|
|
}
|
|
|
|
pw.print(" mToken=");
|
|
|
|
pw.println(conn.mToken);
|
|
|
|
pw.print(" mService=");
|
|
|
|
pw.println(conn.mService);
|
|
|
|
pw.print(" mEngine=");
|
|
|
|
pw.println(conn.mEngine);
|
|
|
|
pw.print(" mLastDiedTime=");
|
|
|
|
pw.println(wallpaper.lastDiedTime - SystemClock.uptimeMillis());
|
|
|
|
}
|
2009-09-07 00:49:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|