Example usage for android.os PowerManager PARTIAL_WAKE_LOCK

List of usage examples for android.os PowerManager PARTIAL_WAKE_LOCK

Introduction

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

Prototype

int PARTIAL_WAKE_LOCK

To view the source code for android.os PowerManager PARTIAL_WAKE_LOCK.

Click Source Link

Document

Wake lock level: Ensures that the CPU is running; the screen and keyboard backlight will be allowed to go off.

Usage

From source file:com.bluros.music.MusicService.java

@Override
public void onCreate() {
    if (D)//ww  w  .  ja  v a  2  s  .  c  om
        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 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(SLEEP_MODE_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(RemoteSelectDialog.REMOTE_START_SCAN);
    filter.addAction(RemoteSelectDialog.REMOTE_STOP_SCAN);
    filter.addAction(RemoteSelectDialog.REMOTE_CONNECT);
    // 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);
}

From source file:rocks.stalin.android.app.playback.RemotePlayback.java

/**
 * Makes sure the media player exists and has been reset. This will create
 * the media player if needed, or reset the existing media player if one
 * already exists.//from  ww  w  . jav  a  2  s.  co  m
 */
private void createMediaPlayerIfNeeded() {
    LogHelper.d(TAG, "createMediaPlayerIfNeeded. needed? ", (mediaPlayer == null));
    if (mediaPlayer == null) {
        MediaPlayerImpl mediaplayer = new MediaPlayerImpl(scheduler);
        mediaPlayer = mediaplayer;

        // Make sure the media 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 stop.
        mediaPlayer.setWakeMode(mContext.getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);

        // we want the media player to notify us when it's ready preparing,
        // and when it's done playing:
        mediaPlayer.setOnPreparedListener(this);
        mediaPlayer.setOnCompletionListener(this);
        mediaPlayer.setOnErrorListener(this);
        mediaPlayer.setOnSeekCompleteListener(this);
    } else {
        mediaPlayer.reset();
    }
}

From source file:org.qeo.android.service.QeoService.java

private void enableNetworkSettings() {
    LOG.fine("Enable network change monitoring");
    mOnNetworkConnectivityChanged = new BroadcastReceiver() {
        @SuppressLint("Wakelock")
        @Override/*from w w  w  .j av  a  2 s  .c  o m*/
        public void onReceive(Context context, Intent intent) {

            /*
             * Check if there is still a connected active network interface. If not, take a wakelock to make sure
             * DDS has the time to let all of it's timers time out properly. This is especially needed when the
             * network goes down due to the device going in sleep mode.
             */
            ConnectivityManager connMgr = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
            NetworkInfo activeNetworkInf = connMgr.getActiveNetworkInfo();
            if (((activeNetworkInf != null) && (!activeNetworkInf.isConnected()))
                    || (activeNetworkInf == null)) {
                PowerManager powerMgr = (PowerManager) getSystemService(POWER_SERVICE);
                PowerManager.WakeLock wakeLock = powerMgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);

                LOG.info("Take wakelock for 40 seconds");
                wakeLock.acquire(40 * 1000);
            }

            configureNetworkSettings(activeNetworkInf);
        }

    };
    registerReceiver(mOnNetworkConnectivityChanged, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connMgr.getActiveNetworkInfo();
    configureNetworkSettings(activeNetworkInfo);
}

From source file:com.smedic.tubtub.BackgroundAudioService.java

private void onVideoStart(SparseArray<YtFile> ytFiles) {
    YtFile ytFile;/*from ww w  .ja v  a2  s  .c  o  m*/
    if (ytFiles == null || (ytFile = findBestStream(ytFiles)) == null) {
        // Something went wrong we got no urls. Always check this.
        Toast.makeText(YTApplication.getAppContext(), R.string.failed_playback, Toast.LENGTH_SHORT).show();

        playNext();
        buildNotification(generateAction(android.R.drawable.ic_media_pause, "Pause", ACTION_PAUSE));
        return;
    }

    final String id = videoItem.getId();
    final String title = videoItem.getTitle();
    final int bitrate = ytFile.getFormat().getAudioBitrate();
    final String message = "Starting: " + title + "(" + id + ")" + ", quality: " + bitrate + "kbps.";
    Log.d(TAG, message);

    try {
        if (mMediaPlayer != null) {
            mMediaPlayer.reset();
            isPrepared = false;

            // Make sure the media 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 stop.
            //
            // Remember that to use this, we have to declare the android.permission.WAKE_LOCK
            // permission in AndroidManifest.xml.
            mMediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
            mMediaPlayer.setDataSource(ytFile.getUrl());
            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mMediaPlayer.prepareAsync();

            if (!mWifiLock.isHeld())
                mWifiLock.acquire();

            Toast.makeText(YTApplication.getAppContext(), message, Toast.LENGTH_SHORT).show();
        }
    } catch (IOException io) {
        io.printStackTrace();
    }
}

From source file:com.bonsai.btcreceive.WalletService.java

@Override
public void onCreate() {
    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mLBM = LocalBroadcastManager.getInstance(this);

    mLogger.info("WalletService created");

    mContext = getApplicationContext();//from  w w  w .j  av a 2s  .  c o m
    mRes = mContext.getResources();

    final String lockName = getPackageName() + " blockchain sync";
    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String fiatRateSource = sharedPref.getString(SettingsActivity.KEY_FIAT_RATE_SOURCE, "");
    setFiatRateSource(fiatRateSource);

    // Register for future preference changes.
    sharedPref.registerOnSharedPreferenceChangeListener(this);
}

From source file:mp.teardrop.PlaybackService.java

@Override
public void onCreate() {
    HandlerThread thread = new HandlerThread("PlaybackService", Process.THREAD_PRIORITY_DEFAULT);
    thread.start();//w w w.jav  a2s.  co  m

    mTimeline = new SongTimeline(this);
    mTimeline.setCallback(this);
    int state = loadState();

    mPlayCounts = new PlayCountsHelper(this);

    mMediaPlayer = getNewMediaPlayer();
    mBastpUtil = new BastpUtil();
    mReadahead = new ReadaheadThread();
    mReadahead.start();

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

    SharedPreferences settings = getSettings(this);
    settings.registerOnSharedPreferenceChangeListener(this);
    mNotificationMode = Integer.parseInt(settings.getString(PrefKeys.NOTIFICATION_MODE, "1"));
    mScrobble = settings.getBoolean(PrefKeys.SCROBBLE, false);
    mIdleTimeout = settings.getBoolean(PrefKeys.USE_IDLE_TIMEOUT, false)
            ? settings.getInt(PrefKeys.IDLE_TIMEOUT, 3600)
            : 0;

    Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_ANDROID, true)
            ? Song.mCoverLoadMode | Song.COVER_MODE_ANDROID
            : Song.mCoverLoadMode & ~(Song.COVER_MODE_ANDROID);
    Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_VANILLA, true)
            ? Song.mCoverLoadMode | Song.COVER_MODE_VANILLA
            : Song.mCoverLoadMode & ~(Song.COVER_MODE_VANILLA);
    Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_SHADOW, true)
            ? Song.mCoverLoadMode | Song.COVER_MODE_SHADOW
            : Song.mCoverLoadMode & ~(Song.COVER_MODE_SHADOW);

    mHeadsetOnly = settings.getBoolean(PrefKeys.HEADSET_ONLY, false);
    mStockBroadcast = settings.getBoolean(PrefKeys.STOCK_BROADCAST, false);
    mInvertNotification = settings.getBoolean(PrefKeys.NOTIFICATION_INVERTED_COLOR, false);
    mNotificationAction = createNotificationAction(settings);
    mHeadsetPause = getSettings(this).getBoolean(PrefKeys.HEADSET_PAUSE, true);
    mShakeAction = settings.getBoolean(PrefKeys.ENABLE_SHAKE, false)
            ? Action.getAction(settings, PrefKeys.SHAKE_ACTION, Action.NextSong)
            : Action.Nothing;
    mShakeThreshold = settings.getInt(PrefKeys.SHAKE_THRESHOLD, 80) / 10.0f;

    mReplayGainTrackEnabled = settings.getBoolean(PrefKeys.ENABLE_TRACK_REPLAYGAIN, false);
    mReplayGainAlbumEnabled = settings.getBoolean(PrefKeys.ENABLE_ALBUM_REPLAYGAIN, false);
    mReplayGainBump = settings.getInt(PrefKeys.REPLAYGAIN_BUMP, 75); /* seek bar is 150 -> 75 == middle == 0 */
    mReplayGainUntaggedDeBump = settings.getInt(PrefKeys.REPLAYGAIN_UNTAGGED_DEBUMP,
            150); /* seek bar is 150 -> == 0 */

    mReadaheadEnabled = settings.getBoolean(PrefKeys.ENABLE_READAHEAD, false);

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TeardropMusicLock");

    mReceiver = new Receiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    registerReceiver(mReceiver, filter);

    getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mObserver);

    CompatIcs.registerRemote(this, mAudioManager);

    mLooper = thread.getLooper();
    mHandler = new Handler(mLooper, this);

    initWidgets();

    updateState(state);
    setCurrentSong(0, false);

    sInstance = this;
    synchronized (sWait) {
        sWait.notifyAll();
    }

    mAccelFiltered = 0.0f;
    mAccelLast = SensorManager.GRAVITY_EARTH;
    setupSensor();
}

From source file:com.mobilyzer.util.PhoneUtils.java

/** Wakes up the CPU of the phone if it is sleeping. */
public synchronized void acquireWakeLock() {
    if (wakeLock == null) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "tag");
    }/*from w  ww . j  av a 2  s  . co m*/
    Logger.d("PowerLock acquired");
    wakeLock.acquire();
}

From source file:com.av.remusic.service.MediaService.java

@Override
public void onCreate() {
    if (D)/*from  w  ww .  j  a  v a2s  .com*/
        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);
}

From source file:com.bayapps.android.robophish.playback.LocalPlayback.java

/**
 * Makes sure the media player exists and has been reset. This will create
 * the media player if needed, or reset the existing media player if one
 * already exists./*from w ww .ja va 2s .co  m*/
 */
private MediaPlayer createMediaPlayer(MediaPlayer player) {
    LogHelper.d(TAG, "createMediaPlayerIfNeeded. needed? ", (player == null));
    if (player == null) {
        player = new MediaPlayer();

        // Make sure the media 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 stop.
        player.setWakeMode(mContext.getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);

        // we want the media player to notify us when it's ready preparing,
        // and when it's done playing:
        player.setOnPreparedListener(this);
        player.setOnCompletionListener(this);
        player.setOnErrorListener(this);
        player.setOnSeekCompleteListener(this);
    } else {
        player.reset();
    }

    return player;
}

From source file:com.droid.app.fotobot.FotoBot.java

/**
 *      ? ,   ?,    ?//w  ww .j a  v  a  2  s  . co  m
 *
 * @param h
 * @param delay
 */
public void fbpause(final Handler h, final int delay) {

    if (delay > 3) {
        SendMessage(".", MSG_INFO);
    }

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");

    wakeLock.acquire();

    Thread thread = new Thread() {
        public void run() {

            PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
            PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                    "MyWakelockTag");

            wakeLock.acquire();

            int n = 5;

            if (delay >= wake_up_interval) {
                n = (int) (delay - ((delay / wake_up_interval) * long_pause * 2));
            }

            for (int i = 1; i <= n; i++) {

                if (i % 3 == 0) {
                    if (isCharging_before != isCharging) {

                        if (isCharging) {
                            SendMessage(getResources().getString(R.string.voltage_restored));
                            if (isCharging_sms)
                                sendSMS(sms_voltage_alert_number,
                                        getResources().getString(R.string.voltage_restored));
                        } else {
                            SendMessage(getResources().getString(R.string.no_voltage));
                            if (isCharging_sms)
                                sendSMS(sms_voltage_alert_number,
                                        getResources().getString(R.string.no_voltage));
                        }

                        isCharging_before = isCharging;

                    }
                }

                Message msg = Message.obtain(); // Creates an new Message instance

                // we make 1 sec for each n
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                if (getstatus() == 3) {
                    return;
                }

                if (i % 5 == 0 && sms_check_file) {
                    // checking for sms file each 5 seconds during big pause between photos
                    File sms_file = null;

                    //                        sms_file = new File((getApplicationContext().getFilesDir().toString() + "/sms.txt"));
                    sms_file = new File(work_dir + "/sms.txt");

                    if (sms_file.isFile()) {

                        sms = file2array(sms_file.toString());

                        sms_getdata();

                        try {
                            TimeUnit.SECONDS.sleep(3);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                        for (int ind = 0; ind < sms.size(); ind++) {
                            SendMessage(sms.get(ind).toString(), MSG_INFO);
                        }

                        SendMessage("SMS:", MSG_INFO);

                        sms_file.delete();

                        sms.clear();

                        sms_update_db = true;

                        if (sms_status && sms_incoming_passwd.equals(sms_passwd)) {
                            sendSMS(sms_sender_num, "Bat: " + battery_level + "%\n" + "Upd: " + Photo_Frequency
                                    + "sec\n" + "Flash: " + Use_Flash + "\n" + "Net: " + network);
                            sms_status = false;
                        }

                        if (sms_net_status && sms_incoming_passwd.equals(sms_passwd)) {
                            sendSMS(sms_sender_num,
                                    "Net: " + network + "\n" + "Ch: " + Network_Channel + "\n" + "Method: "
                                            + Network_Connection_Method + "\n" + "Mail: " + EMail_Recepient
                                            + "\n");
                            sms_net_status = false;
                        }

                        if (sms_email_status && sms_incoming_passwd.equals(sms_passwd)) {
                            sendSMS(sms_sender_num,
                                    "Mail: " + EMail_Recepient + "\n" + "FMail: " + EMail_Sender + "\n"
                                            + "FMailP: " + EMail_Sender_Password + "\n" + "SMTPHost: "
                                            + SMTP_Host + "\n" + "SMTPPort: " + SMTP_Port + "\n");
                            sms_email_status = false;
                        }

                        if (sms_media_status && sms_incoming_passwd.equals(sms_passwd)) {
                            sendSMS(sms_sender_num, "Flash: " + Use_Flash + "\n" + "JPEG: " + JPEG_Compression
                                    + "\n" + "Fc: " + make_photo_fc + "\n" + "Bc: " + make_photo_bc + "\n");
                            sms_media_status = false;
                        }

                        if (sms_incoming_passwd.equals(sms_passwd) && sms_help) {
                            sendSMS(sms_sender_num, sms_commands_list());
                            sms_help = false;
                        }

                        // drop password before next usage
                        sms_incoming_passwd = "";

                        return;

                    } else {

                    }

                }

                if (i % wake_up_interval == 0 && frame_delay) {

                    String cmd = null;

                    try {

                        if (Build.VERSION.SDK_INT <= 12) {
                            cmd = "logcat -v long -d -f " + work_dir + "/logfile.txt" + " Logs:* FotoBot:* *:S";
                        } else {
                            cmd = "logcat -v long -d -f " + work_dir + "/logfile.txt";
                        }
                        Runtime.getRuntime().exec(cmd);

                    } catch (IOException e) {
                        e.printStackTrace();
                        Log.d("LOG_TAG", "logcat2file doesn't work");
                    }

                    try {
                        TimeUnit.SECONDS.sleep(short_pause);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    // ?    log_size,  ? 
                    File logcat_file;
                    logcat_file = new File(work_dir + "/logfile.txt");

                    boolean fileExists = logcat_file.isFile();

                    if (fileExists) {

                        if (logcat_file.length() / 1000 > log_size) {
                            clearLog();
                        }

                    } else {
                        SendMessage("logfile.txt doesn't exist.");
                    }

                    SendMessage(".", MSG_INFO);

                    if (camera == null) {
                        Log.d(LOG_TAG, "camera == null");
                        SendMessage("..", MSG_INFO);
                        try {
                            camera = Camera.open();
                            SendMessage(".", MSG_INFO);
                            Log.d(LOG_TAG, "Camera has been successfully opened");
                        } catch (Exception e) {
                            SendMessage("...", MSG_INFO);
                            Log.d(LOG_TAG, "Problem with camera opening");
                            e.printStackTrace();
                        }
                    }

                    try {
                        camera.setPreviewDisplay(holder);
                        camera.startPreview();
                        SendMessage(".", MSG_INFO);
                        Log.d(LOG_TAG, "Preview started");
                    } catch (Exception e) {
                        e.printStackTrace();
                        SendMessage("...", MSG_INFO);
                        Log.d(LOG_TAG, "Problem with starting of preview");
                    }

                    try {
                        TimeUnit.SECONDS.sleep(long_pause);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    if (camera != null) {
                        Log.d(LOG_TAG, "Camera is busy");
                        try {
                            camera.stopPreview();
                            camera.release();
                            camera = null;
                            Log.d(LOG_TAG, "Camera unlocked");
                        } catch (Exception e) {
                            SendMessage("...", MSG_INFO);
                        }

                    }

                    try {
                        TimeUnit.SECONDS.sleep(long_pause);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }

            }
        }

    };
    thread.start();

    try {
        thread.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    wakeLock.release();

}