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;
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations