/*
- * Copyright (C) 2018 Tobias Brunner
+ * Copyright (C) 2018-2019 Tobias Brunner
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@TargetApi(Build.VERSION_CODES.N)
public class VpnTileService extends TileService implements VpnStateService.VpnStateListener
{
+ private boolean mListening;
private VpnProfileDataSource mDataSource;
private VpnStateService mService;
private final ServiceConnection mServiceConnection = new ServiceConnection()
public void onServiceConnected(ComponentName name, IBinder service)
{
mService = ((VpnStateService.LocalBinder)service).getService();
- if (mDataSource != null)
+ if (mListening && mDataSource != null)
{
mService.registerListener(VpnTileService.this);
updateTile();
Context context = getApplicationContext();
context.bindService(new Intent(context, VpnStateService.class),
mServiceConnection, Service.BIND_AUTO_CREATE);
+
+ mDataSource = new VpnProfileDataSource(this);
+ mDataSource.open();
}
@Override
{
getApplicationContext().unbindService(mServiceConnection);
}
+ mDataSource.close();
+ mDataSource = null;
}
@Override
public void onStartListening()
{
super.onStartListening();
-
- mDataSource = new VpnProfileDataSource(this);
- mDataSource.open();
+ mListening = true;
if (mService != null)
{
public void onStopListening()
{
super.onStopListening();
+ mListening = false;
if (mService != null)
{
mService.unregisterListener(this);
}
-
- mDataSource.close();
- mDataSource = null;
}
private VpnProfile getProfile()
{
uuid = pref.getString(Constants.PREF_MRU_VPN_PROFILE, null);
}
-
- return mDataSource.getVpnProfile(uuid);
+ return mDataSource != null ? mDataSource.getVpnProfile(uuid) : null;
}
@Override
{
profile = getProfile();
}
- else
+ else if (mDataSource != null)
{ /* always get the plain profile without cached password */
profile = mDataSource.getVpnProfile(profile.getId());
}