Java Code Examples for android.os.PersistableBundle#putDouble()

The following examples show how to use android.os.PersistableBundle#putDouble() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Location.java    From your-local-weather with GNU General Public License v3.0 6 votes vote down vote up
public PersistableBundle getPersistableBundle() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        PersistableBundle persistableBundle = new PersistableBundle();
        persistableBundle.putLong("id", id);
        persistableBundle.putDouble("latitude", latitude);
        persistableBundle.putDouble("longitude", longitude);
        persistableBundle.putInt("orderId", orderId);
        persistableBundle.putString("locale", localeAbbrev);
        persistableBundle.putString("nickname", nickname);
        persistableBundle.putDouble("accuracy", new Double(accuracy));
        persistableBundle.putString("locationSource", locationSource);
        persistableBundle.putLong("lastLocationUpdate", lastLocationUpdate);
        persistableBundle.putPersistableBundle("address", PersistableBundleBuilder.fromAddress(address));
        return persistableBundle;
    } else {
        return null;
    }
}
 
Example 2
Source File: PersistableBundleBuilder.java    From your-local-weather with GNU General Public License v3.0 5 votes vote down vote up
public static PersistableBundle fromLocation(android.location.Location location) {
    if (location == null) {
        return null;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        PersistableBundle persistableBundle = new PersistableBundle();
        persistableBundle.putDouble("latitude", location.getLatitude());
        persistableBundle.putDouble("latitude", location.getLatitude());
        persistableBundle.putDouble("accuracy", location.getAccuracy());
        persistableBundle.putString("provider", location.getProvider());
        return persistableBundle;
    } else {
        return null;
    }
}
 
Example 3
Source File: BundleToPersistableBundleConverter.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Copy all entries in the {@link Bundle} that can be part of a {@link PersistableBundle}.
 *
 * @param bundle the {@link Bundle} to convert.
 * @return a result object contain the resulting {@link PersistableBundle} and whether any of
 *         the keys failed.
 */
static Result convert(Bundle bundle) {
    PersistableBundle persistableBundle = new PersistableBundle();
    Set<String> failedKeys = new HashSet<>();
    for (String key : bundle.keySet()) {
        Object obj = bundle.get(key);
        if (obj == null) {
            persistableBundle.putString(key, null);
        } else if (obj instanceof Boolean) {
            persistableBundle.putBoolean(key, (Boolean) obj);
        } else if (obj instanceof boolean[]) {
            persistableBundle.putBooleanArray(key, (boolean[]) obj);
        } else if (obj instanceof Double) {
            persistableBundle.putDouble(key, (Double) obj);
        } else if (obj instanceof double[]) {
            persistableBundle.putDoubleArray(key, (double[]) obj);
        } else if (obj instanceof Integer) {
            persistableBundle.putInt(key, (Integer) obj);
        } else if (obj instanceof int[]) {
            persistableBundle.putIntArray(key, (int[]) obj);
        } else if (obj instanceof Long) {
            persistableBundle.putLong(key, (Long) obj);
        } else if (obj instanceof long[]) {
            persistableBundle.putLongArray(key, (long[]) obj);
        } else if (obj instanceof String) {
            persistableBundle.putString(key, (String) obj);
        } else if (obj instanceof String[]) {
            persistableBundle.putStringArray(key, (String[]) obj);
        } else {
            failedKeys.add(key);
        }
    }
    return new Result(persistableBundle, failedKeys);
}
 
Example 4
Source File: SyncOperation.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    jobInfoExtras.putInt("syncExemptionFlag", syncExemptionFlag);
    return jobInfoExtras;
}
 
Example 5
Source File: PackageManagerShellCommand.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private int runSuspend(boolean suspendedState) {
    final PrintWriter pw = getOutPrintWriter();
    int userId = UserHandle.USER_SYSTEM;
    String dialogMessage = null;
    final PersistableBundle appExtras = new PersistableBundle();
    final PersistableBundle launcherExtras = new PersistableBundle();
    String opt;
    while ((opt = getNextOption()) != null) {
        switch (opt) {
            case "--user":
                userId = UserHandle.parseUserArg(getNextArgRequired());
                break;
            case "--dialogMessage":
                dialogMessage = getNextArgRequired();
                break;
            case "--ael":
            case "--aes":
            case "--aed":
            case "--lel":
            case "--les":
            case "--led":
                final String key = getNextArgRequired();
                final String val = getNextArgRequired();
                if (!suspendedState) {
                    break;
                }
                final PersistableBundle bundleToInsert =
                        opt.startsWith("--a") ? appExtras : launcherExtras;
                switch (opt.charAt(4)) {
                    case 'l':
                        bundleToInsert.putLong(key, Long.valueOf(val));
                        break;
                    case 'd':
                        bundleToInsert.putDouble(key, Double.valueOf(val));
                        break;
                    case 's':
                        bundleToInsert.putString(key, val);
                        break;
                }
                break;
            default:
                pw.println("Error: Unknown option: " + opt);
                return 1;
        }
    }

    final String packageName = getNextArg();
    if (packageName == null) {
        pw.println("Error: package name not specified");
        return 1;
    }
    final String callingPackage =
            (Binder.getCallingUid() == Process.ROOT_UID) ? "root" : "com.android.shell";
    try {
        mInterface.setPackagesSuspendedAsUser(new String[]{packageName}, suspendedState,
                appExtras, launcherExtras, dialogMessage, callingPackage, userId);
        pw.println("Package " + packageName + " new suspended state: "
                + mInterface.isPackageSuspendedForUser(packageName, userId));
        return 0;
    } catch (RemoteException | IllegalArgumentException e) {
        pw.println(e.toString());
        return 1;
    }
}