Search in sources :

Example 31 with PersistableBundle

use of android.os.PersistableBundle in project android_frameworks_base by AOSPA.

the class RestrictionsReceiver method onReceive.

/**
     * Intercept standard Restrictions Provider broadcasts.  Implementations
     * should not override this method; it is better to implement the
     * convenience callbacks for each action.
     */
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (RestrictionsManager.ACTION_REQUEST_PERMISSION.equals(action)) {
        String packageName = intent.getStringExtra(RestrictionsManager.EXTRA_PACKAGE_NAME);
        String requestType = intent.getStringExtra(RestrictionsManager.EXTRA_REQUEST_TYPE);
        String requestId = intent.getStringExtra(RestrictionsManager.EXTRA_REQUEST_ID);
        PersistableBundle request = (PersistableBundle) intent.getParcelableExtra(RestrictionsManager.EXTRA_REQUEST_BUNDLE);
        onRequestPermission(context, packageName, requestType, requestId, request);
    }
}
Also used : PersistableBundle(android.os.PersistableBundle)

Example 32 with PersistableBundle

use of android.os.PersistableBundle in project android_frameworks_base by AOSPA.

the class SyncOperation method toJobInfoExtras.

/**
     * All fields are stored in a corresponding key in the persistable bundle.
     *
     * {@link #extras} is a Bundle and can contain parcelable objects. But only the type Account
     * is allowed {@link ContentResolver#validateSyncExtrasBundle(Bundle)} that can't be stored in
     * a PersistableBundle. For every value of type Account with key 'key', we store a
     * PersistableBundle containing account information at key 'ACCOUNT:key'. The Account object
     * can be reconstructed using this.
     *
     * We put a flag with key 'SyncManagerJob', to identify while reconstructing a sync operation
     * from a bundle whether the bundle actually contains information about a sync.
     * @return A persistable bundle containing all information to re-construct the sync operation.
     */
PersistableBundle toJobInfoExtras() {
    // This will be passed as extras bundle to a JobScheduler job.
    PersistableBundle jobInfoExtras = new PersistableBundle();
    PersistableBundle syncExtrasBundle = new PersistableBundle();
    for (String key : extras.keySet()) {
        Object value = extras.get(key);
        if (value instanceof Account) {
            Account account = (Account) value;
            PersistableBundle accountBundle = new PersistableBundle();
            accountBundle.putString("accountName", account.name);
            accountBundle.putString("accountType", account.type);
            // This is stored in jobInfoExtras so that we don't override a user specified
            // sync extra with the same key.
            jobInfoExtras.putPersistableBundle("ACCOUNT:" + key, accountBundle);
        } else if (value instanceof Long) {
            syncExtrasBundle.putLong(key, (Long) value);
        } else if (value instanceof Integer) {
            syncExtrasBundle.putInt(key, (Integer) value);
        } else if (value instanceof Boolean) {
            syncExtrasBundle.putBoolean(key, (Boolean) value);
        } else if (value instanceof Float) {
            syncExtrasBundle.putDouble(key, (double) (float) value);
        } else if (value instanceof Double) {
            syncExtrasBundle.putDouble(key, (Double) value);
        } else if (value instanceof String) {
            syncExtrasBundle.putString(key, (String) value);
        } else if (value == null) {
            syncExtrasBundle.putString(key, null);
        } else {
            Slog.e(TAG, "Unknown extra type.");
        }
    }
    jobInfoExtras.putPersistableBundle("syncExtras", syncExtrasBundle);
    jobInfoExtras.putBoolean("SyncManagerJob", true);
    jobInfoExtras.putString("provider", target.provider);
    jobInfoExtras.putString("accountName", target.account.name);
    jobInfoExtras.putString("accountType", target.account.type);
    jobInfoExtras.putInt("userId", target.userId);
    jobInfoExtras.putInt("owningUid", owningUid);
    jobInfoExtras.putString("owningPackage", owningPackage);
    jobInfoExtras.putInt("reason", reason);
    jobInfoExtras.putInt("source", syncSource);
    jobInfoExtras.putBoolean("allowParallelSyncs", allowParallelSyncs);
    jobInfoExtras.putInt("jobId", jobId);
    jobInfoExtras.putBoolean("isPeriodic", isPeriodic);
    jobInfoExtras.putInt("sourcePeriodicId", sourcePeriodicId);
    jobInfoExtras.putLong("periodMillis", periodMillis);
    jobInfoExtras.putLong("flexMillis", flexMillis);
    jobInfoExtras.putLong("expectedRuntime", expectedRuntime);
    jobInfoExtras.putInt("retries", retries);
    return jobInfoExtras;
}
Also used : Account(android.accounts.Account) PersistableBundle(android.os.PersistableBundle)

Example 33 with PersistableBundle

use of android.os.PersistableBundle in project android_frameworks_base by AOSPA.

the class SyncOperation method maybeCreateFromJobExtras.

/**
     * Reconstructs a sync operation from an extras Bundle. Returns null if the bundle doesn't
     * contain a valid sync operation.
     */
static SyncOperation maybeCreateFromJobExtras(PersistableBundle jobExtras) {
    String accountName, accountType;
    String provider;
    int userId, owningUid;
    String owningPackage;
    int reason, source;
    int initiatedBy;
    Bundle extras;
    boolean allowParallelSyncs, isPeriodic;
    long periodMillis, flexMillis;
    if (!jobExtras.getBoolean("SyncManagerJob", false)) {
        return null;
    }
    accountName = jobExtras.getString("accountName");
    accountType = jobExtras.getString("accountType");
    provider = jobExtras.getString("provider");
    userId = jobExtras.getInt("userId", Integer.MAX_VALUE);
    owningUid = jobExtras.getInt("owningUid");
    owningPackage = jobExtras.getString("owningPackage");
    reason = jobExtras.getInt("reason", Integer.MAX_VALUE);
    source = jobExtras.getInt("source", Integer.MAX_VALUE);
    allowParallelSyncs = jobExtras.getBoolean("allowParallelSyncs", false);
    isPeriodic = jobExtras.getBoolean("isPeriodic", false);
    initiatedBy = jobExtras.getInt("sourcePeriodicId", NO_JOB_ID);
    periodMillis = jobExtras.getLong("periodMillis");
    flexMillis = jobExtras.getLong("flexMillis");
    extras = new Bundle();
    PersistableBundle syncExtras = jobExtras.getPersistableBundle("syncExtras");
    if (syncExtras != null) {
        extras.putAll(syncExtras);
    }
    for (String key : jobExtras.keySet()) {
        if (key != null && key.startsWith("ACCOUNT:")) {
            // Strip off the 'ACCOUNT:' prefix.
            String newKey = key.substring(8);
            PersistableBundle accountsBundle = jobExtras.getPersistableBundle(key);
            Account account = new Account(accountsBundle.getString("accountName"), accountsBundle.getString("accountType"));
            extras.putParcelable(newKey, account);
        }
    }
    Account account = new Account(accountName, accountType);
    SyncStorageEngine.EndPoint target = new SyncStorageEngine.EndPoint(account, provider, userId);
    SyncOperation op = new SyncOperation(target, owningUid, owningPackage, reason, source, extras, allowParallelSyncs, isPeriodic, initiatedBy, periodMillis, flexMillis);
    op.jobId = jobExtras.getInt("jobId");
    op.expectedRuntime = jobExtras.getLong("expectedRuntime");
    op.retries = jobExtras.getInt("retries");
    return op;
}
Also used : Account(android.accounts.Account) PersistableBundle(android.os.PersistableBundle) Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle)

Example 34 with PersistableBundle

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

the class SyncOperation method maybeCreateFromJobExtras.

/**
     * Reconstructs a sync operation from an extras Bundle. Returns null if the bundle doesn't
     * contain a valid sync operation.
     */
static SyncOperation maybeCreateFromJobExtras(PersistableBundle jobExtras) {
    String accountName, accountType;
    String provider;
    int userId, owningUid;
    String owningPackage;
    int reason, source;
    int initiatedBy;
    Bundle extras;
    boolean allowParallelSyncs, isPeriodic;
    long periodMillis, flexMillis;
    if (!jobExtras.getBoolean("SyncManagerJob", false)) {
        return null;
    }
    accountName = jobExtras.getString("accountName");
    accountType = jobExtras.getString("accountType");
    provider = jobExtras.getString("provider");
    userId = jobExtras.getInt("userId", Integer.MAX_VALUE);
    owningUid = jobExtras.getInt("owningUid");
    owningPackage = jobExtras.getString("owningPackage");
    reason = jobExtras.getInt("reason", Integer.MAX_VALUE);
    source = jobExtras.getInt("source", Integer.MAX_VALUE);
    allowParallelSyncs = jobExtras.getBoolean("allowParallelSyncs", false);
    isPeriodic = jobExtras.getBoolean("isPeriodic", false);
    initiatedBy = jobExtras.getInt("sourcePeriodicId", NO_JOB_ID);
    periodMillis = jobExtras.getLong("periodMillis");
    flexMillis = jobExtras.getLong("flexMillis");
    extras = new Bundle();
    PersistableBundle syncExtras = jobExtras.getPersistableBundle("syncExtras");
    if (syncExtras != null) {
        extras.putAll(syncExtras);
    }
    for (String key : jobExtras.keySet()) {
        if (key != null && key.startsWith("ACCOUNT:")) {
            // Strip off the 'ACCOUNT:' prefix.
            String newKey = key.substring(8);
            PersistableBundle accountsBundle = jobExtras.getPersistableBundle(key);
            Account account = new Account(accountsBundle.getString("accountName"), accountsBundle.getString("accountType"));
            extras.putParcelable(newKey, account);
        }
    }
    Account account = new Account(accountName, accountType);
    SyncStorageEngine.EndPoint target = new SyncStorageEngine.EndPoint(account, provider, userId);
    SyncOperation op = new SyncOperation(target, owningUid, owningPackage, reason, source, extras, allowParallelSyncs, isPeriodic, initiatedBy, periodMillis, flexMillis);
    op.jobId = jobExtras.getInt("jobId");
    op.expectedRuntime = jobExtras.getLong("expectedRuntime");
    op.retries = jobExtras.getInt("retries");
    return op;
}
Also used : Account(android.accounts.Account) PersistableBundle(android.os.PersistableBundle) Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle)

Example 35 with PersistableBundle

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

the class SyncOperation method toJobInfoExtras.

/**
     * All fields are stored in a corresponding key in the persistable bundle.
     *
     * {@link #extras} is a Bundle and can contain parcelable objects. But only the type Account
     * is allowed {@link ContentResolver#validateSyncExtrasBundle(Bundle)} that can't be stored in
     * a PersistableBundle. For every value of type Account with key 'key', we store a
     * PersistableBundle containing account information at key 'ACCOUNT:key'. The Account object
     * can be reconstructed using this.
     *
     * We put a flag with key 'SyncManagerJob', to identify while reconstructing a sync operation
     * from a bundle whether the bundle actually contains information about a sync.
     * @return A persistable bundle containing all information to re-construct the sync operation.
     */
PersistableBundle toJobInfoExtras() {
    // This will be passed as extras bundle to a JobScheduler job.
    PersistableBundle jobInfoExtras = new PersistableBundle();
    PersistableBundle syncExtrasBundle = new PersistableBundle();
    for (String key : extras.keySet()) {
        Object value = extras.get(key);
        if (value instanceof Account) {
            Account account = (Account) value;
            PersistableBundle accountBundle = new PersistableBundle();
            accountBundle.putString("accountName", account.name);
            accountBundle.putString("accountType", account.type);
            // This is stored in jobInfoExtras so that we don't override a user specified
            // sync extra with the same key.
            jobInfoExtras.putPersistableBundle("ACCOUNT:" + key, accountBundle);
        } else if (value instanceof Long) {
            syncExtrasBundle.putLong(key, (Long) value);
        } else if (value instanceof Integer) {
            syncExtrasBundle.putInt(key, (Integer) value);
        } else if (value instanceof Boolean) {
            syncExtrasBundle.putBoolean(key, (Boolean) value);
        } else if (value instanceof Float) {
            syncExtrasBundle.putDouble(key, (double) (float) value);
        } else if (value instanceof Double) {
            syncExtrasBundle.putDouble(key, (Double) value);
        } else if (value instanceof String) {
            syncExtrasBundle.putString(key, (String) value);
        } else if (value == null) {
            syncExtrasBundle.putString(key, null);
        } else {
            Slog.e(TAG, "Unknown extra type.");
        }
    }
    jobInfoExtras.putPersistableBundle("syncExtras", syncExtrasBundle);
    jobInfoExtras.putBoolean("SyncManagerJob", true);
    jobInfoExtras.putString("provider", target.provider);
    jobInfoExtras.putString("accountName", target.account.name);
    jobInfoExtras.putString("accountType", target.account.type);
    jobInfoExtras.putInt("userId", target.userId);
    jobInfoExtras.putInt("owningUid", owningUid);
    jobInfoExtras.putString("owningPackage", owningPackage);
    jobInfoExtras.putInt("reason", reason);
    jobInfoExtras.putInt("source", syncSource);
    jobInfoExtras.putBoolean("allowParallelSyncs", allowParallelSyncs);
    jobInfoExtras.putInt("jobId", jobId);
    jobInfoExtras.putBoolean("isPeriodic", isPeriodic);
    jobInfoExtras.putInt("sourcePeriodicId", sourcePeriodicId);
    jobInfoExtras.putLong("periodMillis", periodMillis);
    jobInfoExtras.putLong("flexMillis", flexMillis);
    jobInfoExtras.putLong("expectedRuntime", expectedRuntime);
    jobInfoExtras.putInt("retries", retries);
    return jobInfoExtras;
}
Also used : Account(android.accounts.Account) PersistableBundle(android.os.PersistableBundle)

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