private void initWallet() { new LinuxSecureRandom(); // init proper random number generator initLogging(); Threading.throwOnLockCycles(); log.info( "=== starting app using configuration: {}, {}", Constants.TEST ? "test" : "prod", Constants.NETWORK_PARAMETERS.getId()); super.onCreate(); CrashReporter.init(getCacheDir()); Threading.uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(final Thread thread, final Throwable throwable) { log.info("peercoinj uncaught exception", throwable); CrashReporter.saveBackgroundTrace(throwable, packageInfo); } }; initMnemonicCode(); config = new Configuration(PreferenceManager.getDefaultSharedPreferences(this)); walletFile = getFileStreamPath(Constants.Files.WALLET_FILENAME_PROTOBUF); // Rename old wallets final File oldWalletFile = getFileStreamPath(Constants.Files.WALLET_FILENAME_PROTOBUF_OLD); if (oldWalletFile.exists()) oldWalletFile.renameTo(walletFile); loadWalletFromProtobuf(); config.updateLastVersionCode(packageInfo.versionCode); afterLoadWallet(); cleanupFiles(); synchronized (this) { isLoaded = true; for (Runnable callback : loadedCallbacks) callback.run(); } }
@Override public void onCreate() { new LinuxSecureRandom(); // init proper random number generator initLogging(); StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder() .detectAll() .permitDiskReads() .permitDiskWrites() .penaltyLog() .build()); Threading.throwOnLockCycles(); log.info( "configuration: " + (Constants.TEST ? "test" : "prod") + ", " + Constants.NETWORK_PARAMETERS.getId()); super.onCreate(); try { packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (final NameNotFoundException x) { throw new RuntimeException(x); } CrashReporter.init(getCacheDir()); Threading.uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(final Thread thread, final Throwable throwable) { log.info("bitcoinj uncaught exception", throwable); CrashReporter.saveBackgroundTrace(throwable, packageInfo); } }; prefs = PreferenceManager.getDefaultSharedPreferences(this); activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); blockchainServiceIntent = new Intent(this, BlockchainServiceImpl.class); blockchainServiceCancelCoinsReceivedIntent = new Intent( BlockchainService.ACTION_CANCEL_COINS_RECEIVED, null, this, BlockchainServiceImpl.class); blockchainServiceResetBlockchainIntent = new Intent( BlockchainService.ACTION_RESET_BLOCKCHAIN, null, this, BlockchainServiceImpl.class); walletFile = getFileStreamPath(Constants.WALLET_FILENAME_PROTOBUF); migrateWalletToProtobuf(); loadWalletFromProtobuf(); wallet.autosaveToFile(walletFile, 1, TimeUnit.SECONDS, new WalletAutosaveEventListener()); final int lastVersionCode = prefs.getInt(Constants.PREFS_KEY_LAST_VERSION, 0); prefs.edit().putInt(Constants.PREFS_KEY_LAST_VERSION, packageInfo.versionCode).commit(); if (packageInfo.versionCode > lastVersionCode) log.info("detected app upgrade: " + lastVersionCode + " -> " + packageInfo.versionCode); else if (packageInfo.versionCode < lastVersionCode) log.warn("detected app downgrade: " + lastVersionCode + " -> " + packageInfo.versionCode); if (lastVersionCode > 0 && lastVersionCode < KEY_ROTATION_VERSION_CODE && packageInfo.versionCode >= KEY_ROTATION_VERSION_CODE) { log.info("detected version jump crossing key rotation"); wallet.setKeyRotationTime(System.currentTimeMillis() / 1000); } ensureKey(); }