Search in sources :

Example 1 with DeadSystemException

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

the class Log method printlns.

/**
     * Helper function for long messages. Uses the LineBreakBufferedWriter to break
     * up long messages and stacktraces along newlines, but tries to write in large
     * chunks. This is to avoid truncation.
     * @hide
     */
public static int printlns(int bufID, int priority, String tag, String msg, Throwable tr) {
    ImmediateLogWriter logWriter = new ImmediateLogWriter(bufID, priority, tag);
    // Acceptable buffer size. Get the native buffer size, subtract two zero terminators,
    // and the length of the tag.
    // Note: we implicitly accept possible truncation for Modified-UTF8 differences. It
    //       is too expensive to compute that ahead of time.
    int bufferSize = // Base.
    NoPreloadHolder.LOGGER_ENTRY_MAX_PAYLOAD - // Two terminators.
    2 - // Tag length.
    (tag != null ? tag.length() : 0) - // Some slack.
    32;
    // At least assume you can print *some* characters (tag is not too large).
    bufferSize = Math.max(bufferSize, 100);
    LineBreakBufferedWriter lbbw = new LineBreakBufferedWriter(logWriter, bufferSize);
    lbbw.println(msg);
    if (tr != null) {
        // This is to reduce the amount of log spew that apps do in the non-error
        // condition of the network being unavailable.
        Throwable t = tr;
        while (t != null) {
            if (t instanceof UnknownHostException) {
                break;
            }
            if (t instanceof DeadSystemException) {
                lbbw.println("DeadSystemException: The system died; " + "earlier logs will point to the root cause");
                break;
            }
            t = t.getCause();
        }
        if (t == null) {
            tr.printStackTrace(lbbw);
        }
    }
    lbbw.flush();
    return logWriter.getWritten();
}
Also used : DeadSystemException(android.os.DeadSystemException) UnknownHostException(java.net.UnknownHostException) LineBreakBufferedWriter(com.android.internal.util.LineBreakBufferedWriter)

Example 2 with DeadSystemException

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

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 3 with DeadSystemException

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

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 4 with DeadSystemException

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

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 5 with DeadSystemException

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

the class WallpaperManager method suggestDesiredDimensions.

/**
     * 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.
     *
     * <p>Note developers, who don't seem to be reading this.  This is
     * for <em>home apps</em> to tell what size wallpaper they would like.
     * Nobody else should be calling this!  Certainly not other non-home
     * apps that change the wallpaper.  Those apps are supposed to
     * <b>retrieve</b> the suggested size so they can construct a wallpaper
     * that matches it.
     *
     * <p>This method requires the caller to hold the permission
     * {@link android.Manifest.permission#SET_WALLPAPER_HINTS}.
     *
     * @param minimumWidth Desired minimum width
     * @param minimumHeight Desired minimum height
     */
public void suggestDesiredDimensions(int minimumWidth, int minimumHeight) {
    try {
        /**
             * The framework makes no attempt to limit the window size
             * to the maximum texture size. Any window larger than this
             * cannot be composited.
             *
             * Read maximum texture size from system property and scale down
             * minimumWidth and minimumHeight accordingly.
             */
        int maximumTextureSize;
        try {
            maximumTextureSize = SystemProperties.getInt("sys.max_texture_size", 0);
        } catch (Exception e) {
            maximumTextureSize = 0;
        }
        if (maximumTextureSize > 0) {
            if ((minimumWidth > maximumTextureSize) || (minimumHeight > maximumTextureSize)) {
                float aspect = (float) minimumHeight / (float) minimumWidth;
                if (minimumWidth > minimumHeight) {
                    minimumWidth = maximumTextureSize;
                    minimumHeight = (int) ((minimumWidth * aspect) + 0.5);
                } else {
                    minimumHeight = maximumTextureSize;
                    minimumWidth = (int) ((minimumHeight / aspect) + 0.5);
                }
            }
        }
        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
            throw new RuntimeException(new DeadSystemException());
        } else {
            sGlobals.mService.setDimensionHints(minimumWidth, minimumHeight, mContext.getOpPackageName());
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
Also used : DeadSystemException(android.os.DeadSystemException) RemoteException(android.os.RemoteException) Paint(android.graphics.Paint) DeadSystemException(android.os.DeadSystemException) NotFoundException(android.content.res.Resources.NotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

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