@Override public void onDestroy() { paymentProtocolThread.stopAccepting(); classicThread.stopAccepting(); unregisterReceiver(bluetoothStateChangeReceiver); wakeLock.release(); handler.removeCallbacksAndMessages(null); super.onDestroy(); log.info( "service was up for " + ((System.currentTimeMillis() - serviceCreatedAt) / 1000 / 60) + " minutes"); }
@Override public void onCreate() { serviceCreatedAt = System.currentTimeMillis(); log.debug(".onCreate()"); super.onCreate(); this.application = (WalletApplication) getApplication(); this.wallet = application.getWallet(); final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock( PowerManager.PARTIAL_WAKE_LOCK, getPackageName() + " bluetooth transaction submission"); wakeLock.acquire(); registerReceiver( bluetoothStateChangeReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)); try { classicThread = new AcceptBluetoothThread.ClassicBluetoothThread(bluetoothAdapter) { @Override public boolean handleTx(final Transaction tx) { return AcceptBluetoothService.this.handleTx(tx); } }; paymentProtocolThread = new AcceptBluetoothThread.PaymentProtocolThread(bluetoothAdapter) { @Override public boolean handleTx(final Transaction tx) { return AcceptBluetoothService.this.handleTx(tx); } }; classicThread.start(); paymentProtocolThread.start(); } catch (final IOException x) { new Toast(this).longToast(R.string.error_bluetooth, x.getMessage()); CrashReporter.saveBackgroundTrace(x, application.packageInfo()); } }