Search in sources :

Example 46 with PowerManager

use of android.os.PowerManager in project GT by Tencent.

the class GTGPSRecordEngine method onCreate.

@Override
public void onCreate(Context context) {
    Toast.makeText(GTApp.getContext(), "start record..", Toast.LENGTH_SHORT).show();
    lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    locationListener = new MyLocationListener();
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    recordFile = GTUtils.getSaveDate() + ".gps";
    isRecord = true;
    for (GPSRecordListener listener : listeners) {
        listener.onRecordStart();
    }
    PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "location_in_bg");
    // 防止休眠锁
    mWakeLock.acquire();
}
Also used : PowerManager(android.os.PowerManager)

Example 47 with PowerManager

use of android.os.PowerManager in project GT by Tencent.

the class PartialWakeLock method toggle.

public static void toggle(Context context) {
    if (wl == null) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "GTPartialLockAction");
    }
    if (flag == false) {
        flag = true;
        wl.acquire();
    } else {
        flag = false;
        wl.release();
    }
}
Also used : PowerManager(android.os.PowerManager)

Example 48 with PowerManager

use of android.os.PowerManager in project android_frameworks_base by ParanoidAndroid.

the class KeyguardFaceUnlockView method maybeStartBiometricUnlock.

/**
     * Starts the biometric unlock if it should be started based on a number of factors.  If it
     * should not be started, it either goes to the back up, or remains showing to prepare for
     * it being started later.
     */
private void maybeStartBiometricUnlock() {
    if (DEBUG)
        Log.d(TAG, "maybeStartBiometricUnlock()");
    if (mBiometricUnlock != null) {
        KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
        final boolean backupIsTimedOut = (monitor.getFailedUnlockAttempts() >= LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT);
        PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        boolean isShowing;
        synchronized (mIsShowingLock) {
            isShowing = mIsShowing;
        }
        // showing.
        if (!powerManager.isScreenOn() || !isShowing) {
            // It shouldn't be running but calling this can't hurt.
            mBiometricUnlock.stop();
            return;
        }
        // the logic here is capable of suppressing Face Unlock.
        if (monitor.getPhoneState() == TelephonyManager.CALL_STATE_IDLE && monitor.isAlternateUnlockEnabled() && !monitor.getMaxBiometricUnlockAttemptsReached() && !backupIsTimedOut) {
            mBiometricUnlock.start();
        } else {
            mBiometricUnlock.stopAndShowBackup();
        }
    }
}
Also used : PowerManager(android.os.PowerManager)

Example 49 with PowerManager

use of android.os.PowerManager in project android_frameworks_base by ParanoidAndroid.

the class PowerManagerService method systemReady.

public void systemReady(TwilightService twilight, DreamManagerService dreamManager) {
    synchronized (mLock) {
        mSystemReady = true;
        mDreamManager = dreamManager;
        PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        mScreenBrightnessSettingMinimum = pm.getMinimumScreenBrightnessSetting();
        mScreenBrightnessSettingMaximum = pm.getMaximumScreenBrightnessSetting();
        mScreenBrightnessSettingDefault = pm.getDefaultScreenBrightnessSetting();
        SensorManager sensorManager = new SystemSensorManager(mContext, mHandler.getLooper());
        // The notifier runs on the system server's main looper so as not to interfere
        // with the animations and other critical functions of the power manager.
        mNotifier = new Notifier(Looper.getMainLooper(), mContext, mBatteryStats, createSuspendBlockerLocked("PowerManagerService.Broadcasts"), mScreenOnBlocker, mPolicy);
        // The display power controller runs on the power manager service's
        // own handler thread to ensure timely operation.
        mDisplayPowerController = new DisplayPowerController(mHandler.getLooper(), mContext, mNotifier, mLightsService, twilight, sensorManager, mDisplayManagerService, mDisplayBlanker, mDisplayPowerControllerCallbacks, mHandler);
        mWirelessChargerDetector = new WirelessChargerDetector(sensorManager, createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector"));
        mSettingsObserver = new SettingsObserver(mHandler);
        mAttentionLight = mLightsService.getLight(LightsService.LIGHT_ID_ATTENTION);
        // Register for broadcasts from other components of the system.
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_BATTERY_CHANGED);
        mContext.registerReceiver(new BatteryReceiver(), filter, null, mHandler);
        filter = new IntentFilter();
        filter.addAction(Intent.ACTION_BOOT_COMPLETED);
        mContext.registerReceiver(new BootCompletedReceiver(), filter, null, mHandler);
        filter = new IntentFilter();
        filter.addAction(Intent.ACTION_DREAMING_STARTED);
        filter.addAction(Intent.ACTION_DREAMING_STOPPED);
        mContext.registerReceiver(new DreamReceiver(), filter, null, mHandler);
        filter = new IntentFilter();
        filter.addAction(Intent.ACTION_USER_SWITCHED);
        mContext.registerReceiver(new UserSwitchedReceiver(), filter, null, mHandler);
        filter = new IntentFilter();
        filter.addAction(Intent.ACTION_DOCK_EVENT);
        mContext.registerReceiver(new DockReceiver(), filter, null, mHandler);
        // Register for settings changes.
        final ContentResolver resolver = mContext.getContentResolver();
        resolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.SCREENSAVER_ENABLED), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.SCREEN_OFF_TIMEOUT), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.Global.getUriFor(Settings.Global.STAY_ON_WHILE_PLUGGED_IN), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_MODE), false, mSettingsObserver, UserHandle.USER_ALL);
        resolver.registerContentObserver(Settings.System.getUriFor(Settings.System.AUTO_BRIGHTNESS_RESPONSIVENESS), false, mSettingsObserver, UserHandle.USER_ALL);
        // Go.
        readConfigurationLocked();
        updateSettingsLocked();
        mDirty |= DIRTY_BATTERY_STATE;
        updatePowerStateLocked();
    }
}
Also used : IntentFilter(android.content.IntentFilter) SystemSensorManager(android.hardware.SystemSensorManager) ContentResolver(android.content.ContentResolver) PowerManager(android.os.PowerManager) IPowerManager(android.os.IPowerManager) SensorManager(android.hardware.SensorManager) SystemSensorManager(android.hardware.SystemSensorManager)

Example 50 with PowerManager

use of android.os.PowerManager in project android_frameworks_base by ParanoidAndroid.

the class LayoutTestsExecutor method onCreate.

/** IMPLEMENTATION */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /**
         * It detects the crash by catching all the uncaught exceptions. However, we
         * still have to kill the process, because after catching the exception the
         * activity remains in a strange state, where intents don't revive it.
         * However, we send the message to the service to speed up the rebooting
         * (we don't have to wait for time-out to kick in).
         */
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread thread, Throwable e) {
            Log.w(LOG_TAG, "onTestCrashed(): " + mCurrentTestRelativePath + " thread=" + thread, e);
            try {
                Message serviceMsg = Message.obtain(null, ManagerService.MSG_CURRENT_TEST_CRASHED);
                mManagerServiceMessenger.send(serviceMsg);
            } catch (RemoteException e2) {
                Log.e(LOG_TAG, "mCurrentTestRelativePath=" + mCurrentTestRelativePath, e2);
            }
            Process.killProcess(Process.myPid());
        }
    });
    requestWindowFeature(Window.FEATURE_PROGRESS);
    Intent intent = getIntent();
    mTestsList = FsUtils.loadTestListFromStorage(intent.getStringExtra(EXTRA_TESTS_FILE));
    mCurrentTestIndex = intent.getIntExtra(EXTRA_TEST_INDEX, -1);
    mTotalTestCount = mCurrentTestIndex + mTestsList.size();
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mScreenDimLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "WakeLock in LayoutTester");
    mScreenDimLock.acquire();
    bindService(new Intent(this, ManagerService.class), mServiceConnection, Context.BIND_AUTO_CREATE);
}
Also used : PowerManager(android.os.PowerManager) ConsoleMessage(android.webkit.ConsoleMessage) Message(android.os.Message) Intent(android.content.Intent) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) RemoteException(android.os.RemoteException)

Aggregations

PowerManager (android.os.PowerManager)289 IntentFilter (android.content.IntentFilter)50 Intent (android.content.Intent)44 Handler (android.os.Handler)33 RemoteException (android.os.RemoteException)31 PendingIntent (android.app.PendingIntent)29 HandlerThread (android.os.HandlerThread)26 Context (android.content.Context)24 IPowerManager (android.os.IPowerManager)21 View (android.view.View)19 Resources (android.content.res.Resources)15 AlarmManager (android.app.AlarmManager)11 SharedPreferences (android.content.SharedPreferences)11 TextView (android.widget.TextView)11 NotificationCompat (android.support.v4.app.NotificationCompat)10 ComponentName (android.content.ComponentName)9 KeyguardManager (android.app.KeyguardManager)8 Vibrator (android.os.Vibrator)8 MotionEvent (android.view.MotionEvent)8 ContentResolver (android.content.ContentResolver)7