use of android.content.ComponentName in project platform_frameworks_base by android.
the class ShortcutPackage method pushOutExcessShortcuts.
/**
* For each target activity, make sure # of dynamic + manifest shortcuts <= max.
* If too many, we'll remove the dynamic with the lowest ranks.
*/
private boolean pushOutExcessShortcuts() {
final ShortcutService service = mShortcutUser.mService;
final int maxShortcuts = service.getMaxActivityShortcuts();
boolean changed = false;
final ArrayMap<ComponentName, ArrayList<ShortcutInfo>> all = sortShortcutsToActivities();
for (int outer = all.size() - 1; outer >= 0; outer--) {
final ArrayList<ShortcutInfo> list = all.valueAt(outer);
if (list.size() <= maxShortcuts) {
continue;
}
// Sort by isManifestShortcut() and getRank().
Collections.sort(list, mShortcutTypeAndRankComparator);
// Keep [0 .. max), and remove (as dynamic) [max .. size)
for (int inner = list.size() - 1; inner >= maxShortcuts; inner--) {
final ShortcutInfo shortcut = list.get(inner);
if (shortcut.isManifestShortcut()) {
// This shouldn't happen -- excess shortcuts should all be non-manifest.
// But just in case.
service.wtf("Found manifest shortcuts in excess list.");
continue;
}
deleteDynamicWithId(shortcut.getId());
}
}
return changed;
}
use of android.content.ComponentName in project platform_frameworks_base by android.
the class ShortcutPackage method parseShortcut.
private static ShortcutInfo parseShortcut(XmlPullParser parser, String packageName, @UserIdInt int userId) throws IOException, XmlPullParserException {
String id;
ComponentName activityComponent;
// Icon icon;
String title;
int titleResId;
String titleResName;
String text;
int textResId;
String textResName;
String disabledMessage;
int disabledMessageResId;
String disabledMessageResName;
Intent intentLegacy;
PersistableBundle intentPersistableExtrasLegacy = null;
ArrayList<Intent> intents = new ArrayList<>();
int rank;
PersistableBundle extras = null;
long lastChangedTimestamp;
int flags;
int iconResId;
String iconResName;
String bitmapPath;
ArraySet<String> categories = null;
id = ShortcutService.parseStringAttribute(parser, ATTR_ID);
activityComponent = ShortcutService.parseComponentNameAttribute(parser, ATTR_ACTIVITY);
title = ShortcutService.parseStringAttribute(parser, ATTR_TITLE);
titleResId = ShortcutService.parseIntAttribute(parser, ATTR_TITLE_RES_ID);
titleResName = ShortcutService.parseStringAttribute(parser, ATTR_TITLE_RES_NAME);
text = ShortcutService.parseStringAttribute(parser, ATTR_TEXT);
textResId = ShortcutService.parseIntAttribute(parser, ATTR_TEXT_RES_ID);
textResName = ShortcutService.parseStringAttribute(parser, ATTR_TEXT_RES_NAME);
disabledMessage = ShortcutService.parseStringAttribute(parser, ATTR_DISABLED_MESSAGE);
disabledMessageResId = ShortcutService.parseIntAttribute(parser, ATTR_DISABLED_MESSAGE_RES_ID);
disabledMessageResName = ShortcutService.parseStringAttribute(parser, ATTR_DISABLED_MESSAGE_RES_NAME);
intentLegacy = ShortcutService.parseIntentAttributeNoDefault(parser, ATTR_INTENT_LEGACY);
rank = (int) ShortcutService.parseLongAttribute(parser, ATTR_RANK);
lastChangedTimestamp = ShortcutService.parseLongAttribute(parser, ATTR_TIMESTAMP);
flags = (int) ShortcutService.parseLongAttribute(parser, ATTR_FLAGS);
iconResId = (int) ShortcutService.parseLongAttribute(parser, ATTR_ICON_RES_ID);
iconResName = ShortcutService.parseStringAttribute(parser, ATTR_ICON_RES_NAME);
bitmapPath = ShortcutService.parseStringAttribute(parser, ATTR_BITMAP_PATH);
final int outerDepth = parser.getDepth();
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
final int depth = parser.getDepth();
final String tag = parser.getName();
if (ShortcutService.DEBUG_LOAD) {
Slog.d(TAG, String.format(" depth=%d type=%d name=%s", depth, type, tag));
}
switch(tag) {
case TAG_INTENT_EXTRAS_LEGACY:
intentPersistableExtrasLegacy = PersistableBundle.restoreFromXml(parser);
continue;
case TAG_INTENT:
intents.add(parseIntent(parser));
continue;
case TAG_EXTRAS:
extras = PersistableBundle.restoreFromXml(parser);
continue;
case TAG_CATEGORIES:
// This just contains string-array.
continue;
case TAG_STRING_ARRAY_XMLUTILS:
if (NAME_CATEGORIES.equals(ShortcutService.parseStringAttribute(parser, ATTR_NAME_XMLUTILS))) {
final String[] ar = XmlUtils.readThisStringArrayXml(parser, TAG_STRING_ARRAY_XMLUTILS, null);
categories = new ArraySet<>(ar.length);
for (int i = 0; i < ar.length; i++) {
categories.add(ar[i]);
}
}
continue;
}
throw ShortcutService.throwForInvalidTag(depth, tag);
}
if (intentLegacy != null) {
// For the legacy file format which supported only one intent per shortcut.
ShortcutInfo.setIntentExtras(intentLegacy, intentPersistableExtrasLegacy);
intents.clear();
intents.add(intentLegacy);
}
return new ShortcutInfo(userId, id, packageName, activityComponent, /* icon =*/
null, title, titleResId, titleResName, text, textResId, textResName, disabledMessage, disabledMessageResId, disabledMessageResName, categories, intents.toArray(new Intent[intents.size()]), rank, extras, lastChangedTimestamp, flags, iconResId, iconResName, bitmapPath);
}
use of android.content.ComponentName in project platform_frameworks_base by android.
the class ShortcutPackage method verifyStates.
@Override
public void verifyStates() {
super.verifyStates();
boolean failed = false;
final ArrayMap<ComponentName, ArrayList<ShortcutInfo>> all = sortShortcutsToActivities();
// Make sure each activity won't have more than max shortcuts.
for (int outer = all.size() - 1; outer >= 0; outer--) {
final ArrayList<ShortcutInfo> list = all.valueAt(outer);
if (list.size() > mShortcutUser.mService.getMaxActivityShortcuts()) {
failed = true;
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": activity " + all.keyAt(outer) + " has " + all.valueAt(outer).size() + " shortcuts.");
}
// Sort by rank.
Collections.sort(list, (a, b) -> Integer.compare(a.getRank(), b.getRank()));
// Split into two arrays for each kind.
final ArrayList<ShortcutInfo> dynamicList = new ArrayList<>(list);
dynamicList.removeIf((si) -> !si.isDynamic());
final ArrayList<ShortcutInfo> manifestList = new ArrayList<>(list);
dynamicList.removeIf((si) -> !si.isManifestShortcut());
verifyRanksSequential(dynamicList);
verifyRanksSequential(manifestList);
}
// Verify each shortcut's status.
for (int i = mShortcuts.size() - 1; i >= 0; i--) {
final ShortcutInfo si = mShortcuts.valueAt(i);
if (!(si.isDeclaredInManifest() || si.isDynamic() || si.isPinned())) {
failed = true;
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is not manifest, dynamic or pinned.");
}
if (si.isDeclaredInManifest() && si.isDynamic()) {
failed = true;
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is both dynamic and manifest at the same time.");
}
if (si.getActivity() == null) {
failed = true;
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " has null activity.");
}
if ((si.isDynamic() || si.isManifestShortcut()) && !si.isEnabled()) {
failed = true;
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is not floating, but is disabled.");
}
if (si.isFloating() && si.getRank() != 0) {
failed = true;
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is floating, but has rank=" + si.getRank());
}
if (si.getIcon() != null) {
failed = true;
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " still has an icon");
}
if (si.hasIconFile() && si.hasIconResource()) {
failed = true;
Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " has both resource and bitmap icons");
}
}
if (failed) {
throw new IllegalStateException("See logcat for errors");
}
}
use of android.content.ComponentName in project platform_frameworks_base by android.
the class DevicePolicyManagerTest method testUserAffiliation.
/**
* Test for:
* {@link DevicePolicyManager#setAffiliationIds}
* {@link DevicePolicyManager#isAffiliatedUser}
*/
public void testUserAffiliation() throws Exception {
mContext.callerPermissions.add(permission.MANAGE_DEVICE_ADMINS);
mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
mContext.callerPermissions.add(permission.INTERACT_ACROSS_USERS_FULL);
// Check that the system user is unaffiliated.
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
assertFalse(dpm.isAffiliatedUser());
// Set a device owner on the system user. Check that the system user becomes affiliated.
setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID);
dpm.setActiveAdmin(admin1, /* replace =*/
false);
assertTrue(dpm.setDeviceOwner(admin1, "owner-name"));
assertTrue(dpm.isAffiliatedUser());
// Install a profile owner whose package name matches the device owner on a test user. Check
// that the test user is unaffiliated.
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
setAsProfileOwner(admin2);
assertFalse(dpm.isAffiliatedUser());
// Have the profile owner specify a set of affiliation ids. Check that the test user remains
// unaffiliated.
final Set<String> userAffiliationIds = new ArraySet<>();
userAffiliationIds.add("red");
userAffiliationIds.add("green");
userAffiliationIds.add("blue");
dpm.setAffiliationIds(admin2, userAffiliationIds);
assertFalse(dpm.isAffiliatedUser());
// Have the device owner specify a set of affiliation ids that do not intersect with those
// specified by the profile owner. Check that the test user remains unaffiliated.
final Set<String> deviceAffiliationIds = new ArraySet<>();
deviceAffiliationIds.add("cyan");
deviceAffiliationIds.add("yellow");
deviceAffiliationIds.add("magenta");
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
dpm.setAffiliationIds(admin1, deviceAffiliationIds);
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
assertFalse(dpm.isAffiliatedUser());
// Have the profile owner specify a set of affiliation ids that intersect with those
// specified by the device owner. Check that the test user becomes affiliated.
userAffiliationIds.add("yellow");
dpm.setAffiliationIds(admin2, userAffiliationIds);
assertTrue(dpm.isAffiliatedUser());
// Change the profile owner to one whose package name does not match the device owner. Check
// that the test user is not affiliated anymore.
dpm.clearProfileOwner(admin2);
final ComponentName admin = new ComponentName("test", "test");
setUpPackageManagerForFakeAdmin(admin, DpmMockContext.CALLER_UID, /* enabledSetting =*/
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, /* appTargetSdk = */
null, admin2);
dpm.setActiveAdmin(admin, /* refreshing =*/
true, DpmMockContext.CALLER_USER_HANDLE);
assertTrue(dpm.setProfileOwner(admin, "owner-name", DpmMockContext.CALLER_USER_HANDLE));
assertFalse(dpm.isAffiliatedUser());
// Check that the system user remains affiliated.
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
assertTrue(dpm.isAffiliatedUser());
}
use of android.content.ComponentName in project platform_frameworks_base by android.
the class DevicePolicyManagerTest method testSetDeviceOwner_noSuchPackage.
/**
* Test for: {@link DevicePolicyManager#setDeviceOwner} Package doesn't exist.
*/
public void testSetDeviceOwner_noSuchPackage() {
mContext.callerPermissions.add(permission.MANAGE_DEVICE_ADMINS);
mContext.callerPermissions.add(permission.MANAGE_USERS);
mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
mContext.callerPermissions.add(permission.INTERACT_ACROSS_USERS_FULL);
// Call from a process on the system user.
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
try {
dpm.setDeviceOwner(new ComponentName("a.b.c", ".def"));
fail("Didn't throw IllegalArgumentException");
} catch (IllegalArgumentException expected) {
assertTrue("Message was: " + expected.getMessage(), expected.getMessage().contains("Invalid component"));
}
}
Aggregations