Example usage for android.content Context POWER_SERVICE

List of usage examples for android.content Context POWER_SERVICE

Introduction

In this page you can find the example usage for android.content Context POWER_SERVICE.

Prototype

String POWER_SERVICE

To view the source code for android.content Context POWER_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.os.PowerManager for controlling power management, including "wake locks," which let you keep the device on while you're running long tasks.

Usage

From source file:com.wirelessmoves.cl.MainActivity.java

@SuppressWarnings("deprecation")
@Override/*  ww w  .ja  v  a 2s. c o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /* If saved variable state exists from last run, recover it */
    if (savedInstanceState != null) {
        NumberOfSignalStrengthUpdates = savedInstanceState.getLong("NumberOfSignalStrengthUpdates");

        LastCellId = savedInstanceState.getLong("LastCellId");
        NumberOfCellChanges = savedInstanceState.getLong("NumberOfCellChanges");

        LastLacId = savedInstanceState.getLong("LastLacId");
        NumberOfLacChanges = savedInstanceState.getLong("NumberOfLacChanges");

        PreviousCells = savedInstanceState.getLongArray("PreviousCells");
        PreviousCellsIndex = savedInstanceState.getInt("PreviousCellsIndex");
        NumberOfUniqueCellChanges = savedInstanceState.getLong("NumberOfUniqueCellChanges");

        outputDebugInfo = savedInstanceState.getBoolean("outputDebugInfo");

        CurrentLocationLong = savedInstanceState.getDouble("CurrentLocationLong");
        CurrentLocationLat = savedInstanceState.getDouble("CurrentLocationLat");

        /* attempt to restore the previous gps location information object */
        PrevLocation = (Location) getLastNonConfigurationInstance();

    } else {
        /* Initialize PreviousCells Array to defined values */
        for (int x = 0; x < PreviousCells.length; x++)
            PreviousCells[x] = 0;
    }

    /* Get a handle to the telephony manager service */
    /* A listener will be installed in the object from the onResume() method */
    MyListener = new MyPhoneStateListener();
    Tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    /* get a handle to the power manager and set a wake lock so the screen saver
     * is not activated after a timeout */
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");

    /* Get a handle to the location system for getting GPS information */
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    gpsListener = new myLocationListener();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, gpsListener);

}

From source file:org.videolan.vlc.MediaService.java

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

    // Get libVLC instance
    try {/*from   w  w w  .jav a2s.  c o  m*/
        mLibVLC = Util.getLibVlcInstance();
    } catch (LibVlcException e) {
        e.printStackTrace();
    }

    Thread.setDefaultUncaughtExceptionHandler(new VlcCrashHandler());

    mCallback = new HashMap<IMediaServiceCallback, Integer>();
    mMediaList = new ArrayList<Media>();
    mPrevious = new Stack<Media>();
    mEventHandler = EventHandler.getInstance();
    mRemoteControlClientReceiverComponent = new ComponentName(getPackageName(),
            RemoteControlClientReceiver.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 stop.
    PowerManager pm = (PowerManager) 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(ACTION_REMOTE_LAST_PLAYLIST);
    filter.addAction(Intent.ACTION_HEADSET_PLUG);
    filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    filter.addAction(VLCApplication.SLEEP_INTENT);
    registerReceiver(serviceReceiver, filter);

    final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    boolean stealRemoteControl = pref.getBoolean("enable_steal_remote_control", false);

    if (!Util.isFroyoOrLater() || stealRemoteControl) {
        /* Backward compatibility for API 7 */
        filter = new IntentFilter();
        if (stealRemoteControl)
            filter.setPriority(Integer.MAX_VALUE);
        filter.addAction(Intent.ACTION_MEDIA_BUTTON);
        mRemoteControlClientReceiver = new RemoteControlClientReceiver();
        registerReceiver(mRemoteControlClientReceiver, filter);
    }

    AudioUtil.prepareCacheFolder(this);
}

From source file:com.ifeng.util.download.DownloadThread.java

/**
 * Executes the download in a separate thread
 *//*from  ww w  .  j  a  va 2  s. c o m*/
@Override
public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

    State state = new State(mInfo);
    ProxyHttpClient client = null;
    PowerManager.WakeLock wakeLock = null;
    int finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR;

    try {
        PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG);
        wakeLock.acquire();

        if (Constants.LOGV) {
            Log.v(Constants.TAG, "initiating download for " + mInfo.mUri);
        }

        client = new ProxyHttpClient(mContext, userAgent());
        boolean finished = false;
        while (!finished) {
            Log.i(Constants.TAG, "Initiating request for download " + mInfo.mId);
            HttpGet request = new HttpGet(state.mRequestUri.trim());
            try {
                executeDownload(state, client, request);
                finished = true;
            } catch (RetryDownload exc) {
                // fall through
                exc.printStackTrace();
            } finally {
                request.abort();
                request = null;
            }
        }

        if (Constants.LOGV) {
            Log.v(Constants.TAG, "download completed for " + mInfo.mUri);
        }
        finalizeDestinationFile(state);
        finalStatus = Downloads.Impl.STATUS_SUCCESS;
    } catch (StopRequest error) {
        // remove the cause before printing, in case it contains PII
        Log.w(Constants.TAG, "Aborting request for download " + mInfo.mId + ": " + error.getMessage());
        Log.w(Constants.TAG, "download error:", error);
        finalStatus = error.mFinalStatus;
        displayMsg(finalStatus, error.getMessage());
        // 
        mInfo.mFailedReason = mInfo.mFailedReason + " |||| " + Utils.getStackTraceString(error);
        // fall through to finally block
    } catch (Throwable ex) { // sometimes the socket code throws unchecked
        // exceptions
        Log.w(Constants.TAG, "Exception for id " + mInfo.mId + ": " + ex);
        Log.w(Constants.TAG, "download error:", ex);
        finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR;
        displayMsg(finalStatus, ex.getMessage());
        // 
        mInfo.mFailedReason = mInfo.mFailedReason + "||||" + Utils.getStackTraceString(ex);
        // falls through to the code that reports an error
    } finally {
        if (wakeLock != null) {
            wakeLock.release();
            wakeLock = null;
        }
        if (client != null) {
            client.close();
            client = null;
        }
        cleanupDestination(state, finalStatus);

        notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter, state.mRedirectCount,
                state.mGotData, state.mFilename, state.mNewUri, state.mMimeType);

        --DownloadService.mCurrentThreadNum;
        if (!Downloads.Impl.isStatusCompleted(finalStatus)) {
            mInfo.mHasActiveThread = false;
        }
    }
}

From source file:com.cyanogenmod.eleven.MediaButtonIntentReceiver.java

private static void acquireWakeLockAndSendMessage(Context context, Message msg, long delay) {
    if (mWakeLock == null) {
        Context appContext = context.getApplicationContext();
        PowerManager pm = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE);
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Eleven headset button");
        mWakeLock.setReferenceCounted(false);
    }/* www.  ja v  a  2  s.c  o m*/
    if (DEBUG)
        Log.v(TAG, "Acquiring wake lock and sending " + msg.what);
    // Make sure we don't indefinitely hold the wake lock under any circumstances
    mWakeLock.acquire(10000);

    mHandler.sendMessageDelayed(msg, delay);
}

From source file:com.yamin.kk.service.AudioService.java

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

    // Get libVLC instance
    try {//from  w ww .  j a v a2 s  .c o m
        mLibVLC = Util.getLibVlcInstance();
    } catch (LibVlcException e) {
        e.printStackTrace();
    }

    mCallback = new HashMap<IAudioServiceCallback, Integer>();
    mCurrentIndex = -1;
    mPrevious = new Stack<Integer>();
    mEventHandler = EventHandler.getInstance();
    mRemoteControlClientReceiverComponent = new ComponentName(getPackageName(),
            RemoteControlClientReceiver.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 stop.
    PowerManager pm = (PowerManager) 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(ACTION_REMOTE_LAST_PLAYLIST);
    filter.addAction(ACTION_WIDGET_INIT);
    filter.addAction(Intent.ACTION_HEADSET_PLUG);
    filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    filter.addAction(VLCApplication.SLEEP_INTENT);
    registerReceiver(serviceReceiver, filter);

    final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    boolean stealRemoteControl = pref.getBoolean("enable_steal_remote_control", false);

    if (!Util.isFroyoOrLater() || stealRemoteControl) {
        /* Backward compatibility for API 7 */
        filter = new IntentFilter();
        if (stealRemoteControl)
            filter.setPriority(Integer.MAX_VALUE);
        filter.addAction(Intent.ACTION_MEDIA_BUTTON);
        mRemoteControlClientReceiver = new RemoteControlClientReceiver();
        registerReceiver(mRemoteControlClientReceiver, filter);
    }
}

From source file:cn.wyl.superwechat.ui.MainActivity.java

private void checkVersion() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String packageName = getPackageName();
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isIgnoringBatteryOptimizations(packageName)) {
            Intent intent = new Intent();
            intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);/*w w  w.j  ava  2  s.c  om*/
        }
    }
}

From source file:com.andrew.apollo.MediaButtonIntentReceiver.java

private static void acquireWakeLockAndSendMessage(Context context, Message msg, long delay) {
    if (mWakeLock == null) {
        Context appContext = context.getApplicationContext();
        PowerManager pm = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE);
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Apollo headset button");
        mWakeLock.setReferenceCounted(false);
    }//w w w  .j av a2 s. com
    if (DEBUG)
        Log.v(TAG, "Acquiring wake lock and sending " + msg.what);
    // Make sure we don't indefinitely hold the wake lock under any circumstances
    mWakeLock.acquire(10000);

    mHandler.sendMessageDelayed(msg, delay);
}

From source file:com.github.diogochbittencourt.googleplaydownloader.downloader.impl.DownloadThread.java

/**
 * Executes the download in a separate thread
 */// ww w .  j a v  a 2 s.c  o m
public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

    State state = new State(mInfo, mService);
    AndroidHttpClient client = null;
    PowerManager.WakeLock wakeLock = null;
    int finalStatus = DownloaderService.STATUS_UNKNOWN_ERROR;

    try {
        PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG);
        wakeLock.acquire();

        if (Constants.LOGV) {
            Log.v(Constants.TAG, "initiating download for " + mInfo.mFileName);
            Log.v(Constants.TAG, "  at " + mInfo.mUri);
        }

        client = AndroidHttpClient.newInstance(userAgent(), mContext);

        boolean finished = false;
        while (!finished) {
            if (Constants.LOGV) {
                Log.v(Constants.TAG, "initiating download for " + mInfo.mFileName);
                Log.v(Constants.TAG, "  at " + mInfo.mUri);
            }
            // Set or unset proxy, which may have changed since last GET
            // request.
            // setDefaultProxy() supports null as proxy parameter.
            ConnRouteParams.setDefaultProxy(client.getParams(),
                    getPreferredHttpHost(mContext, state.mRequestUri));
            HttpGet request = new HttpGet(state.mRequestUri);
            try {
                executeDownload(state, client, request);
                finished = true;
            } catch (RetryDownload exc) {
                // fall through
            } finally {
                request.abort();
                request = null;
            }
        }

        if (Constants.LOGV) {
            Log.v(Constants.TAG, "download completed for " + mInfo.mFileName);
            Log.v(Constants.TAG, "  at " + mInfo.mUri);
        }
        finalizeDestinationFile(state);
        finalStatus = DownloaderService.STATUS_SUCCESS;
    } catch (StopRequest error) {
        // remove the cause before printing, in case it contains PII
        Log.w(Constants.TAG, "Aborting request for download " + mInfo.mFileName + ": " + error.getMessage());
        error.printStackTrace();
        finalStatus = error.mFinalStatus;
        // fall through to finally block
    } catch (Throwable ex) { // sometimes the socket code throws unchecked
        // exceptions
        Log.w(Constants.TAG, "Exception for " + mInfo.mFileName + ": " + ex);
        finalStatus = DownloaderService.STATUS_UNKNOWN_ERROR;
        // falls through to the code that reports an error
    } finally {
        if (wakeLock != null) {
            wakeLock.release();
            wakeLock = null;
        }
        if (client != null) {
            client.close();
            client = null;
        }
        cleanupDestination(state, finalStatus);
        notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter, state.mRedirectCount,
                state.mGotData, state.mFilename);
    }
}

From source file:com.csipsimple.ui.incall.CallActivity.java

@SuppressWarnings("deprecation")
@Override/*  w w w .  j  a  v a  2s .c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //handler.setActivityInstance(this);
    Log.i(TAG, "######## onCreate");
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    this.setFinishOnTouchOutside(false);
    setContentView(R.layout.call_dialog);

    targetName = getIntent().getStringExtra(SipManager.CALLEE_NAME_INTENT_KEY);
    if (targetName != null) {
        Log.i(TAG, "targetName: " + targetName);
    }

    SipCallSession initialSession = getIntent().getParcelableExtra(SipManager.EXTRA_CALL_INFO);
    synchronized (callMutex) {
        callsInfo = new SipCallSession[1];
        callsInfo[0] = initialSession;
    }

    bindService(new Intent(this, SipService.class), connection, Context.BIND_AUTO_CREATE);
    prefsWrapper = new PreferencesProviderWrapper(this);

    // Log.d(TAG, "Creating call handler for " +
    // callInfo.getCallId()+" state "+callInfo.getRemoteContact());
    powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
            | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "com.csipsimple.onIncomingCall");
    wakeLock.setReferenceCounted(false);

    takeKeyEvents(true);

    // Cache findViews
    mainFrame = (ViewGroup) findViewById(R.id.mainFrame);
    //inCallControls = (InCallControls) findViewById(R.id.inCallControls);
    inCallAnswerControls = (InCallAnswerControls) findViewById(R.id.inCallAnswerControls);
    activeCallsGrid = (InCallInfoGrid) findViewById(R.id.activeCallsGrid);
    heldCallsGrid = (InCallInfoGrid) findViewById(R.id.heldCallsGrid);

    // Bind
    attachVideoPreview();

    //inCallControls.setOnTriggerListener(this);
    inCallAnswerControls.setOnTriggerListener(this);

    if (activeCallsAdapter == null) {
        activeCallsAdapter = new CallsAdapter(true);
    }
    activeCallsGrid.setAdapter(activeCallsAdapter);

    if (heldCallsAdapter == null) {
        heldCallsAdapter = new CallsAdapter(false);
    }
    heldCallsGrid.setAdapter(heldCallsAdapter);

    ScreenLocker lockOverlay = (ScreenLocker) findViewById(R.id.lockerOverlay);
    lockOverlay.setActivity(this);
    lockOverlay.setOnLeftRightListener(this);

    /*
    middleAddCall = (Button) findViewById(R.id.add_call_button);
    middleAddCall.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
        onTrigger(ADD_CALL, null);
    }
    });
    if (!prefsWrapper.getPreferenceBooleanValue(SipConfigManager.SUPPORT_MULTIPLE_CALLS)) {
    middleAddCall.setEnabled(false);
    middleAddCall.setText(R.string.not_configured_multiple_calls);
    }
    */

    // Listen to media & sip events to update the UI
    registerReceiver(callStateReceiver, new IntentFilter(SipManager.ACTION_SIP_CALL_CHANGED));
    registerReceiver(callStateReceiver, new IntentFilter(SipManager.ACTION_SIP_MEDIA_CHANGED));
    registerReceiver(callStateReceiver, new IntentFilter(SipManager.ACTION_ZRTP_SHOW_SAS));

    proximityManager = new CallProximityManager(this, this, lockOverlay);
    keyguardManager = KeyguardWrapper.getKeyguardManager(this);

    dialFeedback = new DialingFeedback(this, true);

    if (prefsWrapper.getPreferenceBooleanValue(SipConfigManager.PREVENT_SCREEN_ROTATION)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    if (quitTimer == null) {
        quitTimer = new Timer("Quit-timer");
    }

    useAutoDetectSpeaker = prefsWrapper.getPreferenceBooleanValue(SipConfigManager.AUTO_DETECT_SPEAKER);

    applyTheme();
    proximityManager.startTracking();

    //inCallControls.setCallState(initialSession);
    inCallAnswerControls.setCallState(initialSession);
}

From source file:co.taqat.call.CallActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    instance = this;

    if (getResources().getBoolean(R.bool.orientation_portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }//from w ww  .  j a v a  2 s .com

    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    setContentView(R.layout.call);

    isTransferAllowed = getApplicationContext().getResources().getBoolean(R.bool.allow_transfers);

    if (!BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) {
        BluetoothManager.getInstance().initBluetooth();
    }

    cameraNumber = AndroidCameraConfiguration.retrieveCameras().length;

    try {
        // Yeah, this is hidden field.
        field = PowerManager.class.getClass().getField("PROXIMITY_SCREEN_OFF_WAKE_LOCK").getInt(null);
    } catch (Throwable ignored) {
    }

    powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(field, getLocalClassName());

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);

    mListener = new LinphoneCoreListenerBase() {
        @Override
        public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
            displayMissedChats();
        }

        @Override
        public void callState(LinphoneCore lc, final LinphoneCall call, LinphoneCall.State state,
                String message) {
            if (LinphoneManager.getLc().getCallsNb() == 0) {
                finish();
                return;
            }

            if (state == State.IncomingReceived) {
                startIncomingCallActivity();
                return;
            } else if (state == State.Paused || state == State.PausedByRemote || state == State.Pausing) {
                if (LinphoneManager.getLc().getCurrentCall() != null) {
                    enabledVideoButton(false);
                }
                if (isVideoEnabled(call)) {
                    showAudioView();
                }
            } else if (state == State.Resuming) {
                if (LinphonePreferences.instance().isVideoEnabled()) {
                    status.refreshStatusItems(call, isVideoEnabled(call));
                    if (call.getCurrentParamsCopy().getVideoEnabled()) {
                        showVideoView();
                    }
                }
                if (LinphoneManager.getLc().getCurrentCall() != null) {
                    enabledVideoButton(true);
                }
            } else if (state == State.StreamsRunning) {
                switchVideo(isVideoEnabled(call));
                enableAndRefreshInCallActions();

                if (status != null) {
                    videoProgress.setVisibility(View.GONE);
                    status.refreshStatusItems(call, isVideoEnabled(call));
                }
            } else if (state == State.CallUpdatedByRemote) {
                // If the correspondent proposes video while audio call
                boolean videoEnabled = LinphonePreferences.instance().isVideoEnabled();
                if (!videoEnabled) {
                    acceptCallUpdate(false);
                }

                boolean remoteVideo = call.getRemoteParams().getVideoEnabled();
                boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled();
                boolean autoAcceptCameraPolicy = true;//LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests();
                if (remoteVideo && !localVideo && !autoAcceptCameraPolicy
                        && !LinphoneManager.getLc().isInConference()) {
                    showAcceptCallUpdateDialog();
                    timer = new CountDownTimer(SECONDS_BEFORE_DENYING_CALL_UPDATE, 1000) {
                        public void onTick(long millisUntilFinished) {
                        }

                        public void onFinish() {
                            //TODO dismiss dialog
                            acceptCallUpdate(false);
                        }
                    }.start();

                    /*showAcceptCallUpdateDialog();
                            
                    timer = new CountDownTimer(SECONDS_BEFORE_DENYING_CALL_UPDATE, 1000) {
                       public void onTick(long millisUntilFinished) { }
                       public void onFinish() {
                          //TODO dismiss dialog
                            
                       }
                    }.start();*/

                }
                //                 else if (remoteVideo && !LinphoneManager.getLc().isInConference() && autoAcceptCameraPolicy) {
                //                    mHandler.post(new Runnable() {
                //                       @Override
                //                       public void run() {
                //                          acceptCallUpdate(true);
                //                       }
                //                    });
                //                 }
            }

            refreshIncallUi();
            transfer.setEnabled(LinphoneManager.getLc().getCurrentCall() != null);
        }

        @Override
        public void callEncryptionChanged(LinphoneCore lc, final LinphoneCall call, boolean encrypted,
                String authenticationToken) {
            if (status != null) {
                if (call.getCurrentParamsCopy().getMediaEncryption().equals(LinphoneCore.MediaEncryption.ZRTP)
                        && !call.isAuthenticationTokenVerified()) {
                    status.showZRTPDialog(call);
                }
                status.refreshStatusItems(call, call.getCurrentParamsCopy().getVideoEnabled());
            }
        }

    };

    if (findViewById(R.id.fragmentContainer) != null) {
        initUI();

        if (LinphoneManager.getLc().getCallsNb() > 0) {
            LinphoneCall call = LinphoneManager.getLc().getCalls()[0];

            if (LinphoneUtils.isCallEstablished(call)) {
                enableAndRefreshInCallActions();
            }
        }

        if (savedInstanceState != null) {
            // Fragment already created, no need to create it again (else it will generate a memory leak with duplicated fragments)
            isSpeakerEnabled = savedInstanceState.getBoolean("Speaker");
            isMicMuted = savedInstanceState.getBoolean("Mic");
            isVideoCallPaused = savedInstanceState.getBoolean("VideoCallPaused");
            refreshInCallActions();
            return;
        } else {
            isSpeakerEnabled = LinphoneManager.getLc().isSpeakerEnabled();
            isMicMuted = LinphoneManager.getLc().isMicMuted();
        }

        Fragment callFragment;
        if (isVideoEnabled(LinphoneManager.getLc().getCurrentCall())) {
            callFragment = new CallVideoFragment();
            videoCallFragment = (CallVideoFragment) callFragment;
            displayVideoCall(false);
            LinphoneManager.getInstance().routeAudioToSpeaker();
            isSpeakerEnabled = true;
        } else {
            callFragment = new CallAudioFragment();
            audioCallFragment = (CallAudioFragment) callFragment;
        }

        if (BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) {
            BluetoothManager.getInstance().routeAudioToBluetooth();
        }

        callFragment.setArguments(getIntent().getExtras());
        getFragmentManager().beginTransaction().add(R.id.fragmentContainer, callFragment)
                .commitAllowingStateLoss();
    }
}