Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Wade
DnsChanger
Commits
7ecdf734
Commit
7ecdf734
authored
Apr 09, 2018
by
Daniel Wolf
Browse files
Added NonNull/Nullable annotations
parent
ca3da938
Changes
8
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/frostnerd/dnschanger/database/DatabaseHelper.java
View file @
7ecdf734
...
...
@@ -3,6 +3,7 @@ package com.frostnerd.dnschanger.database;
import
android.content.Context
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
com.frostnerd.dnschanger.database.entities.DNSEntry
;
...
...
@@ -30,6 +31,7 @@ import java.util.Set;
public
class
DatabaseHelper
extends
com
.
frostnerd
.
utils
.
database
.
DatabaseHelper
{
public
static
final
String
DATABASE_NAME
=
"data"
;
public
static
final
int
DATABASE_VERSION
=
3
;
@NonNull
public
static
final
Set
<
Class
<?
extends
Entity
>>
entities
=
new
HashSet
<
Class
<?
extends
Entity
>>(){{
add
(
DNSEntry
.
class
);
add
(
DNSQuery
.
class
);
...
...
@@ -40,9 +42,10 @@ public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper
}};
@Nullable
private
static
DatabaseHelper
instance
;
@NonNull
private
MockedContext
wrappedContext
;
public
static
DatabaseHelper
getInstance
(
Context
context
){
public
static
DatabaseHelper
getInstance
(
@NonNull
Context
context
){
return
instance
==
null
?
instance
=
new
DatabaseHelper
(
mock
(
context
))
:
instance
;
}
...
...
@@ -50,7 +53,7 @@ public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper
return
instance
!=
null
;
}
private
DatabaseHelper
(
Context
context
)
{
private
DatabaseHelper
(
@NonNull
Context
context
)
{
super
(
context
,
DATABASE_NAME
,
DATABASE_VERSION
,
entities
);
wrappedContext
=
(
MockedContext
)
context
;
}
...
...
@@ -118,62 +121,63 @@ public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper
@Override
public
synchronized
void
close
()
{
instance
=
null
;
if
(
wrappedContext
!=
null
)
wrappedContext
.
destroy
(
false
);
wrappedContext
.
destroy
(
false
);
wrappedContext
=
null
;
super
.
close
();
}
public
boolean
dnsRuleExists
(
String
host
){
public
boolean
dnsRuleExists
(
@NonNull
String
host
){
return
this
.
rowExists
(
DNSRule
.
class
,
WhereCondition
.
equal
(
findColumn
(
DNSRule
.
class
,
"host"
),
host
));
}
public
boolean
dnsRuleExists
(
String
host
,
boolean
ipv6
){
public
boolean
dnsRuleExists
(
@NonNull
String
host
,
boolean
ipv6
){
return
this
.
rowExists
(
DNSRule
.
class
,
WhereCondition
.
equal
(
findColumn
(
DNSRule
.
class
,
"host"
),
host
),
WhereCondition
.
equal
(
findColumn
(
DNSRule
.
class
,
"ipv6"
),
ipv6
?
"1"
:
"0"
));
}
public
DNSRule
getDNSRule
(
String
host
,
boolean
ipv6
){
public
DNSRule
getDNSRule
(
@NonNull
String
host
,
boolean
ipv6
){
return
getSQLHandler
(
DNSRule
.
class
).
selectFirstRow
(
this
,
false
,
WhereCondition
.
equal
(
findColumn
(
DNSRule
.
class
,
"host"
),
host
),
WhereCondition
.
equal
(
findColumn
(
DNSRule
.
class
,
"ipv6"
),
ipv6
?
"1"
:
"0"
));
}
public
boolean
deleteDNSRule
(
String
host
,
boolean
ipv6
){
public
boolean
deleteDNSRule
(
@NonNull
String
host
,
boolean
ipv6
){
return
delete
(
DNSRule
.
class
,
WhereCondition
.
equal
(
findColumn
(
DNSRule
.
class
,
"host"
),
host
),
WhereCondition
.
equal
(
findColumn
(
DNSRule
.
class
,
"ipv6"
),
ipv6
?
"1"
:
"0"
))
!=
0
;
}
public
int
editDNSRule
(
String
host
,
boolean
ipv6
,
String
newTarget
){
public
int
editDNSRule
(
@NonNull
String
host
,
boolean
ipv6
,
@NonNull
String
newTarget
){
DNSRule
rule
=
getDNSRule
(
host
,
ipv6
);
rule
.
setTarget
(
newTarget
);
return
update
(
rule
);
}
public
void
createDNSRule
(
String
host
,
String
target
,
boolean
ipv6
,
boolean
wildcard
){
public
void
createDNSRule
(
@NonNull
String
host
,
@NonNull
String
target
,
boolean
ipv6
,
boolean
wildcard
){
insert
(
new
DNSRule
(
host
,
target
,
ipv6
,
wildcard
));
}
public
void
createShortcut
(
String
name
,
IPPortPair
dns1
,
IPPortPair
dns2
,
IPPortPair
dns1v6
,
IPPortPair
dns2v6
){
if
(
dns1
!=
null
)
insert
(
dns1
);
if
(
dns2
!=
null
)
insert
(
dns2
);
if
(
dns1v6
!=
null
)
insert
(
dns1v6
);
if
(
dns2v6
!=
null
)
insert
(
dns2v6
);
public
void
createShortcut
(
@NonNull
String
name
,
@NonNull
IPPortPair
dns1
,
@Nullable
IPPortPair
dns2
,
@NonNull
IPPortPair
dns1v6
,
@Nullable
IPPortPair
dns2v6
)
{
insert
(
dns1
);
if
(
dns2
!=
null
)
insert
(
dns2
);
insert
(
dns1v6
);
if
(
dns2v6
!=
null
)
insert
(
dns2v6
);
insert
(
new
Shortcut
(
name
,
dns1
,
dns2
,
dns1v6
,
dns2v6
));
}
p
ublic
void
createShortcut
(
Shortcut
shortcut
){
if
(
shortcut
.
getDns1
()
!=
null
)
insert
(
shortcut
.
getDns1
());
if
(
shortcut
.
getDns2
()
!=
null
)
insert
(
shortcut
.
getDns2
());
if
(
shortcut
.
getDns1v6
()
!=
null
)
insert
(
shortcut
.
getDns1v6
());
if
(
shortcut
.
getDns2v6
()
!=
null
)
insert
(
shortcut
.
getDns2v6
());
p
rivate
void
createShortcut
(
@NonNull
Shortcut
shortcut
)
{
insert
(
shortcut
.
getDns1
());
if
(
shortcut
.
getDns2
()
!=
null
)
insert
(
shortcut
.
getDns2
());
insert
(
shortcut
.
getDns1v6
());
if
(
shortcut
.
getDns2v6
()
!=
null
)
insert
(
shortcut
.
getDns2v6
());
insert
(
shortcut
);
}
@Nullable
public
DNSEntry
findMatchingDNSEntry
(
String
dnsServer
){
public
DNSEntry
findMatchingDNSEntry
(
@NonNull
String
dnsServer
){
String
address
=
"%"
+
dnsServer
+
"%"
;
if
(
address
.
equals
(
"%%"
))
return
null
;
ParsedEntity
<
DNSEntry
>
parsedEntity
=
getSQLHandler
(
DNSEntry
.
class
);
...
...
app/src/main/java/com/frostnerd/dnschanger/database/entities/DNSEntry.java
View file @
7ecdf734
package
com.frostnerd.dnschanger.database.entities
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
com.frostnerd.dnschanger.database.serializers.IPPortSerializer
;
import
com.frostnerd.utils.database.orm.MultitonEntity
;
...
...
@@ -18,30 +19,37 @@ public class DNSEntry extends MultitonEntity implements Comparable<DNSEntry>{
@Serialized
(
using
=
IPPortSerializer
.
class
)
@Named
(
name
=
"dns1"
)
@NotNull
@NonNull
private
IPPortPair
dns1
;
@Named
(
name
=
"dns2"
)
@Serialized
(
using
=
IPPortSerializer
.
class
)
@Nullable
private
IPPortPair
dns2
;
@Named
(
name
=
"dns1v6"
)
@Serialized
(
using
=
IPPortSerializer
.
class
)
@NotNull
@NonNull
private
IPPortPair
dns1V6
;
@Named
(
name
=
"dns2v6"
)
@Serialized
(
using
=
IPPortSerializer
.
class
)
@Nullable
private
IPPortPair
dns2V6
;
@Named
(
name
=
"name"
)
@NotNull
@Unique
@NonNull
private
String
name
;
@Named
(
name
=
"description"
)
@NonNull
private
String
description
;
@Named
(
name
=
"shortname"
)
@NonNull
private
String
shortName
;
@Named
(
name
=
"customentry"
)
...
...
@@ -104,7 +112,8 @@ public class DNSEntry extends MultitonEntity implements Comparable<DNSEntry>{
"Blocks access to all adult sites. Sites like Reddit are allowed. Google and Bing are set to the Safe Mode."
,
false
),
3
);
}
public
DNSEntry
(
String
name
,
String
shortName
,
IPPortPair
dns1
,
IPPortPair
dns2
,
IPPortPair
dns1V6
,
IPPortPair
dns2V6
,
String
description
,
boolean
customEntry
)
{
public
DNSEntry
(
@NonNull
String
name
,
@NonNull
String
shortName
,
@NonNull
IPPortPair
dns1
,
@Nullable
IPPortPair
dns2
,
@NonNull
IPPortPair
dns1V6
,
@Nullable
IPPortPair
dns2V6
,
@NonNull
String
description
,
boolean
customEntry
)
{
this
.
name
=
name
;
this
.
dns1
=
dns1
;
this
.
dns2
=
dns2
;
...
...
@@ -129,22 +138,27 @@ public class DNSEntry extends MultitonEntity implements Comparable<DNSEntry>{
IPPortPair
.
wrap
(
dns1V6
,
53
),
IPPortPair
.
wrap
(
dns2V6
,
53
),
description
,
customEntry
);
}
@NonNull
public
String
getName
()
{
return
name
;
}
@NonNull
public
IPPortPair
getDns1
()
{
return
dns1
;
}
@Nullable
public
IPPortPair
getDns2
()
{
return
dns2
;
}
@NonNull
public
IPPortPair
getDns1V6
()
{
return
dns1V6
;
}
@Nullable
public
IPPortPair
getDns2V6
()
{
return
dns2V6
;
}
...
...
@@ -153,10 +167,12 @@ public class DNSEntry extends MultitonEntity implements Comparable<DNSEntry>{
return
customEntry
;
}
@NonNull
public
String
getDescription
()
{
return
description
;
}
@NonNull
public
String
getShortName
()
{
return
shortName
;
}
...
...
@@ -165,31 +181,31 @@ public class DNSEntry extends MultitonEntity implements Comparable<DNSEntry>{
return
ID
;
}
public
void
setName
(
String
name
)
{
public
void
setName
(
@NonNull
String
name
)
{
this
.
name
=
name
;
}
public
void
setDns1
(
IPPortPair
dns1
)
{
public
void
setDns1
(
@NonNull
IPPortPair
dns1
)
{
this
.
dns1
=
dns1
;
}
public
void
setDns2
(
IPPortPair
dns2
)
{
public
void
setDns2
(
@Nullable
IPPortPair
dns2
)
{
this
.
dns2
=
dns2
;
}
public
void
setDns1V6
(
IPPortPair
dns1V6
)
{
public
void
setDns1V6
(
@NonNull
IPPortPair
dns1V6
)
{
this
.
dns1V6
=
dns1V6
;
}
public
void
setDns2V6
(
IPPortPair
dns2V6
)
{
public
void
setDns2V6
(
@Nullable
IPPortPair
dns2V6
)
{
this
.
dns2V6
=
dns2V6
;
}
public
void
setDescription
(
String
description
)
{
public
void
setDescription
(
@NonNull
String
description
)
{
this
.
description
=
description
;
}
public
void
setShortName
(
String
shortName
)
{
public
void
setShortName
(
@NonNull
String
shortName
)
{
this
.
shortName
=
shortName
;
}
...
...
@@ -217,7 +233,7 @@ public class DNSEntry extends MultitonEntity implements Comparable<DNSEntry>{
'}'
;
}
private
boolean
entryAddressMatches
(
String
ip
,
IPPortPair
pair
){
private
boolean
entryAddressMatches
(
@Nullable
String
ip
,
@Nullable
IPPortPair
pair
){
return
ip
!=
null
&&
pair
!=
null
&&
ip
.
equals
(
pair
.
getAddress
());
}
}
\ No newline at end of file
app/src/main/java/com/frostnerd/dnschanger/database/entities/DNSQuery.java
View file @
7ecdf734
package
com.frostnerd.dnschanger.database.entities
;
import
android.support.annotation.NonNull
;
import
com.frostnerd.utils.database.orm.MultitonEntity
;
import
com.frostnerd.utils.database.orm.annotations.Named
;
import
com.frostnerd.utils.database.orm.annotations.NotNull
;
import
com.frostnerd.utils.database.orm.annotations.PrimaryKey
;
import
com.frostnerd.utils.database.orm.annotations.Table
;
...
...
@@ -18,6 +21,8 @@ import com.frostnerd.utils.database.orm.annotations.Table;
public
class
DNSQuery
extends
MultitonEntity
{
@PrimaryKey
@Named
(
name
=
"Host"
)
@NonNull
@NotNull
private
String
host
;
@Named
(
name
=
"Ipv6"
)
private
boolean
ipv6
;
...
...
@@ -25,7 +30,7 @@ public class DNSQuery extends MultitonEntity {
@Named
(
name
=
"Time"
)
private
long
time
;
public
DNSQuery
(
String
host
,
boolean
ipv6
,
long
time
)
{
public
DNSQuery
(
@NonNull
String
host
,
boolean
ipv6
,
long
time
)
{
this
.
host
=
host
;
this
.
ipv6
=
ipv6
;
this
.
time
=
time
;
...
...
@@ -35,6 +40,7 @@ public class DNSQuery extends MultitonEntity {
}
@NonNull
public
String
getHost
()
{
return
host
;
}
...
...
app/src/main/java/com/frostnerd/dnschanger/database/entities/DNSRule.java
View file @
7ecdf734
package
com.frostnerd.dnschanger.database.entities
;
import
android.support.annotation.NonNull
;
import
com.frostnerd.utils.database.orm.MultitonEntity
;
import
com.frostnerd.utils.database.orm.annotations.Default
;
import
com.frostnerd.utils.database.orm.annotations.Named
;
...
...
@@ -21,9 +23,12 @@ import com.frostnerd.utils.database.orm.annotations.Table;
public
class
DNSRule
extends
MultitonEntity
{
@PrimaryKey
@Named
(
name
=
"Host"
)
@NonNull
@NotNull
private
String
host
;
@NotNull
@Named
(
name
=
"Target"
)
@NonNull
private
String
target
;
@PrimaryKey
@Named
(
name
=
"Ipv6"
)
...
...
@@ -39,17 +44,19 @@ public class DNSRule extends MultitonEntity{
}
public
DNSRule
(
String
host
,
String
target
,
boolean
ipv6
,
boolean
wildcard
)
{
public
DNSRule
(
@NonNull
String
host
,
@NonNull
String
target
,
boolean
ipv6
,
boolean
wildcard
)
{
this
.
host
=
host
;
this
.
target
=
target
;
this
.
ipv6
=
ipv6
;
this
.
wildcard
=
wildcard
;
}
@NonNull
public
String
getHost
()
{
return
host
;
}
@NonNull
public
String
getTarget
()
{
return
target
;
}
...
...
@@ -62,7 +69,7 @@ public class DNSRule extends MultitonEntity{
return
wildcard
;
}
public
void
setTarget
(
String
target
)
{
public
void
setTarget
(
@NonNull
String
target
)
{
this
.
target
=
target
;
}
...
...
app/src/main/java/com/frostnerd/dnschanger/database/entities/DNSRuleImport.java
View file @
7ecdf734
package
com.frostnerd.dnschanger.database.entities
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
com.frostnerd.utils.database.DatabaseHelper
;
import
com.frostnerd.utils.database.orm.MultitonEntity
;
import
com.frostnerd.utils.database.orm.annotations.ForeignKey
;
import
com.frostnerd.utils.database.orm.annotations.Named
;
import
com.frostnerd.utils.database.orm.annotations.NotNull
;
import
com.frostnerd.utils.database.orm.annotations.Table
;
...
...
@@ -19,6 +23,8 @@ import com.frostnerd.utils.database.orm.annotations.Table;
@Table
(
name
=
"DNSRuleImport"
)
public
class
DNSRuleImport
extends
MultitonEntity
{
@Named
(
name
=
"Filename"
)
@NonNull
@NotNull
private
String
filename
;
@Named
(
name
=
"Time"
)
private
long
time
;
...
...
@@ -29,7 +35,7 @@ public class DNSRuleImport extends MultitonEntity {
@Named
(
name
=
"LastInsert"
)
private
long
lastInsert
;
public
DNSRuleImport
(
String
filename
,
long
time
,
long
firstInsertRowID
,
long
lastInsertRowID
)
{
public
DNSRuleImport
(
@NonNull
String
filename
,
long
time
,
long
firstInsertRowID
,
long
lastInsertRowID
)
{
this
.
filename
=
filename
;
this
.
time
=
time
;
this
.
firstInsert
=
firstInsertRowID
;
...
...
@@ -40,6 +46,7 @@ public class DNSRuleImport extends MultitonEntity {
}
@NonNull
public
String
getFilename
()
{
return
filename
;
}
...
...
@@ -48,11 +55,13 @@ public class DNSRuleImport extends MultitonEntity {
return
time
;
}
public
DNSRule
getFirstInsert
(
DatabaseHelper
databaseHelper
)
{
@Nullable
public
DNSRule
getFirstInsert
(
@NonNull
DatabaseHelper
databaseHelper
)
{
return
databaseHelper
.
getByRowID
(
DNSRule
.
class
,
firstInsert
);
}
public
DNSRule
getLastInsert
(
DatabaseHelper
databaseHelper
)
{
@Nullable
public
DNSRule
getLastInsert
(
@NonNull
DatabaseHelper
databaseHelper
)
{
return
databaseHelper
.
getByRowID
(
DNSRule
.
class
,
firstInsert
);
}
...
...
app/src/main/java/com/frostnerd/dnschanger/database/entities/IPPortPair.java
View file @
7ecdf734
package
com.frostnerd.dnschanger.database.entities
;
import
android.support.annotation.NonNull
;
import
com.frostnerd.dnschanger.util.Util
;
import
com.frostnerd.utils.database.orm.MultitonEntity
;
import
com.frostnerd.utils.database.orm.annotations.Ignore
;
...
...
@@ -15,6 +17,7 @@ import lombok.Getter;
@Table
(
name
=
"IPPortPair"
)
public
class
IPPortPair
extends
MultitonEntity
implements
Serializable
{
@Named
(
name
=
"IP"
)
@NonNull
private
String
ip
;
@Named
(
name
=
"Port"
)
private
int
port
;
...
...
@@ -30,7 +33,7 @@ public class IPPortPair extends MultitonEntity implements Serializable{
}
public
IPPortPair
(
String
ip
,
int
port
,
boolean
IPv6
)
{
public
IPPortPair
(
@NonNull
String
ip
,
int
port
,
boolean
IPv6
)
{
if
(!
ip
.
equals
(
""
)
&&
(
port
<=
0
||
port
>
0xFFFF
))
throw
new
IllegalArgumentException
(
"Invalid port: "
+
port
+
" (Address: "
+
ip
+
")"
,
new
Throwable
(
"The invalid port "
+
port
+
" was supplied"
));
this
.
ip
=
ip
;
...
...
@@ -50,6 +53,7 @@ public class IPPortPair extends MultitonEntity implements Serializable{
return
Util
.
validateInput
(
s
,
s
.
contains
(
"["
)
||
s
.
matches
(
"[a-fA-F0-9:]+"
),
true
,
defPort
);
}
@NonNull
public
String
getAddress
()
{
return
ip
;
}
...
...
@@ -62,7 +66,7 @@ public class IPPortPair extends MultitonEntity implements Serializable{
return
ipv6
;
}
public
void
setIp
(
String
ip
)
{
public
void
setIp
(
@NonNull
String
ip
)
{
this
.
ip
=
ip
;
}
...
...
app/src/main/java/com/frostnerd/dnschanger/database/entities/Shortcut.java
View file @
7ecdf734
package
com.frostnerd.dnschanger.database.entities
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
com.frostnerd.utils.database.orm.MultitonEntity
;
import
com.frostnerd.utils.database.orm.annotations.Named
;
import
com.frostnerd.utils.database.orm.annotations.NotNull
;
...
...
@@ -10,9 +13,11 @@ import java.io.Serializable;
@Table
(
name
=
"Shortcut"
)
public
class
Shortcut
extends
MultitonEntity
implements
Serializable
{
@NotNull
@NonNull
@Named
(
name
=
"Dns1"
)
private
IPPortPair
dns1
;
@NotNull
@NonNull
@Named
(
name
=
"Dns1v6"
)
private
IPPortPair
dns1v6
;
@Named
(
name
=
"Dns2"
)
...
...
@@ -20,10 +25,11 @@ public class Shortcut extends MultitonEntity implements Serializable {
@Named
(
name
=
"Dns2v6"
)
private
IPPortPair
dns2v6
;
@NotNull
@NonNull
@Named
(
name
=
"Name"
)
private
String
name
;
public
Shortcut
(
String
name
,
IPPortPair
dns1
,
IPPortPair
dns2
,
IPPortPair
dns1v6
,
IPPortPair
dns2v6
)
{
public
Shortcut
(
@NonNull
String
name
,
@NonNull
IPPortPair
dns1
,
@Nullable
IPPortPair
dns2
,
@NonNull
IPPortPair
dns1v6
,
@Nullable
IPPortPair
dns2v6
)
{
this
.
dns1
=
dns1
;
this
.
dns2
=
dns2
;
this
.
dns1v6
=
dns1v6
;
...
...
@@ -35,22 +41,27 @@ public class Shortcut extends MultitonEntity implements Serializable {
}
@NonNull
public
IPPortPair
getDns1
()
{
return
dns1
;
}
@NonNull
public
IPPortPair
getDns1v6
()
{
return
dns1v6
;
}
@Nullable
public
IPPortPair
getDns2
()
{
return
dns2
;
}
@Nullable
public
IPPortPair
getDns2v6
()
{
return
dns2v6
;
}
@NonNull
public
String
getName
()
{
return
name
;
}
...
...
app/src/main/java/com/frostnerd/dnschanger/tasker/ConfigureActivity.java
View file @
7ecdf734
...
...
@@ -389,9 +389,9 @@ public class ConfigureActivity extends AppCompatActivity {
setResult
(
RESULT_OK
);
LogFactory
.
writeMessage
(
this
,
LOG_TAG
,
"Shortcut added to Launcher"
);
DatabaseHelper
.
getInstance
(
this
).
createShortcut
(
ed_name
.
getText
().
toString
(),
ipv4Enabled
?
dns1
:
null
,
dns1
,
!
TextUtils
.
isEmpty
(
dns2
.
getAddress
())
&&
ipv4Enabled
?
dns2
:
null
,
ipv6Enabled
?
dns1V6
:
null
,
dns1V6
,
!
TextUtils
.
isEmpty
(
dns2V6
.
getAddress
())
&&
ipv6Enabled
?
dns2V6
:
null
);
}
super
.
finish
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment