Search in sources :

Example 1 with Configuration

use of de.schildbach.wallet.Configuration in project bitcoin-wallet by bitcoin-wallet.

the class BootstrapReceiver method onReceive.

@Override
public void onReceive(final Context context, final Intent intent) {
    log.info("got broadcast: " + intent);
    final WalletApplication application = (WalletApplication) context.getApplicationContext();
    final boolean bootCompleted = Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction());
    final boolean packageReplaced = Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction());
    if (packageReplaced || bootCompleted) {
        // make sure wallet is upgraded to HD
        if (packageReplaced)
            UpgradeWalletService.startUpgrade(context);
        // make sure there is always an alarm scheduled
        BlockchainService.scheduleStart(application);
        // if the app hasn't been used for a while and contains coins, maybe show reminder
        final Configuration config = application.getConfiguration();
        if (config.remindBalance() && config.hasBeenUsed() && config.getLastUsedAgo() > Constants.LAST_USAGE_THRESHOLD_INACTIVE_MS)
            InactivityNotificationService.startMaybeShowNotification(context);
    }
}
Also used : Configuration(de.schildbach.wallet.Configuration) WalletApplication(de.schildbach.wallet.WalletApplication)

Example 2 with Configuration

use of de.schildbach.wallet.Configuration in project bitcoin-wallet by bitcoin-wallet.

the class BlockchainService method scheduleStart.

public static void scheduleStart(final WalletApplication application) {
    final Configuration config = application.getConfiguration();
    final long lastUsedAgo = config.getLastUsedAgo();
    // apply some backoff
    final long alarmInterval;
    if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS)
        alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
    else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS)
        alarmInterval = AlarmManager.INTERVAL_HALF_DAY;
    else
        alarmInterval = AlarmManager.INTERVAL_DAY;
    log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes", lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS);
    final AlarmManager alarmManager = (AlarmManager) application.getSystemService(Context.ALARM_SERVICE);
    final PendingIntent alarmIntent = PendingIntent.getService(application, 0, new Intent(application, BlockchainService.class), 0);
    alarmManager.cancel(alarmIntent);
    // workaround for no inexact set() before KitKat
    final long now = System.currentTimeMillis();
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY, alarmIntent);
}
Also used : Configuration(de.schildbach.wallet.Configuration) AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 3 with Configuration

use of de.schildbach.wallet.Configuration in project bitcoin-wallet by bitcoin-wallet.

the class ReportIssueDialogFragment method appendApplicationInfo.

private static void appendApplicationInfo(final Appendable report, final WalletApplication application) throws IOException {
    final PackageInfo pi = application.packageInfo();
    final Configuration configuration = application.getConfiguration();
    final Calendar calendar = new GregorianCalendar(UTC);
    report.append("Version: " + pi.versionName + " (" + pi.versionCode + ")\n");
    report.append("Package: " + pi.packageName + "\n");
    report.append("Installer: " + application.getPackageManager().getInstallerPackageName(pi.packageName) + "\n");
    report.append("Test/Prod: " + (Constants.TEST ? "test" : "prod") + "\n");
    report.append("Timezone: " + TimeZone.getDefault().getID() + "\n");
    calendar.setTimeInMillis(System.currentTimeMillis());
    report.append("Time: " + String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) + "\n");
    calendar.setTimeInMillis(WalletApplication.TIME_CREATE_APPLICATION);
    report.append("Time of launch: " + String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) + "\n");
    calendar.setTimeInMillis(pi.lastUpdateTime);
    report.append("Time of last update: " + String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) + "\n");
    calendar.setTimeInMillis(pi.firstInstallTime);
    report.append("Time of first install: " + String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) + "\n");
    final long lastBackupTime = configuration.getLastBackupTime();
    calendar.setTimeInMillis(lastBackupTime);
    report.append("Time of backup: " + (lastBackupTime > 0 ? String.format(Locale.US, "%tF %tT %tZ", calendar, calendar, calendar) : "none") + "\n");
    report.append("Network: " + Constants.NETWORK_PARAMETERS.getId() + "\n");
    final Wallet wallet = application.getWallet();
    report.append("Encrypted: " + wallet.isEncrypted() + "\n");
    report.append("Keychain size: " + wallet.getKeyChainGroupSize() + "\n");
    final Set<Transaction> transactions = wallet.getTransactions(true);
    int numInputs = 0;
    int numOutputs = 0;
    int numSpentOutputs = 0;
    for (final Transaction tx : transactions) {
        numInputs += tx.getInputs().size();
        final List<TransactionOutput> outputs = tx.getOutputs();
        numOutputs += outputs.size();
        for (final TransactionOutput txout : outputs) {
            if (!txout.isAvailableForSpending())
                numSpentOutputs++;
        }
    }
    report.append("Transactions: " + transactions.size() + "\n");
    report.append("Inputs: " + numInputs + "\n");
    report.append("Outputs: " + numOutputs + " (spent: " + numSpentOutputs + ")\n");
    report.append("Last block seen: " + wallet.getLastBlockSeenHeight() + " (" + wallet.getLastBlockSeenHash() + ")\n");
    report.append("Databases:");
    for (final String db : application.databaseList()) report.append(" " + db);
    report.append("\n");
    final File filesDir = application.getFilesDir();
    report.append("\nContents of FilesDir " + filesDir + ":\n");
    appendDir(report, filesDir, 0);
}
Also used : TransactionOutput(org.bitcoinj.core.TransactionOutput) Configuration(de.schildbach.wallet.Configuration) PackageInfo(android.content.pm.PackageInfo) Wallet(org.bitcoinj.wallet.Wallet) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Transaction(org.bitcoinj.core.Transaction) File(java.io.File)

Aggregations

Configuration (de.schildbach.wallet.Configuration)3 AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 WalletApplication (de.schildbach.wallet.WalletApplication)1 File (java.io.File)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Transaction (org.bitcoinj.core.Transaction)1 TransactionOutput (org.bitcoinj.core.TransactionOutput)1 Wallet (org.bitcoinj.wallet.Wallet)1