Search in sources :

Example 1 with NsdDiscovery

use of com.genonbeta.TrebleShot.util.NsdDiscovery in project TrebleShot by genonbeta.

the class CommunicationService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mNotificationHelper = new CommunicationNotificationHelper(this);
    mDatabase = new AccessDatabase(this);
    mNsdDiscovery = new NsdDiscovery(getApplicationContext(), getDatabase());
    mMediaScanner = new MediaScannerConnection(this, null);
    mHotspotUtils = HotspotUtils.getInstance(this);
    mWifiLock = ((WifiManager) getApplicationContext().getSystemService(Service.WIFI_SERVICE)).createWifiLock(TAG);
    mReceive.setNotifyDelay(AppConfig.DEFAULT_NOTIFICATION_DELAY);
    mReceive.setBlockingObject(mBlockingObject);
    mSend.setNotifyDelay(AppConfig.DEFAULT_NOTIFICATION_DELAY);
    mSend.setBlockingObject(mBlockingObject);
    mMediaScanner.connect();
    mNsdDiscovery.registerService();
    if (getWifiLock() != null)
        getWifiLock().acquire();
    updateServiceState(getPreferences().getBoolean("trust_always", false));
    if (!AppUtils.checkRunningConditions(this) || !mCommunicationServer.start() || !mSeamlessServer.start())
        stopSelf();
    if (getHotspotUtils() instanceof HotspotUtils.OreoAPI && Build.VERSION.SDK_INT >= 26)
        ((HotspotUtils.OreoAPI) getHotspotUtils()).setSecondaryCallback(new WifiManager.LocalOnlyHotspotCallback() {

            @RequiresApi(api = Build.VERSION_CODES.O)
            @Override
            public void onStarted(WifiManager.LocalOnlyHotspotReservation reservation) {
                super.onStarted(reservation);
                sendHotspotStatus(reservation.getWifiConfiguration());
                if (getPreferences().getBoolean("hotspot_trust", false))
                    updateServiceState(true);
            }
        });
}
Also used : HotspotUtils(com.genonbeta.TrebleShot.util.HotspotUtils) NsdDiscovery(com.genonbeta.TrebleShot.util.NsdDiscovery) CommunicationNotificationHelper(com.genonbeta.TrebleShot.util.CommunicationNotificationHelper) AccessDatabase(com.genonbeta.TrebleShot.database.AccessDatabase) MediaScannerConnection(android.media.MediaScannerConnection)

Example 2 with NsdDiscovery

use of com.genonbeta.TrebleShot.util.NsdDiscovery in project TrebleShot by genonbeta.

the class NetworkDeviceListFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHotspotUtils = HotspotUtils.getInstance(getContext());
    mWifiManager = mHotspotUtils.getWifiManager();
    mConnectivityManager = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    mIntentFilter.addAction(DeviceScannerService.ACTION_SCAN_STARTED);
    mIntentFilter.addAction(CommunicationService.ACTION_HOTSPOT_STATUS);
    mIntentFilter.addAction(DeviceScannerService.ACTION_DEVICE_SCAN_COMPLETED);
    mIntentFilter.addAction(NetworkStatusReceiver.WIFI_AP_STATE_CHANGED);
    mIntentFilter.addAction(AccessDatabase.ACTION_DATABASE_CHANGE);
    mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    mNsdDiscovery = new NsdDiscovery(getContext(), getAdapter().getDatabase());
}
Also used : NsdDiscovery(com.genonbeta.TrebleShot.util.NsdDiscovery)

Aggregations

NsdDiscovery (com.genonbeta.TrebleShot.util.NsdDiscovery)2 MediaScannerConnection (android.media.MediaScannerConnection)1 AccessDatabase (com.genonbeta.TrebleShot.database.AccessDatabase)1 CommunicationNotificationHelper (com.genonbeta.TrebleShot.util.CommunicationNotificationHelper)1 HotspotUtils (com.genonbeta.TrebleShot.util.HotspotUtils)1