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:org.zeroxlab.zeroxbenchmark.Benchmark.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); orientation = getResources().getConfiguration().orientation; PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, TAG); mWakeLock.acquire();/*from w w w . j av a2s. co m*/ setContentView(R.layout.main); mCases = new LinkedList<Case>(); Case arith = new CaseArithmetic(); Case javascript = new CaseJavascript(); Case scimark2 = new CaseScimark2(); Case canvas = new CaseCanvas(); Case glcube = new CaseGLCube(); Case circle = new CaseDrawCircle(); Case nehe08 = new CaseNeheLesson08(); Case nehe16 = new CaseNeheLesson16(); Case teapot = new CaseTeapot(); Case gc = new CaseGC(); Case libMicro = new NativeCaseMicro(); Case libUbench = new NativeCaseUbench(); Case dc2 = new CaseDrawCircle2(); Case dr = new CaseDrawRect(); Case da = new CaseDrawArc(); Case di = new CaseDrawImage(); Case dt = new CaseDrawText(); mCategory.put(D2, new HashSet<Case>()); mCategory.put(D3, new HashSet<Case>()); mCategory.put(MATH, new HashSet<Case>()); mCategory.put(VM, new HashSet<Case>()); mCategory.put(NATIVE, new HashSet<Case>()); mCategory.put(MISC, new HashSet<Case>()); // mflops mCases.add(arith); mCases.add(scimark2); mCases.add(javascript); mCategory.get(MATH).add(arith); mCategory.get(MATH).add(scimark2); mCategory.get(MISC).add(javascript); // 2d mCases.add(canvas); mCases.add(circle); mCases.add(dc2); mCases.add(dr); mCases.add(da); mCases.add(di); mCases.add(dt); mCategory.get(D2).add(canvas); mCategory.get(D2).add(circle); mCategory.get(D2).add(dc2); mCategory.get(D2).add(dr); mCategory.get(D2).add(da); mCategory.get(D2).add(di); mCategory.get(D2).add(dt); // 3d mCases.add(glcube); mCases.add(nehe08); mCases.add(nehe16); mCases.add(teapot); mCategory.get(D3).add(glcube); mCategory.get(D3).add(nehe08); mCategory.get(D3).add(nehe16); mCategory.get(D3).add(teapot); // vm mCases.add(gc); mCategory.get(VM).add(gc); // native mCases.add(libMicro); mCases.add(libUbench); mCategory.get(NATIVE).add(libMicro); mCategory.get(NATIVE).add(libUbench); initViews(); Intent intent = getIntent(); Bundle bundle = intent.getExtras(); if (bundle != null) { mAutoRun = bundle.getBoolean("autorun"); mCheckMath = bundle.getBoolean("math"); mCheck2D = bundle.getBoolean("2d"); mCheck3D = bundle.getBoolean("3d"); mCheckVM = bundle.getBoolean("vm"); mCheckNative = bundle.getBoolean("native"); mAutoUpload = bundle.getBoolean("autoupload"); } if (mCheckMath && !mathCheckBox.isChecked()) { mathCheckBox.performClick(); } if (mCheck2D && !d2CheckBox.isChecked()) { d2CheckBox.performClick(); } if (mCheck3D && !d3CheckBox.isChecked()) { d3CheckBox.performClick(); } if (mCheckVM && !vmCheckBox.isChecked()) { vmCheckBox.performClick(); } if (mCheckNative && !nativeCheckBox.isChecked()) { nativeCheckBox.performClick(); } if (mCheckMisc && !miscCheckBox.isChecked()) { miscCheckBox.performClick(); } /* if (intent.getBooleanExtra("AUTO", false)) { ImageView head = (ImageView)findViewById(R.id.banner_img); head.setImageResource(R.drawable.icon_auto); mTouchable = false; initAuto(); } */ if (mAutoRun) { onClick(mRun); } }
From source file:net.patchingzone.ru4real.nuevo.TorchActivityPlugin.java
private void startWakeLock() { if (wakeLock == null) { Log.d(TAG, "wakeLock is null, getting a new WakeLock"); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); Log.d(TAG, "PowerManager acquired"); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG); Log.d(TAG, "WakeLock set"); }// w w w . jav a 2s . c o m wakeLock.acquire(); Log.d(TAG, "WakeLock acquired"); }
From source file:org.protocoderrunner.base.BaseActivity.java
public boolean isScreenOn() { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); return pm.isScreenOn(); }
From source file:com.simplelife.seeds.android.utils.downloadprocess.DownloadThread.java
/** * Executes the download in a separate thread *///w w w . j a v a2s . c o m public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); State state = new State(mInfo); AndroidHttpClient client = null; PowerManager.WakeLock wakeLock = null; int finalStatus = Downloads.STATUS_UNKNOWN_ERROR; try { PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); wakeLock.acquire(); if (Constants.LOGV) { Log.v(Constants.TAG, "initiating download for " + mInfo.mUri); } client = AndroidHttpClient.newInstance(userAgent(), mContext); boolean finished = false; while (!finished) { Log.i(Constants.TAG, "Initiating request for download " + mInfo.mId); //HttpGet request = new HttpGet(state.mRequestUri); Log.i(Constants.TAG, "mRequestUri: " + state.mRequestUri); Log.i(Constants.TAG, "mRequestRef: " + state.mRequestRef); HttpPost request = new HttpPost(SeedsDefinitions.SEEDS_SERVER_DOWNLOADPHP); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("ref", state.mRequestRef)); request.setEntity(new UrlEncodedFormEntity(params, "utf-8")); try { executeDownload(state, client, request); finished = true; } catch (RetryDownload exc) { // fall through } finally { request.abort(); request = null; } } if (Constants.LOGV) { Log.v(Constants.TAG, "download completed for " + mInfo.mUri); } finalizeDestinationFile(state); finalStatus = Downloads.STATUS_SUCCESS; } catch (StopRequest error) { // remove the cause before printing, in case it contains PII Log.w(Constants.TAG, "Aborting request for download " + mInfo.mId + ": " + error.getMessage()); finalStatus = error.mFinalStatus; // fall through to finally block } catch (Throwable ex) { // sometimes the socket code throws unchecked // exceptions Log.w(Constants.TAG, "Exception for id " + mInfo.mId + ": " + ex); finalStatus = Downloads.STATUS_UNKNOWN_ERROR; // falls through to the code that reports an error } finally { if (wakeLock != null) { wakeLock.release(); wakeLock = null; } if (client != null) { client.close(); client = null; } cleanupDestination(state, finalStatus); notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter, state.mGotData, state.mFilename, state.mNewUri, state.mMimeType); mInfo.mHasActiveThread = false; } }
From source file:net.frygo.findmybuddy.GCMIntentService.java
private static void generateAcceptfriendNotification(Context context, String message, String status) { Random rand = new Random(); int x = rand.nextInt(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, customlistview.class); if (status.equalsIgnoreCase("accept")) message = message + " added you as buddy"; else/*from w w w. j a va 2 s. co m*/ message = message + " rejected you as buddy"; PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis()); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(x, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title); mWakelock.acquire(); // Timer before putting Android Device to sleep mode. Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { mWakelock.release(); } }; timer.schedule(task, 5000); }
From source file:com.nekomeshi312.whiteboardcorrection.WhiteBoardCorrectionActivity.java
@Override public void onCreate(Bundle savedInstanceState) { setTheme(R.style.Theme_Sherlock);// w w w. j av a 2 s . c o m super.onCreate(savedInstanceState); //action bar ???s??status bar? final android.view.Window wnd = getWindow(); wnd.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); wnd.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); setContentView(R.layout.activity_white_board_correction); mCameraSetting = CameraAndParameters.newInstance(this); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayShowHomeEnabled(true); //actionbar????) actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_background)); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); FragmentManager fm = getSupportFragmentManager(); mFragCameraView = (CameraViewFragment) fm.findFragmentByTag(FRAG_CAMERA_VIEW_TAG); mBoardCheckFragment = (WhiteBoardCheckFragment) fm.findFragmentByTag(FRAG_WB_CHECK_TAG); mBoardResultFragment = (WhiteBoardResultFragment) fm.findFragmentByTag(FRAG_WB_RESULT_TAG); Intent intent = (Intent) getIntent(); if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction()) && intent.getType() != null) { if (!intent.getType().equals("image/jpeg") && !intent.getType().equals("image/jpg")) { Toast.makeText(this, R.string.error_msg_non_supported_image_format, Toast.LENGTH_SHORT).show(); Log.w(LOG_TAG, "Intent unsupported image format"); } else { int[] size = new int[2]; String fn = MyUtils.getImageInfoFromIntent(this, intent, size); if (fn != null) { //OpenCV?????? String[] newFn = new String[2]; if (copyImageToSD(fn, newFn) == true) { mWhiteBoardCheckInfo.mFilePath = newFn[0]; mWhiteBoardCheckInfo.mFileName = newFn[1]; mWhiteBoardCheckInfo.mPicWidth = size[0]; mWhiteBoardCheckInfo.mPicHeight = size[1]; mWhiteBoardCheckInfo.mIsCaptured = false; mWhiteBoardCheckInfo.mPrevWidth = 0; mWhiteBoardCheckInfo.mPrevHeight = 0; } } } } }
From source file:com.snda.mymarket.providers.downloads.DownloadTask.java
/** * Executes the download in a separate thread *///from www . j ava2 s . c o m public void run() { if (mInfo.mStatus != Downloads.STATUS_RUNNING) { mInfo.mStatus = Downloads.STATUS_RUNNING; ContentValues values = new ContentValues(); values.put(Downloads.COLUMN_STATUS, mInfo.mStatus); mContext.getContentResolver().update(mInfo.getAllDownloadsUri(), values, null, null); } else { if (Constants.LOGV) { Log.v(Constants.TAG, "download status is: " + mInfo.mStatus); } } Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); State state = new State(mInfo); HttpStack client = null; PowerManager.WakeLock wakeLock = null; int finalStatus = Downloads.STATUS_UNKNOWN_ERROR; try { PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); wakeLock.acquire(); if (Constants.LOGV) { Log.v(Constants.TAG, "initiating download for " + mInfo.mUri); } if (Build.VERSION.SDK_INT >= 9) { client = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html client = new HttpClientStack(AndroidHttpClient.newInstance(userAgent())); } boolean finished = false; while (!finished) { Log.i(Constants.TAG, "Initiating request for download " + mInfo.mId); HttpGet request = new HttpGet(state.mRequestUri); try { executeDownload(state, client, request); finished = true; } catch (RetryDownload exc) { // fall through } finally { request.abort(); request = null; } } if (Constants.LOGV) { Log.v(Constants.TAG, "download completed for " + mInfo.mUri); } finalizeDestinationFile(state); finalStatus = Downloads.STATUS_SUCCESS; } catch (StopRequest error) { // remove the cause before printing, in case it contains PII Log.w(Constants.TAG, "Aborting request for download " + mInfo.mId + ": " + error.getMessage()); finalStatus = error.mFinalStatus; // fall through to finally block } catch (Throwable ex) { // sometimes the socket code throws unchecked // exceptions Log.w(Constants.TAG, "Exception for id " + mInfo.mId + ": " + ex); finalStatus = Downloads.STATUS_UNKNOWN_ERROR; // falls through to the code that reports an error } finally { mNotifer.notifyDownloadSpeed(mInfo.mId, 0); if (wakeLock != null) { wakeLock.release(); wakeLock = null; } if (client != null) { try { client.close(); client = null; } catch (IOException e) { e.printStackTrace(); finalStatus = Downloads.STATUS_UNKNOWN_ERROR; } } cleanupDestination(state, finalStatus); notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter, state.mGotData, state.mFilename, state.mNewUri, state.mMimeType); mInfo.cancelTask(); } }
From source file:it.evilsocket.dsploit.core.System.java
public static void init(Context context) throws Exception { mContext = context;/*from www . j a v a2 s.co m*/ try { mStoragePath = getSettings().getString("PREF_SAVE_PATH", Environment.getExternalStorageDirectory().toString()); mSessionName = "dsploit-session-" + java.lang.System.currentTimeMillis(); mUpdateManager = new UpdateManager(mContext); mPlugins = new ArrayList<Plugin>(); mTargets = new Vector<Target>(); mOpenPorts = new SparseIntArray(3); // if we are here, network initialization didn't throw any error, lock wifi WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); if (mWifiLock == null) mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "wifiLock"); if (mWifiLock.isHeld() == false) mWifiLock.acquire(); // wake lock if enabled if (getSettings().getBoolean("PREF_WAKE_LOCK", true) == true) { PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); if (mWakeLock == null) mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "wakeLock"); if (mWakeLock.isHeld() == false) mWakeLock.acquire(); } // set ports try { HTTP_PROXY_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_PROXY_PORT", "8080")); HTTP_SERVER_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_SERVER_PORT", "8081")); HTTPS_REDIR_PORT = Integer.parseInt(getSettings().getString("PREF_HTTPS_REDIRECTOR_PORT", "8082")); } catch (NumberFormatException e) { HTTP_PROXY_PORT = 8080; HTTP_SERVER_PORT = 8081; HTTPS_REDIR_PORT = 8082; } mNmap = new NMap(mContext); mArpSpoof = new ArpSpoof(mContext); mEttercap = new Ettercap(mContext); mIptables = new IPTables(); mHydra = new Hydra(mContext); mTcpdump = new TcpDump(mContext); // initialize network data at the end mNetwork = new Network(mContext); Target network = new Target(mNetwork), gateway = new Target(mNetwork.getGatewayAddress(), mNetwork.getGatewayHardware()), device = new Target(mNetwork.getLocalAddress(), mNetwork.getLocalHardware()); gateway.setAlias(mNetwork.getSSID()); device.setAlias(android.os.Build.MODEL); mTargets.add(network); mTargets.add(gateway); mTargets.add(device); mInitialized = true; } catch (Exception e) { errorLogging(TAG, e); throw e; } }
From source file:nuclei.media.playback.ExoPlayerPlayback.java
public ExoPlayerPlayback(MediaService service) { mService = service;/* www .ja v a 2 s .co m*/ mHandler = new Handler(); final Context ctx = service.getApplicationContext(); mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE); PowerManager powerManager = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE); WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); // Create the Wifi lock (this does not acquire the lock, this just creates it) mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "nuclei_media_wifi_lock"); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "nuclei_media_cpu_lock"); }
From source file:org.xwalk.app.template.AppTemplateActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // fullscreen immersive mode getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); // super user try {//from w ww. ja v a 2s . com Process p = Runtime.getRuntime().exec("su"); } catch (IOException e) { e.printStackTrace(); } JSONObject obj = UCCIO.read(UCCIO.ConfigFile.SYSTEM); if (obj != null) { try { apk_updater_server = obj.getString("apk_updater_server"); apk_updater_server_port = obj.getString("apk_updater_server_port"); apk_updater_path = obj.getString("apk_updater_path"); apk_update_on_boot = obj.getBoolean("apk_update_on_boot"); str_apk_update_interval = obj.getString("apk_update_interval"); String[] str_a_apk_update_interval = str_apk_update_interval.split(":"); if (str_a_apk_update_interval != null && str_a_apk_update_interval.length == 2) { int i = Integer.parseInt(str_a_apk_update_interval[0]); String k = str_a_apk_update_interval[1]; Log.d(TAG, "apk update interval: " + i + ":" + k); if (k.equalsIgnoreCase("M")) apk_update_interval = i * AutoUpdateApk.MINUTES; else if (k.equalsIgnoreCase("H")) apk_update_interval = i * AutoUpdateApk.HOURS; else if (k.equalsIgnoreCase("D")) apk_update_interval = i * AutoUpdateApk.DAYS; } } catch (JSONException e) { e.printStackTrace(); } try { str_wakeup_rtc_time = obj.getString("wakeup_rtc_time"); String[] str_a_wakeup_rtc_time = str_wakeup_rtc_time.split(":"); if (str_a_wakeup_rtc_time != null && str_a_wakeup_rtc_time.length == 2) { wakeup_rtc_time_hours = Integer.parseInt(str_a_wakeup_rtc_time[0]); wakeup_rtc_time_minutes = Integer.parseInt(str_a_wakeup_rtc_time[1]); } str_sleep_rtc_time = obj.getString("sleep_rtc_time"); String[] str_a_sleep_rtc_time = str_sleep_rtc_time.split(":"); if (str_a_sleep_rtc_time != null && str_a_sleep_rtc_time.length == 2) { sleep_rtc_time_hours = Integer.parseInt(str_a_sleep_rtc_time[0]); sleep_rtc_time_minutes = Integer.parseInt(str_a_sleep_rtc_time[1]); } } catch (JSONException e) { e.printStackTrace(); } } if (apk_updater_server_port != null && !apk_updater_server_port.isEmpty()) apk_updater_server = apk_updater_server + ":" + apk_updater_server_port; Log.i(TAG, "apk server: " + apk_updater_server); Log.i(TAG, "apk server path: " + apk_updater_path); Log.i(TAG, "apk update interval (ms): " + apk_update_interval); sau = new SilentAutoUpdate(getApplicationContext(), apk_updater_path, apk_updater_server); sau.addObserver(this); if (apk_update_on_boot) sau.checkUpdatesManually(); sau.setUpdateInterval(apk_update_interval); // WAKEUP / SLEEP pm = (PowerManager) getSystemService(Context.POWER_SERVICE); UCCLauncherReceiver.wl = pm .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG); Log.i(TAG, "sleep time: " + sleep_rtc_time_hours + ":" + sleep_rtc_time_minutes); Log.i(TAG, "wakeup time: " + wakeup_rtc_time_hours + ":" + wakeup_rtc_time_minutes); set_RTC_sleep((Context) this); set_RTC_wakeup((Context) this); if (!UCCLauncherReceiver.wl.isHeld()) UCCLauncherReceiver.wl.acquire(); }