mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Remove redundant file and introduce cheaper isInternetHelperBound()
This commit is contained in:
committed by
Arjan Schrijver
parent
d928d00b44
commit
fa5e52013b
+2
-2
@@ -169,7 +169,7 @@ public class BangleJSCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
|
||||
@Override
|
||||
public boolean supportsAppsManagement(final GBDevice device) {
|
||||
return GBApplication.hasDirectInternetAccess() || InternetHelperSingleton.INSTANCE.ensureInternetHelperBound();
|
||||
return GBApplication.hasDirectInternetAccess() || InternetHelperSingleton.INSTANCE.isInternetHelperBound();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -233,7 +233,7 @@ public class BangleJSCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
|
||||
settings.add(R.xml.devicesettings_header_connection);
|
||||
settings.add(R.xml.devicesettings_high_mtu);
|
||||
if (GBApplication.hasDirectInternetAccess() || InternetHelperSingleton.INSTANCE.ensureInternetHelperBound())
|
||||
if (GBApplication.hasDirectInternetAccess() || InternetHelperSingleton.INSTANCE.isInternetHelperBound())
|
||||
settings.add(R.xml.devicesettings_device_internet_access);
|
||||
|
||||
settings.add(R.xml.devicesettings_banglejs_activity);
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/* Copyright (C) 2023 José Rebelo
|
||||
|
||||
This file is part of Gadgetbridge.
|
||||
|
||||
Gadgetbridge is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Gadgetbridge is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.network;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.util.GB.toast;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
public class InternetHelper {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(InternetHelper.class);
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
public InternetHelper(final Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return "nodomain.freeyourgadget.internethelper";
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return getPackageName() + ".INTERNET";
|
||||
}
|
||||
|
||||
public boolean requestPermissions(final Activity activity) {
|
||||
if (ActivityCompat.checkSelfPermission(mContext, getPermission()) != PackageManager.PERMISSION_GRANTED) {
|
||||
LOG.warn("No permission to access internet, requesting");
|
||||
ActivityCompat.requestPermissions(activity, new String[]{getPermission()}, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,10 @@ object InternetHelperSingleton {
|
||||
}
|
||||
}
|
||||
|
||||
fun isInternetHelperBound(): Boolean {
|
||||
return internetHelperBound
|
||||
}
|
||||
|
||||
fun ensureInternetHelperBound(): Boolean {
|
||||
val context = GBApplication.getContext()
|
||||
if (!internetHelperBound) {
|
||||
|
||||
Reference in New Issue
Block a user