android.telephony.PhoneStateListener Java Examples

The following examples show how to use android.telephony.PhoneStateListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: sana.mobile   Author: SanaMobile   File: BackgroundUploader.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Log.v(TAG, "onCreate()");
    try {
        queue = QueueManager.initQueue(this);

        // Try to process the upload queue. Will check credentials if necessary.
        processUploadQueue();
    } catch (Exception e) {
        Log.e(TAG, "Exception creating background uploading service: "
                + e.toString());
        e.printStackTrace();
    }
    TelephonyManager telephony = (TelephonyManager) getSystemService(
            Application.TELEPHONY_SERVICE);
    if (telephony != null) {
        telephony.listen(new DataConnectionListener(),
                PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
    }
}
 
Example #2
/**
 * Full stop using brute force. Works with many Android versions.
 */
public void stopLocation(){
    if(_phoneStateListener != null && _telephonyManager != null){
        _telephonyManager.listen(_phoneStateListener, PhoneStateListener.LISTEN_NONE);
    }

    if(_signalStrengthListener != null && _telephonyManager != null){
        _telephonyManager.listen(_signalStrengthListener, PhoneStateListener.LISTEN_NONE);
    }

    _signalStrengthListener = null;
    _phoneStateListener = null;
    _telephonyManager = null;

    try {
        Thread.currentThread().interrupt();
    }
    catch(SecurityException exc){
        Log.e(TAG, exc.getMessage());
        sendCallback(PluginResult.Status.ERROR,
                JSONHelper.errorJSON(CELLINFO_PROVIDER, ErrorMessages.FAILED_THREAD_INTERRUPT()));
    }

    Log.d(TAG, "Stopping cell location listeners");
}
 
Example #3
Source Project: android_9.0.0_r45   Author: lulululbj   File: TelephonyRegistry.java    License: Apache License 2.0 6 votes vote down vote up
public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) {
    if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) {
        return;
    }
    if (VDBG) {
        log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId
                + " state=" + state);
    }
    synchronized (mRecords) {
        if (validatePhoneId(phoneId)) {
            mMessageWaiting[phoneId] = state;
            for (Record r : mRecords) {
                if (r.matchPhoneStateListenerEvent(
                        PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) &&
                        idMatch(r.subId, subId, phoneId)) {
                    try {
                        r.callback.onUserMobileDataStateChanged(state);
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
        }
        handleRemoveListLocked();
    }
}
 
Example #4
Source Project: android_9.0.0_r45   Author: lulululbj   File: TelephonyRegistry.java    License: Apache License 2.0 6 votes vote down vote up
public void notifyDataActivityForSubscriber(int subId, int state) {
    if (!checkNotifyPermission("notifyDataActivity()" )) {
        return;
    }
    int phoneId = SubscriptionManager.getPhoneId(subId);
    synchronized (mRecords) {
        if (validatePhoneId(phoneId)) {
            mDataActivity[phoneId] = state;
            for (Record r : mRecords) {
                // Notify by correct subId.
                if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
                        idMatch(r.subId, subId, phoneId)) {
                    try {
                        r.callback.onDataActivity(state);
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
        }
        handleRemoveListLocked();
    }
}
 
Example #5
Source Project: example   Author: pratamawijaya   File: StreamService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    Log.d("tag", "remove notification");
    if (mediaPlayer != null) {
        if (mediaPlayer.isPlaying()) {
            mediaPlayer.stop();
        }
        mediaPlayer.release();
    }

    if (phoneStateListener != null) {
        telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
    }

    cancelNotification();
}
 
Example #6
Source Project: android_9.0.0_r45   Author: lulululbj   File: TelephonyRegistry.java    License: Apache License 2.0 6 votes vote down vote up
public void notifyPreciseDataConnectionFailed(String reason, String apnType,
        String apn, String failCause) {
    if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
        return;
    }
    synchronized (mRecords) {
        mPreciseDataConnectionState = new PreciseDataConnectionState(
                TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN,
                apnType, apn, reason, null, failCause);
        for (Record r : mRecords) {
            if (r.matchPhoneStateListenerEvent(
                    PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
                try {
                    r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
                } catch (RemoteException ex) {
                    mRemoveList.add(r.binder);
                }
            }
        }
        handleRemoveListLocked();
    }
    broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN,
            TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
}
 
Example #7
Source Project: android_9.0.0_r45   Author: lulululbj   File: TelephonyRegistry.java    License: Apache License 2.0 6 votes vote down vote up
public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) {
    if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) {
        return;
    }
    synchronized (mRecords) {
        mVoLteServiceState = lteState;
        for (Record r : mRecords) {
            if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) {
                try {
                    r.callback.onVoLteServiceStateChanged(
                            new VoLteServiceState(mVoLteServiceState));
                } catch (RemoteException ex) {
                    mRemoveList.add(r.binder);
                }
            }
        }
        handleRemoveListLocked();
    }
}
 
Example #8
Source Project: android_9.0.0_r45   Author: lulululbj   File: TelephonyRegistry.java    License: Apache License 2.0 6 votes vote down vote up
public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
    if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
        return;
    }

    synchronized (mRecords) {
        for (Record r : mRecords) {
            if (VDBG) {
                log("notifyOemHookRawEventForSubscriber:  r=" + r + " subId=" + subId);
            }
            if ((r.matchPhoneStateListenerEvent(
                    PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
                    ((r.subId == subId) ||
                    (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
                try {
                    r.callback.onOemHookRawEvent(rawData);
                } catch (RemoteException ex) {
                    mRemoveList.add(r.binder);
                }
            }
        }
        handleRemoveListLocked();
    }
}
 
Example #9
Source Project: tracker-control-android   Author: OxfordHCC   File: ServiceSinkhole.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void listenConnectivityChanges() {
    // Listen for connectivity updates
    Log.i(TAG, "Starting listening to connectivity changes");
    IntentFilter ifConnectivity = new IntentFilter();
    ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(connectivityChangedReceiver, ifConnectivity);
    registeredConnectivityChanged = true;

    // Listen for phone state changes
    Log.i(TAG, "Starting listening to service state changes");
    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (tm != null) {
        tm.listen(phoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
        phone_state = true;
    }
}
 
Example #10
Source Project: dcs-sdk-java   Author: dueros   File: MediaPlayerImpl.java    License: Apache License 2.0 6 votes vote down vote up
public MediaPlayerImpl() {
    mMediaPlayer = new MediaPlayer();
    // set audio stream type
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mMediaPlayer.setOnBufferingUpdateListener(bufferingUpdateListener);
    mMediaPlayer.setOnErrorListener(errorListener);
    mMediaPlayer.setOnPreparedListener(preparedListener);
    mMediaPlayer.setOnCompletionListener(completionListener);
    mMediaPlayer.setOnSeekCompleteListener(seekCompleteListener);
    // 不同的音频源,此回调有的不回调!!!
    // mMediaPlayer.setOnInfoListener(infoListener);

    // 读取音量和静音的数据
    currentVolume = (float) MediaPlayerPreferenceUtil.get(context,
            KEY_SP_VOLUME, 0.8f);
    isMute = (boolean) MediaPlayerPreferenceUtil.get(context,
            KEY_SP_MUTE, false);
    // LinkedList
    mediaPlayerListeners = Collections.synchronizedList(new LinkedList<IMediaPlayer.IMediaPlayerListener>());
    posHandler = new PosHandler(Looper.getMainLooper());

    // 来电监听
    telephonyManager = (TelephonyManager)
            context.getSystemService(Service.TELEPHONY_SERVICE);
    telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
 
Example #11
Source Project: commcare-android   Author: dimagi   File: CallOutActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void dispatchAction() {
    if (Intent.ACTION_CALL.equals(calloutAction)) {
        tManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);

        Intent call = new Intent(Intent.ACTION_CALL);
        call.setData(Uri.parse("tel:" + number));
        if (call.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(call, CALL_RESULT);
        } else {
            Toast.makeText(this, Localization.get("callout.failure.dialer"), Toast.LENGTH_SHORT).show();
            finish();
        }
    } else {
        Intent sms = new Intent(Intent.ACTION_SENDTO);
        sms.setData(Uri.parse("smsto:" + number));
        if (sms.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(sms, SMS_RESULT);
        } else {
            Toast.makeText(this, Localization.get("callout.failure.sms"), Toast.LENGTH_SHORT).show();
            finish();
        }
    }
}
 
Example #12
Source Project: DMAudioStreamer   Author: dibakarece   File: AudioStreamingService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    if (remoteControlClient != null) {
        RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
        metadataEditor.clear();
        metadataEditor.apply();
        audioManager.unregisterRemoteControlClient(remoteControlClient);
    }
    try {
        TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        if (mgr != null) {
            mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
        }
    } catch (Exception e) {
        Log.e("tmessages", e.toString());
    }
    NotificationManager.getInstance().removeObserver(this, NotificationManager.audioProgressDidChanged);
    NotificationManager.getInstance().removeObserver(this, NotificationManager.audioPlayStateChanged);
}
 
Example #13
Source Project: freemp   Author: recoilme   File: ServicePlayer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onDestroy() {
    if (tm != null) {
        tm.listen(telephone, PhoneStateListener.LISTEN_NONE);
        tm = null;
    }
    if (myBroadcastReceiver != null) {
        unregisterReceiver(myBroadcastReceiver);
    }
    if (mAudioManager != null) {
        mAudioManager.unregisterMediaButtonEventReceiver(new ComponentName(getPackageName(), RcvMediaControl.class.getName()));
    }
    if (android.os.Build.VERSION.SDK_INT >= 14 && remoteControlClient != null) {
        unregisterRemoteControl();
    }
    // "free" the output device and all plugins
    BASS.BASS_Free();
    BASS.BASS_PluginFree(0);

    // Stop foreground
    stopForeground(true);
    stopUpdateProgress();

    super.onDestroy();
}
 
Example #14
Source Project: GravityBox   Author: WrBug   File: TrafficMeterAbstract.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    if (!mAttached) {
        mAttached = true;
        if (DEBUG) log("attached to window");
        IntentFilter filter = new IntentFilter();
        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        filter.addAction(ModDownloadProvider.ACTION_DOWNLOAD_STATE_CHANGED);
        getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());

        if (mPhone != null) {
            mPhone.listen(mPhoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
        }

        updateState();
    }
}
 
Example #15
Source Project: androidpn-client   Author: daktak   File: NotificationService.java    License: Apache License 2.0 5 votes vote down vote up
private void registerConnectivityReceiver() {
    Log.d(LOGTAG, "registerConnectivityReceiver()...");
    telephonyManager.listen(phoneStateListener,
            PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
    IntentFilter filter = new IntentFilter();
    // filter.addAction(android.net.wifi.WifiManager.NETWORK_STATE_CHANGED_ACTION);
    filter.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(connectivityReceiver, filter);
}
 
Example #16
Source Project: mollyim-android   Author: mollyim   File: WebRtcCallService.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroy() {
  super.onDestroy();
  Log.i(TAG, "onDestroy");

  if (callManager != null) {
    try {
      callManager.close();
    } catch (CallException e) {
      Log.w(TAG, "Unable to close call manager: ", e);
    }
    callManager = null;
  }

  if (callReceiver != null) {
    unregisterReceiver(callReceiver);
  }

  if (uncaughtExceptionHandlerManager != null) {
    uncaughtExceptionHandlerManager.unregister();
  }

  if (bluetoothStateManager != null) {
    bluetoothStateManager.onDestroy();
  }

  if (wiredHeadsetStateReceiver != null) {
    unregisterReceiver(wiredHeadsetStateReceiver);
    wiredHeadsetStateReceiver = null;
  }

  if (powerButtonReceiver != null) {
    unregisterReceiver(powerButtonReceiver);
    powerButtonReceiver = null;
  }

  TelephonyUtil.getManager(this)
               .listen(hangUpRtcOnDeviceCallAnswered, PhoneStateListener.LISTEN_NONE);
}
 
Example #17
Source Project: PowerSwitch_Android   Author: Power-Switch   File: IncomingCallReceiver.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    mContext = context;
    mIntent = intent;
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    int events = PhoneStateListener.LISTEN_CALL_STATE;
    tm.listen(phoneStateListener, events);
}
 
Example #18
Source Project: bcm-android   Author: bcmapp   File: ServiceRequirementProvider.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void handleInService() {
  if (listeningForServiceState.compareAndSet(true, false)) {
    this.telephonyManager.listen(serviceStateListener, PhoneStateListener.LISTEN_NONE);
  }

  if (requirementListener != null) {
    requirementListener.onRequirementStatusChanged();
  }
}
 
Example #19
Source Project: Noyze   Author: Tombarr   File: VolumePanel.java    License: Apache License 2.0 5 votes vote down vote up
public VolumePanel(PopupWindowManager manager) {
	super(manager);
	Context context = manager.getContext();
       app = (NoyzeApp) context.getApplicationContext();
	mStreamControls = new SparseArray<StreamControl>(StreamResources.STREAMS.length);
	mHandler = new VolumeMediaHandler(context.getMainLooper());
	mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
       mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
       mVolumeManager = new VolumeManager(mAudioManager);
       mAudioHelper = AudioHelper.getHelper(context, mAudioManager);
       // mAudioFlingerProxy = new AudioFlingerProxy();
       mAudioHelper.setHandler(mHandler);
       mLongPressTimeout = ViewConfiguration.getLongPressTimeout();

       if (MediaProviderDelegate.IS_V18)
           mMediaProviderDelegate = MediaProviderDelegate.getDelegate(context);

       // Register here: be SURE that the handler is not null.
       if (null == mVolumeMediaReceiver) {
           mVolumeMediaReceiver = new VolumeMediaReceiver(mHandler);
           IntentFilter events = Utils.merge(VOLUME_MUSIC_EVENTS(), Constants.MEDIA_ACTION_FILTER());
           context.registerReceiver(mVolumeMediaReceiver, events);
           mVolumeMediaReceiver.setHandler(mHandler);
       }

       // Register for events related to the call state.
       if (null == mCallStateListener) {
           mCallState = mTelephonyManager.getCallState();
           mCallStateListener = new CallStateListener(mHandler);
           mTelephonyManager.listen(mCallStateListener, PhoneStateListener.LISTEN_CALL_STATE);
       }

	initState();
}
 
Example #20
Source Project: MiBandDecompiled   Author: vishnudevk   File: ai.java    License: Apache License 2.0 5 votes vote down vote up
static void a(ai ai1, PhoneStateListener phonestatelistener)
{
    if (ai1.b != null)
    {
        ai1.b.listen(phonestatelistener, 273);
    }
}
 
Example #21
Source Project: android_9.0.0_r45   Author: lulululbj   File: TelephonyRegistry.java    License: Apache License 2.0 5 votes vote down vote up
public void notifyCallState(int state, String phoneNumber) {
    if (!checkNotifyPermission("notifyCallState()")) {
        return;
    }

    if (VDBG) {
        log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
    }

    synchronized (mRecords) {
        for (Record r : mRecords) {
            if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
                    (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
                try {
                    // Ensure the listener has read call log permission; if they do not return
                    // an empty phone number.
                    String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
                    r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
                } catch (RemoteException ex) {
                    mRemoveList.add(r.binder);
                }
            }
        }
        handleRemoveListLocked();
    }

    // Called only by Telecomm to communicate call state across different phone accounts. So
    // there is no need to add a valid subId or slotId.
    broadcastCallStateChanged(state, phoneNumber,
            SubscriptionManager.INVALID_PHONE_INDEX,
            SubscriptionManager.INVALID_SUBSCRIPTION_ID);
}
 
Example #22
Source Project: open-rmbt   Author: alladin-IT   File: InformationCollector.java    License: Apache License 2.0 5 votes vote down vote up
private void unregisterListeners()
{
    Log.d(DEBUG_TAG, "unregistering listener");
    
    if (telManager != null)
    {
        telManager.listen(telListener, PhoneStateListener.LISTEN_NONE);
        telListener = null;
        telManager = null;
    }
}
 
Example #23
Source Project: react-native-android-audio-streaming-aac   Author: EstebanFuentealba   File: Signal.java    License: MIT License 5 votes vote down vote up
public void setData(Context context, Class<?> clsActivity, AACStreamingModule module) {
  this.context = context;
  this.clsActivity = clsActivity;
  this.module = module;

  this.eventsReceiver = new EventsReceiver(this.module);


  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.CREATED));
  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.DESTROYED));
  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.STARTED));
  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.CONNECTING));
  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.START_PREPARING));
  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.PREPARED));
  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.PLAYING));
  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.STOPPED));
  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.COMPLETED));
  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.ERROR));
  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.BUFFERING_START));
  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.BUFFERING_END));
  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.METADATA_UPDATED));
  registerReceiver(this.eventsReceiver, new IntentFilter(Mode.ALBUM_UPDATED));


  this.phoneStateListener = new PhoneListener(this.module);
  this.phoneManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
  if (this.phoneManager != null) {
    this.phoneManager.listen(this.phoneStateListener , PhoneStateListener.LISTEN_CALL_STATE);
  }


}
 
Example #24
Source Project: Silence   Author: SilenceIM   File: ServiceRequirementProvider.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void handleInService() {
  if (listeningForServiceState.compareAndSet(true, false)) {
    this.telephonyManager.listen(serviceStateListener, PhoneStateListener.LISTEN_NONE);
  }

  if (requirementListener != null) {
    requirementListener.onRequirementStatusChanged();
  }
}
 
Example #25
Source Project: Status   Author: fennifith   File: DataIconData.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void register() {
    if (dataListener != null)
        telephonyManager.listen(dataListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
    isRegistered = true;

    onDataChanged();
}
 
Example #26
Source Project: android_9.0.0_r45   Author: lulululbj   File: TelephonyRegistry.java    License: Apache License 2.0 5 votes vote down vote up
public void notifyCellLocationForSubscriber(int subId, Bundle cellLocation) {
    log("notifyCellLocationForSubscriber: subId=" + subId
            + " cellLocation=" + cellLocation);
    if (!checkNotifyPermission("notifyCellLocation()")) {
        return;
    }
    if (VDBG) {
        log("notifyCellLocationForSubscriber: subId=" + subId
            + " cellLocation=" + cellLocation);
    }
    int phoneId = SubscriptionManager.getPhoneId(subId);
    synchronized (mRecords) {
        if (validatePhoneId(phoneId)) {
            mCellLocation[phoneId] = cellLocation;
            for (Record r : mRecords) {
                if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_LOCATION) &&
                        idMatch(r.subId, subId, phoneId) &&
                        checkLocationAccess(r)) {
                    try {
                        if (DBG_LOC) {
                            log("notifyCellLocation: cellLocation=" + cellLocation
                                    + " r=" + r);
                        }
                        r.callback.onCellLocationChanged(new Bundle(cellLocation));
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
        }
        handleRemoveListLocked();
    }
}
 
Example #27
Source Project: PocketMaps   Author: junjunguo   File: MainActivity.java    License: MIT License 5 votes vote down vote up
private PhoneStateListener createCallListener()
{
  return new PhoneStateListener()
  {
    @Override
    public void onCallStateChanged(int state, String incomingNumber)
    {
      boolean mute = true;
      if (state==TelephonyManager.CALL_STATE_OFFHOOK) {}
      else if (state==TelephonyManager.CALL_STATE_RINGING) {}
      else if (state==TelephonyManager.CALL_STATE_IDLE) { mute = false; }
      NaviEngine.getNaviEngine().setNaviVoiceMute(mute);
    }
  };
}
 
Example #28
Source Project: mytracks   Author: Plonk42   File: AnnouncementPeriodicTask.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Listens to phone state.
 * 
 * @param listener the listener
 * @param events the interested events
 */
@VisibleForTesting
protected void listenToPhoneState(PhoneStateListener listener, int events) {
  TelephonyManager telephony = (TelephonyManager) context.getSystemService(
      Context.TELEPHONY_SERVICE);
  if (telephony != null) {
    telephony.listen(listener, events);
  }
}
 
Example #29
Source Project: mytracks   Author: Plonk42   File: AnnouncementPeriodicTask.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
  if (tts == null) {
    tts = newTextToSpeech(context, new OnInitListener() {
        @Override
      public void onInit(int status) {
        initStatus = status;
      }
    });
  }
  speechAllowed = true;
  listenToPhoneState(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
 
Example #30
Source Project: android_9.0.0_r45   Author: lulululbj   File: TelephonyRegistry.java    License: Apache License 2.0 5 votes vote down vote up
private boolean checkListenerPermission(
        int events, int subId, String callingPackage, String message) {
    if ((events & ENFORCE_COARSE_LOCATION_PERMISSION_MASK) != 0) {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
        if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
                callingPackage) != AppOpsManager.MODE_ALLOWED) {
            return false;
        }
    }

    if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
        if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
                mContext, subId, callingPackage, message)) {
            return false;
        }
    }

    if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.READ_PRECISE_PHONE_STATE, null);
    }

    if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null);
    }

    return true;
}