Example usage for android.os PowerManager newWakeLock

List of usage examples for android.os PowerManager newWakeLock

Introduction

In this page you can find the example usage for android.os PowerManager newWakeLock.

Prototype

public WakeLock newWakeLock(int levelAndFlags, String tag) 

Source Link

Document

Creates a new wake lock with the specified level and flags.

Usage

From source file:dk.nota.lyt.libvlc.PlaybackService.java

@Override
public void onCreate() {
    super.onCreate();

    mSettings = PreferenceManager.getDefaultSharedPreferences(this);
    mMediaPlayer = newMediaPlayer();/*from   ww  w. j  a v  a  2  s . com*/
    if (!Utils.testCompatibleCPU(this)) {
        stopSelf();
        return;
    }

    mDetectHeadset = mSettings.getBoolean("enable_headset_detection", true);

    mCurrentIndex = -1;
    mPrevIndex = -1;
    mNextIndex = -1;
    mPrevious = new Stack<Integer>();
    mRemoteControlClientReceiverComponent = new ComponentName(this.getApplicationContext(),
            RemoteControlEventReceiver.class.getName());

    // Make sure the audio player will acquire a wake-lock while playing. If we don't do
    // that, the CPU might go to sleep while the song is playing, causing playback to stopService.
    PowerManager pm = (PowerManager) this.getApplicationContext().getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);

    IntentFilter filter = new IntentFilter();
    filter.setPriority(Integer.MAX_VALUE);
    filter.addAction(ACTION_REMOTE_BACKWARD);
    filter.addAction(ACTION_REMOTE_PLAYPAUSE);
    filter.addAction(ACTION_REMOTE_PLAY);
    filter.addAction(ACTION_REMOTE_PAUSE);
    filter.addAction(ACTION_REMOTE_STOP);
    filter.addAction(ACTION_REMOTE_FORWARD);
    filter.addAction(Intent.ACTION_HEADSET_PLUG);
    filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    registerReceiver(mReceiver, filter);
}

From source file:com.fastbootmobile.encore.service.PlaybackService.java

/**
 * Called when the service is created/*from   ww  w  .j  av  a 2 s. c  o  m*/
 */
@Override
public void onCreate() {
    super.onCreate();
    mListenLogger = new ListenLogger(this);
    mPrefetcher = new Prefetcher(this);

    mCommandsHandlerThread = new HandlerThread("PlaybackServiceCommandsHandler");
    mCommandsHandlerThread.start();

    mCommandsHandler = new CommandHandler(this, mCommandsHandlerThread);

    // Register package manager to receive updates
    mPacManReceiver = new PacManReceiver();
    IntentFilter pacManFilter = new IntentFilter();
    pacManFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    pacManFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    pacManFilter.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED);
    pacManFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    pacManFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    pacManFilter.addDataScheme("package");
    registerReceiver(mPacManReceiver, pacManFilter);

    // Really Google, I'd love to use your new APIs... But they're not working. If you use
    // the new Lollipop metadata system, you lose Bluetooth AVRCP since the Bluetooth
    // package still use the old RemoteController system.
    /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    mRemoteMetadata = new RemoteMetadataManagerv21(this);
    } else*/ {
        mRemoteMetadata = new RemoteMetadataManager(this);
    }

    ProviderAggregator.getDefault().addUpdateCallback(this);

    // Native playback initialization
    mNativeHub = new NativeHub(getApplicationContext());
    mNativeSink = new NativeAudioSink();
    mNativeHub.setSinkPointer(mNativeSink.getPlayer().getHandle());
    mNativeHub.setOnAudioWrittenListener(this);
    mNativeHub.onStart();

    mDSPProcessor = new DSPProcessor(this);
    mDSPProcessor.restoreChain(this);

    // Plugins initialization
    PluginsLookup.getDefault().initialize(getApplicationContext());
    PluginsLookup.getDefault().registerProviderListener(this);

    List<ProviderConnection> connections = PluginsLookup.getDefault().getAvailableProviders();
    for (ProviderConnection conn : connections) {
        if (conn.getBinder(false) != null) {
            assignProviderAudioSocket(conn);
        } else {
            Log.w(TAG, "Cannot assign audio socket to " + conn.getIdentifier() + ", binder is null");
        }
    }

    // Setup
    mIsStopping = false;

    // Bind to all provider
    List<ProviderConnection> providers = PluginsLookup.getDefault().getAvailableProviders();
    for (ProviderConnection pc : providers) {
        try {
            IMusicProvider binder = pc.getBinder(false);
            if (binder != null) {
                binder.registerCallback(mProviderCallback);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Cannot register callback", e);
        }
    }

    // Register AutoMix manager
    mCallbacks.add(AutoMixManager.getDefault());

    // Setup notification system
    mNotification = new ServiceNotification(this);
    mNotification.setOnNotificationChangedListener(new ServiceNotification.NotificationChangedListener() {
        @Override
        public void onNotificationChanged(ServiceNotification notification) {
            NotificationManagerCompat nmc = NotificationManagerCompat.from(PlaybackService.this);
            if (mIsForeground) {
                notification.notify(nmc);
                mIsForeground = true;
            } else {
                notification.notify(PlaybackService.this);
            }

            BitmapDrawable albumArt = notification.getAlbumArt();
            mRemoteMetadata.setAlbumArt(albumArt);
        }
    });

    // Setup lockscreen remote controls
    mRemoteMetadata.setup();

    // Setup playback wakelock (but don't acquire it yet)
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "OmniMusicPlayback");

    // Restore preferences
    SharedPreferences prefs = getSharedPreferences(SERVICE_SHARED_PREFS, MODE_PRIVATE);
    mRepeatMode = prefs.getBoolean(PREF_KEY_REPEAT, false);
    mShuffleMode = prefs.getBoolean(PREF_KEY_SHUFFLE, false);

    // TODO: Use callbacks
    // Restore playback queue after one second - we have multiple things to wait here:
    //  - The callbacks of the main app's UI
    //  - The providers connecting
    //  - The providers ready to send us data
    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            SharedPreferences queuePrefs = getSharedPreferences(QUEUE_SHARED_PREFS, MODE_PRIVATE);
            mPlaybackQueue.restore(queuePrefs);
            mCurrentTrack = queuePrefs.getInt("current", -1);
            mCurrentTrackLoaded = false;
            mNotification.setHasNext(mPlaybackQueue.size() > 1 || (mPlaybackQueue.size() > 0 && mRepeatMode));
        }
    }, 1000);
}

From source file:org.proninyaroslav.libretorrent.services.TorrentTaskService.java

private void setKeepCpuAwake(boolean enable) {
    if (enable) {
        if (wakeLock == null) {
            PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
            wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
        }/*from  w  w  w .  j a  va 2 s.c o  m*/

        if (!wakeLock.isHeld()) {
            wakeLock.acquire();
        }

    } else {
        if (wakeLock == null) {
            return;
        }

        if (wakeLock.isHeld()) {
            wakeLock.release();
        }
    }
}

From source file:com.goftagram.telegram.messenger.NotificationsController.java

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

    try {/*from   w w w . j  av a 2  s.com*/
        audioManager = (AudioManager) ApplicationLoader.applicationContext
                .getSystemService(Context.AUDIO_SERVICE);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    try {
        alarmManager = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
    } catch (Exception e) {
        FileLog.e("tmessages", 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("tmessages", e);
    }

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

From source file:jackpal.androidterm.Term.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    Log.v(TermDebug.LOG_TAG, "onCreate");

    mPrivateAlias = new ComponentName(this, RemoteInterface.PRIVACT_ACTIVITY_ALIAS);

    if (icicle == null)
        onNewIntent(getIntent());// ww  w.jav a 2  s  . c o  m

    final SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mSettings = new TermSettings(getResources(), mPrefs);
    mPrefs.registerOnSharedPreferenceChangeListener(this);

    boolean vimflavor = this.getPackageName().matches(".*vim.androidterm.*");

    if (!vimflavor && mSettings.doPathExtensions()) {
        mPathReceiver = new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                String path = makePathFromBundle(getResultExtras(false));
                if (intent.getAction().equals(ACTION_PATH_PREPEND_BROADCAST)) {
                    mSettings.setPrependPath(path);
                } else {
                    mSettings.setAppendPath(path);
                }
                mPendingPathBroadcasts--;

                if (mPendingPathBroadcasts <= 0 && mTermService != null) {
                    populateViewFlipper();
                    populateWindowList();
                }
            }
        };

        Intent broadcast = new Intent(ACTION_PATH_BROADCAST);
        if (AndroidCompat.SDK >= 12) {
            broadcast.addFlags(FLAG_INCLUDE_STOPPED_PACKAGES);
        }
        mPendingPathBroadcasts++;
        sendOrderedBroadcast(broadcast, PERMISSION_PATH_BROADCAST, mPathReceiver, null, RESULT_OK, null, null);

        if (mSettings.allowPathPrepend()) {
            broadcast = new Intent(broadcast);
            broadcast.setAction(ACTION_PATH_PREPEND_BROADCAST);
            mPendingPathBroadcasts++;
            sendOrderedBroadcast(broadcast, PERMISSION_PATH_PREPEND_BROADCAST, mPathReceiver, null, RESULT_OK,
                    null, null);
        }
    }

    TSIntent = new Intent(this, TermService.class);
    startService(TSIntent);

    if (AndroidCompat.SDK >= 11) {
        int theme = mSettings.getColorTheme();
        int actionBarMode = mSettings.actionBarMode();
        mActionBarMode = actionBarMode;
        switch (actionBarMode) {
        case TermSettings.ACTION_BAR_MODE_ALWAYS_VISIBLE:
            if (theme == 0) {
                setTheme(R.style.Theme_Holo);
            } else {
                setTheme(R.style.Theme_Holo_Light);
            }
            break;
        case TermSettings.ACTION_BAR_MODE_HIDES + 1:
        case TermSettings.ACTION_BAR_MODE_HIDES:
            if (theme == 0) {
                setTheme(R.style.Theme_Holo_ActionBarOverlay);
            } else {
                setTheme(R.style.Theme_Holo_Light_ActionBarOverlay);
            }
            break;
        }
    } else {
        mActionBarMode = TermSettings.ACTION_BAR_MODE_ALWAYS_VISIBLE;
    }

    setContentView(R.layout.term_activity);
    mViewFlipper = (TermViewFlipper) findViewById(VIEW_FLIPPER);
    setFunctionKeyListener();

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TermDebug.LOG_TAG);
    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    int wifiLockMode = WifiManager.WIFI_MODE_FULL;
    if (AndroidCompat.SDK >= 12) {
        wifiLockMode = WIFI_MODE_FULL_HIGH_PERF;
    }
    mWifiLock = wm.createWifiLock(wifiLockMode, TermDebug.LOG_TAG);

    ActionBarCompat actionBar = ActivityCompat.getActionBar(this);
    if (actionBar != null) {
        mActionBar = actionBar;
        actionBar.setNavigationMode(ActionBarCompat.NAVIGATION_MODE_LIST);
        actionBar.setDisplayOptions(0, ActionBarCompat.DISPLAY_SHOW_TITLE);
        if (mActionBarMode >= TermSettings.ACTION_BAR_MODE_HIDES) {
            actionBar.hide();
        }
    }

    mHaveFullHwKeyboard = checkHaveFullHwKeyboard(getResources().getConfiguration());
    setSoftInputMode(mHaveFullHwKeyboard);

    if (mFunctionBar == -1)
        mFunctionBar = mSettings.showFunctionBar() ? 1 : 0;
    if (mFunctionBar == 1)
        setFunctionBar(mFunctionBar);

    updatePrefs();
    permissionCheckExternalStorage();
    mAlreadyStarted = true;
}

From source file:org.moire.ultrasonic.service.DownloadServiceImpl.java

@SuppressLint("NewApi")
@Override//from  www.  j  a  v  a  2s. c om
public void onCreate() {
    super.onCreate();

    new Thread(new Runnable() {
        @Override
        public void run() {
            Thread.currentThread().setName("DownloadServiceImpl");

            Looper.prepare();

            if (mediaPlayer != null) {
                mediaPlayer.release();
            }

            mediaPlayer = new MediaPlayer();
            mediaPlayer.setWakeMode(DownloadServiceImpl.this, PowerManager.PARTIAL_WAKE_LOCK);

            mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                @Override
                public boolean onError(MediaPlayer mediaPlayer, int what, int more) {
                    handleError(new Exception(String.format("MediaPlayer error: %d (%d)", what, more)));
                    return false;
                }
            });

            try {
                Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
                i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mediaPlayer.getAudioSessionId());
                i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
                sendBroadcast(i);
            } catch (Throwable e) {
                // Froyo or lower
            }

            mediaPlayerLooper = Looper.myLooper();
            mediaPlayerHandler = new Handler(mediaPlayerLooper);
            Looper.loop();
        }
    }).start();

    audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    setUpRemoteControlClient();

    if (equalizerAvailable) {
        equalizerController = new EqualizerController(this, mediaPlayer);
        if (!equalizerController.isAvailable()) {
            equalizerController = null;
        } else {
            equalizerController.loadSettings();
        }
    }
    if (visualizerAvailable) {
        visualizerController = new VisualizerController(mediaPlayer);
        if (!visualizerController.isAvailable()) {
            visualizerController = null;
        }
    }

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
    wakeLock.setReferenceCounted(false);

    instance = this;
    lifecycleSupport.onCreate();
}

From source file:net.ustyugov.jtalk.service.JTalkService.java

@Override
public void onCreate() {
    configure();/*  w w w.  j  av  a  2 s .  c  o m*/
    js = this;
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    iconPicker = new IconPicker(this);

    //        updateReceiver = new BroadcastReceiver() {
    //         @Override
    //         public void onReceive(Context arg0, Intent arg1) {
    //            updateWidget();
    //         }
    //        };
    //        registerReceiver(updateReceiver, new IntentFilter(Constants.UPDATE));

    connectionReceiver = new ChangeConnectionReceiver();
    registerReceiver(connectionReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    screenStateReceiver = new ScreenStateReceiver();
    registerReceiver(new ScreenStateReceiver(), new IntentFilter(Intent.ACTION_SCREEN_ON));
    registerReceiver(new ScreenStateReceiver(), new IntentFilter(Intent.ACTION_SCREEN_OFF));

    Intent i = new Intent(this, RosterActivity.class);
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setSmallIcon(R.drawable.stat_offline);
    mBuilder.setContentTitle(getString(R.string.app_name));
    mBuilder.setContentIntent(contentIntent);

    startForeground(Notify.NOTIFICATION, mBuilder.build());

    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "jTalk");
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "jTalk");

    started = true;

    Cursor cursor = getContentResolver().query(JTalkProvider.ACCOUNT_URI, null,
            AccountDbHelper.ENABLED + " = '" + 1 + "'", null, null);
    if (cursor != null && cursor.getCount() > 0) {
        connect();
        cursor.close();
    }
}

From source file:org.mariotaku.harmony.MusicPlaybackService.java

@Override
public void onCreate() {
    super.onCreate();
    // Needs to be done in this thread, since otherwise
    // ApplicationContext.getPowerManager() crashes.
    mResources = getResources();/*w  w w  . j  a v a  2  s.c  o  m*/
    mPlayer = new MultiPlayer(this);
    mResolver = getContentResolver();
    mPlayer.setHandler(mMediaplayerHandler);

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    mAudioManager.registerMediaButtonEventReceiver(
            new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()));

    mPreferences = new PreferencesEditor(this);

    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    mCardId = MusicUtils.getCardId(this);

    registerExternalStorageListener();
    registerA2dpServiceListener();

    reloadQueue();

    IntentFilter commandFilter = new IntentFilter();
    commandFilter.addAction(SERVICECMD);
    commandFilter.addAction(TOGGLEPAUSE_ACTION);
    commandFilter.addAction(PAUSE_ACTION);
    commandFilter.addAction(NEXT_ACTION);
    commandFilter.addAction(PREVIOUS_ACTION);
    commandFilter.addAction(CYCLEREPEAT_ACTION);
    commandFilter.addAction(TOGGLESHUFFLE_ACTION);
    commandFilter.addAction(BROADCAST_PLAYSTATUS_REQUEST);
    registerReceiver(mIntentReceiver, commandFilter);

    registerReceiver(mExternalAudioDeviceStatusReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
    mWakeLock.setReferenceCounted(false);

    // If the service was idle, but got killed before it stopped itself, the
    // system will relaunch it. Make sure it gets stopped again in that
    // case.
    Message msg = mDelayedStopHandler.obtainMessage();
    mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY);
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

public static void powersaving_wakeUp(Context ctx) {

    if (wakeLock != null)
        wakeLock.release();//from  www  . j a  v  a 2s  . c  o  m

    PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "javocsoft_library_wakeup");
    wakeLock.acquire();
}

From source file:com.naman14.timber.musicplayer.MusicService.java

@Override
public void onCreate() {
    if (D)/*from   w w w . j  a  va 2s  .c o m*/
        Log.d(TAG, "Creating service");
    super.onCreate();

    mNotificationManager = NotificationManagerCompat.from(this);

    // 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 MultiPlayer2(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);

    // 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, MusicService.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);
}