List of usage examples for android.content Context POWER_SERVICE
String POWER_SERVICE
To view the source code for android.content Context POWER_SERVICE.
Click Source Link
From source file:com.mybitcoin.wallet.service.BlockchainServiceImpl.java
@Override public void onCreate() { serviceCreatedAt = System.currentTimeMillis(); // log.debug(".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); application = (WalletApplication) getApplication(); config = application.getConfiguration(); final Wallet wallet = application.getWallet(); bestChainHeightEver = config.getBestChainHeightEver(); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);/* w w w. j ava 2 s. c om*/ final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { log.info("blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); wallet.setLastBlockSeenHeight(-1); // magic value wallet.setLastBlockSeenHash(null); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); blockStore.getChainHead(); // detect corruptions as early as possible final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); if (!blockChainFileExists && earliestKeyCreationTime > 0) { try { final InputStream checkpointsInputStream = getAssets().open(Constants.CHECKPOINTS_FILENAME); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore, earliestKeyCreationTime); } catch (final IOException x) { log.error("problem reading checkpoints, continuing without", x); } } } catch (final BlockStoreException x) { blockChainFile.delete(); final String msg = "blockstore cannot be created"; log.error(msg, x); throw new Error(msg, x); } log.info("using " + blockStore.getClass().getName()); try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener, Threading.SAME_THREAD); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); maybeRotateKeys(); }
From source file:crea.wallet.lite.service.CreativeCoinService.java
@Override public void onCreate() { serviceCreatedAt = System.currentTimeMillis(); super.onCreate(); boolean startService = WalletHelper.INSTANCE != null; transactionsReceived = new HashMap<>(); Log.e(TAG, "START_SERVICE=" + startService); if (startService) { nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); WalletHelper.INSTANCE.autoSave(10); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); application = WalletApplication.INSTANCE; setWalletListener();//from w w w . ja v a2 s.c o m peerConnectivityListener = new PeerConnectivityListener(); blockChainFile = Constants.WALLET.BLOCKCHAIN_FILE; final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { new File(Constants.WALLET.WALLET_PATH).mkdirs(); } try { blockStore = new SPVBlockStore(NETWORK_PARAMETERS, blockChainFile); blockStore.getChainHead(); // detect corruptions as early as possible final long earliestKeyCreationTime = WalletHelper.INSTANCE.getKeyCreationTime(); Log.e(TAG, "CREATION_TIME=" + earliestKeyCreationTime + " BLOCKCHAIN_FILE=" + blockChainFileExists); if (!blockChainFileExists && earliestKeyCreationTime > 0) { try { Configuration.getInstance().setDeletingBlockchain(true); final long start = System.currentTimeMillis(); final InputStream checkpointsInputStream = getAssets() .open("bitcoin/" + Constants.WALLET.CHECKPOINTS_FILENAME); CheckpointManager.checkpoint(NETWORK_PARAMETERS, checkpointsInputStream, blockStore, earliestKeyCreationTime); Log.e(TAG, String.format("checkpoints loaded from '%1$s', took %2$dms", Constants.WALLET.CHECKPOINTS_FILENAME, System.currentTimeMillis() - start)); } catch (final IOException x) { Log.e(TAG, "problem reading checkpoints, continuing without", x); } } } catch (final BlockStoreException x) { blockChainFile.delete(); final String msg = "blockstore cannot be created"; Log.e(TAG, msg, x); } try { blockChain = new BlockChain(NETWORK_PARAMETERS, WalletHelper.INSTANCE.getWallet(), blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); // implicitly start PeerGroup registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); } else { Log.e(TAG, "Incomplete conditions for start service"); stopSelf(); } }
From source file:im.vector.notifications.NotificationUtils.java
/** * Add the notification sound.// w w w.j a v a 2 s .c o m * * @param context the context * @param builder the notification builder * @param isBackground true if the notification is a background one * @param isBing true if the notification should play sound */ @SuppressLint("NewApi") private static void manageNotificationSound(Context context, NotificationCompat.Builder builder, boolean isBackground, boolean isBing) { @ColorInt int highlightColor = ContextCompat.getColor(context, R.color.vector_fuchsia_color); int defaultColor = Color.TRANSPARENT; if (isBackground) { builder.setPriority(NotificationCompat.PRIORITY_DEFAULT); builder.setColor(defaultColor); } else if (isBing) { builder.setPriority(NotificationCompat.PRIORITY_HIGH); builder.setColor(highlightColor); } else { builder.setPriority(NotificationCompat.PRIORITY_DEFAULT); builder.setColor(Color.TRANSPARENT); } if (!isBackground) { builder.setDefaults(Notification.DEFAULT_LIGHTS); if (isBing && (null != PreferencesManager.getNotificationRingTone(context))) { builder.setSound(PreferencesManager.getNotificationRingTone(context)); if (Build.VERSION.SDK_INT >= 26) { builder.setChannelId(NOISY_NOTIFICATION_CHANNEL_ID); } } // turn the screen on for 3 seconds if (Matrix.getInstance(VectorApp.getInstance()).getSharedGCMRegistrationManager().isScreenTurnedOn()) { PowerManager pm = (PowerManager) VectorApp.getInstance().getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock( PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "manageNotificationSound"); wl.acquire(3000); wl.release(); } } }
From source file:com.master.metehan.filtereagle.Util.java
public static String getGeneralInfo(Context context) { StringBuilder sb = new StringBuilder(); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); sb.append(String.format("Interactive %B\r\n", isInteractive(context))); sb.append(String.format("Connected %B\r\n", isConnected(context))); sb.append(String.format("WiFi %B\r\n", isWifiActive(context))); sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context))); sb.append(String.format("Roaming %B\r\n", isRoaming(context))); sb.append(String.format("Type %s\r\n", getPhoneTypeName(tm.getPhoneType()))); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1 || !hasPhoneStatePermission(context)) { if (tm.getSimState() == TelephonyManager.SIM_STATE_READY) sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(), tm.getSimOperator())); if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN) sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(), tm.getNetworkOperatorName(), tm.getNetworkOperator())); }//ww w. j av a 2 s . c om PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode())); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) sb.append(String.format("Battery optimizing %B\r\n", !pm.isIgnoringBatteryOptimizations(context.getPackageName()))); if (sb.length() > 2) sb.setLength(sb.length() - 2); return sb.toString(); }
From source file:com.blu3f1re.reddwallet.service.BlockchainServiceImpl.java
@Override public void onCreate() { serviceCreatedAt = System.currentTimeMillis(); log.debug(".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); application = (WalletApplication) getApplication(); config = application.getConfiguration(); final Wallet wallet = application.getWallet(); bestChainHeightEver = config.getBestChainHeightEver(); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);// ww w . j a va 2 s. c o m final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { log.info("blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); wallet.setLastBlockSeenHeight(-1); // magic value wallet.setLastBlockSeenHash(null); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); blockStore.getChainHead(); // detect corruptions as early as possible final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); if (!blockChainFileExists && earliestKeyCreationTime > 0) { try { final InputStream checkpointsInputStream = getAssets().open(Constants.CHECKPOINTS_FILENAME); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore, earliestKeyCreationTime); } catch (final IOException x) { log.error("problem reading checkpoints, continuing without", x); } } } catch (final BlockStoreException x) { blockChainFile.delete(); final String msg = "blockstore cannot be created"; log.error(msg, x); throw new Error(msg, x); } log.info("using " + blockStore.getClass().getName()); try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener, Threading.SAME_THREAD); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); maybeRotateKeys(); }
From source file:com.kncwallet.wallet.service.BlockchainServiceImpl.java
@Override public void onCreate() { serviceCreatedAt = System.currentTimeMillis(); log.debug(".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); application = (WalletApplication) getApplication(); prefs = PreferenceManager.getDefaultSharedPreferences(this); final Wallet wallet = application.getWallet(); bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);/*from www. j ava 2 s.co m*/ final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { log.info("blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); wallet.setLastBlockSeenHeight(-1); // magic value wallet.setLastBlockSeenHash(null); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); blockStore.getChainHead(); // detect corruptions as early as possible final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); if (!blockChainFileExists && earliestKeyCreationTime > 0) { try { final InputStream checkpointsInputStream = getAssets().open(Constants.CHECKPOINTS_FILENAME); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore, earliestKeyCreationTime); } catch (final IOException x) { log.error("problem reading checkpoints, continuing without", x); } } } catch (final BlockStoreException x) { blockChainFile.delete(); final String msg = "blockstore cannot be created"; log.error(msg, x); throw new Error(msg, x); } log.info("using " + blockStore.getClass().getName()); try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); maybeRotateKeys(); }
From source file:uk.co.armedpineapple.cth.SDLActivity.java
protected void onResume() { super.onResume(); Log.d(LOG_TAG, "onResume()"); if (app.configuration != null && app.configuration.getKeepScreenOn()) { Log.d(LOG_TAG, "Getting wakelock"); PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); wake = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "Keep Screen On Wakelock"); wake.acquire();//from www.java 2 s .co m } if (mDrawerLayout != null) { mDrawerLayout.closeDrawers(); } }
From source file:com.wheelphone.remotemini.WheelphoneRemoteMini.java
public void onCreate(Bundle savedInstanceState) { if (debugUsbComm) { logString = TAG + ": onCreate"; Log.d(TAG, logString);/* w w w .j av a 2 s . com*/ appendLog("debugUsbComm.txt", logString, false); } super.onCreate(savedInstanceState); setContentView(R.layout.main); camera = (SurfaceView) findViewById(R.id.smallcameraview); context = this.getApplicationContext(); line1 = (TextView) findViewById(R.id.line1); line2 = (TextView) findViewById(R.id.line2); version = (TextView) findViewById(R.id.version); signWifi = (TextView) findViewById(R.id.advice); signStreaming = (TextView) findViewById(R.id.streaming); signInformation = (LinearLayout) findViewById(R.id.information); pulseAnimation = AnimationUtils.loadAnimation(this, R.anim.pulse); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); settings.registerOnSharedPreferenceChangeListener(this); camera.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); holder = camera.getHolder(); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "com.wheelphone.remotemini.wakelock"); httpServer = new CustomHttpServer(8080, this.getApplicationContext(), handler); soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { soundPool.play(sampleId, 0.99f, 0.99f, 1, 0, 1); } }); timerImg = new Timer(); intent = new Intent(context, FrontImageActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //startActivity(intent); // Query the QCAR initialization flags: mQCARFlags = getInitializationFlags(); // Update the application status to start initializing application updateApplicationStatus(APPSTATUS_INIT_APP); Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); updateRendering(size.x, size.y); btnStart = (Button) findViewById(R.id.btnStart); //Make sure that the app stays open: getWindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); wheelphone = new WheelphoneRobot(getApplicationContext(), getIntent()); wheelphone.enableSpeedControl(); wheelphone.setWheelPhoneRobotListener(this); }
From source file:org.mariotaku.harmony.MusicPlaybackService.java
@Override public void onCreate() { super.onCreate(); // Needs to be done in this thread, since otherwise // ApplicationContext.getPowerManager() crashes. mResources = getResources();/*w w w . j a v a 2 s . c om*/ mPlayer = new MultiPlayer(this); mResolver = getContentResolver(); mPlayer.setHandler(mMediaplayerHandler); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); mAudioManager.registerMediaButtonEventReceiver( new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName())); mPreferences = new PreferencesEditor(this); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mCardId = MusicUtils.getCardId(this); registerExternalStorageListener(); registerA2dpServiceListener(); reloadQueue(); IntentFilter commandFilter = new IntentFilter(); commandFilter.addAction(SERVICECMD); commandFilter.addAction(TOGGLEPAUSE_ACTION); commandFilter.addAction(PAUSE_ACTION); commandFilter.addAction(NEXT_ACTION); commandFilter.addAction(PREVIOUS_ACTION); commandFilter.addAction(CYCLEREPEAT_ACTION); commandFilter.addAction(TOGGLESHUFFLE_ACTION); commandFilter.addAction(BROADCAST_PLAYSTATUS_REQUEST); registerReceiver(mIntentReceiver, commandFilter); registerReceiver(mExternalAudioDeviceStatusReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG)); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); mWakeLock.setReferenceCounted(false); // If the service was idle, but got killed before it stopped itself, the // system will relaunch it. Make sure it gets stopped again in that // case. Message msg = mDelayedStopHandler.obtainMessage(); mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY); }
From source file:org.metawatch.manager.Monitors.java
public static void updateWeatherData(final Context context) { Thread thread = new Thread("WeatherUpdater") { @Override//from w w w. j a v a2s.co m public void run() { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Weather"); wl.acquire(); switch (Preferences.weatherProvider) { case WeatherProvider.GOOGLE: updateWeatherDataGoogle(context); break; case WeatherProvider.WUNDERGROUND: updateWeatherDataWunderground(context); break; } wl.release(); } }; thread.start(); }