mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Fix crash on LineageWeatherManagerService for some devices
This commit is contained in:
@@ -88,14 +88,15 @@ public class LineageWeatherManager {
|
||||
public static final int NO_MATCH_FOUND = -4;
|
||||
}
|
||||
|
||||
private LineageWeatherManager(Context context) {
|
||||
private LineageWeatherManager(Context context) throws Exception {
|
||||
Context appContext = context.getApplicationContext();
|
||||
mContext = (appContext != null) ? appContext : context;
|
||||
sWeatherManagerService = getService();
|
||||
|
||||
if (context.getPackageManager().hasSystemFeature(
|
||||
LineageContextConstants.Features.WEATHER_SERVICES) && (sWeatherManagerService == null)) {
|
||||
Log.wtf(TAG, "Unable to bind the LineageWeatherManagerService");
|
||||
// We replaced Log.wtf here, since it would crash some ROMs
|
||||
throw new Exception("Unable to bind the LineageWeatherManagerService");
|
||||
}
|
||||
mHandler = new Handler(appContext.getMainLooper());
|
||||
}
|
||||
@@ -107,7 +108,11 @@ public class LineageWeatherManager {
|
||||
*/
|
||||
public static LineageWeatherManager getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new LineageWeatherManager(context);
|
||||
try {
|
||||
sInstance = new LineageWeatherManager(context);
|
||||
} catch (final Exception e) {
|
||||
Log.e(TAG, "Unable to bind the LineageWeatherManagerService", e);
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
@@ -124,20 +129,14 @@ public class LineageWeatherManager {
|
||||
// This is a Gadgetbridge hack
|
||||
IBinder binder = null;
|
||||
try {
|
||||
Class localClass = Class.forName("android.os.ServiceManager");
|
||||
Class<?> localClass = Class.forName("android.os.ServiceManager");
|
||||
Method getService = localClass.getMethod("getService", String.class);
|
||||
Object result = getService.invoke(localClass, LineageContextConstants.LINEAGE_WEATHER_SERVICE);
|
||||
if (result != null) {
|
||||
binder = (IBinder) result;
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
|
||||
Log.d(TAG, "Failed to get lineageos weather service", e);
|
||||
}
|
||||
if (binder != null) {
|
||||
sWeatherManagerService = ILineageWeatherManager.Stub.asInterface(binder);
|
||||
|
||||
+5
-1
@@ -129,7 +129,11 @@ public class LineageOsWeatherReceiver extends BroadcastReceiver implements Linea
|
||||
}
|
||||
|
||||
private void requestWeather() {
|
||||
final LineageWeatherManager weatherManager = LineageWeatherManager.getInstance(GBApplication.getContext());
|
||||
final LineageWeatherManager weatherManager = LineageWeatherManager.getInstance(mContext);
|
||||
if (weatherManager == null) {
|
||||
LOG.warn("Unable to request weather - weatherManager is null");
|
||||
return;
|
||||
}
|
||||
if (weatherManager.getActiveWeatherServiceProviderLabel() != null && weatherLocation != null) {
|
||||
weatherManager.requestWeatherUpdate(weatherLocation, this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user