Move some logic
This commit is contained in:
parent
3f28f51f93
commit
b1b5c7c731
|
@ -6,12 +6,12 @@ import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.telecom.TelecomManager;
|
import android.telecom.TelecomManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.internal.telephony.ITelephony;
|
import com.android.internal.telephony.ITelephony;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -21,8 +21,6 @@ import java.lang.reflect.Method;
|
||||||
|
|
||||||
import dummydomain.yetanothercallblocker.sia.DatabaseSingleton;
|
import dummydomain.yetanothercallblocker.sia.DatabaseSingleton;
|
||||||
import dummydomain.yetanothercallblocker.sia.model.NumberInfo;
|
import dummydomain.yetanothercallblocker.sia.model.NumberInfo;
|
||||||
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem;
|
|
||||||
import dummydomain.yetanothercallblocker.sia.model.database.FeaturedDatabaseItem;
|
|
||||||
|
|
||||||
public class CallReceiver extends BroadcastReceiver {
|
public class CallReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@ -58,7 +56,7 @@ public class CallReceiver extends BroadcastReceiver {
|
||||||
} else if (TelephonyManager.EXTRA_STATE_RINGING.equals(telephonyExtraState)) {
|
} else if (TelephonyManager.EXTRA_STATE_RINGING.equals(telephonyExtraState)) {
|
||||||
if (incomingNumber == null) return;
|
if (incomingNumber == null) return;
|
||||||
|
|
||||||
NumberInfo numberInfo = getNumberInfo(incomingNumber);
|
NumberInfo numberInfo = DatabaseSingleton.getNumberInfo(incomingNumber);
|
||||||
|
|
||||||
boolean blocked = false;
|
boolean blocked = false;
|
||||||
if (!isOnCall && numberInfo.rating == NumberInfo.Rating.NEGATIVE
|
if (!isOnCall && numberInfo.rating == NumberInfo.Rating.NEGATIVE
|
||||||
|
@ -77,41 +75,6 @@ public class CallReceiver extends BroadcastReceiver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NumberInfo getNumberInfo(String number) {
|
|
||||||
LOG.debug("getNumberInfo({}) started", number);
|
|
||||||
// TODO: check number format
|
|
||||||
|
|
||||||
CommunityDatabaseItem communityItem = DatabaseSingleton.getCommunityDatabase()
|
|
||||||
.getDbItemByNumber(number);
|
|
||||||
LOG.trace("getNumberInfo() communityItem={}", communityItem);
|
|
||||||
|
|
||||||
FeaturedDatabaseItem featuredItem = DatabaseSingleton.getFeaturedDatabase()
|
|
||||||
.getDbItemByNumber(number);
|
|
||||||
LOG.trace("getNumberInfo() featuredItem={}", featuredItem);
|
|
||||||
|
|
||||||
NumberInfo numberInfo = new NumberInfo();
|
|
||||||
numberInfo.number = number;
|
|
||||||
if (featuredItem != null) numberInfo.name = featuredItem.getName();
|
|
||||||
|
|
||||||
if (communityItem != null && communityItem.hasRatings()) {
|
|
||||||
if (communityItem.getNegativeRatingsCount() > communityItem.getPositiveRatingsCount()
|
|
||||||
+ communityItem.getNeutralRatingsCount()) {
|
|
||||||
numberInfo.rating = NumberInfo.Rating.NEGATIVE;
|
|
||||||
} else if (communityItem.getPositiveRatingsCount() > communityItem.getNeutralRatingsCount()
|
|
||||||
+ communityItem.getNegativeRatingsCount()) {
|
|
||||||
numberInfo.rating = NumberInfo.Rating.POSITIVE;
|
|
||||||
} else if (communityItem.getNeutralRatingsCount() > communityItem.getPositiveRatingsCount()
|
|
||||||
+ communityItem.getNegativeRatingsCount()) {
|
|
||||||
numberInfo.rating = NumberInfo.Rating.NEUTRAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
numberInfo.communityDatabaseItem = communityItem;
|
|
||||||
|
|
||||||
LOG.trace("getNumberInfo() rating={}", numberInfo.rating);
|
|
||||||
|
|
||||||
return numberInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
private boolean rejectCall(@NonNull Context context) {
|
private boolean rejectCall(@NonNull Context context) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
package dummydomain.yetanothercallblocker.sia;
|
package dummydomain.yetanothercallblocker.sia;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import dummydomain.yetanothercallblocker.sia.model.NumberInfo;
|
||||||
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabase;
|
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabase;
|
||||||
|
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem;
|
||||||
import dummydomain.yetanothercallblocker.sia.model.database.FeaturedDatabase;
|
import dummydomain.yetanothercallblocker.sia.model.database.FeaturedDatabase;
|
||||||
|
import dummydomain.yetanothercallblocker.sia.model.database.FeaturedDatabaseItem;
|
||||||
|
|
||||||
import static dummydomain.yetanothercallblocker.sia.SiaConstants.*;
|
import static dummydomain.yetanothercallblocker.sia.SiaConstants.*;
|
||||||
|
|
||||||
|
@ -10,6 +16,8 @@ public class DatabaseSingleton {
|
||||||
private static final CommunityDatabase COMMUNITY_DATABASE = new CommunityDatabase(SIA_PATH_PREFIX, SIA_SECONDARY_PATH_PREFIX);
|
private static final CommunityDatabase COMMUNITY_DATABASE = new CommunityDatabase(SIA_PATH_PREFIX, SIA_SECONDARY_PATH_PREFIX);
|
||||||
private static final FeaturedDatabase FEATURED_DATABASE = new FeaturedDatabase(SIA_PATH_PREFIX);
|
private static final FeaturedDatabase FEATURED_DATABASE = new FeaturedDatabase(SIA_PATH_PREFIX);
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(DatabaseSingleton.class);
|
||||||
|
|
||||||
public static CommunityDatabase getCommunityDatabase() {
|
public static CommunityDatabase getCommunityDatabase() {
|
||||||
return COMMUNITY_DATABASE;
|
return COMMUNITY_DATABASE;
|
||||||
}
|
}
|
||||||
|
@ -18,4 +26,39 @@ public class DatabaseSingleton {
|
||||||
return FEATURED_DATABASE;
|
return FEATURED_DATABASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static NumberInfo getNumberInfo(String number) {
|
||||||
|
LOG.debug("getNumberInfo({}) started", number);
|
||||||
|
// TODO: check number format
|
||||||
|
|
||||||
|
CommunityDatabaseItem communityItem = DatabaseSingleton.getCommunityDatabase()
|
||||||
|
.getDbItemByNumber(number);
|
||||||
|
LOG.trace("getNumberInfo() communityItem={}", communityItem);
|
||||||
|
|
||||||
|
FeaturedDatabaseItem featuredItem = DatabaseSingleton.getFeaturedDatabase()
|
||||||
|
.getDbItemByNumber(number);
|
||||||
|
LOG.trace("getNumberInfo() featuredItem={}", featuredItem);
|
||||||
|
|
||||||
|
NumberInfo numberInfo = new NumberInfo();
|
||||||
|
numberInfo.number = number;
|
||||||
|
if (featuredItem != null) numberInfo.name = featuredItem.getName();
|
||||||
|
|
||||||
|
if (communityItem != null && communityItem.hasRatings()) {
|
||||||
|
if (communityItem.getNegativeRatingsCount() > communityItem.getPositiveRatingsCount()
|
||||||
|
+ communityItem.getNeutralRatingsCount()) {
|
||||||
|
numberInfo.rating = NumberInfo.Rating.NEGATIVE;
|
||||||
|
} else if (communityItem.getPositiveRatingsCount() > communityItem.getNeutralRatingsCount()
|
||||||
|
+ communityItem.getNegativeRatingsCount()) {
|
||||||
|
numberInfo.rating = NumberInfo.Rating.POSITIVE;
|
||||||
|
} else if (communityItem.getNeutralRatingsCount() > communityItem.getPositiveRatingsCount()
|
||||||
|
+ communityItem.getNegativeRatingsCount()) {
|
||||||
|
numberInfo.rating = NumberInfo.Rating.NEUTRAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
numberInfo.communityDatabaseItem = communityItem;
|
||||||
|
|
||||||
|
LOG.trace("getNumberInfo() rating={}", numberInfo.rating);
|
||||||
|
|
||||||
|
return numberInfo;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue