Fix testcases with sdk 23: don't call Notificaton API during local tests
This commit is contained in:
parent
49c9b92020
commit
25ddc20f89
|
@ -11,6 +11,7 @@ import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -47,6 +48,9 @@ public class GB {
|
||||||
public static GBEnvironment environment;
|
public static GBEnvironment environment;
|
||||||
|
|
||||||
public static Notification createNotification(String text, Context context) {
|
public static Notification createNotification(String text, Context context) {
|
||||||
|
if (env().isLocalTest()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Intent notificationIntent = new Intent(context, ControlCenter.class);
|
Intent notificationIntent = new Intent(context, ControlCenter.class);
|
||||||
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
|
@ -54,7 +58,7 @@ public class GB {
|
||||||
notificationIntent, 0);
|
notificationIntent, 0);
|
||||||
|
|
||||||
return new NotificationCompat.Builder(context)
|
return new NotificationCompat.Builder(context)
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
// .setVisibility(Notification.VISIBILITY_PUBLIC)
|
||||||
.setContentTitle(context.getString(R.string.app_name))
|
.setContentTitle(context.getString(R.string.app_name))
|
||||||
.setTicker(text)
|
.setTicker(text)
|
||||||
.setContentText(text)
|
.setContentText(text)
|
||||||
|
@ -65,9 +69,15 @@ public class GB {
|
||||||
|
|
||||||
public static void updateNotification(String text, Context context) {
|
public static void updateNotification(String text, Context context) {
|
||||||
Notification notification = createNotification(text, context);
|
Notification notification = createNotification(text, context);
|
||||||
|
updateNotification(notification, NOTIFICATION_ID, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updateNotification(@Nullable Notification notification, int id, Context context) {
|
||||||
|
if (notification == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
nm.notify(NOTIFICATION_ID, notification);
|
nm.notify(id, notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setReceiversEnableState(boolean enable, Context context) {
|
public static void setReceiversEnableState(boolean enable, Context context) {
|
||||||
|
@ -293,9 +303,7 @@ public class GB {
|
||||||
|
|
||||||
public static void updateInstallNotification(String text, boolean ongoing, int percentage, Context context) {
|
public static void updateInstallNotification(String text, boolean ongoing, int percentage, Context context) {
|
||||||
Notification notification = createInstallNotification(text, ongoing, percentage, context);
|
Notification notification = createInstallNotification(text, ongoing, percentage, context);
|
||||||
|
updateNotification(notification, NOTIFICATION_ID_INSTALL, context);
|
||||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
||||||
nm.notify(NOTIFICATION_ID_INSTALL, notification);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Notification createBatteryNotification(String text, String bigText, Context context) {
|
private static Notification createBatteryNotification(String text, String bigText, Context context) {
|
||||||
|
@ -310,7 +318,7 @@ public class GB {
|
||||||
.setContentText(text)
|
.setContentText(text)
|
||||||
.setContentIntent(pendingIntent)
|
.setContentIntent(pendingIntent)
|
||||||
.setSmallIcon(R.drawable.ic_notification_low_battery)
|
.setSmallIcon(R.drawable.ic_notification_low_battery)
|
||||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
.setPriority(Notification.PRIORITY_HIGH)
|
||||||
.setOngoing(false);
|
.setOngoing(false);
|
||||||
|
|
||||||
if (bigText != null) {
|
if (bigText != null) {
|
||||||
|
@ -321,10 +329,11 @@ public class GB {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateBatteryNotification(String text, String bigText, Context context) {
|
public static void updateBatteryNotification(String text, String bigText, Context context) {
|
||||||
|
if (env().isLocalTest()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Notification notification = createBatteryNotification(text, bigText, context);
|
Notification notification = createBatteryNotification(text, bigText, context);
|
||||||
|
updateNotification(notification, NOTIFICATION_ID_LOW_BATTERY, context);
|
||||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
||||||
nm.notify(NOTIFICATION_ID_LOW_BATTERY, notification);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GBEnvironment env() {
|
public static GBEnvironment env() {
|
||||||
|
|
Loading…
Reference in New Issue