Search in sources :

Example 1 with HandlerThread

use of android.os.HandlerThread in project PlayerHater by chrisrhoden.

the class SongQueue method getHandler.

private static Handler getHandler() {
    if (sHandler == null) {
        HandlerThread thread = new HandlerThread("SongQueue");
        thread.start();
        sHandler = new Handler(thread.getLooper()) {

            @Override
            public void handleMessage(Message msg) {
                SongMessage m = (SongMessage) msg.obj;
                switch(msg.what) {
                    case CURRENT_SONG:
                        m.queue.sendSongChanged(m.song, m.oldSong);
                        break;
                    case NEXT_SONG:
                        m.queue.sendNextSongChanged(m.song, m.oldSong);
                }
            }
        };
    }
    return sHandler;
}
Also used : HandlerThread(android.os.HandlerThread) Message(android.os.Message) Handler(android.os.Handler)

Example 2 with HandlerThread

use of android.os.HandlerThread 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 3 with HandlerThread

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

the class NativeDaemonConnector method run.

@Override
public void run() {
    HandlerThread thread = new HandlerThread(TAG + ".CallbackHandler");
    thread.start();
    mCallbackHandler = new Handler(thread.getLooper(), this);
    while (true) {
        try {
            listenToSocket();
        } catch (Exception e) {
            loge("Error in NativeDaemonConnector: " + e);
            SystemClock.sleep(5000);
        }
    }
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) IOException(java.io.IOException)

Example 4 with HandlerThread

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

the class PowerManagerService method init.

/**
     * Initialize the power manager.
     * Must be called before any other functions within the power manager are called.
     */
public void init(Context context, LightsService ls, ActivityManagerService am, BatteryService bs, IBatteryStats bss, DisplayManagerService dm) {
    mContext = context;
    mLightsService = ls;
    mBatteryService = bs;
    mBatteryStats = bss;
    mDisplayManagerService = dm;
    mHandlerThread = new HandlerThread(TAG);
    mHandlerThread.start();
    mHandler = new PowerManagerHandler(mHandlerThread.getLooper());
    Watchdog.getInstance().addMonitor(this);
    // Forcibly turn the screen on at boot so that it is in a known power state.
    // We do this in init() rather than in the constructor because setting the
    // screen state requires a call into surface flinger which then needs to call back
    // into the activity manager to check permissions.  Unfortunately the
    // activity manager is not running when the constructor is called, so we
    // have to defer setting the screen state until this point.
    mDisplayBlanker.unblankAllDisplays();
}
Also used : HandlerThread(android.os.HandlerThread)

Example 5 with HandlerThread

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

the class WifiManager method init.

private void init() {
    synchronized (sThreadRefLock) {
        if (++sThreadRefCount == 1) {
            Messenger messenger = getWifiServiceMessenger();
            if (messenger == null) {
                sAsyncChannel = null;
                return;
            }
            sHandlerThread = new HandlerThread("WifiManager");
            sAsyncChannel = new AsyncChannel();
            sConnected = new CountDownLatch(1);
            sHandlerThread.start();
            Handler handler = new ServiceHandler(sHandlerThread.getLooper());
            sAsyncChannel.connect(mContext, handler, messenger);
            try {
                sConnected.await();
            } catch (InterruptedException e) {
                Log.e(TAG, "interrupted wait at init");
            }
        }
    }
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) AsyncChannel(com.android.internal.util.AsyncChannel) Messenger(android.os.Messenger) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

HandlerThread (android.os.HandlerThread)503 Handler (android.os.Handler)241 Test (org.junit.Test)55 IntentFilter (android.content.IntentFilter)39 Context (android.content.Context)37 Intent (android.content.Intent)37 Message (android.os.Message)33 Looper (android.os.Looper)32 PowerManager (android.os.PowerManager)26 CountDownLatch (java.util.concurrent.CountDownLatch)23 View (android.view.View)17 PendingIntent (android.app.PendingIntent)15 IOException (java.io.IOException)15 Runnable (java.lang.Runnable)15 ComponentName (android.content.ComponentName)14 Bundle (android.os.Bundle)12 RemoteException (android.os.RemoteException)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 SmallTest (android.test.suitebuilder.annotation.SmallTest)12 NetworkRequest (android.net.NetworkRequest)11