@ -41,7 +41,6 @@ import org.apache.commons.io.FileUtils
import timber.log.Timber
import timber.log.Timber
import java.io.File
import java.io.File
import java.io.IOException
import java.io.IOException
import java.sql.Timestamp
import java.util.Objects
import java.util.Objects
class SetupActivity : AppCompatActivity ( ) , LanguageActivity {
class SetupActivity : AppCompatActivity ( ) , LanguageActivity {
@ -69,27 +68,7 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
}
}
val binding = ActivitySetupBinding . inflate ( layoutInflater )
val binding = ActivitySetupBinding . inflate ( layoutInflater )
setContentView ( binding . root )
setContentView ( binding . root )
val ts = Timestamp ( System . currentTimeMillis ( ) - 30L * 24 * 60 * 60 * 1000 )
MainApplication . getInstance ( ) . check ( this )
val buildTime = Timestamp ( BuildConfig . BUILD _TIME )
if ( BuildConfig . DEBUG ) {
if ( ts . time > buildTime . time ) {
val pm = packageManager
val intent = Intent ( this , ExpiredActivity :: class . java )
val resolveInfo = pm . queryIntentActivities ( intent , 0 )
if ( resolveInfo . size > 0 ) {
startActivity ( intent )
finish ( )
return
} else {
throw IllegalAccessError ( " This build has expired " )
}
}
} else {
val ts2 = Timestamp ( System . currentTimeMillis ( ) - 180L * 24 * 60 * 60 * 1000 )
if ( ts2 . time > buildTime . time ) {
Toast . makeText ( this , R . string . build _expired , Toast . LENGTH _LONG ) . show ( )
}
}
val view : View = binding . root
val view : View = binding . root
// if our application id is "com.androidacy.mmm" or begins with it, check if com.fox2code.mmm is installed and offer to uninstall it. if we're com.fox2code.mmm, check if com.fox2code.mmm.fdroid or com.fox2code.mmm.debug is installed and offer to uninstall it
// if our application id is "com.androidacy.mmm" or begins with it, check if com.fox2code.mmm is installed and offer to uninstall it. if we're com.fox2code.mmm, check if com.fox2code.mmm.fdroid or com.fox2code.mmm.debug is installed and offer to uninstall it
val ourPackageName = BuildConfig . APPLICATION _ID
val ourPackageName = BuildConfig . APPLICATION _ID
@ -112,7 +91,12 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
if ( packageName == foxPkgNameDebug || packageName == foxPkgNameFdroid || packageName == foxPkgNamePlay ) {
if ( packageName == foxPkgNameDebug || packageName == foxPkgNameFdroid || packageName == foxPkgNamePlay ) {
val materialAlertDialogBuilder = MaterialAlertDialogBuilder ( this )
val materialAlertDialogBuilder = MaterialAlertDialogBuilder ( this )
materialAlertDialogBuilder . setTitle ( R . string . setup _uninstall _title )
materialAlertDialogBuilder . setTitle ( R . string . setup _uninstall _title )
materialAlertDialogBuilder . setMessage ( getString ( R . string . setup _uninstall _message , packageName ) )
materialAlertDialogBuilder . setMessage (
getString (
R . string . setup _uninstall _message ,
packageName
)
)
materialAlertDialogBuilder . setPositiveButton ( R . string . uninstall ) { _ : DialogInterface ? , _ : Int ->
materialAlertDialogBuilder . setPositiveButton ( R . string . uninstall ) { _ : DialogInterface ? , _ : Int ->
// start uninstall intent
// start uninstall intent
val intent = Intent ( Intent . ACTION _DELETE )
val intent = Intent ( Intent . ACTION _DELETE )
@ -122,11 +106,17 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
materialAlertDialogBuilder . setNegativeButton ( R . string . cancel ) { _ : DialogInterface ? , _ : Int -> }
materialAlertDialogBuilder . setNegativeButton ( R . string . cancel ) { _ : DialogInterface ? , _ : Int -> }
}
}
}
}
androidacyPkgName -> {
androidacyPkgName -> {
if ( packageName == foxPkgName || packageName == foxPkgNameFdroid || packageName == foxPkgNameDebug || packageName == foxPkgNamePlay ) {
if ( packageName == foxPkgName || packageName == foxPkgNameFdroid || packageName == foxPkgNameDebug || packageName == foxPkgNamePlay ) {
val materialAlertDialogBuilder = MaterialAlertDialogBuilder ( this )
val materialAlertDialogBuilder = MaterialAlertDialogBuilder ( this )
materialAlertDialogBuilder . setTitle ( R . string . setup _uninstall _title )
materialAlertDialogBuilder . setTitle ( R . string . setup _uninstall _title )
materialAlertDialogBuilder . setMessage ( getString ( R . string . setup _uninstall _message , packageName ) )
materialAlertDialogBuilder . setMessage (
getString (
R . string . setup _uninstall _message ,
packageName
)
)
materialAlertDialogBuilder . setPositiveButton ( R . string . uninstall ) { _ : DialogInterface ? , _ : Int ->
materialAlertDialogBuilder . setPositiveButton ( R . string . uninstall ) { _ : DialogInterface ? , _ : Int ->
// start uninstall intent
// start uninstall intent
val intent = Intent ( Intent . ACTION _DELETE )
val intent = Intent ( Intent . ACTION _DELETE )
@ -136,11 +126,17 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
materialAlertDialogBuilder . setNegativeButton ( R . string . cancel ) { _ : DialogInterface ? , _ : Int -> }
materialAlertDialogBuilder . setNegativeButton ( R . string . cancel ) { _ : DialogInterface ? , _ : Int -> }
}
}
}
}
else -> {
else -> {
if ( packageName == foxPkgNameDebug ) {
if ( packageName == foxPkgNameDebug ) {
val materialAlertDialogBuilder = MaterialAlertDialogBuilder ( this )
val materialAlertDialogBuilder = MaterialAlertDialogBuilder ( this )
materialAlertDialogBuilder . setTitle ( R . string . setup _uninstall _title )
materialAlertDialogBuilder . setTitle ( R . string . setup _uninstall _title )
materialAlertDialogBuilder . setMessage ( getString ( R . string . setup _uninstall _message , packageName ) )
materialAlertDialogBuilder . setMessage (
getString (
R . string . setup _uninstall _message ,
packageName
)
)
materialAlertDialogBuilder . setPositiveButton ( R . string . uninstall ) { _ : DialogInterface ? , _ : Int ->
materialAlertDialogBuilder . setPositiveButton ( R . string . uninstall ) { _ : DialogInterface ? , _ : Int ->
// start uninstall intent
// start uninstall intent
val intent = Intent ( Intent . ACTION _DELETE )
val intent = Intent ( Intent . ACTION _DELETE )
@ -157,8 +153,7 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
val setupCrashReporting = view . findViewById < MaterialSwitch > ( R . id . setup _crash _reporting )
val setupCrashReporting = view . findViewById < MaterialSwitch > ( R . id . setup _crash _reporting )
val analyticsEnabled = view . findViewById < MaterialSwitch > ( R . id . setup _app _analytics )
val analyticsEnabled = view . findViewById < MaterialSwitch > ( R . id . setup _app _analytics )
val crashReportingPii = view . findViewById < MaterialSwitch > ( R . id . setup _crash _reporting _pii )
val crashReportingPii = view . findViewById < MaterialSwitch > ( R . id . setup _crash _reporting _pii )
setupCrashReporting . isChecked =
setupCrashReporting . isChecked = BuildConfig . DEFAULT _ENABLE _CRASH _REPORTING
BuildConfig . DEFAULT _ENABLE _CRASH _REPORTING
// if analytics is disabled, force disable crash reporting
// if analytics is disabled, force disable crash reporting
if ( ! view . findViewById < MaterialSwitch > ( R . id . setup _app _analytics ) . isChecked ) {
if ( ! view . findViewById < MaterialSwitch > ( R . id . setup _app _analytics ) . isChecked ) {
setupCrashReporting . isEnabled = false
setupCrashReporting . isEnabled = false
@ -167,20 +162,20 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
crashReportingPii . isChecked = false
crashReportingPii . isChecked = false
}
}
// switch summary for setup_app_analytics_summary
// switch summary for setup_app_analytics_summary
val setupAppAnalyticsSummary = view . findViewById < MaterialTextView > ( R . id . setup _app _analytics _summary )
val setupAppAnalyticsSummary =
view . findViewById < MaterialTextView > ( R . id . setup _app _analytics _summary )
// listen for changes to the analytics switch
// listen for changes to the analytics switch
analyticsEnabled . setOnCheckedChangeListener { _ : CompoundButton ? , isChecked : Boolean ->
analyticsEnabled . setOnCheckedChangeListener { _ : CompoundButton ? , isChecked : Boolean ->
if ( BuildConfig . DEBUG ) Timber . i (
if ( BuildConfig . DEBUG ) Timber . i (
" Analytics: %s " ,
" Analytics: %s " , isChecked
isChecked )
)
// if analytics is disabled, force disable crash reporting
// if analytics is disabled, force disable crash reporting
if ( !is Checked ) {
if ( !is Checked ) {
setupCrashReporting . isChecked = false
setupCrashReporting . isChecked = false
setupCrashReporting . isEnabled = false
setupCrashReporting . isEnabled = false
} else {
} else {
setupCrashReporting . isEnabled = true
setupCrashReporting . isEnabled = true
setupCrashReporting . isChecked =
setupCrashReporting . isChecked = BuildConfig . DEFAULT _ENABLE _CRASH _REPORTING
BuildConfig . DEFAULT _ENABLE _CRASH _REPORTING
}
}
if ( !is Checked ) {
if ( !is Checked ) {
setupAppAnalyticsSummary . setText ( R . string . analytics _disabled _desc )
setupAppAnalyticsSummary . setText ( R . string . analytics _disabled _desc )
@ -189,8 +184,7 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
}
}
}
}
// pref_analytics_enabled
// pref_analytics_enabled
analyticsEnabled . isChecked =
analyticsEnabled . isChecked = BuildConfig . DEFAULT _ENABLE _ANALYTICS
BuildConfig . DEFAULT _ENABLE _ANALYTICS
// Repos are a little harder, as the enabled_repos build config is an arraylist
// Repos are a little harder, as the enabled_repos build config is an arraylist
val andRepoView =
val andRepoView =
Objects . requireNonNull < Any > ( view . findViewById ( R . id . setup _androidacy _repo ) ) as MaterialSwitch
Objects . requireNonNull < Any > ( view . findViewById ( R . id . setup _androidacy _repo ) ) as MaterialSwitch
@ -202,32 +196,27 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
if ( BuildConfig . DEBUG ) {
if ( BuildConfig . DEBUG ) {
( Objects . requireNonNull < Any > ( view . findViewById ( R . id . setup _background _update _check ) ) as MaterialSwitch ) . setOnCheckedChangeListener { _ : CompoundButton ? , isChecked : Boolean ->
( Objects . requireNonNull < Any > ( view . findViewById ( R . id . setup _background _update _check ) ) as MaterialSwitch ) . setOnCheckedChangeListener { _ : CompoundButton ? , isChecked : Boolean ->
if ( MainApplication . forceDebugLogging ) Timber . i (
if ( MainApplication . forceDebugLogging ) Timber . i (
" Automatic update Check: %s " ,
" Automatic update Check: %s " , isChecked
isChecked
)
)
}
}
setupCrashReporting . setOnCheckedChangeListener { _ : CompoundButton ? , isChecked : Boolean ->
setupCrashReporting . setOnCheckedChangeListener { _ : CompoundButton ? , isChecked : Boolean ->
if ( MainApplication . forceDebugLogging ) Timber . i (
if ( MainApplication . forceDebugLogging ) Timber . i (
" Crash Reporting: %s " ,
" Crash Reporting: %s " , isChecked
isChecked
)
)
}
}
( Objects . requireNonNull < Any > ( view . findViewById ( R . id . setup _crash _reporting _pii ) ) as MaterialSwitch ) . setOnCheckedChangeListener { _ : CompoundButton ? , isChecked : Boolean ->
( Objects . requireNonNull < Any > ( view . findViewById ( R . id . setup _crash _reporting _pii ) ) as MaterialSwitch ) . setOnCheckedChangeListener { _ : CompoundButton ? , isChecked : Boolean ->
if ( MainApplication . forceDebugLogging ) Timber . i (
if ( MainApplication . forceDebugLogging ) Timber . i (
" Crash Reporting PII: %s " ,
" Crash Reporting PII: %s " , isChecked
isChecked
)
)
}
}
( Objects . requireNonNull < Any > ( view . findViewById ( R . id . setup _androidacy _repo ) ) as MaterialSwitch ) . setOnCheckedChangeListener { _ : CompoundButton ? , isChecked : Boolean ->
( Objects . requireNonNull < Any > ( view . findViewById ( R . id . setup _androidacy _repo ) ) as MaterialSwitch ) . setOnCheckedChangeListener { _ : CompoundButton ? , isChecked : Boolean ->
if ( MainApplication . forceDebugLogging ) Timber . i (
if ( MainApplication . forceDebugLogging ) Timber . i (
" Androidacy Repo: %s " ,
" Androidacy Repo: %s " , isChecked
isChecked
)
)
}
}
( Objects . requireNonNull < Any > ( view . findViewById ( R . id . setup _magisk _alt _repo ) ) as MaterialSwitch ) . setOnCheckedChangeListener { _ : CompoundButton ? , isChecked : Boolean ->
( Objects . requireNonNull < Any > ( view . findViewById ( R . id . setup _magisk _alt _repo ) ) as MaterialSwitch ) . setOnCheckedChangeListener { _ : CompoundButton ? , isChecked : Boolean ->
if ( MainApplication . forceDebugLogging ) Timber . i (
if ( MainApplication . forceDebugLogging ) Timber . i (
" Magisk Alt Repo: %s " ,
" Magisk Alt Repo: %s " , isChecked
isChecked
)
)
}
}
}
}
@ -258,8 +247,7 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
builder . setCancelable ( true )
builder . setCancelable ( true )
// Create the dialog
// Create the dialog
builder . setSingleChoiceItems (
builder . setSingleChoiceItems (
themeNames ,
themeNames , checkedItem
checkedItem
) { dialog : DialogInterface , which : Int ->
) { dialog : DialogInterface , which : Int ->
// Set the theme
// Set the theme
prefs . edit ( ) . putString ( " pref_theme " , themeValues [ which ] ) . commit ( )
prefs . edit ( ) . putString ( " pref_theme " , themeValues [ which ] ) . commit ( )
@ -300,9 +288,7 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
// if agreeEula is not checked, show a toast and return
// if agreeEula is not checked, show a toast and return
if ( ! agreeEula . isChecked ) {
if ( ! agreeEula . isChecked ) {
Toast . makeText (
Toast . makeText (
this ,
this , R . string . setup _agree _eula _toast , Toast . LENGTH _LONG
R . string . setup _agree _eula _toast ,
Toast . LENGTH _LONG
) . show ( )
) . show ( )
return @setOnClickListener
return @setOnClickListener
}
}
@ -329,8 +315,7 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
)
)
// Set the crash reporting pref
// Set the crash reporting pref
editor . putBoolean (
editor . putBoolean (
" pref_crash_reporting " ,
" pref_crash_reporting " , setupCrashReporting . isChecked
setupCrashReporting . isChecked
)
)
// Set the crash reporting PII pref
// Set the crash reporting PII pref
editor . putBoolean (
editor . putBoolean (
@ -355,8 +340,7 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
if ( MainApplication . forceDebugLogging ) Timber . d ( " Saving preferences " )
if ( MainApplication . forceDebugLogging ) Timber . d ( " Saving preferences " )
// now basically do the same thing for room db
// now basically do the same thing for room db
val db = Room . databaseBuilder (
val db = Room . databaseBuilder (
applicationContext ,
applicationContext , ReposListDatabase :: class . java , " ReposList.db "
ReposListDatabase :: class . java , " ReposList.db "
) . allowMainThreadQueries ( ) . build ( )
) . allowMainThreadQueries ( ) . build ( )
val androidacyRepoRoom = andRepoView . isChecked
val androidacyRepoRoom = andRepoView . isChecked
val magiskAltRepoRoom = magiskAltRepoView . isChecked
val magiskAltRepoRoom = magiskAltRepoView . isChecked
@ -371,18 +355,27 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
// Commit the changes
// Commit the changes
editor . commit ( )
editor . commit ( )
// Log the changes
// Log the changes
if ( MainApplication . forceDebugLogging ) Timber . d ( " Setup finished. Preferences: %s " , prefs . all )
if ( MainApplication . forceDebugLogging ) Timber . d (
if ( MainApplication . forceDebugLogging ) Timber . d ( " Androidacy repo: %s " , androidacyRepoRoom )
" Setup finished. Preferences: %s " ,
if ( MainApplication . forceDebugLogging ) Timber . d ( " Magisk Alt repo: %s " , magiskAltRepoRoom )
prefs . all
)
if ( MainApplication . forceDebugLogging ) Timber . d (
" Androidacy repo: %s " ,
androidacyRepoRoom
)
if ( MainApplication . forceDebugLogging ) Timber . d (
" Magisk Alt repo: %s " ,
magiskAltRepoRoom
)
// log last shown setup
// log last shown setup
if ( MainApplication . forceDebugLogging ) Timber . d ( " Last shown setup: %s " , prefs . getString ( " last_shown_setup " , " v0 " ) )
if ( MainApplication . forceDebugLogging ) Timber . d (
" Last shown setup: %s " ,
prefs . getString ( " last_shown_setup " , " v0 " )
)
// Restart the activity
// Restart the activity
MainActivity . doSetupRestarting = true
MainActivity . doSetupRestarting = true
val pendingIntent = PendingIntent . getActivity (
val pendingIntent = PendingIntent . getActivity (
this ,
this , 0 , Intent ( this , MainActivity :: class . java ) , PendingIntent . FLAG _IMMUTABLE
0 ,
Intent ( this , MainActivity :: class . java ) ,
PendingIntent . FLAG _IMMUTABLE
)
)
try {
try {
pendingIntent . send ( )
pendingIntent . send ( )
@ -459,17 +452,13 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
val thread = Thread {
val thread = Thread {
if ( MainApplication . forceDebugLogging ) Timber . d ( " Creating databases " )
if ( MainApplication . forceDebugLogging ) Timber . d ( " Creating databases " )
val startTime = System . currentTimeMillis ( )
val startTime = System . currentTimeMillis ( )
val appContext = MainApplication . INSTANCE!! . applicationContext
val appContext = MainApplication . getInstance( ) . applicationContext
val db = Room . databaseBuilder ( appContext , ReposListDatabase :: class . java , " ReposList.db " )
val db = Room . databaseBuilder ( appContext , ReposListDatabase :: class . java , " ReposList.db " )
. fallbackToDestructiveMigration ( ) . build ( )
. fallbackToDestructiveMigration ( ) . build ( )
// same for modulelistcache
// same for modulelistcache
val db2 = Room . databaseBuilder (
val db2 = Room . databaseBuilder (
appContext ,
appContext , ModuleListCacheDatabase :: class . java , " ModuleListCache.db "
ModuleListCacheDatabase :: class . java ,
) . fallbackToDestructiveMigration ( ) . allowMainThreadQueries ( ) . build ( )
" ModuleListCache.db "
)
. fallbackToDestructiveMigration ( )
. allowMainThreadQueries ( ) . build ( )
val reposListDao = db . reposListDao ( )
val reposListDao = db . reposListDao ( )
val moduleListCacheDao = db2 . moduleListCacheDao ( )
val moduleListCacheDao = db2 . moduleListCacheDao ( )
@ -533,9 +522,7 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
// show a toast
// show a toast
runOnUiThread {
runOnUiThread {
Toast . makeText (
Toast . makeText (
this ,
this , R . string . error _creating _repos _database , Toast . LENGTH _LONG
R . string . error _creating _repos _database ,
Toast . LENGTH _LONG
) . show ( )
) . show ( )
}
}
} else {
} else {
@ -547,9 +534,7 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
// show a toast
// show a toast
runOnUiThread {
runOnUiThread {
Toast . makeText (
Toast . makeText (
this ,
this , R . string . error _creating _modulelistcache _database , Toast . LENGTH _LONG
R . string . error _creating _modulelistcache _database ,
Toast . LENGTH _LONG
) . show ( )
) . show ( )
}
}
} else {
} else {
@ -558,7 +543,10 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
// close the databases
// close the databases
db . close ( )
db . close ( )
db2 . close ( )
db2 . close ( )
if ( MainApplication . forceDebugLogging ) Timber . d ( " Databases created in %s ms " , System . currentTimeMillis ( ) - startTime )
if ( MainApplication . forceDebugLogging ) Timber . d (
" Databases created in %s ms " ,
System . currentTimeMillis ( ) - startTime
)
}
}
thread . start ( )
thread . start ( )
}
}
@ -572,17 +560,15 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
// show a toast
// show a toast
runOnUiThread {
runOnUiThread {
Toast . makeText (
Toast . makeText (
this ,
this , R . string . error _creating _cookie _database , Toast . LENGTH _LONG
R . string . error _creating _cookie _database ,
Toast . LENGTH _LONG
) . show ( )
) . show ( )
}
}
}
}
// we literally only use these to create the http cache folders
// we literally only use these to create the http cache folders
try {
try {
FileUtils . forceMkdir ( File ( MainApplication . INSTANCE!! . dataDir . toString ( ) + " /cache/cronet " ) )
FileUtils . forceMkdir ( File ( MainApplication . getInstance( ) . dataDir . toString ( ) + " /cache/cronet " ) )
FileUtils . forceMkdir ( File ( MainApplication . INSTANCE!! . dataDir . toString ( ) + " /cache/WebView/Default/HTTP Cache/Code Cache/wasm " ) )
FileUtils . forceMkdir ( File ( MainApplication . getInstance( ) . dataDir . toString ( ) + " /cache/WebView/Default/HTTP Cache/Code Cache/wasm " ) )
FileUtils . forceMkdir ( File ( MainApplication . INSTANCE!! . dataDir . toString ( ) + " /cache/WebView/Default/HTTP Cache/Code Cache/js " ) )
FileUtils . forceMkdir ( File ( MainApplication . getInstance( ) . dataDir . toString ( ) + " /cache/WebView/Default/HTTP Cache/Code Cache/js " ) )
} catch ( e : IOException ) {
} catch ( e : IOException ) {
Timber . e ( e )
Timber . e ( e )
}
}