Java 类android.os.PowerManager 实例源码
项目:LocationAware
文件:AlarmActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "AlarmActivity");
mWakeLock.acquire(2 * 60 * 1000L);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
window.setStatusBarColor(Color.TRANSPARENT);
}
setContentView(R.layout.activity_alarm);
if (getActivityComponent() != null) {
getActivityComponent().inject(this);
alarmPresenter.onAttach(this);
}
initViews();
bindEvents();
processIntent();
}
项目:buildAPKsApps
文件:AlarmNotificationService.java
@Override
public void onReceive(Context c, Intent i) {
final long alarmid = i.getLongExtra(ALARM_ID, -1);
@SuppressWarnings("deprecation") // SCREEN_DIM_WAKE_LOCK
PowerManager.WakeLock w =
((PowerManager)c.getSystemService(Context.POWER_SERVICE))
.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP, "wake id " + nextid);
w.setReferenceCounted(false);
w.acquire();
locks.put(nextid, w);
Log.i(TAG, "Acquired lock " + nextid + " for alarm " + alarmid);
c.startService(new Intent(c, AlarmNotificationService.class)
.putExtra(ALARM_ID, alarmid)
.putExtra(COMMAND, TRIGGER_ALARM_NOTIFICATION)
.putExtra(WAKELOCK_ID, nextid++));
}
项目:Cable-Android
文件:DirectoryRefreshJob.java
@Override
public void onRun() throws IOException {
Log.w("DirectoryRefreshJob", "DirectoryRefreshJob.onRun()");
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Directory Refresh");
try {
wakeLock.acquire();
if (recipients == null) {
DirectoryHelper.refreshDirectory(context, KeyCachingService.getMasterSecret(context));
} else {
DirectoryHelper.refreshDirectoryFor(context, masterSecret, recipients, TextSecurePreferences.getLocalNumber(context));
}
SecurityEvent.broadcastSecurityUpdateEvent(context);
} finally {
if (wakeLock.isHeld()) wakeLock.release();
}
}
项目:Linphone4Android
文件:LinphoneManager.java
protected LinphoneManager(final Context c) {
sExited = false;
echoTesterIsRunning = false;
mServiceContext = c;
basePath = c.getFilesDir().getAbsolutePath();
mLPConfigXsd = basePath + "/lpconfig.xsd";
mLinphoneFactoryConfigFile = basePath + "/linphonerc";
mLinphoneConfigFile = basePath + "/.linphonerc";
mLinphoneRootCaFile = basePath + "/rootca.pem";
mRingSoundFile = basePath + "/ringtone.mkv";
mRingbackSoundFile = basePath + "/ringback.wav";
mPauseSoundFile = basePath + "/hold.mkv";
mChatDatabaseFile = basePath + "/linphone-history.db";
mCallLogDatabaseFile = basePath + "/linphone-log-history.db";
mFriendsDatabaseFile = basePath + "/linphone-friends.db";
mErrorToneFile = basePath + "/error.wav";
mUserCertificatePath = basePath;
mPrefs = LinphonePreferences.instance();
mAudioManager = ((AudioManager) c.getSystemService(Context.AUDIO_SERVICE));
mVibrator = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE);
mPowerManager = (PowerManager) c.getSystemService(Context.POWER_SERVICE);
mConnectivityManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
mR = c.getResources();
mPendingChatFileMessage = new ArrayList<LinphoneChatMessage>();
}
项目:MyAnimeViewer
文件:AnimeDownloadManager.java
@Override
public void run() {
super.run();
PowerManager.WakeLock lock = getLock(mContext);
while (isRunning) {
AnimeDownloadTask task = mTaskQueue.poll();
if (task != null) {
if (!lock.isHeld()) {
lock.acquire();
}
mDownloadingTasks.add(task);
task.execute();
}
}
if (lock.isHeld()) {
lock.release();
}
}
项目:Cable-Android
文件:LockManager.java
public LockManager(Context context) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
fullLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "RedPhone Full");
partialLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RedPhone Partial");
proximityLock = new ProximityLock(pm);
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "RedPhone Wifi");
fullLock.setReferenceCounted(false);
partialLock.setReferenceCounted(false);
wifiLock.setReferenceCounted(false);
accelerometerListener = new AccelerometerListener(context, new AccelerometerListener.OrientationListener() {
@Override
public void orientationChanged(int newOrientation) {
orientation = newOrientation;
Log.d(TAG, "Orentation Update: " + newOrientation);
updateInCallLockState();
}
});
wifiLockEnforced = isWifiPowerActiveModeEnabled(context);
}
项目:stynico
文件:AppCompatDlalog.java
private void wakeAndUnlock()
{
//获取电源管理器对象
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
//获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
//点亮屏幕
wl.acquire(1000);
//得到键盘锁管理器对象
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
kl = km.newKeyguardLock("unLock");
//解锁
kl.disableKeyguard();
}
项目:xwallet
文件:BlockchainService.java
/**
*
*/
private void acquireWakeLocks() {
if(_wakeLock == null) {
PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE);
_wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BlockchainServiceLockTag");
}
if (_wifiLock == null) {
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
_wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "BlockchainServiceWifiLockTag");
}
if (!_wakeLock.isHeld())
_wakeLock.acquire();
if (!_wifiLock.isHeld())
_wifiLock.acquire();
}
项目:GravityBox
文件:ModPower.java
private static void toggleWakeUpWithProximityFeature(boolean enabled) {
try {
if (enabled) {
mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
mProxSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
mWakeLock = ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE))
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
} else {
unregisterProxSensorListener();
mProxSensor = null;
mSensorManager = null;
mWakeLock = null;
}
if (DEBUG) log("toggleWakeUpWithProximityFeature: " + enabled);
} catch (Throwable t) {
XposedBridge.log(t);
}
}
项目:PeSanKita-android
文件:ApplicationMigrationService.java
@Override
public void run() {
notification = initializeBackgroundNotification();
PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Migration");
try {
wakeLock.acquire();
setState(new ImportState(ImportState.STATE_MIGRATING_BEGIN, null));
SmsMigrator.migrateDatabase(ApplicationMigrationService.this,
masterSecret,
ApplicationMigrationService.this);
setState(new ImportState(ImportState.STATE_MIGRATING_COMPLETE, null));
setDatabaseImported(ApplicationMigrationService.this);
stopForeground(true);
notifyImportComplete();
stopSelf();
} finally {
wakeLock.release();
}
}
项目:PeSanKita-android
文件:LockManager.java
public LockManager(Context context) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
fullLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "RedPhone Full");
partialLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RedPhone Partial");
proximityLock = new ProximityLock(pm);
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "RedPhone Wifi");
fullLock.setReferenceCounted(false);
partialLock.setReferenceCounted(false);
wifiLock.setReferenceCounted(false);
accelerometerListener = new AccelerometerListener(context, new AccelerometerListener.OrientationListener() {
@Override
public void orientationChanged(int newOrientation) {
orientation = newOrientation;
Log.d(TAG, "Orentation Update: " + newOrientation);
updateInCallLockState();
}
});
wifiLockEnforced = isWifiPowerActiveModeEnabled(context);
}
项目:MyAnimeViewer
文件:ParseAnimeService.java
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
PowerManager.WakeLock lock = getLock(this.getApplicationContext());
if (!lock.isHeld() || (flags & START_FLAG_REDELIVERY) != 0) {
lock.acquire();
}
if (mServiceHandler != null) {
if (intent != null && intent.getExtras() != null) {
// For each start request, send a message to start a job and deliver the
// start ID so we know which request we're stopping when we finish the job
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = startId;
msg.setData(intent.getExtras());
mServiceHandler.sendMessage(msg);
} else
stopSelf();
}
// If we get killed, after returning from here, restart
return START_STICKY;
}
项目:ReplyMessage
文件:AutoReplyService.java
private void wakeAndUnlock() {
//获取电源管理器对象
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
//获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
//点亮屏幕
wl.acquire(1000);
//得到键盘锁管理器对象
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
kl = km.newKeyguardLock("unLock");
//解锁
kl.disableKeyguard();
}
项目:QiangHongBao
文件:NotifyUtils.java
public static void wakeAndUnlock() {
//获取电源管理器对象
PowerManager pm = getPowerManager();
//获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
//点亮屏幕
wl.acquire(1000);
//得到键盘锁管理器对象
KeyguardManager km = getKeyguardManager();
KeyguardManager.KeyguardLock kl = km.newKeyguardLock("unLock");
//解锁
kl.disableKeyguard();
}
项目:chat-sdk-android-push-firebase
文件:NotificationUtils.java
/**
* Waking up the screen
* * * */
private static void wakeScreen(Context context){
// Waking the screen so the user will see the notification
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH)
isScreenOn = pm.isScreenOn();
else
isScreenOn = pm.isInteractive();
if(!isScreenOn)
{
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
|PowerManager.ON_AFTER_RELEASE
|PowerManager.ACQUIRE_CAUSES_WAKEUP, "MyLock");
wl.acquire(5000);
wl.release();
}
}
项目:localcloud_fe
文件:ForegroundService.java
/**
* Put the service in a foreground state to prevent app from being killed
* by the OS.
*/
private void keepAwake() {
JSONObject settings = BackgroundMode.getSettings();
boolean isSilent = settings.optBoolean("silent", false);
if (!isSilent) {
startForeground(NOTIFICATION_ID, makeNotification());
}
PowerManager powerMgr = (PowerManager)
getSystemService(POWER_SERVICE);
wakeLock = powerMgr.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, "BackgroundMode");
wakeLock.acquire();
}
项目:Android-Show-Reader
文件:UnlockDeviceAndroidJUnitRunner.java
@SuppressWarnings("MissingPermission")
@Override
public void onStart() {
Application application = (Application) getTargetContext().getApplicationContext();
String simpleName = UnlockDeviceAndroidJUnitRunner.class.getSimpleName();
// Unlock the device so that the tests can input keystrokes.
((KeyguardManager) application.getSystemService(KEYGUARD_SERVICE))
.newKeyguardLock(simpleName)
.disableKeyguard();
// Wake up the screen.
PowerManager powerManager = ((PowerManager) application.getSystemService(POWER_SERVICE));
mWakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP |
ON_AFTER_RELEASE, simpleName);
mWakeLock.acquire();
super.onStart();
}
项目:2017.2-codigo
文件:WakeLockActivity.java
@Override
protected void onResume() {
super.onResume();
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");
wakeLock.acquire();
/*
*
*
* Flag Value CPU Screen Keyboard
PARTIAL_WAKE_LOCK On* Off Off
SCREEN_DIM_WAKE_LOCK On Dim Off
SCREEN_BRIGHT_WAKE_LOCK On Bright Off
FULL_WAKE_LOCK On Bright Bright
*
* */
}
项目:Nird2
文件:TorPlugin.java
TorPlugin(Executor ioExecutor, Context appContext,
LocationUtils locationUtils, DevReporter reporter,
SocketFactory torSocketFactory, Backoff backoff,
DuplexPluginCallback callback, String architecture, int maxLatency,
int maxIdleTime) {
this.ioExecutor = ioExecutor;
this.appContext = appContext;
this.locationUtils = locationUtils;
this.reporter = reporter;
this.torSocketFactory = torSocketFactory;
this.backoff = backoff;
this.callback = callback;
this.architecture = architecture;
this.maxLatency = maxLatency;
this.maxIdleTime = maxIdleTime;
if (maxIdleTime > Integer.MAX_VALUE / 2)
socketTimeout = Integer.MAX_VALUE;
else socketTimeout = maxIdleTime * 2;
connectionStatus = new ConnectionStatus();
torDirectory = appContext.getDir("tor", MODE_PRIVATE);
torFile = new File(torDirectory, "tor");
geoIpFile = new File(torDirectory, "geoip");
configFile = new File(torDirectory, "torrc");
doneFile = new File(torDirectory, "done");
cookieFile = new File(torDirectory, ".tor/control_auth_cookie");
Object o = appContext.getSystemService(POWER_SERVICE);
PowerManager pm = (PowerManager) o;
wakeLock = pm.newWakeLock(PARTIAL_WAKE_LOCK, "TorPlugin");
wakeLock.setReferenceCounted(false);
}
项目:GravityBox
文件:ModPowerMenu.java
private static void doReboot(Context context, int mode) {
final PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (mode == 0) {
pm.reboot(null);
} else if (mode == 1) {
Utils.performSoftReboot();
} else if (mode == 2) {
replaceRecoveryMessage();
pm.reboot("recovery");
} else if (mode == 3) {
pm.reboot("bootloader");
}
}
项目:MainCalendar
文件:AlarmNoticeActivity.java
/**
* 获取解锁权
*/
private void acquireScreenCpuWakeLock() {
if (mWakeLock != null) {
return;
}
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE,
AppConstants.LOG_TAG);
mWakeLock.acquire();
}
项目:android-mqtt-service
文件:BackgroundService.java
@Override
public void onCreate() {
super.onCreate();
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getSimpleName());
mWakeLock.acquire();
mWorkerThread = new HandlerThread(getClass().getSimpleName(),
android.os.Process.THREAD_PRIORITY_BACKGROUND);
mWorkerThread.start();
mHandler = new Handler(mWorkerThread.getLooper());
}
项目:q-mail
文件:CoreReceiver.java
private static Integer getWakeLock(Context context) {
TracingPowerManager pm = TracingPowerManager.getPowerManager(context);
TracingWakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CoreReceiver getWakeLock");
wakeLock.setReferenceCounted(false);
wakeLock.acquire(QMail.BOOT_RECEIVER_WAKE_LOCK_TIMEOUT);
Integer tmpWakeLockId = wakeLockSeq.getAndIncrement();
wakeLocks.put(tmpWakeLockId, wakeLock);
Timber.v("CoreReceiver Created wakeLock %d", tmpWakeLockId);
return tmpWakeLockId;
}
项目:superglue
文件:DebugViewContainer.java
/**
* Show the activity over the lock-screen and wake up the device. If you launched the app manually
* both of these conditions are already true. If you deployed from the IDE, however, this will
* save you from hundreds of power button presses and pattern swiping per day!
*/
public static void riseAndShine(Activity activity) {
activity.getWindow().addFlags(FLAG_SHOW_WHEN_LOCKED);
PowerManager power = (PowerManager) activity.getSystemService(POWER_SERVICE);
PowerManager.WakeLock lock =
power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, "wakeup!");
lock.acquire();
lock.release();
}
项目:GitHub
文件:CircularProgressDrawable.java
/**
* Private method, use #Builder instead
*/
private CircularProgressDrawable(PowerManager powerManager, Options options) {
mOptions = options;
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(options.borderWidth);
mPaint.setStrokeCap(options.style == STYLE_ROUNDED ? Paint.Cap.ROUND : Paint.Cap.BUTT);
mPaint.setColor(options.colors[0]);
mPowerManager = powerManager;
initDelegate();
}
项目:PlusGram
文件:ConnectionsManager.java
public ConnectionsManager() {
try {
PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
wakeLock.setReferenceCounted(false);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
项目:chromium-net-for-android
文件:ApiCompatibilityUtils.java
/**
* @return Whether the screen of the device is interactive.
*/
@SuppressWarnings("deprecation")
public static boolean isInteractive(Context context) {
PowerManager manager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
return manager.isInteractive();
} else {
return manager.isScreenOn();
}
}
项目:GitHub
文件:DeviceUtils.java
/**
* 重启
* <p>需系统权限 {@code <android:sharedUserId="android.uid.system"/>}</p>
*
* @param reason 传递给内核来请求特殊的引导模式,如"recovery"
*/
public static void reboot(final String reason) {
PowerManager mPowerManager = (PowerManager) Utils.getApp().getSystemService(Context.POWER_SERVICE);
try {
mPowerManager.reboot(reason);
} catch (Exception e) {
e.printStackTrace();
}
}
项目:MyAnimeViewer
文件:AnimeDownloadManager.java
synchronized private static PowerManager.WakeLock getLock(Context context) {
if (lockStatic == null) {
PowerManager mgr =
(PowerManager) context.getSystemService(Context.POWER_SERVICE);
lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, NAME);
lockStatic.setReferenceCounted(true);
}
return (lockStatic);
}
项目:xmrwallet
文件:WalletActivity.java
void acquireWakeLock() {
if ((wl != null) && wl.isHeld()) return;
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
this.wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, getString(R.string.app_name));
try {
wl.acquire();
Timber.d("WakeLock acquired");
} catch (SecurityException ex) {
Timber.w("WakeLock NOT acquired: %s", ex.getLocalizedMessage());
wl = null;
}
}
项目:fitnotifications
文件:NLService.java
private boolean isScreenOn() {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
// API >= 20
return pm.isInteractive();
}
// API <= 19, use deprecated
//noinspection deprecation
return pm.isScreenOn();
}
项目:GravityBox
文件:SleepTile.java
@Override
public void handleClick() {
try {
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
XposedHelpers.callMethod(pm, "goToSleep", SystemClock.uptimeMillis());
} catch(Throwable t) {
log(getKey() + ": Error calling PowerManager goToSleep(): ");
XposedBridge.log(t);
}
super.handleClick();
}
项目:unlock-apk
文件:MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// add flag to current window
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
// init KeyguardManager
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
if (keyguardManager.inKeyguardRestrictedInputMode()) {
KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(getLocalClassName());
keyguardLock.disableKeyguard();
}
// wake up screen light
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "");
wakeLock.acquire();
// finish current activity
finish();
}
项目:habpanelviewer
文件:ScreenController.java
public ScreenController(PowerManager pwrManager, Activity activity, ServerConnection serverConnection) {
mServerConnection = serverConnection;
this.activity = activity;
EventBus.getDefault().register(this);
screenOnLock = pwrManager.newWakeLock(
PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "HabpanelViewer");
}
项目:sctalk
文件:IMReconnectManager.java
/**
* 获取电源锁,保持该服务在屏幕熄灭时仍然获取CPU时,保持运行
* 由于重连流程中充满了异步操作,按照函数执行流判断加锁代码侵入性较大,而且还需要traceId跟踪(因为可能会并发)
* 所以这个锁定义为时间锁,15s的重连容忍时间
*/
private void acquireWakeLock() {
try {
if (null == wakeLock) {
PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "teamtalk_reconnecting_wakelock");
logger.i("acquireWakeLock#call acquireWakeLock");
wakeLock.acquire(15000);
}
}catch (Exception e){
e.printStackTrace();
}
}
项目:PosTrainer
文件:ApplicationModule.java
public ApplicationModule(Context application) {
this.applicationContext = application;
this.wakeLock = ((PowerManager) applicationContext
.getSystemService(POWER_SERVICE))
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Alarm");
this.audioManager = ((AudioManager) applicationContext.getSystemService(Context.AUDIO_SERVICE));
this.vibrator = ((Vibrator) applicationContext.getSystemService(Context.VIBRATOR_SERVICE));
this.alarmManager = ((AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE));
this.mediaPlayer = MediaPlayer.create(application, Settings.System.DEFAULT_ALARM_ALERT_URI);
}
项目:Open-Quran-Radio
文件:PlayerService.java
@Override
protected void onPostExecute(Boolean result) {
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setOnCompletionListener(PlayerService.this);
mMediaPlayer.setOnPreparedListener(PlayerService.this);
mMediaPlayer.setOnErrorListener(PlayerService.this);
mMediaPlayer.setOnInfoListener(PlayerService.this);
mMediaPlayer.setOnBufferingUpdateListener(PlayerService.this);
mMediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); // needs android.permission.WAKE_LOCK
try {
//mMediaPlayer.setDataSource(mStreamUri);
if (result) {
// stream is HLS - do not extract metadata
mMediaPlayer.setDataSource(mStreamUri);
} else {
// normal stream - extract metadata
//mMetadataHelper = new MetadataHelper(getApplicationContext(), mStation);
MetadataHelper.prepareMetadata(mStreamUri, mStation, getApplicationContext());
mMediaPlayer.setDataSource(mStreamUri);
//mMediaPlayer.setDataSource(mMetadataHelper.getShoutcastProxy());
}
mMediaPlayer.prepareAsync();
} catch (IOException e) {
e.printStackTrace();
}
}
项目:stynico
文件:Air.java
private void wakeAndUnlock2(boolean b)
{
if(b)
{
//获取电源管理器对象
pm=(PowerManager) getSystemService(Context.POWER_SERVICE);
//获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
//点亮屏幕
wl.acquire();
//得到键盘锁管理器对象
km= (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
kl = km.newKeyguardLock("unLock");
//解锁
kl.disableKeyguard();
}
else
{
//锁屏
kl.reenableKeyguard();
//释放wakeLock,关灯
wl.release();
}
}
项目:BaseCore
文件:DeviceUtils.java
/**
* 重启
* <p>需系统权限 {@code <android:sharedUserId="android.uid.system"/>}</p>
*
* @param reason 传递给内核来请求特殊的引导模式,如"recovery"
*/
public static void reboot(String reason) {
PowerManager mPowerManager = (PowerManager) Utils.getContext().getSystemService(Context.POWER_SERVICE);
try {
mPowerManager.reboot(reason);
} catch (Exception e) {
e.printStackTrace();
}
}
项目:stynico
文件:MD5_jni.java
/**
*
* @description: 检查屏幕是否亮着并且唤醒屏幕
* @date: 2016-1-29 下午2:08:25
* @author: yems
*/
private void checkScreen(Context context)
{
// TODO Auto-generated method stub
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (!pm.isScreenOn())
{
wakeUpAndUnlock(context);
}
}