Search in sources :

Example 6 with PowerManager

use of android.os.PowerManager in project remusic by aa112901.

the class MediaService method onCreate.

@Override
public void onCreate() {
    if (D)
        Log.d(TAG, "Creating service");
    super.onCreate();
    mGetUrlThread.start();
    mLrcThread.start();
    mProxy = new MediaPlayerProxy(this);
    mProxy.init();
    mProxy.start();
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // gets a pointer to the playback state store
    mPlaybackStateStore = MusicPlaybackState.getInstance(this);
    mSongPlayCount = SongPlayCount.getInstance(this);
    mRecentStore = RecentStore.getInstance(this);
    mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND);
    mHandlerThread.start();
    mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper());
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setUpMediaSession();
    }
    mPreferences = getSharedPreferences("Service", 0);
    mCardId = getCardId();
    registerExternalStorageListener();
    mPlayer = new MultiPlayer(this);
    mPlayer.setHandler(mPlayerHandler);
    // Initialize the intent filter and each action
    final IntentFilter filter = new IntentFilter();
    filter.addAction(SERVICECMD);
    filter.addAction(TOGGLEPAUSE_ACTION);
    filter.addAction(PAUSE_ACTION);
    filter.addAction(STOP_ACTION);
    filter.addAction(NEXT_ACTION);
    filter.addAction(PREVIOUS_ACTION);
    filter.addAction(PREVIOUS_FORCE_ACTION);
    filter.addAction(REPEAT_ACTION);
    filter.addAction(SHUFFLE_ACTION);
    filter.addAction(TRY_GET_TRACKINFO);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(LOCK_SCREEN);
    filter.addAction(SEND_PROGRESS);
    filter.addAction(SETQUEUE);
    // Attach the broadcast listener
    registerReceiver(mIntentReceiver, filter);
    mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver);
    // Initialize the wake lock
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    mWakeLock.setReferenceCounted(false);
    final Intent shutdownIntent = new Intent(this, MediaService.class);
    shutdownIntent.setAction(SHUTDOWN);
    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0);
    scheduleDelayedShutdown();
    reloadQueueAfterPermissionCheck();
    notifyChange(QUEUE_CHANGED);
    notifyChange(META_CHANGED);
}
Also used : PowerManager(android.os.PowerManager) IntentFilter(android.content.IntentFilter) MediaPlayerProxy(com.wm.remusic.proxy.utils.MediaPlayerProxy) HandlerThread(android.os.HandlerThread) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 7 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 8 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 9 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)

Example 10 with PowerManager

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

the class FrameworkPerfActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set the layout for this activity.  You can find it
    // in res/layout/hello_activity.xml
    setContentView(R.layout.main);
    mFgSpinner = (Spinner) findViewById(R.id.fgspinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mAvailOpLabels);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mFgSpinner.setAdapter(adapter);
    mFgSpinner.setOnItemSelectedListener(this);
    mBgSpinner = (Spinner) findViewById(R.id.bgspinner);
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mAvailOpLabels);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mBgSpinner.setAdapter(adapter);
    mBgSpinner.setOnItemSelectedListener(this);
    mLimitSpinner = (Spinner) findViewById(R.id.limitspinner);
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mLimitLabels);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mLimitSpinner.setAdapter(adapter);
    mLimitSpinner.setOnItemSelectedListener(this);
    mTestTime = (TextView) findViewById(R.id.testtime);
    mLimitLabel = (TextView) findViewById(R.id.limitlabel);
    mStartButton = (Button) findViewById(R.id.start);
    mStartButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startRunning();
        }
    });
    mStopButton = (Button) findViewById(R.id.stop);
    mStopButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            stopRunning();
        }
    });
    mStopButton.setEnabled(false);
    mLocalCheckBox = (CheckBox) findViewById(R.id.local);
    mLog = (TextView) findViewById(R.id.log);
    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    mPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Scheduler");
    mPartialWakeLock.setReferenceCounted(false);
}
Also used : PowerManager(android.os.PowerManager) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

PowerManager (android.os.PowerManager)598 Context (android.content.Context)112 Handler (android.os.Handler)112 Intent (android.content.Intent)93 IntentFilter (android.content.IntentFilter)72 PendingIntent (android.app.PendingIntent)46 RemoteException (android.os.RemoteException)37 IPowerManager (android.os.IPowerManager)33 SuppressLint (android.annotation.SuppressLint)30 View (android.view.View)27 IOException (java.io.IOException)27 ContentResolver (android.content.ContentResolver)26 HandlerThread (android.os.HandlerThread)26 SharedPreferences (android.content.SharedPreferences)23 KeyguardManager (android.app.KeyguardManager)18 ComponentName (android.content.ComponentName)18 Resources (android.content.res.Resources)18 TextView (android.widget.TextView)18 PackageManager (android.content.pm.PackageManager)17 Uri (android.net.Uri)16