Example usage for android.content Context POWER_SERVICE

List of usage examples for android.content Context POWER_SERVICE

Introduction

In this page you can find the example usage for android.content Context POWER_SERVICE.

Prototype

String POWER_SERVICE

To view the source code for android.content Context POWER_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.os.PowerManager for controlling power management, including "wake locks," which let you keep the device on while you're running long tasks.

Usage

From source file:biz.bokhorst.bpt.BPTService.java

@Override
public IBinder onBind(Intent intent) {
    // Start foreground service
    startForeground(1, getNotification(getString(R.string.Running)));

    // Instantiate helpers
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    databaseHelper = new DatabaseHelper(this);
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    taskHandler = new Handler();
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BPT");
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Intent alarmIntent = new Intent("BPT_ALARM");
    pendingAlarmIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmReceiver = new BPTAlarmReceiver();
    registerReceiver(alarmReceiver, new IntentFilter("BPT_ALARM"));

    bound = true;/* w w w .ja v  a2  s.c o m*/
    return serverMessenger.getBinder();
}

From source file:com.simicart.core.notification.GCMIntentService.java

private void onRecieveMessage(Context context) {
    // Sang man hinh khi co notification
    PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
    WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK
            | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
    wakeLock.acquire(5000);//from ww  w .j  a v  a 2 s . c  o  m

    // // Am thanh mac dinh
    // try {
    // Uri notification = RingtoneManager
    // .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    // Ringtone r = RingtoneManager.getRingtone(getApplicationContext(),
    // notification);
    // r.play();
    // } catch (Exception e) {
    // e.printStackTrace();
    // }

    // check app open or close
    if (MainActivity.context != null && MainActivity.state != MainActivity.PAUSE
            && notificationData.getShowPopup().equals("1")) {
        createNotification(context);
    } else {
        generateNotification(context, notificationData);
    }
}

From source file:com.android.mms.quickmessage.QuickMessagePopup.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initialise the message list and other variables
    mContext = this;
    mMessageList = new ArrayList<QuickMessage>();
    mDefaultContactImage = getResources().getDrawable(R.drawable.ic_contact_picture);
    mNumTemplates = getTemplatesCount();
    mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);

    // Get the preferences
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    mFullTimestamp = prefs.getBoolean(MessagingPreferenceActivity.FULL_TIMESTAMP, false);
    mCloseClosesAll = prefs.getBoolean(MessagingPreferenceActivity.QM_CLOSE_ALL_ENABLED, false);
    mWakeAndUnlock = prefs.getBoolean(MessagingPreferenceActivity.QM_LOCKSCREEN_ENABLED, false);
    mDarkTheme = prefs.getBoolean(MessagingPreferenceActivity.QM_DARK_THEME_ENABLED, false);
    mUnicodeStripping = prefs.getInt(MessagingPreferenceActivity.UNICODE_STRIPPING_VALUE,
            MessagingPreferenceActivity.UNICODE_STRIPPING_LEAVE_INTACT);
    mInputMethod = Integer.parseInt(prefs.getString(MessagingPreferenceActivity.INPUT_TYPE,
            Integer.toString(InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE)));

    mDarkTheme = mContext.getResources()
            .getConfiguration().uiThemeMode == Configuration.UI_THEME_MODE_HOLO_DARK;

    // Set the window features and layout
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.dialog_quickmessage);

    // Turn on the Options Menu
    invalidateOptionsMenu();//from  w  ww .j  av a  2 s .c  om

    // Load the views and Parse the intent to show the QuickMessage
    setupViews();
    parseIntent(getIntent().getExtras(), false);

    setFinishOnTouchOutside(false);
}

From source file:org.csploit.android.core.System.java

public static void init(Context context) throws Exception {
    mContext = context;//from   ww w.ja  va  2 s.co  m
    try {
        Logger.debug("initializing System...");
        mStoragePath = getSettings().getString("PREF_SAVE_PATH",
                Environment.getExternalStorageDirectory().toString());
        mSessionName = "csploit-session-" + java.lang.System.currentTimeMillis();
        mKnownIssues = new KnownIssues();
        mPlugins = new ArrayList<>();
        mOpenPorts = new SparseIntArray(3);
        mServices = new HashMap<>();
        mPorts = new HashMap<>();

        // 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())
            mWifiLock.acquire();

        // wake lock if enabled
        if (getSettings().getBoolean("PREF_WAKE_LOCK", true)) {
            PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);

            if (mWakeLock == null)
                mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "wakeLock");

            if (!mWakeLock.isHeld())
                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"));
            MSF_RPC_PORT = Integer.parseInt(getSettings().getString("MSF_RPC_PORT", "55553"));
        } catch (NumberFormatException e) {
            HTTP_PROXY_PORT = 8080;
            HTTP_SERVER_PORT = 8081;
            HTTPS_REDIR_PORT = 8082;
            MSF_RPC_PORT = 55553;
        }

        uncaughtReloadNetworkMapping();

        ThreadHelper.getSharedExecutor().execute(new Runnable() {
            @Override
            public void run() {
                preloadServices();
                preloadVendors();
            }
        });
    } catch (Exception e) {
        if (!(e instanceof NoRouteToHostException))
            errorLogging(e);

        throw e;
    }
}

From source file:com.nbplus.vbroadlauncher.BaseActivity.java

public void acquireCpuWakeLock() {
    Log.e(TAG, "Acquiring cpu wake lock");
    if (mCpuWakeLock != null) {
        return;// w w  w. j a v  a 2 s  .c  o m
    }

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

    mCpuWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
            | PowerManager.ON_AFTER_RELEASE, "I'm your father");
    mCpuWakeLock.acquire();

    Window window = this.getWindow();
    mDefaultWindowFlags = window.getAttributes().flags;
    window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}

From source file:org.zeroxlab.benchmark.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 a v  a 2 s.  c om
    sTexture = new BitmapShader(BitmapFactory.decodeResource(getResources(), R.drawable.crate), TileMode.REPEAT,
            TileMode.REPEAT);

    setContentView(R.layout.main);
    mCases = new LinkedList<Case>();
    Case arith = new CaseArithmetic();
    Case javascript = new CaseJavascript();
    Case scimark2 = new CaseScimark2();
    Case glcube = new CaseGLCube();
    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 canvas = new CaseCanvas(true, false, false);
    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(D2HW, new HashSet<Case>());
    mCategory.put(D2SW1, new HashSet<Case>());
    mCategory.put(D2SW2, 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(dc2);
    mCases.add(dr);
    mCases.add(da);
    mCases.add(di);
    mCases.add(dt);

    mCategory.get(D2).add(canvas);
    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);

    Case canvas2 = new CaseCanvas(false, false, false);//HW
    Case canvas3 = new CaseCanvas(false, true, false);//SW Window
    Case canvas4 = new CaseCanvas(false, false, true);//SW Layer
    Case circle = new CaseDrawCircle(false, false, false);//HW
    Case circle2 = new CaseDrawCircle(false, true, false);//SW Window
    Case circle3 = new CaseDrawCircle(false, false, true);//SW Layer
    Case dc22 = new CaseDrawCircle2(false, false, false);//HW
    Case dc23 = new CaseDrawCircle2(false, true, false);//SW Window
    Case dc24 = new CaseDrawCircle2(false, false, true);//SW Layer
    Case dr2 = new CaseDrawRect(false, false, false);//HW
    Case dr3 = new CaseDrawRect(false, true, false);//SW Window
    Case dr4 = new CaseDrawRect(false, false, true);//SW Layer
    Case da2 = new CaseDrawArc(false, false, false);//HW
    Case da3 = new CaseDrawArc(false, true, false);//SW Window
    Case da4 = new CaseDrawArc(false, false, true);//SW Layer
    Case di2 = new CaseDrawImage(false, false, false);//HW
    Case di3 = new CaseDrawImage(false, true, false);//SW Window
    Case di4 = new CaseDrawImage(false, false, true);//SW Layer
    Case dt2 = new CaseDrawText(false, false, false);//HW
    Case dt3 = new CaseDrawText(false, true, false);//SW Window
    Case dt4 = new CaseDrawText(false, false, true);//SW Layer

    mCases.add(canvas2);
    mCases.add(circle);
    mCases.add(dc22);
    mCases.add(dr2);
    mCases.add(da2);
    mCases.add(di2);
    mCases.add(dt2);

    mCases.add(canvas3);
    mCases.add(circle2);
    mCases.add(dc23);
    mCases.add(dr3);
    mCases.add(da3);
    mCases.add(di3);
    mCases.add(dt3);

    mCases.add(canvas4);
    mCases.add(circle3);
    mCases.add(dc24);
    mCases.add(dr4);
    mCases.add(da4);
    mCases.add(di4);
    mCases.add(dt4);

    //2d(HW)
    mCategory.get(D2HW).add(canvas2);
    mCategory.get(D2HW).add(circle);
    mCategory.get(D2HW).add(dc22);
    mCategory.get(D2HW).add(da2);
    mCategory.get(D2HW).add(dr2);
    mCategory.get(D2HW).add(di2);
    mCategory.get(D2HW).add(dt2);

    //2d(SW1)
    mCategory.get(D2SW1).add(canvas3);
    mCategory.get(D2SW1).add(circle2);
    mCategory.get(D2SW1).add(dc23);
    mCategory.get(D2SW1).add(da3);
    mCategory.get(D2SW1).add(dr3);
    mCategory.get(D2SW1).add(di3);
    mCategory.get(D2SW1).add(dt3);

    //2d(SW2)
    mCategory.get(D2SW2).add(canvas4);
    mCategory.get(D2SW2).add(circle3);
    mCategory.get(D2SW2).add(dc24);
    mCategory.get(D2SW2).add(da4);
    mCategory.get(D2SW2).add(dr4);
    mCategory.get(D2SW2).add(di4);
    mCategory.get(D2SW2).add(dt4);

    // 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:com.ferdi2005.secondgram.NotificationsController.java

public NotificationsController() {
    notificationManager = NotificationManagerCompat.from(ApplicationLoader.applicationContext);
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications",
            Context.MODE_PRIVATE);
    inChatSoundEnabled = preferences.getBoolean("EnableInChatSound", true);

    try {//w  w  w. ja va  2  s .  c  o  m
        audioManager = (AudioManager) ApplicationLoader.applicationContext
                .getSystemService(Context.AUDIO_SERVICE);
    } catch (Exception e) {
        FileLog.e(e);
    }
    try {
        alarmManager = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
    } catch (Exception e) {
        FileLog.e(e);
    }

    try {
        PowerManager pm = (PowerManager) ApplicationLoader.applicationContext
                .getSystemService(Context.POWER_SERVICE);
        notificationDelayWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
        notificationDelayWakelock.setReferenceCounted(false);
    } catch (Exception e) {
        FileLog.e(e);
    }

    notificationDelayRunnable = new Runnable() {
        @Override
        public void run() {
            FileLog.e("delay reached");
            if (!delayedPushMessages.isEmpty()) {
                showOrUpdateNotification(true);
                delayedPushMessages.clear();
            }
            try {
                if (notificationDelayWakelock.isHeld()) {
                    notificationDelayWakelock.release();
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
    };
}

From source file:com.almarsoft.GroundhogReader.MessageListActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.messagelist);
    Context context = getApplicationContext();

    // Config checker alert dialog
    mConfigAlert = new AlertDialog.Builder(this).create();
    mConfigAlert.setButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dlg, int sumthin) {
            startActivity(new Intent(MessageListActivity.this, OptionsActivity.class));
        }/*  w  w  w  .j av  a 2  s . c  om*/
    });

    mNumUnread = 0; // Loaded in OnResume || threadMessagesFromDB()
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mOfflineMode = mPrefs.getBoolean("offlineMode", true);

    // Get the selected group from the GroupListActivity-passed bundle
    mTitleBar = (TextView) this.findViewById(R.id.topbar_text);
    mGroup = getIntent().getExtras().getString("selectedGroup");
    mGroupID = DBUtils.getGroupIdFromName(mGroup, context);

    mGoGroups = (ImageButton) this.findViewById(R.id.btn_gogroups);
    mGoGroups.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            MessageListActivity.this
                    .startActivity(new Intent(MessageListActivity.this, GroupListActivity.class));
        }
    });

    mServerManager = new ServerManager(context);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,
            "GroundhogThreading");

    mMsgList = (ListView) this.findViewById(R.id.list_msgs);
    mMsgList.setOnItemClickListener(mListItemClickListener);
    registerForContextMenu(mMsgList);
    Drawable dw = getResources().getDrawable(R.drawable.greyline2);
    mMsgList.setDivider(dw);

    // Show the progress dialog, get messages from server, write to DB
    // and call the loading of message from DB and threading when it ends
    mWakeLock.acquire();
    threadMessagesFromDB();
}

From source file:de.ub0r.android.portaltimer.UpdateReceiver.java

private void schedNext(final Context context) {
    Log.d(TAG, "schedNext()");
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Log.d(TAG, "current: " + mNow);
    long t;/*from   w w  w  .jav  a2  s. c  o m*/
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (pm.isScreenOn()) {
        t = mNow + 1000L;
    } else {
        t = mNextTarget - mNow;
        Log.d(TAG, "t: " + t);
        if (t < 0) { // IllegalState?
            t = 30000;
        } else if (t < 30000) {
            t = 5000;
        } else if (t < 60000) {
            t = 15000;
        } else {
            t = 30000;
        }
        Log.d(TAG, "t: " + t);
        long diff = mNextTarget - (mNow + t);
        diff = (diff / 5000) * 5000;
        Log.d(TAG, "diff: " + diff);
        if (diff == 0) {
            t = mNow + 5000;
        } else {
            t = mNextTarget - diff - 1000;
        }
    }
    Log.d(TAG, "next: " + t);
    long et;
    if (t - System.currentTimeMillis() < 100) { // IllegalState?
        et = 1000 + SystemClock.elapsedRealtime();
    } else {
        et = t - System.currentTimeMillis() + SystemClock.elapsedRealtime();
    }
    am.set(AlarmManager.ELAPSED_REALTIME, et, PendingIntent.getBroadcast(context, 0,
            new Intent(context, UpdateReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT));
}

From source file:com.arifin.taxi.penumpang.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from   w  ww .ja va2s .  com*/
private void generateNotification(Context context, String message) {
    // System.out.println("this is message " + message);
    // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + message);
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification = new Notification(icon, message, when);

    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MainDrawerActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    notification = builder.setContentIntent(intent).setSmallIcon(icon).setTicker(message).setWhen(when)
            .setAutoCancel(true).setContentTitle(title).setContentText(message).build();
    // mNM.notify(NOTIFICATION, notification);

    /*notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;*/

    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(0, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();
}