Search in sources :

Example 86 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.

the class ShortcutService method shrinkBitmap.

@VisibleForTesting
static Bitmap shrinkBitmap(Bitmap in, int maxSize) {
    // Original width/height.
    final int ow = in.getWidth();
    final int oh = in.getHeight();
    if ((ow <= maxSize) && (oh <= maxSize)) {
        if (DEBUG) {
            Slog.d(TAG, String.format("Icon size %dx%d, no need to shrink", ow, oh));
        }
        return in;
    }
    final int longerDimension = Math.max(ow, oh);
    // New width and height.
    final int nw = ow * maxSize / longerDimension;
    final int nh = oh * maxSize / longerDimension;
    if (DEBUG) {
        Slog.d(TAG, String.format("Icon size %dx%d, shrinking to %dx%d", ow, oh, nw, nh));
    }
    final Bitmap scaledBitmap = Bitmap.createBitmap(nw, nh, Bitmap.Config.ARGB_8888);
    final Canvas c = new Canvas(scaledBitmap);
    final RectF dst = new RectF(0, 0, nw, nh);
    c.drawBitmap(in, /*src=*/
    null, dst, /* paint =*/
    null);
    return scaledBitmap;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 87 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.

the class ShortcutService method updateConfigurationLocked.

/**
     * Load the configuration from Settings.
     */
@VisibleForTesting
boolean updateConfigurationLocked(String config) {
    boolean result = true;
    final KeyValueListParser parser = new KeyValueListParser(',');
    try {
        parser.setString(config);
    } catch (IllegalArgumentException e) {
        // Failed to parse the settings string, log this and move on
        // with defaults.
        Slog.e(TAG, "Bad shortcut manager settings", e);
        result = false;
    }
    mSaveDelayMillis = Math.max(0, (int) parser.getLong(ConfigConstants.KEY_SAVE_DELAY_MILLIS, DEFAULT_SAVE_DELAY_MS));
    mResetInterval = Math.max(1, parser.getLong(ConfigConstants.KEY_RESET_INTERVAL_SEC, DEFAULT_RESET_INTERVAL_SEC) * 1000L);
    mMaxUpdatesPerInterval = Math.max(0, (int) parser.getLong(ConfigConstants.KEY_MAX_UPDATES_PER_INTERVAL, DEFAULT_MAX_UPDATES_PER_INTERVAL));
    mMaxShortcuts = Math.max(0, (int) parser.getLong(ConfigConstants.KEY_MAX_SHORTCUTS, DEFAULT_MAX_SHORTCUTS_PER_APP));
    final int iconDimensionDp = Math.max(1, injectIsLowRamDevice() ? (int) parser.getLong(ConfigConstants.KEY_MAX_ICON_DIMENSION_DP_LOWRAM, DEFAULT_MAX_ICON_DIMENSION_LOWRAM_DP) : (int) parser.getLong(ConfigConstants.KEY_MAX_ICON_DIMENSION_DP, DEFAULT_MAX_ICON_DIMENSION_DP));
    mMaxIconDimension = injectDipToPixel(iconDimensionDp);
    mIconPersistFormat = CompressFormat.valueOf(parser.getString(ConfigConstants.KEY_ICON_FORMAT, DEFAULT_ICON_PERSIST_FORMAT));
    mIconPersistQuality = (int) parser.getLong(ConfigConstants.KEY_ICON_QUALITY, DEFAULT_ICON_PERSIST_QUALITY);
    return result;
}
Also used : KeyValueListParser(android.util.KeyValueListParser) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 88 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.

the class ShortcutService method saveBaseStateLocked.

@VisibleForTesting
void saveBaseStateLocked() {
    final AtomicFile file = getBaseStateFile();
    if (DEBUG) {
        Slog.d(TAG, "Saving to " + file.getBaseFile());
    }
    FileOutputStream outs = null;
    try {
        outs = file.startWrite();
        // Write to XML
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(outs, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, TAG_ROOT);
        // Body.
        writeTagValue(out, TAG_LAST_RESET_TIME, mRawLastResetTime);
        // Epilogue.
        out.endTag(null, TAG_ROOT);
        out.endDocument();
        // Close.
        file.finishWrite(outs);
    } catch (IOException e) {
        Slog.e(TAG, "Failed to write to file " + file.getBaseFile(), e);
        file.failWrite(outs);
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) AtomicFile(android.util.AtomicFile) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 89 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by DirtyUnicorns.

the class ShortcutService method injectIsActivityEnabledAndExported.

/**
     * Return whether an activity is enabled and exported.
     */
@VisibleForTesting
boolean injectIsActivityEnabledAndExported(@NonNull ComponentName activity, @UserIdInt int userId) {
    final long start = injectElapsedRealtime();
    final long token = injectClearCallingIdentity();
    try {
        return queryActivities(new Intent(), activity.getPackageName(), activity, userId).size() > 0;
    } finally {
        injectRestoreCallingIdentity(token);
        logDurationStat(Stats.IS_ACTIVITY_ENABLED, start);
    }
}
Also used : Intent(android.content.Intent) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 90 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by DirtyUnicorns.

the class ShortcutService method updateConfigurationLocked.

/**
     * Load the configuration from Settings.
     */
@VisibleForTesting
boolean updateConfigurationLocked(String config) {
    boolean result = true;
    final KeyValueListParser parser = new KeyValueListParser(',');
    try {
        parser.setString(config);
    } catch (IllegalArgumentException e) {
        // Failed to parse the settings string, log this and move on
        // with defaults.
        Slog.e(TAG, "Bad shortcut manager settings", e);
        result = false;
    }
    mSaveDelayMillis = Math.max(0, (int) parser.getLong(ConfigConstants.KEY_SAVE_DELAY_MILLIS, DEFAULT_SAVE_DELAY_MS));
    mResetInterval = Math.max(1, parser.getLong(ConfigConstants.KEY_RESET_INTERVAL_SEC, DEFAULT_RESET_INTERVAL_SEC) * 1000L);
    mMaxUpdatesPerInterval = Math.max(0, (int) parser.getLong(ConfigConstants.KEY_MAX_UPDATES_PER_INTERVAL, DEFAULT_MAX_UPDATES_PER_INTERVAL));
    mMaxShortcuts = Math.max(0, (int) parser.getLong(ConfigConstants.KEY_MAX_SHORTCUTS, DEFAULT_MAX_SHORTCUTS_PER_APP));
    final int iconDimensionDp = Math.max(1, injectIsLowRamDevice() ? (int) parser.getLong(ConfigConstants.KEY_MAX_ICON_DIMENSION_DP_LOWRAM, DEFAULT_MAX_ICON_DIMENSION_LOWRAM_DP) : (int) parser.getLong(ConfigConstants.KEY_MAX_ICON_DIMENSION_DP, DEFAULT_MAX_ICON_DIMENSION_DP));
    mMaxIconDimension = injectDipToPixel(iconDimensionDp);
    mIconPersistFormat = CompressFormat.valueOf(parser.getString(ConfigConstants.KEY_ICON_FORMAT, DEFAULT_ICON_PERSIST_FORMAT));
    mIconPersistQuality = (int) parser.getLong(ConfigConstants.KEY_ICON_QUALITY, DEFAULT_ICON_PERSIST_QUALITY);
    return result;
}
Also used : KeyValueListParser(android.util.KeyValueListParser) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.android.internal.annotations.VisibleForTesting)141 ArrayList (java.util.ArrayList)39 IOException (java.io.IOException)26 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)18 ComponentName (android.content.ComponentName)15 File (java.io.File)14 RemoteException (android.os.RemoteException)13 ArraySet (android.util.ArraySet)10 AtomicFile (android.util.AtomicFile)10 FileInputStream (java.io.FileInputStream)10 Locale (java.util.Locale)10 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)9 FileNotFoundException (java.io.FileNotFoundException)9 Notification (android.app.Notification)6 ErrnoException (android.system.ErrnoException)6 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)6 FileOutputStream (java.io.FileOutputStream)6 XmlSerializer (org.xmlpull.v1.XmlSerializer)6 ITransientNotification (android.app.ITransientNotification)5 UserInfo (android.content.pm.UserInfo)5