Merge change Ia428b2c2 into eclair
* changes: This time for sure: make wallpapers work
This commit is contained in:
@@ -125,13 +125,29 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
|
|
||||||
int mWidth = -1;
|
int mWidth = -1;
|
||||||
int mHeight = -1;
|
int mHeight = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resource name if using a picture from the wallpaper gallery
|
||||||
|
*/
|
||||||
String mName = "";
|
String mName = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The component name of the currently set live wallpaper. This will be null if the
|
* The component name of the currently set live wallpaper.
|
||||||
* wallpaper uses the built in ImageWallpaper component to display a bitmap.
|
|
||||||
*/
|
*/
|
||||||
ComponentName mWallpaperComponent;
|
ComponentName mWallpaperComponent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The component name of the wallpaper that should be set next.
|
||||||
|
*/
|
||||||
|
ComponentName mNextWallpaperComponent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the component used to display bitmap wallpapers from either the gallery or
|
||||||
|
* built-in wallpapers.
|
||||||
|
*/
|
||||||
|
ComponentName mImageWallpaperComponent = new ComponentName("android",
|
||||||
|
ImageWallpaper.class.getName());
|
||||||
|
|
||||||
WallpaperConnection mWallpaperConnection;
|
WallpaperConnection mWallpaperConnection;
|
||||||
long mLastDiedTime;
|
long mLastDiedTime;
|
||||||
|
|
||||||
@@ -169,7 +185,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
if ((mLastDiedTime+MIN_WALLPAPER_CRASH_TIME)
|
if ((mLastDiedTime+MIN_WALLPAPER_CRASH_TIME)
|
||||||
< SystemClock.uptimeMillis()) {
|
< SystemClock.uptimeMillis()) {
|
||||||
Log.w(TAG, "Reverting to built-in wallpaper!");
|
Log.w(TAG, "Reverting to built-in wallpaper!");
|
||||||
bindWallpaperComponentLocked(null, false);
|
bindWallpaperComponentLocked(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,7 +206,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public WallpaperManagerService(Context context) {
|
public WallpaperManagerService(Context context) {
|
||||||
if (DEBUG) Log.d(TAG, "WallpaperService startup");
|
if (DEBUG) Log.v(TAG, "WallpaperService startup");
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mIWindowManager = IWindowManager.Stub.asInterface(
|
mIWindowManager = IWindowManager.Stub.asInterface(
|
||||||
ServiceManager.getService(Context.WINDOW_SERVICE));
|
ServiceManager.getService(Context.WINDOW_SERVICE));
|
||||||
@@ -206,13 +222,14 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void systemReady() {
|
public void systemReady() {
|
||||||
|
if (DEBUG) Log.v(TAG, "systemReady");
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
try {
|
try {
|
||||||
bindWallpaperComponentLocked(mWallpaperComponent, false);
|
bindWallpaperComponentLocked(mNextWallpaperComponent);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
Log.w(TAG, "Failure starting previous wallpaper", e);
|
Log.w(TAG, "Failure starting previous wallpaper", e);
|
||||||
try {
|
try {
|
||||||
bindWallpaperComponentLocked(null, false);
|
bindWallpaperComponentLocked(null);
|
||||||
} catch (RuntimeException e2) {
|
} catch (RuntimeException e2) {
|
||||||
Log.w(TAG, "Failure starting default wallpaper", e2);
|
Log.w(TAG, "Failure starting default wallpaper", e2);
|
||||||
clearWallpaperComponentLocked();
|
clearWallpaperComponentLocked();
|
||||||
@@ -222,6 +239,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clearWallpaper() {
|
public void clearWallpaper() {
|
||||||
|
if (DEBUG) Log.v(TAG, "clearWallpaper");
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
File f = WALLPAPER_FILE;
|
File f = WALLPAPER_FILE;
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
@@ -229,7 +247,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
}
|
}
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
bindWallpaperComponentLocked(null, false);
|
bindWallpaperComponentLocked(null);
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(ident);
|
Binder.restoreCallingIdentity(ident);
|
||||||
}
|
}
|
||||||
@@ -306,6 +324,8 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ParcelFileDescriptor setWallpaper(String name) {
|
public ParcelFileDescriptor setWallpaper(String name) {
|
||||||
|
if (DEBUG) Log.v(TAG, "setWallpaper");
|
||||||
|
|
||||||
checkPermission(android.Manifest.permission.SET_WALLPAPER);
|
checkPermission(android.Manifest.permission.SET_WALLPAPER);
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
@@ -313,7 +333,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name);
|
ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name);
|
||||||
if (pfd != null) {
|
if (pfd != null) {
|
||||||
// Bind the wallpaper to an ImageWallpaper
|
// Bind the wallpaper to an ImageWallpaper
|
||||||
bindWallpaperComponentLocked(null, true);
|
bindWallpaperComponentLocked(mImageWallpaperComponent);
|
||||||
saveSettingsLocked();
|
saveSettingsLocked();
|
||||||
}
|
}
|
||||||
return pfd;
|
return pfd;
|
||||||
@@ -337,62 +357,65 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setWallpaperComponent(ComponentName name) {
|
public void setWallpaperComponent(ComponentName name) {
|
||||||
|
if (DEBUG) Log.v(TAG, "setWallpaperComponent name=" + name);
|
||||||
checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT);
|
checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT);
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
bindWallpaperComponentLocked(name, false);
|
bindWallpaperComponentLocked(name);
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(ident);
|
Binder.restoreCallingIdentity(ident);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bindWallpaperComponentLocked(ComponentName componentName, boolean isBitmap) {
|
void bindWallpaperComponentLocked(ComponentName componentName) {
|
||||||
|
if (DEBUG) Log.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName);
|
||||||
|
|
||||||
// Has the component changed?
|
// Has the component changed?
|
||||||
if (mWallpaperConnection != null) {
|
if (mWallpaperConnection != null) {
|
||||||
if (mWallpaperComponent == null) {
|
if (mWallpaperComponent == null) {
|
||||||
if (componentName == null) {
|
if (componentName == null) {
|
||||||
|
if (DEBUG) Log.v(TAG, "bindWallpaperComponentLocked: still using default");
|
||||||
// Still using default wallpaper.
|
// Still using default wallpaper.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (mWallpaperComponent.equals(componentName)) {
|
} else if (mWallpaperComponent.equals(componentName)) {
|
||||||
// Changing to same wallpaper.
|
// Changing to same wallpaper.
|
||||||
|
if (DEBUG) Log.v(TAG, "same wallpaper");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ComponentName realComponentName = componentName;
|
if (componentName == null) {
|
||||||
if (realComponentName == null) {
|
|
||||||
String defaultComponent =
|
String defaultComponent =
|
||||||
mContext.getString(com.android.internal.R.string.default_wallpaper_component);
|
mContext.getString(com.android.internal.R.string.default_wallpaper_component);
|
||||||
if (defaultComponent != null && !isBitmap) {
|
if (defaultComponent != null) {
|
||||||
// See if there is a default wallpaper component specified
|
// See if there is a default wallpaper component specified
|
||||||
// Only look for this if the wallpaper is not being set to a bitmap
|
componentName = ComponentName.unflattenFromString(defaultComponent);
|
||||||
realComponentName = ComponentName.unflattenFromString(defaultComponent);
|
if (DEBUG) Log.v(TAG, "Use default component walpaper:" + componentName);
|
||||||
componentName = realComponentName;
|
|
||||||
}
|
}
|
||||||
if (realComponentName == null) {
|
if (componentName == null) {
|
||||||
// Fall back to static image wallpaper
|
// Fall back to static image wallpaper
|
||||||
realComponentName = new ComponentName("android",
|
componentName = mImageWallpaperComponent;
|
||||||
ImageWallpaper.class.getName());
|
|
||||||
//clearWallpaperComponentLocked();
|
//clearWallpaperComponentLocked();
|
||||||
//return;
|
//return;
|
||||||
|
if (DEBUG) Log.v(TAG, "Using image wallpaper");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ServiceInfo si = mContext.getPackageManager().getServiceInfo(realComponentName,
|
ServiceInfo si = mContext.getPackageManager().getServiceInfo(componentName,
|
||||||
PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS);
|
PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS);
|
||||||
if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) {
|
if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) {
|
||||||
throw new SecurityException("Selected service does not require "
|
throw new SecurityException("Selected service does not require "
|
||||||
+ android.Manifest.permission.BIND_WALLPAPER
|
+ android.Manifest.permission.BIND_WALLPAPER
|
||||||
+ ": " + realComponentName);
|
+ ": " + componentName);
|
||||||
}
|
}
|
||||||
|
|
||||||
WallpaperInfo wi = null;
|
WallpaperInfo wi = null;
|
||||||
|
|
||||||
Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
|
Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
|
||||||
if (componentName != null) {
|
if (componentName != null && !componentName.equals(mImageWallpaperComponent)) {
|
||||||
// Make sure the selected service is actually a wallpaper service.
|
// Make sure the selected service is actually a wallpaper service.
|
||||||
List<ResolveInfo> ris = mContext.getPackageManager()
|
List<ResolveInfo> ris = mContext.getPackageManager()
|
||||||
.queryIntentServices(intent, PackageManager.GET_META_DATA);
|
.queryIntentServices(intent, PackageManager.GET_META_DATA);
|
||||||
@@ -412,13 +435,14 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
}
|
}
|
||||||
if (wi == null) {
|
if (wi == null) {
|
||||||
throw new SecurityException("Selected service is not a wallpaper: "
|
throw new SecurityException("Selected service is not a wallpaper: "
|
||||||
+ realComponentName);
|
+ componentName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind the service!
|
// Bind the service!
|
||||||
|
if (DEBUG) Log.v(TAG, "Binding to:" + componentName);
|
||||||
WallpaperConnection newConn = new WallpaperConnection(wi);
|
WallpaperConnection newConn = new WallpaperConnection(wi);
|
||||||
intent.setComponent(realComponentName);
|
intent.setComponent(componentName);
|
||||||
intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
|
intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
|
||||||
com.android.internal.R.string.wallpaper_binding_label);
|
com.android.internal.R.string.wallpaper_binding_label);
|
||||||
intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
|
intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
|
||||||
@@ -475,7 +499,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
mWidth, mHeight);
|
mWidth, mHeight);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.w(TAG, "Failed attaching wallpaper; clearing", e);
|
Log.w(TAG, "Failed attaching wallpaper; clearing", e);
|
||||||
bindWallpaperComponentLocked(null, false);
|
bindWallpaperComponentLocked(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,6 +566,8 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadSettingsLocked() {
|
private void loadSettingsLocked() {
|
||||||
|
if (DEBUG) Log.v(TAG, "loadSettingsLocked");
|
||||||
|
|
||||||
JournaledFile journal = makeJournaledFile();
|
JournaledFile journal = makeJournaledFile();
|
||||||
FileInputStream stream = null;
|
FileInputStream stream = null;
|
||||||
File file = journal.chooseForRead();
|
File file = journal.chooseForRead();
|
||||||
@@ -561,9 +587,16 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
mHeight = Integer.parseInt(parser.getAttributeValue(null, "height"));
|
mHeight = Integer.parseInt(parser.getAttributeValue(null, "height"));
|
||||||
mName = parser.getAttributeValue(null, "name");
|
mName = parser.getAttributeValue(null, "name");
|
||||||
String comp = parser.getAttributeValue(null, "component");
|
String comp = parser.getAttributeValue(null, "component");
|
||||||
mWallpaperComponent = comp != null
|
mNextWallpaperComponent = comp != null
|
||||||
? ComponentName.unflattenFromString(comp)
|
? ComponentName.unflattenFromString(comp)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.v(TAG, "mWidth:" + mWidth);
|
||||||
|
Log.v(TAG, "mHeight:" + mHeight);
|
||||||
|
Log.v(TAG, "mName:" + mName);
|
||||||
|
Log.v(TAG, "mNextWallpaperComponent:" + mNextWallpaperComponent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (type != XmlPullParser.END_DOCUMENT);
|
} while (type != XmlPullParser.END_DOCUMENT);
|
||||||
@@ -595,15 +628,30 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void settingsRestored() {
|
void settingsRestored() {
|
||||||
|
if (DEBUG) Log.v(TAG, "settingsRestored");
|
||||||
|
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
loadSettingsLocked();
|
loadSettingsLocked();
|
||||||
// If there's a wallpaper name, we use that. If that can't be loaded, then we
|
if (mNextWallpaperComponent != null &&
|
||||||
// use the default.
|
!mNextWallpaperComponent.equals(mImageWallpaperComponent)) {
|
||||||
if ("".equals(mName)) {
|
// We can't restore live wallpapers, so just go with the default
|
||||||
|
bindWallpaperComponentLocked(null);
|
||||||
success = true;
|
success = true;
|
||||||
} else {
|
} else {
|
||||||
success = restoreNamedResourceLocked();
|
// If there's a wallpaper name, we use that. If that can't be loaded, then we
|
||||||
|
// use the default.
|
||||||
|
if ("".equals(mName)) {
|
||||||
|
if (DEBUG) Log.v(TAG, "settingsRestored: name is empty");
|
||||||
|
success = true;
|
||||||
|
} else {
|
||||||
|
if (DEBUG) Log.v(TAG, "settingsRestored: attempting to restore named resource");
|
||||||
|
success = restoreNamedResourceLocked();
|
||||||
|
}
|
||||||
|
if (DEBUG) Log.v(TAG, "settingsRestored: success=" + success);
|
||||||
|
if (success) {
|
||||||
|
bindWallpaperComponentLocked(mImageWallpaperComponent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,7 +708,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
|
|||||||
}
|
}
|
||||||
// mWallpaperObserver will notice the close and send the change broadcast
|
// mWallpaperObserver will notice the close and send the change broadcast
|
||||||
|
|
||||||
Log.d(TAG, "Restored wallpaper: " + resName);
|
Log.v(TAG, "Restored wallpaper: " + resName);
|
||||||
return true;
|
return true;
|
||||||
} catch (NameNotFoundException e) {
|
} catch (NameNotFoundException e) {
|
||||||
Log.e(TAG, "Package name " + pkg + " not found");
|
Log.e(TAG, "Package name " + pkg + " not found");
|
||||||
|
|||||||
Reference in New Issue
Block a user