Search in sources :

Example 11 with DeadSystemException

use of android.os.DeadSystemException in project platform_frameworks_base by android.

the class WallpaperManager method hasResourceWallpaper.

/**
     * Return whether any users are currently set to use the wallpaper
     * with the given resource ID.  That is, their wallpaper has been
     * set through {@link #setResource(int)} with the same resource id.
     */
public boolean hasResourceWallpaper(@RawRes int resid) {
    if (sGlobals.mService == null) {
        Log.w(TAG, "WallpaperService not running");
        throw new RuntimeException(new DeadSystemException());
    }
    try {
        Resources resources = mContext.getResources();
        String name = "res:" + resources.getResourceName(resid);
        return sGlobals.mService.hasNamedWallpaper(name);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
Also used : DeadSystemException(android.os.DeadSystemException) Resources(android.content.res.Resources) RemoteException(android.os.RemoteException)

Example 12 with DeadSystemException

use of android.os.DeadSystemException in project android_frameworks_base by crdroidandroid.

the class WallpaperManager method hasResourceWallpaper.

/**
     * Return whether any users are currently set to use the wallpaper
     * with the given resource ID.  That is, their wallpaper has been
     * set through {@link #setResource(int)} with the same resource id.
     */
public boolean hasResourceWallpaper(@RawRes int resid) {
    if (sGlobals.mService == null) {
        Log.w(TAG, "WallpaperService not running");
        throw new RuntimeException(new DeadSystemException());
    }
    try {
        Resources resources = mContext.getResources();
        String name = "res:" + resources.getResourceName(resid);
        return sGlobals.mService.hasNamedWallpaper(name);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
Also used : DeadSystemException(android.os.DeadSystemException) Resources(android.content.res.Resources) RemoteException(android.os.RemoteException)

Example 13 with DeadSystemException

use of android.os.DeadSystemException in project android_frameworks_base by crdroidandroid.

the class WallpaperManager method setBitmap.

/**
     * Like {@link #setBitmap(Bitmap, Rect, boolean, int)}, but allows to pass in an explicit user
     * id. If the user id doesn't match the user id the process is running under, calling this
     * requires permission {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}.
     * @hide
     */
public int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup, @SetWallpaperFlags int which, int userId) throws IOException {
    validateRect(visibleCropHint);
    if (sGlobals.mService == null) {
        Log.w(TAG, "WallpaperService not running");
        throw new RuntimeException(new DeadSystemException());
    }
    final Bundle result = new Bundle();
    final WallpaperSetCompletion completion = new WallpaperSetCompletion();
    try {
        ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null, mContext.getOpPackageName(), visibleCropHint, allowBackup, result, which, completion, userId);
        if (fd != null) {
            FileOutputStream fos = null;
            try {
                fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
                fullImage.compress(Bitmap.CompressFormat.PNG, 90, fos);
                fos.close();
                completion.waitForCompletion();
            } finally {
                IoUtils.closeQuietly(fos);
            }
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
    return result.getInt(EXTRA_NEW_WALLPAPER_ID, 0);
}
Also used : DeadSystemException(android.os.DeadSystemException) Bundle(android.os.Bundle) FileOutputStream(java.io.FileOutputStream) ParcelFileDescriptor(android.os.ParcelFileDescriptor) RemoteException(android.os.RemoteException)

Example 14 with DeadSystemException

use of android.os.DeadSystemException in project android_frameworks_base by crdroidandroid.

the class WallpaperManager method setResource.

/**
     * Version of {@link #setResource(int)} that allows the caller to specify which
     * of the supported wallpaper categories to set.
     *
     * @param resid The resource ID of the bitmap to be used as the wallpaper image
     * @param which Flags indicating which wallpaper(s) to configure with the new imagery
     *
     * @see #FLAG_LOCK
     * @see #FLAG_SYSTEM
     *
     * @return An integer ID assigned to the newly active wallpaper; or zero on failure.
     *
     * @throws IOException
     */
public int setResource(@RawRes int resid, @SetWallpaperFlags int which) throws IOException {
    if (sGlobals.mService == null) {
        Log.w(TAG, "WallpaperService not running");
        throw new RuntimeException(new DeadSystemException());
    }
    final Bundle result = new Bundle();
    final WallpaperSetCompletion completion = new WallpaperSetCompletion();
    try {
        Resources resources = mContext.getResources();
        /* Set the wallpaper to the default values */
        ParcelFileDescriptor fd = sGlobals.mService.setWallpaper("res:" + resources.getResourceName(resid), mContext.getOpPackageName(), null, false, result, which, completion, UserHandle.myUserId());
        if (fd != null) {
            FileOutputStream fos = null;
            boolean ok = false;
            try {
                fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
                copyStreamToWallpaperFile(resources.openRawResource(resid), fos);
                // The 'close()' is the trigger for any server-side image manipulation,
                // so we must do that before waiting for completion.
                fos.close();
                completion.waitForCompletion();
            } finally {
                // Might be redundant but completion shouldn't wait unless the write
                // succeeded; this is a fallback if it threw past the close+wait.
                IoUtils.closeQuietly(fos);
            }
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
    return result.getInt(EXTRA_NEW_WALLPAPER_ID, 0);
}
Also used : DeadSystemException(android.os.DeadSystemException) Bundle(android.os.Bundle) FileOutputStream(java.io.FileOutputStream) ParcelFileDescriptor(android.os.ParcelFileDescriptor) Resources(android.content.res.Resources) RemoteException(android.os.RemoteException)

Example 15 with DeadSystemException

use of android.os.DeadSystemException in project android_frameworks_base by AOSPA.

the class WallpaperManager method setResource.

/**
     * Version of {@link #setResource(int)} that allows the caller to specify which
     * of the supported wallpaper categories to set.
     *
     * @param resid The resource ID of the bitmap to be used as the wallpaper image
     * @param which Flags indicating which wallpaper(s) to configure with the new imagery
     *
     * @see #FLAG_LOCK
     * @see #FLAG_SYSTEM
     *
     * @return An integer ID assigned to the newly active wallpaper; or zero on failure.
     *
     * @throws IOException
     */
public int setResource(@RawRes int resid, @SetWallpaperFlags int which) throws IOException {
    if (sGlobals.mService == null) {
        Log.w(TAG, "WallpaperService not running");
        throw new RuntimeException(new DeadSystemException());
    }
    final Bundle result = new Bundle();
    final WallpaperSetCompletion completion = new WallpaperSetCompletion();
    try {
        Resources resources = mContext.getResources();
        /* Set the wallpaper to the default values */
        ParcelFileDescriptor fd = sGlobals.mService.setWallpaper("res:" + resources.getResourceName(resid), mContext.getOpPackageName(), null, false, result, which, completion, UserHandle.myUserId());
        if (fd != null) {
            FileOutputStream fos = null;
            boolean ok = false;
            try {
                fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
                copyStreamToWallpaperFile(resources.openRawResource(resid), fos);
                // The 'close()' is the trigger for any server-side image manipulation,
                // so we must do that before waiting for completion.
                fos.close();
                completion.waitForCompletion();
            } finally {
                // Might be redundant but completion shouldn't wait unless the write
                // succeeded; this is a fallback if it threw past the close+wait.
                IoUtils.closeQuietly(fos);
            }
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
    return result.getInt(EXTRA_NEW_WALLPAPER_ID, 0);
}
Also used : DeadSystemException(android.os.DeadSystemException) Bundle(android.os.Bundle) FileOutputStream(java.io.FileOutputStream) ParcelFileDescriptor(android.os.ParcelFileDescriptor) Resources(android.content.res.Resources) RemoteException(android.os.RemoteException)

Aggregations

DeadSystemException (android.os.DeadSystemException)35 RemoteException (android.os.RemoteException)25 Resources (android.content.res.Resources)15 Bundle (android.os.Bundle)15 ParcelFileDescriptor (android.os.ParcelFileDescriptor)15 FileOutputStream (java.io.FileOutputStream)15 Paint (android.graphics.Paint)10 IOException (java.io.IOException)10 NotFoundException (android.content.res.Resources.NotFoundException)5 Bitmap (android.graphics.Bitmap)5 BitmapFactory (android.graphics.BitmapFactory)5 BitmapRegionDecoder (android.graphics.BitmapRegionDecoder)5 Canvas (android.graphics.Canvas)5 Matrix (android.graphics.Matrix)5 Rect (android.graphics.Rect)5 RectF (android.graphics.RectF)5 BitmapDrawable (android.graphics.drawable.BitmapDrawable)5 LineBreakBufferedWriter (com.android.internal.util.LineBreakBufferedWriter)5 BufferedInputStream (java.io.BufferedInputStream)5 FileInputStream (java.io.FileInputStream)5