android.telephony.ServiceState Java Examples

The following examples show how to use android.telephony.ServiceState. 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 File: RetroWatchService.java    From retrowatch with Apache License 2.0 6 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState) {
	int state = serviceState.getState();
	
	switch (state) {
	case ServiceState.STATE_IN_SERVICE:
	case ServiceState.STATE_OUT_OF_SERVICE:
	case ServiceState.STATE_EMERGENCY_ONLY:
	case ServiceState.STATE_POWER_OFF:
		ContentObject co = mContentManager.addRFStateObject(state);
		if(mActivityHandler != null)
			mActivityHandler.obtainMessage(Constants.MESSAGE_RF_STATE_RECEIVED, co).sendToTarget();
		// send to device
		if(co != null)
			sendContentsToDevice(co);
		else
			deleteEmergencyOfDevice(EmergencyObject.EMERGENCY_TYPE_RF_STATE);
		break;
	}
}
 
Example #2
Source File: RetroWatchService.java    From retrowatch with Apache License 2.0 6 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState) {
	Logs.d("# PhoneStateListener - onServiceStateChanged();");
	int state = serviceState.getState();
	
	switch (state) {
	case ServiceState.STATE_IN_SERVICE:
		Logs.d("# PhoneStateListener - onServiceStateChanged(); - reserve update");
		reserveRemoteUpdate(DEFAULT_UPDATE_DELAY);
		break;
	case ServiceState.STATE_OUT_OF_SERVICE:
	case ServiceState.STATE_EMERGENCY_ONLY:
	case ServiceState.STATE_POWER_OFF:
		ContentObject co = mContentManager.addRFStateObject(state);
		if(mActivityHandler != null)
			mActivityHandler.obtainMessage(Constants.MESSAGE_RF_STATE_RECEIVED, co).sendToTarget();
		// send to device
		if(co != null)
			sendContentsToDevice(co);
		else
			deleteEmergencyOfDevice(EmergencyObject.EMERGENCY_TYPE_RF_STATE);
		break;
	}
}
 
Example #3
Source File: TelephonyRegistry.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
    long ident = Binder.clearCallingIdentity();
    try {
        mBatteryStats.notePhoneState(state.getState());
    } catch (RemoteException re) {
        // Can't do much
    } finally {
        Binder.restoreCallingIdentity(ident);
    }

    Intent intent = new Intent(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
    intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
    Bundle data = new Bundle();
    state.fillInNotifierBundle(data);
    intent.putExtras(data);
    // Pass the subscription along with the intent.
    intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
    intent.putExtra(PhoneConstants.SLOT_KEY, phoneId);
    mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
}
 
Example #4
Source File: LegacyGlobalActions.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState) {
    if (!mHasTelephony) return;
    final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
    mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
    mAirplaneModeOn.updateState(mAirplaneState);
    mAdapter.notifyDataSetChanged();
}
 
Example #5
Source File: PieController.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
public String getOperatorState() {
    if (!mHasTelephony) {
        return null;
    }
    if (mServiceState == null || mServiceState.getState() == ServiceState.STATE_OUT_OF_SERVICE) {
        return mGbResources.getString(R.string.pie_phone_status_no_service);
    }
    if (mServiceState.getState() == ServiceState.STATE_POWER_OFF) {
        return mGbResources.getString(R.string.pie_phone_status_airplane_mode);
    }
    if ((Boolean)XposedHelpers.callMethod(mServiceState, "isEmergencyOnly")) {
        return mGbResources.getString(R.string.pie_phone_status_emergency_only);
    }
    return mServiceState.getOperatorAlphaLong();
}
 
Example #6
Source File: HomeActivity.java    From apollo-DuerOS with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
protected void onCreate(Bundle savedInstanceState) {
    ScreenAdapter.getInstance().adaptDensity(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initView();

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (mLocationManager != null) {
        mLocationManager.addGpsStatusListener(mGpsStatusListener);
    }

    mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mReceiver, intentFilter);

    updateBlueToothStatus();

    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager != null) {
        telephonyManager.listen(new PhoneStateListener() {
            @Override
            public void onServiceStateChanged(ServiceState serviceState) {
                super.onServiceStateChanged(serviceState);
                updateNetworkStatus();
            }
        }, PhoneStateListener.LISTEN_SERVICE_STATE);
    }
}
 
Example #7
Source File: PhoneStateMonitor.java    From LibreTasks with Apache License 2.0 5 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState){      
  if (serviceState.getState() == ServiceState.STATE_IN_SERVICE ) {
    Intent intent = new Intent(ServiceAvailableEvent.ACTION_NAME);
    context.sendBroadcast(intent);
    serviceAvailable = true;
  } else {
    serviceAvailable = false;
  }
}
 
Example #8
Source File: ServiceStateAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public ServiceStateAssert(ServiceState actual) {
  super(actual, ServiceStateAssert.class);
}
 
Example #9
Source File: TelephonyServiceState.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState) {
  this.connected = (serviceState.getState() == ServiceState.STATE_IN_SERVICE);
  looper.quit();
}
 
Example #10
Source File: XTelephonyManager.java    From XPrivacy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState) {
	mListener.onServiceStateChanged(serviceState);
}
 
Example #11
Source File: GsmService.java    From Local-GSM-Backend with Apache License 2.0 4 votes vote down vote up
private void setServiceRunning(boolean st) {
    final boolean cur_st = (worker != null);

    if (cur_st  == st)
        return;

    if (st) {
        tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
        th = new TelephonyHelper(ctx);

        try {
            if (worker != null && worker.isAlive()) worker.interrupt();

            worker = new Thread() {

                public void run() {
                    if (DEBUG) Log.i(TAG, "Starting reporter thread");
                    Looper.prepare();

                    final PhoneStateListener listener = new PhoneStateListener() {
                        public void onServiceStateChanged(ServiceState serviceState) {
                            scanGsm("onServiceStateChanged: ");
                        }

                        public void onCellLocationChanged(CellLocation location) {
                            scanGsm("onCellLocationChanged: ");
                        }

                        public void onCellInfoChanged(List<android.telephony.CellInfo> cellInfo) {
                            scanGsm("onCellInfoChanged: ");
                        }
                    };
                    tm.listen(
                            listener,
                            PhoneStateListener.LISTEN_CELL_INFO |
                                    PhoneStateListener.LISTEN_CELL_LOCATION |
                                    PhoneStateListener.LISTEN_SERVICE_STATE
                    );
                    Looper.loop();
                }
            };
            worker.start();
        } catch (Exception e) {
            if (DEBUG) Log.e(TAG, "Start failed: " + e.getMessage());
            e.printStackTrace();
            worker = null;
        }
    } else {
        try {
            if (worker != null && worker.isAlive())
                worker.interrupt();

            if (worker != null)
                worker = null;

        } finally {
            worker = null;
        }
    }
}
 
Example #12
Source File: PhoneStateScanner.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@Override
public void onServiceStateChanged (ServiceState serviceState) {
    super.onServiceStateChanged(serviceState);

    //PPApplication.logE("PhoneStateScanner.onServiceStateChanged", "telephonyManager=" + telephonyManager);
    //CallsCounter.logCounter(context, "PhoneStateScanner.onServiceStateChanged", "PhoneStateScanner_onServiceStateChanged");

    final Context appContext = context.getApplicationContext();
    PPApplication.startHandlerThread(/*"PhoneStateScanner.onServiceStateChanged"*/);
    final Handler handler = new Handler(PPApplication.handlerThread.getLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            PowerManager powerManager = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE);
            PowerManager.WakeLock wakeLock = null;
            try {
                if (powerManager != null) {
                    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, PPApplication.PACKAGE_NAME + ":PhoneStateScanner_onServiceStateChanged");
                    wakeLock.acquire(10 * 60 * 1000);
                }

                //PPApplication.logE("PPApplication.startHandlerThread", "START run - from=PhoneStateScanner.onServiceStateChanged");

                getRegisteredCell();
                /*if (PPApplication.logEnabled()) {
                    if (isValidCellId(registeredCell))
                        PPApplication.logE("PhoneStateScanner.onServiceStateChanged", "registeredCell=" + registeredCell);
                    else
                        PPApplication.logE("PhoneStateScanner.onServiceStateChanged", "registeredCell=NOT valid");
                }*/

                //PPApplication.logE("[TEST BATTERY] PhoneStateScanner.onServiceStateChanged()", "xxx");
                handleEvents(/*appContext*/);

                //PPApplication.logE("PPApplication.startHandlerThread", "END run - from=PhoneStateScanner.onServiceStateChanged");
            } finally {
                if ((wakeLock != null) && wakeLock.isHeld()) {
                    try {
                        wakeLock.release();
                    } catch (Exception ignored) {
                    }
                }
            }
        }
    });
}
 
Example #13
Source File: ServiceRequirementProvider.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState) {
  if (serviceState.getState() == ServiceState.STATE_IN_SERVICE) {
    handleInService();
  }
}
 
Example #14
Source File: TelephonyServiceState.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState) {
  this.connected = (serviceState.getState() == ServiceState.STATE_IN_SERVICE);
  looper.quit();
}
 
Example #15
Source File: CellularDrawer.java    From meter with Apache License 2.0 4 votes vote down vote up
public CellularDrawer(final Context context){
    super(
            context,
            context.getResources().getColor(R.color.cellular_background),
            context.getResources().getColor(R.color.cellular_triangle_background),
            context.getResources().getColor(R.color.cellular_triangle_foreground),
            context.getResources().getColor(R.color.cellular_triangle_critical)
    );

    this.label1 = "Cellular";

    tManager = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
    setLabel2();

    tManager.listen(new PhoneStateListener(){
        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            super.onSignalStrengthsChanged(signalStrength);

            int level = 0;
            String tech = "";

            if( isAirplaneModeOn(context) ){
                percent = 0f;
                connected = false;
                label1 = "No connection";
                label2 = "Airplane Mode Enabled";
                return;
            }

            List<CellInfo> infos = null;

            try {
                infos = tManager.getAllCellInfo();
            } catch (SecurityException e){
                Log.e(TAG, e.toString());
            }

            if( infos == null ){
                connected = false;
                return;
            }

            for (final CellInfo info : infos) {
                if (info instanceof CellInfoWcdma) {
                    final CellSignalStrengthWcdma  wcdma = ((CellInfoWcdma) info).getCellSignalStrength();

                    if(level < wcdma.getLevel()) {
                        level = wcdma.getLevel();
                        tech = "wcdma";
                    }
                } else if (info instanceof CellInfoGsm) {
                    final CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();

                    if(level < gsm.getLevel()) {
                        level = gsm.getLevel();
                        tech = "gsm";
                    }
                } else if (info instanceof CellInfoCdma) {
                    final CellSignalStrengthCdma cdma = ((CellInfoCdma) info).getCellSignalStrength();

                    if(level < cdma.getLevel()) {
                        level = cdma.getLevel();
                        tech = "cdma";
                    }
                } else if (info instanceof CellInfoLte) {
                    final CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();

                    if(level < lte.getLevel()) {
                        level = lte.getLevel();
                        tech = "lte";
                    }

                }
            }

            connected = true;
            label1 = "Cellular";
            percent = (float) (level / 4.0);

            if (firstRead) {
                firstRead = false;
                _percent = (float) (percent - 0.001);
            }
        }

        @Override
        public void onServiceStateChanged(ServiceState serviceState) {
            super.onServiceStateChanged(serviceState);
            setLabel2();
            Log.d(TAG,"STATE "+String.valueOf(serviceState)+"   "+serviceState.getState());
        }
    },PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_SERVICE_STATE);

}
 
Example #16
Source File: MobileNetworkStateListener.java    From mobile-messaging-sdk-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState) {
    mobileNetworkChangeHandler.handleNetworkStateChange();
}
 
Example #17
Source File: MapViewerOsmDroid.java    From AIMSICDL with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState) {
    loadEntries();
}
 
Example #18
Source File: MapFragment.java    From AIMSICDL with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState) {
    loadEntries();
}
 
Example #19
Source File: CellTracker.java    From AIMSICDL with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState) {
    handle();
}
 
Example #20
Source File: TelephonyRegistry.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public void notifyServiceStateForPhoneId(int phoneId, int subId, ServiceState state) {
    if (!checkNotifyPermission("notifyServiceState()")){
        return;
    }

    synchronized (mRecords) {
        String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId
                + " state=" + state;
        if (VDBG) {
            log(str);
        }
        mLocalLog.log(str);
        if (validatePhoneId(phoneId)) {
            mServiceState[phoneId] = state;

            for (Record r : mRecords) {
                if (VDBG) {
                    log("notifyServiceStateForSubscriber: r=" + r + " subId=" + subId
                            + " phoneId=" + phoneId + " state=" + state);
                }
                if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_SERVICE_STATE) &&
                        idMatch(r.subId, subId, phoneId)) {
                    try {
                        if (DBG) {
                            log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
                                    + " subId=" + subId + " phoneId=" + phoneId
                                    + " state=" + state);
                        }
                        r.callback.onServiceStateChanged(new ServiceState(state));
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
        } else {
            log("notifyServiceStateForSubscriber: INVALID phoneId=" + phoneId);
        }
        handleRemoveListLocked();
    }
    broadcastServiceStateChanged(state, phoneId, subId);
}
 
Example #21
Source File: TelephonyRegistry.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
TelephonyRegistry(Context context) {
    CellLocation  location = CellLocation.getEmpty();

    mContext = context;
    mBatteryStats = BatteryStatsService.getService();

    int numPhones = TelephonyManager.getDefault().getPhoneCount();
    if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
    mNumPhones = numPhones;
    mCallState = new int[numPhones];
    mDataActivity = new int[numPhones];
    mDataConnectionState = new int[numPhones];
    mDataConnectionNetworkType = new int[numPhones];
    mCallIncomingNumber = new String[numPhones];
    mServiceState = new ServiceState[numPhones];
    mVoiceActivationState = new int[numPhones];
    mDataActivationState = new int[numPhones];
    mUserMobileDataState = new boolean[numPhones];
    mSignalStrength = new SignalStrength[numPhones];
    mMessageWaiting = new boolean[numPhones];
    mCallForwarding = new boolean[numPhones];
    mCellLocation = new Bundle[numPhones];
    mCellInfo = new ArrayList<List<CellInfo>>();
    mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
    for (int i = 0; i < numPhones; i++) {
        mCallState[i] =  TelephonyManager.CALL_STATE_IDLE;
        mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
        mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
        mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
        mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
        mCallIncomingNumber[i] =  "";
        mServiceState[i] =  new ServiceState();
        mSignalStrength[i] =  new SignalStrength();
        mUserMobileDataState[i] = false;
        mMessageWaiting[i] =  false;
        mCallForwarding[i] =  false;
        mCellLocation[i] = new Bundle();
        mCellInfo.add(i, null);
        mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
    }

    // Note that location can be null for non-phone builds like
    // like the generic one.
    if (location != null) {
        for (int i = 0; i < numPhones; i++) {
            location.fillInNotifierBundle(mCellLocation[i]);
        }
    }

    mAppOps = mContext.getSystemService(AppOpsManager.class);
}
 
Example #22
Source File: DataConnectionStats.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState state) {
    mServiceState = state;
    notePhoneDataConnectionState();
}
 
Example #23
Source File: DataConnectionStats.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private boolean hasService() {
    return mServiceState != null
            && mServiceState.getState() != ServiceState.STATE_OUT_OF_SERVICE
            && mServiceState.getState() != ServiceState.STATE_POWER_OFF;
}
 
Example #24
Source File: ServiceRequirementProvider.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState) {
  if (serviceState.getState() == ServiceState.STATE_IN_SERVICE) {
    handleInService();
  }
}
 
Example #25
Source File: TelephonyServiceState.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onServiceStateChanged(ServiceState serviceState) {
  this.connected = (serviceState.getState() == ServiceState.STATE_IN_SERVICE);
  looper.quit();
}
 
Example #26
Source File: DeviceInfoActivty.java    From PracticeDemo with Apache License 2.0 2 votes vote down vote up
/**
 * ServiceState.STATE_EMERGENCY_ONLY   仅限紧急呼叫
 * ServiceState.STATE_IN_SERVICE       信号正常
 * ServiceState.STATE_OUT_OF_SERVICE   不在服务区
 * ServiceState.STATE_POWER_OFF        断电
 */
@Override
public void onServiceStateChanged(ServiceState serviceState) {
    super.onServiceStateChanged(serviceState);
    Log.d(TAG, "onServiceStateChanged() called with " + "serviceState = [" + serviceState + "]");
}