Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
55b7e95d
Unverified
Commit
55b7e95d
authored
8 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Update Tor assets if they're older than the APK.
#582
parent
36d15358
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-android/src/org/briarproject/plugins/tor/TorPlugin.java
+22
-42
22 additions, 42 deletions
...r-android/src/org/briarproject/plugins/tor/TorPlugin.java
with
22 additions
and
42 deletions
briar-android/src/org/briarproject/plugins/tor/TorPlugin.java
+
22
−
42
View file @
55b7e95d
...
...
@@ -4,6 +4,9 @@ import android.content.BroadcastReceiver;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.content.pm.PackageManager.NameNotFoundException
;
import
android.net.ConnectivityManager
;
import
android.net.NetworkInfo
;
import
android.os.FileObserver
;
...
...
@@ -150,16 +153,8 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
@Override
public
boolean
start
()
throws
IOException
{
if
(
used
.
getAndSet
(
true
))
throw
new
IllegalStateException
();
// Install the binary, possibly overwriting an older version
if
(!
installBinary
())
{
LOG
.
warning
(
"Could not install Tor binary"
);
return
false
;
}
// Install the GeoIP database and config file if necessary
if
(!
isConfigInstalled
()
&&
!
installConfig
())
{
LOG
.
warning
(
"Could not install Tor config"
);
return
false
;
}
// Install or update the assets if necessary
if
(!
assetsAreUpToDate
())
installAssets
();
LOG
.
info
(
"Starting Tor"
);
// Watch for the auth cookie file being updated
cookieFile
.
getParentFile
().
mkdirs
();
...
...
@@ -176,10 +171,8 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
Process
torProcess
;
try
{
torProcess
=
Runtime
.
getRuntime
().
exec
(
cmd
,
env
,
torDirectory
);
}
catch
(
SecurityException
e1
)
{
if
(
LOG
.
isLoggable
(
WARNING
))
LOG
.
log
(
WARNING
,
e1
.
toString
(),
e1
);
return
false
;
}
catch
(
SecurityException
e
)
{
throw
new
IOException
(
e
);
}
// Log the process's standard output until it detaches
if
(
LOG
.
isLoggable
(
INFO
))
{
...
...
@@ -201,7 +194,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
if
(
LOG
.
isLoggable
(
INFO
))
listFiles
(
torDirectory
);
return
false
;
}
}
catch
(
InterruptedException
e
1
)
{
}
catch
(
InterruptedException
e
)
{
LOG
.
warning
(
"Interrupted while starting Tor"
);
Thread
.
currentThread
().
interrupt
();
return
false
;
...
...
@@ -232,37 +225,27 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
return
true
;
}
private
boolean
installBinary
()
{
private
boolean
assetsAreUpToDate
()
{
try
{
PackageManager
pm
=
appContext
.
getPackageManager
();
PackageInfo
pi
=
pm
.
getPackageInfo
(
appContext
.
getPackageName
(),
0
);
return
doneFile
.
lastModified
()
>
pi
.
lastUpdateTime
;
}
catch
(
NameNotFoundException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
private
void
installAssets
()
throws
IOException
{
InputStream
in
=
null
;
OutputStream
out
=
null
;
try
{
doneFile
.
delete
();
// Unzip the Tor binary to the filesystem
in
=
getTorInputStream
();
out
=
new
FileOutputStream
(
torFile
);
copy
(
in
,
out
);
// Make the Tor binary executable
if
(!
torFile
.
setExecutable
(
true
,
true
))
{
LOG
.
warning
(
"Could not make Tor binary executable"
);
return
false
;
}
return
true
;
}
catch
(
IOException
e
)
{
if
(
LOG
.
isLoggable
(
WARNING
))
LOG
.
log
(
WARNING
,
e
.
toString
(),
e
);
tryToClose
(
in
);
tryToClose
(
out
);
return
false
;
}
}
private
boolean
isConfigInstalled
()
{
return
geoIpFile
.
exists
()
&&
configFile
.
exists
()
&&
doneFile
.
exists
();
}
private
boolean
installConfig
()
{
LOG
.
info
(
"Installing Tor config"
);
InputStream
in
=
null
;
OutputStream
out
=
null
;
try
{
if
(!
torFile
.
setExecutable
(
true
,
true
))
throw
new
IOException
();
// Unzip the GeoIP database to the filesystem
in
=
getGeoIpInputStream
();
out
=
new
FileOutputStream
(
geoIpFile
);
...
...
@@ -271,14 +254,11 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
in
=
getConfigInputStream
();
out
=
new
FileOutputStream
(
configFile
);
copy
(
in
,
out
);
// Create a file to indicate that installation succeeded
doneFile
.
createNewFile
();
return
true
;
}
catch
(
IOException
e
)
{
if
(
LOG
.
isLoggable
(
WARNING
))
LOG
.
log
(
WARNING
,
e
.
toString
(),
e
);
tryToClose
(
in
);
tryToClose
(
out
);
return
fals
e
;
throw
e
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment