summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Android (Google) Code Review <android-gerrit@google.com> 2009-08-05 21:39:14 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2009-08-05 21:39:14 -0700
commit9488437b4f55c425b0168d612d729427b19b85ad (patch)
tree95c3b2a5958d8af662f2456caaf60dcdb5e0dba7
parent71cb821c05659d02856ba361d490aa703ff08e37 (diff)
parent8cc6a5026aeb5cf9cc36529426fe0cc66714f5fb (diff)
Merge change 20240
* changes: First bit of wallpaper work.
-rw-r--r--Android.mk5
-rw-r--r--api/current.xml186
-rw-r--r--core/java/android/app/ApplicationContext.java172
-rw-r--r--core/java/android/app/IWallpaperManager.aidl (renamed from core/java/android/app/IWallpaperService.aidl)6
-rw-r--r--core/java/android/app/IWallpaperManagerCallback.aidl (renamed from core/java/android/app/IWallpaperServiceCallback.aidl)4
-rw-r--r--core/java/android/app/WallpaperManager.java288
-rw-r--r--core/java/android/content/Context.java73
-rw-r--r--core/java/android/service/wallpaper/IWallpaperService.aidl24
-rw-r--r--core/java/android/service/wallpaper/WallpaperService.java83
-rw-r--r--services/java/com/android/server/SystemBackupAgent.java2
-rw-r--r--services/java/com/android/server/SystemServer.java2
-rw-r--r--services/java/com/android/server/WallpaperManagerService.java (renamed from services/java/com/android/server/WallpaperService.java)14
12 files changed, 629 insertions, 230 deletions
diff --git a/Android.mk b/Android.mk
index 275807a5282e..8791627be6a5 100644
--- a/Android.mk
+++ b/Android.mk
@@ -83,8 +83,8 @@ LOCAL_SRC_FILES += \
core/java/android/app/IStatusBar.aidl \
core/java/android/app/IThumbnailReceiver.aidl \
core/java/android/app/ITransientNotification.aidl \
- core/java/android/app/IWallpaperService.aidl \
- core/java/android/app/IWallpaperServiceCallback.aidl \
+ core/java/android/app/IWallpaperManager.aidl \
+ core/java/android/app/IWallpaperManagerCallback.aidl \
core/java/android/backup/IBackupManager.aidl \
core/java/android/backup/IRestoreObserver.aidl \
core/java/android/backup/IRestoreSession.aidl \
@@ -114,6 +114,7 @@ LOCAL_SRC_FILES += \
core/java/android/os/IParentalControlCallback.aidl \
core/java/android/os/IPermissionController.aidl \
core/java/android/os/IPowerManager.aidl \
+ core/java/android/service/wallpaper/IWallpaperService.aidl \
core/java/android/text/IClipboard.aidl \
core/java/android/view/accessibility/IAccessibilityManager.aidl \
core/java/android/view/accessibility/IAccessibilityManagerClient.aidl \
diff --git a/api/current.xml b/api/current.xml
index c4cac831508a..04b7c9aa6e0b 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -26742,6 +26742,132 @@
</parameter>
</method>
</interface>
+<class name="WallpaperManager"
+ extends="java.lang.Object"
+ abstract="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<method name="clear"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<exception name="IOException" type="java.io.IOException">
+</exception>
+</method>
+<method name="get"
+ return="android.graphics.drawable.Drawable"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getDesiredMinimumHeight"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getDesiredMinimumWidth"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="peek"
+ return="android.graphics.drawable.Drawable"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="set"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="resid" type="int">
+</parameter>
+<exception name="IOException" type="java.io.IOException">
+</exception>
+</method>
+<method name="set"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="bitmap" type="android.graphics.Bitmap">
+</parameter>
+<exception name="IOException" type="java.io.IOException">
+</exception>
+</method>
+<method name="set"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="data" type="java.io.InputStream">
+</parameter>
+<exception name="IOException" type="java.io.IOException">
+</exception>
+</method>
+<method name="setDimensionHints"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="minimumWidth" type="int">
+</parameter>
+<parameter name="minimumHeight" type="int">
+</parameter>
+</method>
+</class>
</package>
<package name="android.appwidget"
>
@@ -30791,7 +30917,7 @@
synchronized="false"
static="false"
final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
visibility="public"
>
<exception name="IOException" type="java.io.IOException">
@@ -31240,7 +31366,7 @@
synchronized="false"
static="false"
final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
visibility="public"
>
</method>
@@ -31251,7 +31377,7 @@
synchronized="false"
static="false"
final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
visibility="public"
>
</method>
@@ -31262,7 +31388,7 @@
synchronized="false"
static="false"
final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
visibility="public"
>
</method>
@@ -31414,7 +31540,7 @@
synchronized="false"
static="false"
final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
visibility="public"
>
</method>
@@ -31581,7 +31707,7 @@
synchronized="false"
static="false"
final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
visibility="public"
>
<parameter name="bitmap" type="android.graphics.Bitmap">
@@ -31596,7 +31722,7 @@
synchronized="false"
static="false"
final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
visibility="public"
>
<parameter name="data" type="java.io.InputStream">
@@ -115818,6 +115944,50 @@
</implements>
</interface>
</package>
+<package name="android.service.wallpaper"
+>
+<class name="WallpaperService"
+ extends="android.app.Service"
+ abstract="true"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<constructor name="WallpaperService"
+ type="android.service.wallpaper.WallpaperService"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</constructor>
+<method name="onBind"
+ return="android.os.IBinder"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="intent" type="android.content.Intent">
+</parameter>
+</method>
+<field name="SERVICE_INTERFACE"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.service.wallpaper.WallpaperService&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+</class>
+</package>
<package name="android.speech"
>
<class name="RecognizerIntent"
@@ -146176,7 +146346,7 @@
deprecated="not deprecated"
visibility="public"
>
-<parameter name="index" type="int">
+<parameter name="pointerIndex" type="int">
</parameter>
</method>
<method name="getPressure"
diff --git a/core/java/android/app/ApplicationContext.java b/core/java/android/app/ApplicationContext.java
index b095e3079cc7..8ac95575d783 100644
--- a/core/java/android/app/ApplicationContext.java
+++ b/core/java/android/app/ApplicationContext.java
@@ -59,8 +59,6 @@ import android.content.res.XmlResourceParser;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.hardware.SensorManager;
import android.location.ILocationManager;
@@ -78,7 +76,6 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.IPowerManager;
import android.os.Looper;
-import android.os.ParcelFileDescriptor;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
@@ -88,10 +85,8 @@ import android.os.FileUtils.FileStatus;
import android.telephony.TelephonyManager;
import android.text.ClipboardManager;
import android.util.AndroidRuntimeException;
-import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ContextThemeWrapper;
-import android.view.Display;
import android.view.LayoutInflater;
import android.view.WindowManagerImpl;
import android.view.accessibility.AccessibilityManager;
@@ -165,7 +160,6 @@ class ApplicationContext extends Context {
private static LocationManager sLocationManager;
private static boolean sIsBluetoothDeviceCached = false;
private static BluetoothDevice sBluetoothDevice;
- private static IWallpaperService sWallpaperService;
private static final HashMap<File, SharedPreferencesImpl> sSharedPrefs =
new HashMap<File, SharedPreferencesImpl>();
@@ -180,8 +174,8 @@ class ApplicationContext extends Context {
private Resources.Theme mTheme = null;
private PackageManager mPackageManager;
private NotificationManager mNotificationManager = null;
- private AccessibilityManager mAccessibilityManager = null;
private ActivityManager mActivityManager = null;
+ private WallpaperManager mWallpaperManager = null;
private Context mReceiverRestrictedContext = null;
private SearchManager mSearchManager = null;
private SensorManager mSensorManager = null;
@@ -201,9 +195,6 @@ class ApplicationContext extends Context {
private File mCacheDir;
- private Drawable mWallpaper;
- private IWallpaperServiceCallback mWallpaperCallback = null;
-
private static long sInstanceCount = 0;
private static final String[] EMPTY_FILE_LIST = {};
@@ -523,130 +514,37 @@ class ApplicationContext extends Context {
@Override
public Drawable getWallpaper() {
- Drawable dr = peekWallpaper();
- return dr != null ? dr : getResources().getDrawable(
- com.android.internal.R.drawable.default_wallpaper);
+ return getWallpaperManager().get();
}
@Override
- public synchronized Drawable peekWallpaper() {
- if (mWallpaper != null) {
- return mWallpaper;
- }
- mWallpaperCallback = new WallpaperCallback(this);
- mWallpaper = getCurrentWallpaperLocked();
- return mWallpaper;
- }
-
- private Drawable getCurrentWallpaperLocked() {
- try {
- ParcelFileDescriptor fd = getWallpaperService().getWallpaper(mWallpaperCallback);
- if (fd != null) {
- Bitmap bm = BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
- if (bm != null) {
- // For now clear the density until we figure out how
- // to deal with it for wallpapers.
- bm.setDensity(0);
- return new BitmapDrawable(getResources(), bm);
- }
- }
- } catch (RemoteException e) {
- }
- return null;
+ public Drawable peekWallpaper() {
+ return getWallpaperManager().peek();
}
@Override
public int getWallpaperDesiredMinimumWidth() {
- try {
- return getWallpaperService().getWidthHint();
- } catch (RemoteException e) {
- // Shouldn't happen!
- return 0;
- }
+ return getWallpaperManager().getDesiredMinimumWidth();
}
@Override
public int getWallpaperDesiredMinimumHeight() {
- try {
- return getWallpaperService().getHeightHint();
- } catch (RemoteException e) {
- // Shouldn't happen!
- return 0;
- }
+ return getWallpaperManager().getDesiredMinimumHeight();
}
@Override
public void setWallpaper(Bitmap bitmap) throws IOException {
- try {
- ParcelFileDescriptor fd = getWallpaperService().setWallpaper(null);
- if (fd == null) {
- return;
- }
- FileOutputStream fos = null;
- try {
- fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
- bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
- } finally {
- if (fos != null) {
- fos.close();
- }
- }
- } catch (RemoteException e) {
- }
+ getWallpaperManager().set(bitmap);
}
@Override
public void setWallpaper(InputStream data) throws IOException {
- try {
- ParcelFileDescriptor fd = getWallpaperService().setWallpaper(null);
- if (fd == null) {
- return;
- }
- FileOutputStream fos = null;
- try {
- fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
- setWallpaper(data, fos);
- } finally {
- if (fos != null) {
- fos.close();
- }
- }
- } catch (RemoteException e) {
- }
- }
-
- private void setWallpaper(InputStream data, FileOutputStream fos)
- throws IOException {
- byte[] buffer = new byte[32768];
- int amt;
- while ((amt=data.read(buffer)) > 0) {
- fos.write(buffer, 0, amt);
- }
+ getWallpaperManager().set(data);
}
@Override
public void clearWallpaper() throws IOException {
- try {
- Resources resources = getResources();
- /* Set the wallpaper to the default values */
- ParcelFileDescriptor fd = getWallpaperService().setWallpaper(
- "res:" + resources.getResourceName(
- com.android.internal.R.drawable.default_wallpaper));
- if (fd != null) {
- FileOutputStream fos = null;
- try {
- fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
- setWallpaper(resources.openRawResource(
- com.android.internal.R.drawable.default_wallpaper),
- fos);
- } finally {
- if (fos != null) {
- fos.close();
- }
- }
- }
- } catch (RemoteException e) {
- }
+ getWallpaperManager().clear();
}
@Override
@@ -907,6 +805,8 @@ class ApplicationContext extends Context {
}
} else if (ACTIVITY_SERVICE.equals(name)) {
return getActivityManager();
+ } else if (INPUT_METHOD_SERVICE.equals(name)) {
+ return InputMethodManager.getInstance(this);
} else if (ALARM_SERVICE.equals(name)) {
return getAlarmManager();
} else if (ACCOUNT_SERVICE.equals(name)) {
@@ -927,7 +827,7 @@ class ApplicationContext extends Context {
return getLocationManager();
} else if (SEARCH_SERVICE.equals(name)) {
return getSearchManager();
- } else if ( SENSOR_SERVICE.equals(name)) {
+ } else if (SENSOR_SERVICE.equals(name)) {
return getSensorManager();
} else if (BLUETOOTH_SERVICE.equals(name)) {
return getBluetoothDevice();
@@ -946,8 +846,8 @@ class ApplicationContext extends Context {
return getTelephonyManager();
} else if (CLIPBOARD_SERVICE.equals(name)) {
return getClipboardManager();
- } else if (INPUT_METHOD_SERVICE.equals(name)) {
- return InputMethodManager.getInstance(this);
+ } else if (WALLPAPER_SERVICE.equals(name)) {
+ return getWallpaperManager();
}
return null;
@@ -1020,8 +920,7 @@ class ApplicationContext extends Context {
return sWifiManager;
}
- private NotificationManager getNotificationManager()
- {
+ private NotificationManager getNotificationManager() {
synchronized (mSync) {
if (mNotificationManager == null) {
mNotificationManager = new NotificationManager(
@@ -1032,6 +931,16 @@ class ApplicationContext extends Context {
return mNotificationManager;
}
+ private WallpaperManager getWallpaperManager() {
+ synchronized (mSync) {
+ if (mWallpaperManager == null) {
+ mWallpaperManager = new WallpaperManager(getOuterContext(),
+ mMainThread.getHandler());
+ }
+ }
+ return mWallpaperManager;
+ }
+
private TelephonyManager getTelephonyManager() {
synchronized (mSync) {
if (mTelephonyManager == null) {
@@ -1106,16 +1015,6 @@ class ApplicationContext extends Context {
return mVibrator;
}
- private IWallpaperService getWallpaperService() {
- synchronized (sSync) {
- if (sWallpaperService == null) {
- IBinder b = ServiceManager.getService(WALLPAPER_SERVICE);
- sWallpaperService = IWallpaperService.Stub.asInterface(b);
- }
- }
- return sWallpaperService;
- }
-
private AudioManager getAudioManager()
{
if (mAudioManager == null) {
@@ -2820,25 +2719,4 @@ class ApplicationContext extends Context {
return false;
}
}
-
- private static class WallpaperCallback extends IWallpaperServiceCallback.Stub {
- private WeakReference<ApplicationContext> mContext;
-
- public WallpaperCallback(ApplicationContext context) {
- mContext = new WeakReference<ApplicationContext>(context);
- }
-
- public synchronized void onWallpaperChanged() {
-
- /* The wallpaper has changed but we shouldn't eagerly load the
- * wallpaper as that would be inefficient. Reset the cached wallpaper
- * to null so if the user requests the wallpaper again then we'll
- * fetch it.
- */
- final ApplicationContext applicationContext = mContext.get();
- if (applicationContext != null) {
- applicationContext.mWallpaper = null;
- }
- }
- }
}
diff --git a/core/java/android/app/IWallpaperService.aidl b/core/java/android/app/IWallpaperManager.aidl
index 281a060274b8..1ed9b9f18d02 100644
--- a/core/java/android/app/IWallpaperService.aidl
+++ b/core/java/android/app/IWallpaperManager.aidl
@@ -17,10 +17,10 @@
package android.app;
import android.os.ParcelFileDescriptor;
-import android.app.IWallpaperServiceCallback;
+import android.app.IWallpaperManagerCallback;
/** @hide */
-interface IWallpaperService {
+interface IWallpaperManager {
/**
* Set the wallpaper.
@@ -30,7 +30,7 @@ interface IWallpaperService {
/**
* Get the wallpaper.
*/
- ParcelFileDescriptor getWallpaper(IWallpaperServiceCallback cb);
+ ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb);
/**
* Clear the wallpaper.
diff --git a/core/java/android/app/IWallpaperServiceCallback.aidl b/core/java/android/app/IWallpaperManagerCallback.aidl
index 6086f400267d..991b2bc924b5 100644
--- a/core/java/android/app/IWallpaperServiceCallback.aidl
+++ b/core/java/android/app/IWallpaperManagerCallback.aidl
@@ -17,13 +17,13 @@
package android.app;
/**
- * Callback interface used by IWallpaperService to send asynchronous
+ * Callback interface used by IWallpaperManager to send asynchronous
* notifications back to its clients. Note that this is a
* one-way interface so the server does not block waiting for the client.
*
* @hide
*/
-oneway interface IWallpaperServiceCallback {
+oneway interface IWallpaperManagerCallback {
/**
* Called when the wallpaper has changed
*/
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
new file mode 100644
index 000000000000..0a354c07e358
--- /dev/null
+++ b/core/java/android/app/WallpaperManager.java
@@ -0,0 +1,288 @@
+package android.app;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class WallpaperManager {
+ private static String TAG = "WallpaperManager";
+ private static boolean DEBUG = false;
+
+ private final Context mContext;
+
+ static class Globals extends IWallpaperManagerCallback.Stub {
+ private IWallpaperManager mService;
+ private Drawable mWallpaper;
+
+ Globals() {
+ IBinder b = ServiceManager.getService(Context.WALLPAPER_SERVICE);
+ mService = IWallpaperManager.Stub.asInterface(b);
+ }
+
+ public void onWallpaperChanged() {
+ /* The wallpaper has changed but we shouldn't eagerly load the
+ * wallpaper as that would be inefficient. Reset the cached wallpaper
+ * to null so if the user requests the wallpaper again then we'll
+ * fetch it.
+ */
+ synchronized (this) {
+ mWallpaper = null;
+ }
+ }
+
+ public Drawable peekWallpaper(Context context) {
+ synchronized (this) {
+ if (mWallpaper != null) {
+ return mWallpaper;
+ }
+ mWallpaper = getCurrentWallpaperLocked(context);
+ return mWallpaper;
+ }
+ }
+
+ private Drawable getCurrentWallpaperLocked(Context context) {
+ try {
+ ParcelFileDescriptor fd = mService.getWallpaper(this);
+ if (fd != null) {
+ Bitmap bm = BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
+ if (bm != null) {
+ // For now clear the density until we figure out how
+ // to deal with it for wallpapers.
+ bm.setDensity(0);
+ return new BitmapDrawable(context.getResources(), bm);
+ }
+ }
+ } catch (RemoteException e) {
+ }
+ return null;
+ }
+ }
+
+ private static Object mSync = new Object();
+ private static Globals sGlobals;
+
+ static Globals getGlobals() {
+ synchronized (mSync) {
+ if (sGlobals == null) {
+ sGlobals = new Globals();
+ }
+ return sGlobals;
+ }
+ }
+
+ /*package*/ WallpaperManager(Context context, Handler handler) {
+ mContext = context;
+ }
+
+ /**
+ * Like {@link #peekWallpaper}, but always returns a valid Drawable. If
+ * no wallpaper is set, the system default wallpaper is returned.
+ *
+ * @return Returns a Drawable object that will draw the wallpaper.
+ */
+ public Drawable get() {
+ Drawable dr = peek();
+ return dr != null ? dr : Resources.getSystem().getDrawable(
+ com.android.internal.R.drawable.default_wallpaper);
+ }
+
+ /**
+ * Retrieve the current system wallpaper. This is returned as an
+ * abstract Drawable that you can install in a View to display whatever
+ * wallpaper the user has currently set. If there is no wallpaper set,
+ * a null pointer is returned.
+ *
+ * @return Returns a Drawable object that will draw the wallpaper or a
+ * null pointer if these is none.
+ */
+ public Drawable peek() {
+ return getGlobals().peekWallpaper(mContext);
+ }
+
+ /**
+ * Change the current system wallpaper to the bitmap in the given resource.
+ * The resource is opened as a raw data stream and copied into the
+ * wallpaper; it must be a valid PNG or JPEG image. On success, the intent
+ * {@link Intent#ACTION_WALLPAPER_CHANGED} is broadcast.
+ *
+ * @param resid The bitmap to save.
+ *
+ * @throws IOException If an error occurs reverting to the default
+ * wallpaper.
+ */
+ public void set(int resid) throws IOException {
+ try {
+ Resources resources = mContext.getResources();
+ /* Set the wallpaper to the default values */
+ ParcelFileDescriptor fd = getGlobals().mService.setWallpaper(
+ "res:" + resources.getResourceName(resid));
+ if (fd != null) {
+ FileOutputStream fos = null;
+ try {
+ fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
+ setWallpaper(resources.openRawResource(resid), fos);
+ } finally {
+ if (fos != null) {
+ fos.close();
+ }
+ }
+ }
+ } catch (RemoteException e) {
+ }
+ }
+
+ /**
+ * Change the current system wallpaper to a bitmap. The given bitmap is
+ * converted to a PNG and stored as the wallpaper. On success, the intent
+ * {@link Intent#ACTION_WALLPAPER_CHANGED} is broadcast.
+ *
+ * @param bitmap The bitmap to save.
+ *
+ * @throws IOException If an error occurs reverting to the default
+ * wallpaper.
+ */
+ public void set(Bitmap bitmap) throws IOException {
+ try {
+ ParcelFileDescriptor fd = getGlobals().mService.setWallpaper(null);
+ if (fd == null) {
+ return;
+ }
+ FileOutputStream fos = null;
+ try {
+ fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
+ bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
+ } finally {
+ if (fos != null) {
+ fos.close();
+ }
+ }
+ } catch (RemoteException e) {
+ }
+ }
+
+ /**
+ * Change the current system wallpaper to a specific byte stream. The
+ * give InputStream is copied into persistent storage and will now be
+ * used as the wallpaper. Currently it must be either a JPEG or PNG
+ * image. On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED}
+ * is broadcast.
+ *
+ * @param data A stream containing the raw data to install as a wallpaper.
+ *
+ * @throws IOException If an error occurs reverting to the default
+ * wallpaper.
+ */
+ public void set(InputStream data) throws IOException {
+ try {
+ ParcelFileDescriptor fd = getGlobals().mService.setWallpaper(null);
+ if (fd == null) {
+ return;
+ }
+ FileOutputStream fos = null;
+ try {
+ fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
+ setWallpaper(data, fos);
+ } finally {
+ if (fos != null) {
+ fos.close();
+ }
+ }
+ } catch (RemoteException e) {
+ }
+ }
+
+ private void setWallpaper(InputStream data, FileOutputStream fos)
+ throws IOException {
+ byte[] buffer = new byte[32768];
+ int amt;
+ while ((amt=data.read(buffer)) > 0) {
+ fos.write(buffer, 0, amt);
+ }
+ }
+
+ /**
+ * Returns the desired minimum width for the wallpaper. Callers of
+ * {@link #set(android.graphics.Bitmap)} or
+ * {@link #set(java.io.InputStream)} should check this value
+ * beforehand to make sure the supplied wallpaper respects the desired
+ * minimum width.
+ *
+ * If the returned value is <= 0, the caller should use the width of
+ * the default display instead.
+ *
+ * @return The desired minimum width for the wallpaper. This value should
+ * be honored by applications that set the wallpaper but it is not
+ * mandatory.
+ */
+ public int getDesiredMinimumWidth() {
+ try {
+ return getGlobals().mService.getWidthHint();
+ } catch (RemoteException e) {
+ // Shouldn't happen!
+ return 0;
+ }
+ }
+
+ /**
+ * Returns the desired minimum height for the wallpaper. Callers of
+ * {@link #set(android.graphics.Bitmap)} or
+ * {@link #set(java.io.InputStream)} should check this value
+ * beforehand to make sure the supplied wallpaper respects the desired
+ * minimum height.
+ *
+ * If the returned value is <= 0, the caller should use the height of
+ * the default display instead.
+ *
+ * @return The desired minimum height for the wallpaper. This value should
+ * be honored by applications that set the wallpaper but it is not
+ * mandatory.
+ */
+ public int getDesiredMinimumHeight() {
+ try {
+ return getGlobals().mService.getHeightHint();
+ } catch (RemoteException e) {
+ // Shouldn't happen!
+ return 0;
+ }
+ }
+
+ /**
+ * For use only by the current home application, to specify the size of
+ * wallpaper it would like to use. This allows such applications to have
+ * a virtual wallpaper that is larger than the physical screen, matching
+ * the size of their workspace.
+ * @param minimumWidth Desired minimum width
+ * @param minimumHeight Desired minimum height
+ */
+ public void setDimensionHints(int minimumWidth, int minimumHeight) {
+ try {
+ getGlobals().mService.setDimensionHints(minimumWidth, minimumHeight);
+ } catch (RemoteException e) {
+ }
+ }
+
+ /**
+ * Remove any currently set wallpaper, reverting to the system's default
+ * wallpaper. On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED}
+ * is broadcast.
+ *
+ * @throws IOException If an error occurs reverting to the default
+ * wallpaper.
+ */
+ public void clear() throws IOException {
+ set(com.android.internal.R.drawable.default_wallpaper);
+ }
+}
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 84449ef8f3c7..1105899e3841 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -488,89 +488,44 @@ public abstract class Context {
public abstract String[] databaseList();
/**
- * Like {@link #peekWallpaper}, but always returns a valid Drawable. If
- * no wallpaper is set, the system default wallpaper is returned.
- *
- * @return Returns a Drawable object that will draw the wallpaper.
+ * @deprecated Use {@link android.app.WallpaperManager#get
+ * WallpaperManager.get()} instead.
*/
public abstract Drawable getWallpaper();
/**
- * Retrieve the current system wallpaper. This is returned as an
- * abstract Drawable that you can install in a View to display whatever
- * wallpaper the user has currently set. If there is no wallpaper set,
- * a null pointer is returned.
- *
- * @return Returns a Drawable object that will draw the wallpaper or a
- * null pointer if these is none.
+ * @deprecated Use {@link android.app.WallpaperManager#peek
+ * WallpaperManager.peek()} instead.
*/
public abstract Drawable peekWallpaper();
/**
- * Returns the desired minimum width for the wallpaper. Callers of
- * {@link #setWallpaper(android.graphics.Bitmap)} or
- * {@link #setWallpaper(java.io.InputStream)} should check this value
- * beforehand to make sure the supplied wallpaper respects the desired
- * minimum width.
- *
- * If the returned value is <= 0, the caller should use the width of
- * the default display instead.
- *
- * @return The desired minimum width for the wallpaper. This value should
- * be honored by applications that set the wallpaper but it is not
- * mandatory.
+ * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
+ * WallpaperManager.getDesiredMinimumWidth()} instead.
*/
public abstract int getWallpaperDesiredMinimumWidth();
/**
- * Returns the desired minimum height for the wallpaper. Callers of
- * {@link #setWallpaper(android.graphics.Bitmap)} or
- * {@link #setWallpaper(java.io.InputStream)} should check this value
- * beforehand to make sure the supplied wallpaper respects the desired
- * minimum height.
- *
- * If the returned value is <= 0, the caller should use the height of
- * the default display instead.
- *
- * @return The desired minimum height for the wallpaper. This value should
- * be honored by applications that set the wallpaper but it is not
- * mandatory.
+ * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
+ * WallpaperManager.getDesiredMinimumHeight()} instead.
*/
public abstract int getWallpaperDesiredMinimumHeight();
/**
- * Change the current system wallpaper to a bitmap. The given bitmap is
- * converted to a PNG and stored as the wallpaper. On success, the intent
- * {@link Intent#ACTION_WALLPAPER_CHANGED} is broadcast.
- *
- * @param bitmap The bitmap to save.
- *
- * @throws IOException If an error occurs reverting to the default
- * wallpaper.
+ * @deprecated Use {@link android.app.WallpaperManager#set(Bitmap)
+ * WallpaperManager.set()} instead.
*/
public abstract void setWallpaper(Bitmap bitmap) throws IOException;
/**
- * Change the current system wallpaper to a specific byte stream. The
- * give InputStream is copied into persistent storage and will now be
- * used as the wallpaper. Currently it must be either a JPEG or PNG
- * image. On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED}
- * is broadcast.
- *
- * @param data A stream containing the raw data to install as a wallpaper.
- *
- * @throws IOException If an error occurs reverting to the default
- * wallpaper.
+ * @deprecated Use {@link android.app.WallpaperManager#set(InputStream)
+ * WallpaperManager.set()} instead.
*/
public abstract void setWallpaper(InputStream data) throws IOException;
/**
- * Remove any currently set wallpaper, reverting to the system's default
- * wallpaper. On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED}
- * is broadcast.
- *
- * @throws IOException If an error occurs reverting to the default
- * wallpaper.
+ * @deprecated Use {@link android.app.WallpaperManager#clear
+ * WallpaperManager.clear()} instead.
*/
public abstract void clearWallpaper() throws IOException;
diff --git a/core/java/android/service/wallpaper/IWallpaperService.aidl b/core/java/android/service/wallpaper/IWallpaperService.aidl
new file mode 100644
index 000000000000..97e032b9f5e8
--- /dev/null
+++ b/core/java/android/service/wallpaper/IWallpaperService.aidl
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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 android.service.wallpaper;
+
+/**
+ * @hide
+ */
+oneway interface IWallpaperService {
+ void onInterrupt();
+}
diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java
new file mode 100644
index 000000000000..a729ed5a2a7f
--- /dev/null
+++ b/core/java/android/service/wallpaper/WallpaperService.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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 android.service.wallpaper;
+
+import com.android.internal.os.HandlerCaller;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.RemoteException;
+import android.util.Log;
+
+/**
+ * A wallpaper service is responsible for showing a live wallpaper behind
+ * applications that would like to sit on top of it.
+ */
+public abstract class WallpaperService extends Service {
+ /**
+ * The {@link Intent} that must be declared as handled by the service.
+ */
+ public static final String SERVICE_INTERFACE =
+ "android.service.wallpaper.WallpaperService";
+
+ private static final String LOG_TAG = "WallpaperService";
+
+ /**
+ * Implement to return the implementation of the internal accessibility
+ * service interface. Subclasses should not override.
+ */
+ @Override
+ public final IBinder onBind(Intent intent) {
+ return new IWallpaperServiceWrapper(this);
+ }
+
+ /**
+ * Implements the internal {@link IWallpaperService} interface to convert
+ * incoming calls to it back to calls on an {@link WallpaperService}.
+ */
+ class IWallpaperServiceWrapper extends IWallpaperService.Stub
+ implements HandlerCaller.Callback {
+
+ private static final int DO_ON_INTERRUPT = 10;
+
+ private final HandlerCaller mCaller;
+
+ private WallpaperService mTarget;
+
+ public IWallpaperServiceWrapper(WallpaperService context) {
+ mTarget = context;
+ mCaller = new HandlerCaller(context, this);
+ }
+
+ public void onInterrupt() {
+ Message message = mCaller.obtainMessage(DO_ON_INTERRUPT);
+ mCaller.sendMessage(message);
+ }
+
+ public void executeMessage(Message message) {
+ switch (message.what) {
+ case DO_ON_INTERRUPT :
+ //mTarget.onInterrupt();
+ return;
+ default :
+ Log.w(LOG_TAG, "Unknown message type " + message.what);
+ }
+ }
+ }
+}
diff --git a/services/java/com/android/server/SystemBackupAgent.java b/services/java/com/android/server/SystemBackupAgent.java
index b6819615db22..17d0f1d9edba 100644
--- a/services/java/com/android/server/SystemBackupAgent.java
+++ b/services/java/com/android/server/SystemBackupAgent.java
@@ -53,7 +53,7 @@ public class SystemBackupAgent extends BackupHelperAgent {
try {
super.onRestore(data, appVersionCode, newState);
- WallpaperService wallpaper = (WallpaperService)ServiceManager.getService(
+ WallpaperManagerService wallpaper = (WallpaperManagerService)ServiceManager.getService(
Context.WALLPAPER_SERVICE);
wallpaper.settingsRestored();
} catch (IOException ex) {
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 48d97eca19d1..c30386e8cfe5 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -301,7 +301,7 @@ class ServerThread extends Thread {
try {
Log.i(TAG, "Starting Wallpaper Service");
- ServiceManager.addService(Context.WALLPAPER_SERVICE, new WallpaperService(context));
+ ServiceManager.addService(Context.WALLPAPER_SERVICE, new WallpaperManagerService(context));
} catch (Throwable e) {
Log.e(TAG, "Failure starting Wallpaper Service", e);
}
diff --git a/services/java/com/android/server/WallpaperService.java b/services/java/com/android/server/WallpaperManagerService.java
index 67b60a63d4e9..c5fd9850dff3 100644
--- a/services/java/com/android/server/WallpaperService.java
+++ b/services/java/com/android/server/WallpaperManagerService.java
@@ -19,8 +19,8 @@ package com.android.server;
import static android.os.FileObserver.*;
import static android.os.ParcelFileDescriptor.*;
-import android.app.IWallpaperService;
-import android.app.IWallpaperServiceCallback;
+import android.app.IWallpaperManager;
+import android.app.IWallpaperManagerCallback;
import android.backup.BackupManager;
import android.content.Context;
import android.content.Intent;
@@ -49,7 +49,7 @@ import org.xmlpull.v1.XmlSerializer;
import com.android.internal.util.FastXmlSerializer;
-class WallpaperService extends IWallpaperService.Stub {
+class WallpaperManagerService extends IWallpaperManager.Stub {
private static final String TAG = "WallpaperService";
private Object mLock = new Object();
@@ -63,8 +63,8 @@ class WallpaperService extends IWallpaperService.Stub {
* List of callbacks registered they should each be notified
* when the wallpaper is changed.
*/
- private final RemoteCallbackList<IWallpaperServiceCallback> mCallbacks
- = new RemoteCallbackList<IWallpaperServiceCallback>();
+ private final RemoteCallbackList<IWallpaperManagerCallback> mCallbacks
+ = new RemoteCallbackList<IWallpaperManagerCallback>();
/**
* Observes the wallpaper for changes and notifies all IWallpaperServiceCallbacks
@@ -100,7 +100,7 @@ class WallpaperService extends IWallpaperService.Stub {
private int mHeight = -1;
private String mName = "";
- public WallpaperService(Context context) {
+ public WallpaperManagerService(Context context) {
if (Config.LOGD) Log.d(TAG, "WallpaperService startup");
mContext = context;
WALLPAPER_DIR.mkdirs();
@@ -151,7 +151,7 @@ class WallpaperService extends IWallpaperService.Stub {
}
}
- public ParcelFileDescriptor getWallpaper(IWallpaperServiceCallback cb) {
+ public ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb) {
synchronized (mLock) {
try {
mCallbacks.register(cb);