SmsReceiver extends BroadcastReceiver { public static boolean isSmsBackupDefaultSmsApp(@NonNull Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { RoleManager roleManager = (RoleManager) context.getSystemService(Context.ROLE_SERVICE); return (roleManager != null && roleManager.isRoleHeld(ROLE_SMS)); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return context.getPackageName().equals(Sms.getDefaultSmsPackage(context)); } else { return false; } }  @Override void onReceive(Context context, Intent intent); static boolean isSmsBackupDefaultSmsApp(@NonNull Context context); static void enable(Context context); static void disable(Context context);  }
@Test @Config(sdk = Build.VERSION_CODES.JELLY_BEAN) public void testIsSmsBackupDefaultSmsAppPreKitKat() { assertThat(SmsReceiver.isSmsBackupDefaultSmsApp(RuntimeEnvironment.application)).isFalse(); }
@Test @Config(sdk = Build.VERSION_CODES.KITKAT) public void testIsSmsBackupDefaultSmsAppKitKat() { assertThat(SmsReceiver.isSmsBackupDefaultSmsApp(RuntimeEnvironment.application)).isFalse(); }