@Override public Intent getInitIntent() throws RemoteException { return LocationBackendService.this.getInitIntent(); }
@Override public void disconnect() { if (callback != null) { onClose(); callback = null; } }
@Override public void close() throws RemoteException { disconnect(); }
@Override public void open(LocationCallback callback) throws RemoteException { LocationBackendService.this.callback = callback; if (waiting != null) { callback.report(waiting); waiting = null; } onOpen(); }
@Override public Intent getAboutIntent() throws RemoteException { return LocationBackendService.this.getAboutIntent(); } }
@Override public Intent getSettingsIntent() throws RemoteException { return LocationBackendService.this.getSettingsIntent(); }
@Override public Location update() throws RemoteException { return LocationBackendService.this.update(); }
@Override public void onCreate() { //Log.d(TAG, "onCreate() entry."); super.onCreate(); nullIsland.setLatitude(0.0); nullIsland.setLongitude(0.0); }
@Override protected void onOpen() { super.onOpen(); regular = new Thread(new Runnable() { @Override public void run() { synchronized (regular) { while (!regular.isInterrupted()) { try { regular.wait(60000); } catch (InterruptedException e) { return; } Location location = LocationHelper.create("random", random.nextDouble() * 90, random.nextDouble() * 90, random.nextFloat() * 90); Log.d(TAG, "Just reported: " + location); report(location); } } } }); regular.start(); }
/** * We are starting to run, get the resources we need to do our job. */ @Override protected void onOpen() { Log.d(TAG, "onOpen() entry."); super.onOpen(); instance = this; nextReportTime = 0; nextMobileScanTime = 0; nextWlanScanTime = 0; wifiBroadcastReceiverRegistered = false; wifiScanInprogress = false; if (emitterCache == null) emitterCache = new Cache(this); permissionsOkay = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Check our needed permissions, don't run unless we can. for (String s : myPerms) { permissionsOkay &= (checkSelfPermission(s) == PackageManager.PERMISSION_GRANTED); } } if (permissionsOkay) { setgpsMonitorRunning(true); this.registerReceiver(wifiBroadcastReceiver, wifiBroadcastFilter); wifiBroadcastReceiverRegistered = true; } else { Log.d(TAG, "onOpen() - Permissions not granted, soft fail."); } }
/** * Called by MicroG/UnifiedNlp when our backend is enabled. We return a list of * the Android permissions we need but have not (yet) been granted. MicroG will * handle putting up the dialog boxes, etc. to get our permissions granted. * * @return An intent with the list of permissions we need to run. */ @Override protected Intent getInitIntent() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Build list of permissions we need but have not been granted List<String> perms = new LinkedList<>(); for (String s : myPerms) { if (checkSelfPermission(s) != PackageManager.PERMISSION_GRANTED) perms.add(s); } // Send the list of permissions we need to UnifiedNlp so it can ask for // them to be granted. if (perms.isEmpty()) return null; Intent intent = new Intent(this, MPermissionHelperActivity.class); intent.putExtra(MPermissionHelperActivity.EXTRA_PERMISSIONS, perms.toArray(new String[perms.size()])); return intent; } return super.getInitIntent(); }
/** * Closing down, release our dynamic resources. */ @Override protected synchronized void onClose() { super.onClose(); Log.d(TAG, "onClose()"); if (wifiBroadcastReceiverRegistered) { this.unregisterReceiver(wifiBroadcastReceiver); } setgpsMonitorRunning(false); if (emitterCache != null) { emitterCache.close(); emitterCache = null; } if (instance == this) { instance = null; } }
@Override protected Intent getInitIntent() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Consider permissions List<String> perms = new LinkedList<String>(); for (AbstractBackendHelper helper : helpers) { perms.addAll(Arrays.asList(helper.getRequiredPermissions())); } for (Iterator<String> iterator = perms.iterator(); iterator.hasNext(); ) { String perm = iterator.next(); if (checkSelfPermission(perm) == PackageManager.PERMISSION_GRANTED) { iterator.remove(); } } if (perms.isEmpty()) return null; Intent intent = new Intent(this, MPermissionHelperActivity.class); intent.putExtra(MPermissionHelperActivity.EXTRA_PERMISSIONS, perms.toArray(new String[perms.size()])); return intent; } return super.getInitIntent(); } }