Search in sources :

Example 36 with PersistableBundle

use of android.os.PersistableBundle in project platform_frameworks_base by android.

the class UserManagerService method readUserLP.

private UserData readUserLP(int id) {
    int flags = 0;
    int serialNumber = id;
    String name = null;
    String account = null;
    String iconPath = null;
    long creationTime = 0L;
    long lastLoggedInTime = 0L;
    String lastLoggedInFingerprint = null;
    int profileGroupId = UserInfo.NO_PROFILE_GROUP_ID;
    int restrictedProfileParentId = UserInfo.NO_PROFILE_GROUP_ID;
    boolean partial = false;
    boolean guestToRemove = false;
    boolean persistSeedData = false;
    String seedAccountName = null;
    String seedAccountType = null;
    PersistableBundle seedAccountOptions = null;
    Bundle baseRestrictions = new Bundle();
    Bundle localRestrictions = new Bundle();
    FileInputStream fis = null;
    try {
        AtomicFile userFile = new AtomicFile(new File(mUsersDir, Integer.toString(id) + XML_SUFFIX));
        fis = userFile.openRead();
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(fis, StandardCharsets.UTF_8.name());
        int type;
        while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
        // Skip
        }
        if (type != XmlPullParser.START_TAG) {
            Slog.e(LOG_TAG, "Unable to read user " + id);
            return null;
        }
        if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_USER)) {
            int storedId = readIntAttribute(parser, ATTR_ID, -1);
            if (storedId != id) {
                Slog.e(LOG_TAG, "User id does not match the file name");
                return null;
            }
            serialNumber = readIntAttribute(parser, ATTR_SERIAL_NO, id);
            flags = readIntAttribute(parser, ATTR_FLAGS, 0);
            iconPath = parser.getAttributeValue(null, ATTR_ICON_PATH);
            creationTime = readLongAttribute(parser, ATTR_CREATION_TIME, 0);
            lastLoggedInTime = readLongAttribute(parser, ATTR_LAST_LOGGED_IN_TIME, 0);
            lastLoggedInFingerprint = parser.getAttributeValue(null, ATTR_LAST_LOGGED_IN_FINGERPRINT);
            profileGroupId = readIntAttribute(parser, ATTR_PROFILE_GROUP_ID, UserInfo.NO_PROFILE_GROUP_ID);
            restrictedProfileParentId = readIntAttribute(parser, ATTR_RESTRICTED_PROFILE_PARENT_ID, UserInfo.NO_PROFILE_GROUP_ID);
            String valueString = parser.getAttributeValue(null, ATTR_PARTIAL);
            if ("true".equals(valueString)) {
                partial = true;
            }
            valueString = parser.getAttributeValue(null, ATTR_GUEST_TO_REMOVE);
            if ("true".equals(valueString)) {
                guestToRemove = true;
            }
            seedAccountName = parser.getAttributeValue(null, ATTR_SEED_ACCOUNT_NAME);
            seedAccountType = parser.getAttributeValue(null, ATTR_SEED_ACCOUNT_TYPE);
            if (seedAccountName != null || seedAccountType != null) {
                persistSeedData = true;
            }
            int outerDepth = parser.getDepth();
            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                    continue;
                }
                String tag = parser.getName();
                if (TAG_NAME.equals(tag)) {
                    type = parser.next();
                    if (type == XmlPullParser.TEXT) {
                        name = parser.getText();
                    }
                } else if (TAG_RESTRICTIONS.equals(tag)) {
                    UserRestrictionsUtils.readRestrictions(parser, baseRestrictions);
                } else if (TAG_DEVICE_POLICY_RESTRICTIONS.equals(tag)) {
                    UserRestrictionsUtils.readRestrictions(parser, localRestrictions);
                } else if (TAG_ACCOUNT.equals(tag)) {
                    type = parser.next();
                    if (type == XmlPullParser.TEXT) {
                        account = parser.getText();
                    }
                } else if (TAG_SEED_ACCOUNT_OPTIONS.equals(tag)) {
                    seedAccountOptions = PersistableBundle.restoreFromXml(parser);
                    persistSeedData = true;
                }
            }
        }
        // Create the UserInfo object that gets passed around
        UserInfo userInfo = new UserInfo(id, name, iconPath, flags);
        userInfo.serialNumber = serialNumber;
        userInfo.creationTime = creationTime;
        userInfo.lastLoggedInTime = lastLoggedInTime;
        userInfo.lastLoggedInFingerprint = lastLoggedInFingerprint;
        userInfo.partial = partial;
        userInfo.guestToRemove = guestToRemove;
        userInfo.profileGroupId = profileGroupId;
        userInfo.restrictedProfileParentId = restrictedProfileParentId;
        // Create the UserData object that's internal to this class
        UserData userData = new UserData();
        userData.info = userInfo;
        userData.account = account;
        userData.seedAccountName = seedAccountName;
        userData.seedAccountType = seedAccountType;
        userData.persistSeedData = persistSeedData;
        userData.seedAccountOptions = seedAccountOptions;
        synchronized (mRestrictionsLock) {
            mBaseUserRestrictions.put(id, baseRestrictions);
            mDevicePolicyLocalUserRestrictions.put(id, localRestrictions);
        }
        return userData;
    } catch (IOException ioe) {
    } catch (XmlPullParserException pe) {
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
            }
        }
    }
    return null;
}
Also used : Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) XmlPullParser(org.xmlpull.v1.XmlPullParser) UserInfo(android.content.pm.UserInfo) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) PersistableBundle(android.os.PersistableBundle) AtomicFile(android.util.AtomicFile) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) AtomicFile(android.util.AtomicFile) File(java.io.File)

Example 37 with PersistableBundle

use of android.os.PersistableBundle 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);
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Example 38 with PersistableBundle

use of android.os.PersistableBundle in project platform_frameworks_base by android.

the class SyncOperationTest method testConversionFromExtras.

@SmallTest
public void testConversionFromExtras() {
    PersistableBundle extras = new PersistableBundle();
    SyncOperation op = SyncOperation.maybeCreateFromJobExtras(extras);
    assertTrue("Non sync operation bundle falsely converted to SyncOperation.", op == null);
}
Also used : PersistableBundle(android.os.PersistableBundle) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 39 with PersistableBundle

use of android.os.PersistableBundle in project platform_frameworks_base by android.

the class SyncOperationTest method testConversionToExtras.

@SmallTest
public void testConversionToExtras() {
    Account account1 = new Account("account1", "type1");
    Bundle b1 = new Bundle();
    b1.putParcelable("acc", account1);
    b1.putString("str", "String");
    SyncOperation op1 = new SyncOperation(account1, 0, 1, "foo", 0, SyncOperation.REASON_PERIODIC, "authority1", b1, false);
    PersistableBundle pb = op1.toJobInfoExtras();
    SyncOperation op2 = SyncOperation.maybeCreateFromJobExtras(pb);
    assertTrue("Account fields in extras not persisted.", account1.equals(op2.extras.get("acc")));
    assertTrue("Fields in extras not persisted", "String".equals(op2.extras.getString("str")));
}
Also used : Account(android.accounts.Account) PersistableBundle(android.os.PersistableBundle) Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 40 with PersistableBundle

use of android.os.PersistableBundle in project platform_frameworks_base by android.

the class CarrierDefaultReceiverTest method testOnReceiveRedirection.

@Test
public void testOnReceiveRedirection() {
    // carrier action idx list includes 4(portal notification) & 1(disable metered APNs)
    // upon redirection signal
    PersistableBundle b = new PersistableBundle();
    b.putStringArray(CarrierConfigManager.KEY_CARRIER_DEFAULT_ACTIONS_ON_REDIRECTION_STRING_ARRAY, new String[] { "4,1" });
    doReturn(b).when(mCarrierConfigMgr).getConfig();
    Intent intent = new Intent(TelephonyIntents.ACTION_CARRIER_SIGNAL_REDIRECTED);
    intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
    Rlog.d(TAG, "OnReceive redirection intent");
    mReceiver.onReceive(mContext, intent);
    mContext.waitForMs(100);
    Rlog.d(TAG, "verify carrier action: showPortalNotification");
    verify(mNotificationMgr, times(1)).notify(mString.capture(), mInt.capture(), mNotification.capture());
    assertEquals(PORTAL_NOTIFICATION_ID, (int) mInt.getValue());
    assertEquals(PORTAL_NOTIFICATION_TAG, mString.getValue());
    PendingIntent pendingIntent = mNotification.getValue().contentIntent;
    assertNotNull(pendingIntent);
    Rlog.d(TAG, "verify carrier action: disable all metered apns");
    verify(mTelephonyMgr).carrierActionSetMeteredApnsEnabled(eq(subId), eq(false));
}
Also used : PersistableBundle(android.os.PersistableBundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Test(org.junit.Test)

Aggregations

PersistableBundle (android.os.PersistableBundle)321 CarrierConfigManager (android.telephony.CarrierConfigManager)87 ComponentName (android.content.ComponentName)67 Intent (android.content.Intent)63 ShortcutInfo (android.content.pm.ShortcutInfo)48 Test (org.junit.Test)35 Bundle (android.os.Bundle)28 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)25 IOException (java.io.IOException)21 Icon (android.graphics.drawable.Icon)17 JobInfo (android.app.job.JobInfo)15 IntentFilter (android.content.IntentFilter)15 Account (android.accounts.Account)14 Activity (android.app.Activity)12 TelephonyManager (android.telephony.TelephonyManager)12 SmallTest (android.test.suitebuilder.annotation.SmallTest)12 XmlPullParser (org.xmlpull.v1.XmlPullParser)12 Before (org.junit.Before)11 PendingIntent (android.app.PendingIntent)9 PackageManager (android.content.pm.PackageManager)9