Merge "Implement a global maximum on number of shortcuts an app can publish" into rvc-dev
This commit is contained in:
@@ -1332,9 +1332,15 @@ class ShortcutPackage extends ShortcutPackageItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Then make sure none of the activities have more than the max number of shortcuts.
|
// Then make sure none of the activities have more than the max number of shortcuts.
|
||||||
|
int total = 0;
|
||||||
for (int i = counts.size() - 1; i >= 0; i--) {
|
for (int i = counts.size() - 1; i >= 0; i--) {
|
||||||
service.enforceMaxActivityShortcuts(counts.valueAt(i));
|
int count = counts.valueAt(i);
|
||||||
|
service.enforceMaxActivityShortcuts(count);
|
||||||
|
total += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finally make sure that the app doesn't have more than the max number of shortcuts.
|
||||||
|
service.enforceMaxAppShortcuts(total);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -171,6 +171,9 @@ public class ShortcutService extends IShortcutService.Stub {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int DEFAULT_MAX_SHORTCUTS_PER_ACTIVITY = 15;
|
static final int DEFAULT_MAX_SHORTCUTS_PER_ACTIVITY = 15;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static final int DEFAULT_MAX_SHORTCUTS_PER_APP = 60;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int DEFAULT_MAX_ICON_DIMENSION_DP = 96;
|
static final int DEFAULT_MAX_ICON_DIMENSION_DP = 96;
|
||||||
|
|
||||||
@@ -245,6 +248,11 @@ public class ShortcutService extends IShortcutService.Stub {
|
|||||||
*/
|
*/
|
||||||
String KEY_MAX_SHORTCUTS = "max_shortcuts";
|
String KEY_MAX_SHORTCUTS = "max_shortcuts";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key name for the max dynamic shortcuts per app. (int)
|
||||||
|
*/
|
||||||
|
String KEY_MAX_SHORTCUTS_PER_APP = "max_shortcuts_per_app";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key name for icon compression quality, 0-100.
|
* Key name for icon compression quality, 0-100.
|
||||||
*/
|
*/
|
||||||
@@ -301,10 +309,15 @@ public class ShortcutService extends IShortcutService.Stub {
|
|||||||
private final SparseArray<ShortcutNonPersistentUser> mShortcutNonPersistentUsers =
|
private final SparseArray<ShortcutNonPersistentUser> mShortcutNonPersistentUsers =
|
||||||
new SparseArray<>();
|
new SparseArray<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Max number of dynamic + manifest shortcuts that each activity can have at a time.
|
||||||
|
*/
|
||||||
|
private int mMaxShortcutsPerActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Max number of dynamic + manifest shortcuts that each application can have at a time.
|
* Max number of dynamic + manifest shortcuts that each application can have at a time.
|
||||||
*/
|
*/
|
||||||
private int mMaxShortcuts;
|
private int mMaxShortcutsPerApp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Max number of updating API calls that each application can make during the interval.
|
* Max number of updating API calls that each application can make during the interval.
|
||||||
@@ -729,9 +742,12 @@ public class ShortcutService extends IShortcutService.Stub {
|
|||||||
mMaxUpdatesPerInterval = Math.max(0, (int) parser.getLong(
|
mMaxUpdatesPerInterval = Math.max(0, (int) parser.getLong(
|
||||||
ConfigConstants.KEY_MAX_UPDATES_PER_INTERVAL, DEFAULT_MAX_UPDATES_PER_INTERVAL));
|
ConfigConstants.KEY_MAX_UPDATES_PER_INTERVAL, DEFAULT_MAX_UPDATES_PER_INTERVAL));
|
||||||
|
|
||||||
mMaxShortcuts = Math.max(0, (int) parser.getLong(
|
mMaxShortcutsPerActivity = Math.max(0, (int) parser.getLong(
|
||||||
ConfigConstants.KEY_MAX_SHORTCUTS, DEFAULT_MAX_SHORTCUTS_PER_ACTIVITY));
|
ConfigConstants.KEY_MAX_SHORTCUTS, DEFAULT_MAX_SHORTCUTS_PER_ACTIVITY));
|
||||||
|
|
||||||
|
mMaxShortcutsPerApp = Math.max(0, (int) parser.getLong(
|
||||||
|
ConfigConstants.KEY_MAX_SHORTCUTS_PER_APP, DEFAULT_MAX_SHORTCUTS_PER_APP));
|
||||||
|
|
||||||
final int iconDimensionDp = Math.max(1, injectIsLowRamDevice()
|
final int iconDimensionDp = Math.max(1, injectIsLowRamDevice()
|
||||||
? (int) parser.getLong(
|
? (int) parser.getLong(
|
||||||
ConfigConstants.KEY_MAX_ICON_DIMENSION_DP_LOWRAM,
|
ConfigConstants.KEY_MAX_ICON_DIMENSION_DP_LOWRAM,
|
||||||
@@ -1649,16 +1665,33 @@ public class ShortcutService extends IShortcutService.Stub {
|
|||||||
* {@link #getMaxActivityShortcuts()}.
|
* {@link #getMaxActivityShortcuts()}.
|
||||||
*/
|
*/
|
||||||
void enforceMaxActivityShortcuts(int numShortcuts) {
|
void enforceMaxActivityShortcuts(int numShortcuts) {
|
||||||
if (numShortcuts > mMaxShortcuts) {
|
if (numShortcuts > mMaxShortcutsPerActivity) {
|
||||||
throw new IllegalArgumentException("Max number of dynamic shortcuts exceeded");
|
throw new IllegalArgumentException("Max number of dynamic shortcuts exceeded");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws IllegalArgumentException if {@code numShortcuts} is bigger than
|
||||||
|
* {@link #getMaxAppShortcuts()}.
|
||||||
|
*/
|
||||||
|
void enforceMaxAppShortcuts(int numShortcuts) {
|
||||||
|
if (numShortcuts > mMaxShortcutsPerApp) {
|
||||||
|
throw new IllegalArgumentException("Max number of dynamic shortcuts per app exceeded");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the max number of dynamic + manifest shortcuts for each launcher icon.
|
* Return the max number of dynamic + manifest shortcuts for each launcher icon.
|
||||||
*/
|
*/
|
||||||
int getMaxActivityShortcuts() {
|
int getMaxActivityShortcuts() {
|
||||||
return mMaxShortcuts;
|
return mMaxShortcutsPerActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the max number of dynamic + manifest shortcuts for each launcher icon.
|
||||||
|
*/
|
||||||
|
int getMaxAppShortcuts() {
|
||||||
|
return mMaxShortcutsPerApp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2075,6 +2108,8 @@ public class ShortcutService extends IShortcutService.Stub {
|
|||||||
ps.ensureNotImmutable(shortcut.getId(), /*ignoreInvisible=*/ true);
|
ps.ensureNotImmutable(shortcut.getId(), /*ignoreInvisible=*/ true);
|
||||||
fillInDefaultActivity(Arrays.asList(shortcut));
|
fillInDefaultActivity(Arrays.asList(shortcut));
|
||||||
|
|
||||||
|
enforceMaxAppShortcuts(ps.getShortcutCount());
|
||||||
|
|
||||||
if (!shortcut.hasRank()) {
|
if (!shortcut.hasRank()) {
|
||||||
shortcut.setRank(0);
|
shortcut.setRank(0);
|
||||||
}
|
}
|
||||||
@@ -2493,7 +2528,7 @@ public class ShortcutService extends IShortcutService.Stub {
|
|||||||
throws RemoteException {
|
throws RemoteException {
|
||||||
verifyCaller(packageName, userId);
|
verifyCaller(packageName, userId);
|
||||||
|
|
||||||
return mMaxShortcuts;
|
return mMaxShortcutsPerActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -4411,7 +4446,7 @@ public class ShortcutService extends IShortcutService.Stub {
|
|||||||
pw.print(" maxUpdatesPerInterval: ");
|
pw.print(" maxUpdatesPerInterval: ");
|
||||||
pw.println(mMaxUpdatesPerInterval);
|
pw.println(mMaxUpdatesPerInterval);
|
||||||
pw.print(" maxShortcutsPerActivity: ");
|
pw.print(" maxShortcutsPerActivity: ");
|
||||||
pw.println(mMaxShortcuts);
|
pw.println(mMaxShortcutsPerActivity);
|
||||||
pw.println();
|
pw.println();
|
||||||
|
|
||||||
mStatLogger.dump(pw, " ");
|
mStatLogger.dump(pw, " ");
|
||||||
@@ -4848,7 +4883,7 @@ public class ShortcutService extends IShortcutService.Stub {
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
int getMaxShortcutsForTest() {
|
int getMaxShortcutsForTest() {
|
||||||
return mMaxShortcuts;
|
return mMaxShortcutsPerActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|||||||
Reference in New Issue
Block a user