Search in sources :

Example 1 with CommunicationNotificationHelper

use of com.genonbeta.TrebleShot.util.CommunicationNotificationHelper 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)

Aggregations

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 NsdDiscovery (com.genonbeta.TrebleShot.util.NsdDiscovery)1