Skip to content

Commit 6351451

Browse files
committed
Fix foreground service
Fix CI
1 parent 3fe362b commit 6351451

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

play-services-base/core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.content.Context;
1212
import android.content.ContextWrapper;
1313
import android.content.Intent;
14+
import android.graphics.drawable.Icon;
1415
import android.net.Uri;
1516
import android.os.PowerManager;
1617
import android.provider.Settings;
@@ -41,12 +42,13 @@ public ComponentName startService(Intent service) {
4142
return super.startService(service);
4243
}
4344

44-
@RequiresApi(23)
4545
private boolean isIgnoringBatteryOptimizations() {
4646
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
4747
return powerManager.isIgnoringBatteryOptimizations(getPackageName());
4848
}
4949

50+
/** @noinspection deprecation*/
51+
@SuppressLint("DiscouragedApi")
5052
private static String getServiceName(Service service) {
5153
String serviceName = null;
5254
try {
@@ -81,7 +83,7 @@ public static void completeForegroundService(Service service, Intent intent, Str
8183
try {
8284
Notification notification = buildForegroundNotification(service, serviceName);
8385
service.startForeground(serviceName.hashCode(), notification);
84-
Log.d(tag, "Notification: " + notification.toString());
86+
Log.d(tag, "Notification: " + notification);
8587
} catch (Exception e) {
8688
Log.w(tag, e);
8789
}
@@ -130,8 +132,17 @@ private static Notification buildForegroundNotification(Context context, String
130132
);
131133

132134
// Notification actions
133-
Action batteryAction = new Action.Builder(R.drawable.ic_battery_action, context.getString(R.string.foreground_action_battery_optimization), batteryPendingIntent).build();
134-
Action notificationAction = new Action.Builder(R.drawable.ic_notification_action, context.getString(R.string.foreground_action_notification_settings), notificationCategoryPendingIntent).build();
135+
Action batteryAction = new Action.Builder(
136+
Icon.createWithResource(context, R.drawable.ic_battery_action),
137+
context.getString(R.string.foreground_action_battery_optimization),
138+
batteryPendingIntent
139+
).build();
140+
141+
Action notificationAction = new Action.Builder(
142+
Icon.createWithResource(context, R.drawable.ic_notification_action),
143+
context.getString(R.string.foreground_action_notification_settings),
144+
notificationCategoryPendingIntent
145+
).build();
135146

136147
Log.d(TAG, notifyTitle + " // " + firstLine + " // " + secondLine);
137148

@@ -143,11 +154,10 @@ private static Notification buildForegroundNotification(Context context, String
143154
.setStyle(new Notification.BigTextStyle().bigText(firstLine + "\n" + secondLine))
144155
.setPriority(Notification.PRIORITY_HIGH)
145156
.setShowWhen(false)
146-
.setFullScreenIntent(notificationCategoryPendingIntent, true)
157+
.setContentIntent(notificationCategoryPendingIntent)
147158
.setContentIntent(mainSettingsPendingIntent)
148159
.addAction(batteryAction)
149160
.addAction(notificationAction)
150161
.build();
151162
}
152-
153163
}

0 commit comments

Comments
 (0)