@Override public void onGpsStatusChanged(final int event) { switch (event) { case GpsStatus.GPS_EVENT_FIRST_FIX: case GpsStatus.GPS_EVENT_SATELLITE_STATUS: { final GpsStatus status = geoManager.getGpsStatus(null); int visible = 0; int fixed = 0; for (final GpsSatellite satellite : status.getSatellites()) { if (satellite.usedInFix()) { fixed++; } visible++; } if (visible == latest.satellitesVisible && fixed == latest.satellitesFixed) { return; } latest = new Status(true, visible, fixed); break; } case GpsStatus.GPS_EVENT_STARTED: latest = new Status(true, 0, 0); break; case GpsStatus.GPS_EVENT_STOPPED: latest = new Status(false, 0, 0); break; default: throw new IllegalStateException(); } subscriber.onNext(latest); }
public void onGpsStatusChanged(int event) { switch (event) { // 第一次定位 case GpsStatus.GPS_EVENT_FIRST_FIX: Log.i(TAG, "第一次定位"); break; // 卫星状态改变 case GpsStatus.GPS_EVENT_SATELLITE_STATUS: Log.i(TAG, "卫星状态改变"); // 获取当前状态 GpsStatus gpsStatus = lm.getGpsStatus(null); // 获取卫星颗数的默认最大值 int maxSatellites = gpsStatus.getMaxSatellites(); System.out.println("搜索到:" + maxSatellites + "颗卫星"); break; // 定位启动 case GpsStatus.GPS_EVENT_STARTED: // Log.i(TAG, "定位启动"); break; // 定位结束 case GpsStatus.GPS_EVENT_STOPPED: break; } };
/** * Tracks the current GPS status. Is called when the GPS is started, stopped, and receives * updates. */ @Override public void onGpsStatusChanged(int event) { // Count the current number of satellites in contact with the GPS GpsStatus status = mLocationManager.getGpsStatus(null); int count = 0; Iterable<GpsSatellite> sats = status.getSatellites(); for (Iterator<GpsSatellite> i = sats.iterator(); i.hasNext(); i.next()) { count++; } // If there are 3 or fewer satellites that we are connected, we've // probably lost GPS a lock if (count < 4) gpsWorking = false; }
/** * Used by {@link LocationManager#getGpsStatus} to copy LocationManager's cached GpsStatus * instance to the client's copy. Since this method is only used within {@link * LocationManager#getGpsStatus}, it does not need to be synchronized. */ void setStatus(GpsStatus status) { mTimeToFirstFix = status.getTimeToFirstFix(); for (int i = 0; i < mSatellites.length; i++) { mSatellites[i].setStatus(status.mSatellites[i]); } }
/** Called by {@link MainActivity} when the status of the GPS changes. Updates GPS display. */ public void onGpsStatusChanged( GpsStatus status, int satsInView, int satsUsed, Iterable<GpsSatellite> sats) { gpsSats.setText(String.valueOf(satsUsed) + "/" + String.valueOf(satsInView)); gpsTtff.setText(String.valueOf(status.getTimeToFirstFix() / 1000)); gpsStatusView.showSats(sats); gpsSnrView.showSats(sats); }
/** * Used by {@link LocationManager#getGpsStatus} to copy LocationManager's cached GpsStatus * instance to the client's copy. Since this method is only used within {@link * LocationManager#getGpsStatus}, it does not need to be synchronized. */ void setStatus(GpsStatus status) { mTimeToFirstFix = status.getTimeToFirstFix(); clearSatellites(); SparseArray<GpsSatellite> otherSatellites = status.mSatellites; int otherSatellitesCount = otherSatellites.size(); int satelliteIndex = 0; // merge both sparse arrays, note that we have already invalidated the elements in the // receiver array for (int i = 0; i < otherSatellitesCount; ++i) { GpsSatellite otherSatellite = otherSatellites.valueAt(i); int otherSatellitePrn = otherSatellite.getPrn(); int satellitesCount = mSatellites.size(); while (satelliteIndex < satellitesCount && mSatellites.valueAt(satelliteIndex).getPrn() < otherSatellitePrn) { ++satelliteIndex; } if (satelliteIndex < mSatellites.size()) { GpsSatellite satellite = mSatellites.valueAt(satelliteIndex); if (satellite.getPrn() == otherSatellitePrn) { satellite.setStatus(otherSatellite); } else { satellite = new GpsSatellite(otherSatellitePrn); satellite.setStatus(otherSatellite); mSatellites.put(otherSatellitePrn, satellite); } } else { GpsSatellite satellite = new GpsSatellite(otherSatellitePrn); satellite.setStatus(otherSatellite); mSatellites.append(otherSatellitePrn, satellite); } } }
public void onGpsStatusChanged(int state) { GpsStatus gpsStatus = locationManager.getGpsStatus(null); if (state == GpsStatus.GPS_EVENT_STOPPED) { hasFix = false; numSatellites = 0; updateSolution(LocationProvider.OUT_OF_SERVICE); } else if ((System.currentTimeMillis() - lastFixTimestamp) > 3000) { invalidateFix(); } if (state == GpsStatus.GPS_EVENT_STARTED) { // FIXME do what's needed updateSolution(LocationProvider.AVAILABLE); } gpsState = state; if (state == GpsStatus.GPS_EVENT_SATELLITE_STATUS && gpsStatus != null) { for (int j = 0; j < 36; j++) { /** Resetting all the satellites to non locked */ if ((satellites[j] != null)) { satellites[j].isLocked(false); } } Iterable<GpsSatellite> andSatellites = gpsStatus.getSatellites(); Iterator<GpsSatellite> sat = andSatellites.iterator(); int i = 0; while (sat.hasNext()) { GpsSatellite satellite = sat.next(); if (satellites[i] == null) { satellites[i] = new Satellite(); } if (i < 36) { satellites[i].isLocked(satellite.usedInFix()); satellites[i].id = i; satellites[i].azimut = satellite.getAzimuth(); satellites[i].elev = satellite.getElevation(); satellites[i].snr = (int) satellite.getSnr(); if (satellite.usedInFix()) { i++; } } } numSatellites = i; if (numSatellites > 0) { receiverList.receiveSatellites(satellites); } } // updateSolution(state); }
@Override public void onGpsStatusChanged(int event) { if (locationManager == null) return; android.location.GpsStatus gpsStatus = locationManager.getGpsStatus(null); if (gpsStatus == null) return; int cnt0 = 0, cnt1 = 0; Iterable<GpsSatellite> list = gpsStatus.getSatellites(); for (GpsSatellite satellite : list) { cnt0++; if (satellite.usedInFix()) { cnt1++; } } mKnownSatellites = cnt0; mUsedInLastFixSatellites = cnt1; if (listener != null) listener.onTick(); }
/////// GPS status callback public void onGpsStatusChanged(int status) { DataOutputStream file = fout[2]; long tim = System.currentTimeMillis(); // Get the status GpsStatus lStatus = null; lStatus = mLocMan.getGpsStatus(null); if (status == GpsStatus.GPS_EVENT_FIRST_FIX) { mLV.addtext("GPS_EVENT_FIRST_FIX - TTFX =" + lStatus.getTimeToFirstFix()); } else if (status == GpsStatus.GPS_EVENT_STARTED) { mLV.addtext("GPS_EVENT_STARTED " + tim); } else if (status == GpsStatus.GPS_EVENT_STOPPED) { mLV.addtext("GPS_EVENT_STOPPED " + tim); } if (lStatus != null) { if (file != null) { try { file.writeLong(tim); Iterable<GpsSatellite> satlist = lStatus.getSatellites(); for (GpsSatellite sat : satlist) { file.writeInt(sat.getPrn()); file.writeFloat(sat.getAzimuth()); file.writeFloat(sat.getElevation()); file.writeFloat(sat.getSnr()); file.writeBoolean(sat.hasAlmanac()); file.writeBoolean(sat.hasEphemeris()); file.writeBoolean(sat.usedInFix()); if (satlist.iterator().hasNext()) file.writeChar('@'); else file.writeChar('#'); } } catch (IOException e) { e.printStackTrace(); } } } }
/* (non-Javadoc) * @see android.location.GpsStatus.Listener#onGpsStatusChanged(int) */ @Override public void onGpsStatusChanged(final int event) { int satCount = -1; switch (event) { case GpsStatus.GPS_EVENT_FIRST_FIX: satCount = 0; break; case GpsStatus.GPS_EVENT_STARTED: satCount = -1; break; case GpsStatus.GPS_EVENT_STOPPED: satCount = -1; break; case GpsStatus.GPS_EVENT_SATELLITE_STATUS: // first of all we check if the time from the last used fix to the current fix is greater // than the logging interval if ((event != GpsStatus.GPS_EVENT_SATELLITE_STATUS) || (mLastGPSTimestamp + gpsLoggingInterval) < System.currentTimeMillis()) { mLastGPSTimestamp = System.currentTimeMillis(); // save the time of this fix final GpsStatus status = lmgr.getGpsStatus(null); // Count active satellites satCount = 0; for (@SuppressWarnings("unused") final GpsSatellite sat : status.getSatellites()) { satCount++; } } break; default: break; } if (mListener != null) { mListener.onSatInfo(satCount); } }
static String gpsToString(GpsStatus status, int eventType) { StringBuilder sb = new StringBuilder(); sb.append(eventType); sb.append("|ttff:"); sb.append(status.getTimeToFirstFix()); sb.append("|maxSatellites:"); sb.append(status.getMaxSatellites()); sb.append("|"); int i = 0; for (GpsSatellite sat : status.getSatellites()) { i++; sb.append("Satellite_"); sb.append(i); sb.append("::hasAlmanac:"); sb.append(sat.hasAlmanac()); sb.append("::hasEphemeris:"); sb.append(sat.hasEphemeris()); sb.append("::usedInFix:"); sb.append(sat.usedInFix()); sb.append("|"); } return sb.toString(); }
@Override protected void after(MethodHookParam param) throws Throwable { if (mMethod != Methods.addGeofence && mMethod != Methods.addNmeaListener && mMethod != Methods.addProximityAlert && mMethod != Methods.removeUpdates && mMethod != Methods.requestLocationUpdates && mMethod != Methods.requestSingleUpdate) if (mMethod == Methods.isProviderEnabled) { if (isRestricted(param)) param.setResult(false); } else if (mMethod == Methods.getGpsStatus) { if (param.getResult() != null && isRestricted(param)) { GpsStatus status = (GpsStatus) param.getResult(); // private GpsSatellite mSatellites[] try { Field mSatellites = status.getClass().getDeclaredField("mSatellites"); mSatellites.setAccessible(true); mSatellites.set(status, new GpsSatellite[0]); } catch (Throwable ex) { Util.bug(null, ex); } } } else if (mMethod == Methods.getLastLocation || mMethod == Methods.getLastKnownLocation) { Location location = (Location) param.getResult(); if (location != null && isRestricted(param)) param.setResult(PrivacyManager.getDefacedLocation(Binder.getCallingUid(), location)); } else if (mMethod == Methods.getProviders) { if (param.getResult() != null && isRestricted(param)) param.setResult(new ArrayList<String>()); } else if (mMethod == Methods.sendExtraCommand) { if (isRestricted(param)) param.setResult(false); } else Util.log(this, Log.WARN, "Unknown method=" + param.method.getName()); }
public void onGpsStatusChanged(int event) { switch (event) { case GpsStatus.GPS_EVENT_SATELLITE_STATUS: GpsStatus gpsStatus = mLocationManager.getGpsStatus(null); int satsInView = 0; int satsUsed = 0; Iterable<GpsSatellite> sats = gpsStatus.getSatellites(); for (GpsSatellite sat : sats) { satsInView++; if (sat.usedInFix()) { satsUsed++; } } satellite.setText(String.valueOf(satsUsed) + "/" + String.valueOf(satsInView)); if (satsUsed == 0) { fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_play)); data.setRunning(false); status.setText(""); stopService(new Intent(getBaseContext(), GpsServices.class)); fab.setVisibility(View.INVISIBLE); refresh.setVisibility(View.INVISIBLE); accuracy.setText(""); status.setText(getResources().getString(R.string.waiting_for_fix)); firstfix = true; } break; case GpsStatus.GPS_EVENT_STOPPED: if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { showGpsDisabledDialog(); } break; case GpsStatus.GPS_EVENT_FIRST_FIX: break; } }
private void showSats() { int satNum = 0; StringBuilder builder = new StringBuilder(); for (GpsSatellite sat : gps.getSatellites()) { builder.append("Satellite Data: "); builder.append("\nnumber: "); builder.append(satNum); builder.append("\nAzimuth: "); builder.append(sat.getAzimuth()); builder.append("\nElevation: "); builder.append(sat.getElevation()); builder.append("\nSNR: "); builder.append(sat.getSnr()); builder.append("\nUsed in fix?: "); builder.append(sat.usedInFix()); log("\n\n" + builder.toString()); builder.delete(0, builder.length()); satNum++; } }
public void onGpsStatusChanged(int event) { switch (event) { case GpsStatus.GPS_EVENT_SATELLITE_STATUS: boolean switchedAlready = switchToNetwork; status = locationManager.getGpsStatus(status); if (!switchToNetwork) { int sat_counter = 0; Iterator<GpsSatellite> it = status.getSatellites().iterator(); while (it.hasNext()) { it.next(); sat_counter++; } satsAvailable = sat_counter; if (firstFixReceived) { // If after a firstFix was received, we get less than 3 sats // available, we switch to network if (satsAvailable < GPS_AVAILABLE_SATS_INTERVAL_2_NUMBER) { switchToNetwork = true; } } else { timeInterval = System.currentTimeMillis() - startTime; if (timeInterval > GPS_AVAILABLE_SATS_INTERVAL_1) { // Check do we have enough satellites on wait interval 1 if (satsAvailable < GPS_AVAILABLE_SATS_INTERVAL_1_NUMBER) { switchToNetwork = true; } } if (timeInterval > GPS_AVAILABLE_SATS_INTERVAL_2) { // Check do we have enough satellites on wait interval 2 if (satsAvailable < GPS_AVAILABLE_SATS_INTERVAL_2_NUMBER) { switchToNetwork = true; } } if (timeInterval > GPS_AVAILABLE_SATS_INTERVAL_3) { // Check do we have enough satellites on wait interval 3 if (satsAvailable < GPS_AVAILABLE_SATS_INTERVAL_3_NUMBER) { switchToNetwork = true; } } if (timeInterval > GPS_FINAL_WAIT_INTERVAL) { // If we are unable to get the fix till now, we switch // to network anyway switchToNetwork = true; } } } if (!switchedAlready && switchToNetwork) { locationManager.removeUpdates(locationListener); if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, minTime, minDistance, locationListener); ((TextView) activity.findViewById(R.id.information)) .setText(R.string.geo_message_receiving_from_network); } else { Toast.makeText( activity.getApplicationContext(), R.string.gps_failed_network_disabled, Toast.LENGTH_LONG) .show(); openSettings(); } } break; case GpsStatus.GPS_EVENT_STARTED: startTime = System.currentTimeMillis(); switchToNetwork = false; firstFixReceived = false; break; case GpsStatus.GPS_EVENT_FIRST_FIX: firstFixReceived = true; break; } ((TextView) activity.findViewById(R.id.satscount)) .setText(activity.getText(R.string.geo_text_sats_available) + ": " + satsAvailable); ((TextView) activity.findViewById(R.id.time)) .setText( activity.getText(R.string.geo_text_wait) + ": " + Math.round(timeInterval / 1000) + " s"); }