2828import android .app .NotificationManager ;
2929import android .content .Context ;
3030import android .content .SharedPreferences ;
31- import android .os .Build ;
3231import android .text .TextUtils ;
3332
3433import com .leanplum .internal .CollectionUtil ;
3534import com .leanplum .internal .Constants ;
3635import com .leanplum .internal .JsonConverter ;
3736import com .leanplum .internal .Log ;
3837import com .leanplum .internal .Util ;
38+ import com .leanplum .utils .BuildUtil ;
3939import com .leanplum .utils .SharedPreferencesUtil ;
4040
4141import org .json .JSONArray ;
4242
43- import java .util .ArrayList ;
4443import java .util .HashMap ;
4544import java .util .Iterator ;
4645import java .util .List ;
5453 */
5554@ TargetApi (26 )
5655class LeanplumNotificationChannel {
57- private static int targetSdk = -1 ;
5856
5957 /**
6058 * Configures notification channels.
@@ -359,7 +357,7 @@ private static void createNotificationChannel(Context context, String channelId,
359357 if (context == null || TextUtils .isEmpty (channelId )) {
360358 return ;
361359 }
362- if (isNotificationChannelSupported (context )) {
360+ if (BuildUtil . isNotificationChannelSupported (context )) {
363361 try {
364362 NotificationManager notificationManager =
365363 context .getSystemService (NotificationManager .class );
@@ -408,7 +406,7 @@ private static void deleteNotificationChannel(Context context, String channelId)
408406 if (context == null ) {
409407 return ;
410408 }
411- if (isNotificationChannelSupported (context )) {
409+ if (BuildUtil . isNotificationChannelSupported (context )) {
412410 try {
413411 NotificationManager notificationManager =
414412 (NotificationManager ) context .getSystemService (Context .NOTIFICATION_SERVICE );
@@ -451,7 +449,7 @@ private static void createNotificationGroup(Context context, String groupId, Str
451449 if (context == null || TextUtils .isEmpty (groupId )) {
452450 return ;
453451 }
454- if (isNotificationChannelSupported (context )) {
452+ if (BuildUtil . isNotificationChannelSupported (context )) {
455453 try {
456454 NotificationManager notificationManager =
457455 (NotificationManager ) context .getSystemService (Context .NOTIFICATION_SERVICE );
@@ -478,7 +476,7 @@ private static void deleteNotificationGroup(Context context, String groupId) {
478476 if (context == null || TextUtils .isEmpty (groupId )) {
479477 return ;
480478 }
481- if (isNotificationChannelSupported (context )) {
479+ if (BuildUtil . isNotificationChannelSupported (context )) {
482480 try {
483481 NotificationManager notificationManager =
484482 (NotificationManager ) context .getSystemService (Context .NOTIFICATION_SERVICE );
@@ -501,7 +499,7 @@ private static void deleteNotificationGroup(Context context, String groupId) {
501499 * @return Returns all notification channels belonging to the calling package.
502500 */
503501 static List <NotificationChannel > getNotificationChannels (Context context ) {
504- if (isNotificationChannelSupported (context )) {
502+ if (BuildUtil . isNotificationChannelSupported (context )) {
505503 NotificationManager notificationManager =
506504 (NotificationManager ) context .getSystemService (Context .NOTIFICATION_SERVICE );
507505 if (notificationManager == null ) {
@@ -520,7 +518,7 @@ static List<NotificationChannel> getNotificationChannels(Context context) {
520518 * @return Id of default notification channel.
521519 */
522520 static String getDefaultNotificationChannelId (Context context ) {
523- if (isNotificationChannelSupported (context )) {
521+ if (BuildUtil . isNotificationChannelSupported (context )) {
524522 return retrieveDefaultNotificationChannel (context );
525523 }
526524 return null ;
@@ -533,7 +531,7 @@ static String getDefaultNotificationChannelId(Context context) {
533531 * @return Returns all notification groups.
534532 */
535533 static List <NotificationChannelGroup > getNotificationGroups (Context context ) {
536- if (isNotificationChannelSupported (context )) {
534+ if (BuildUtil . isNotificationChannelSupported (context )) {
537535 NotificationManager notificationManager = (NotificationManager ) context .getSystemService (
538536 Context .NOTIFICATION_SERVICE );
539537 if (notificationManager == null ) {
@@ -545,29 +543,6 @@ static List<NotificationChannelGroup> getNotificationGroups(Context context) {
545543 return null ;
546544 }
547545
548- /**
549- * Whether notification channels are supported.
550- *
551- * @param context The application context.
552- * @return True if notification channels are supported, false otherwise.
553- */
554- static boolean isNotificationChannelSupported (Context context ) {
555- return Build .VERSION .SDK_INT >= 26 && getTargetSdkVersion (context ) >= 26 ;
556- }
557-
558- /**
559- * Returns target SDK version parsed from manifest.
560- *
561- * @param context The application context.
562- * @return Target SDK version.
563- */
564- private static int getTargetSdkVersion (Context context ) {
565- if (targetSdk == -1 && context != null ) {
566- targetSdk = context .getApplicationInfo ().targetSdkVersion ;
567- }
568- return targetSdk ;
569- }
570-
571546 /**
572547 * Helper class holding Notification Channel data parsed from JSON.
573548 */
0 commit comments