@ -61,14 +61,11 @@ public class AndroidacyWebAPI {
this . downloadMode = false ;
}
void openNativeModuleDialogRaw ( String moduleUrl , String moduleId , String installTitle ,
String checksum , boolean canInstall ) {
if ( BuildConfig . DEBUG ) Log . i ( TAG , "ModuleDialog, downloadUrl: " + AndroidacyUtil . hideToken ( moduleUrl ) +
", moduleId: " + moduleId + ", installTitle: " + installTitle +
", checksum: " + checksum + ", canInstall: " + canInstall ) ;
void openNativeModuleDialogRaw ( String moduleUrl , String moduleId , String installTitle , String checksum , boolean canInstall ) {
if ( BuildConfig . DEBUG )
Log . d ( TAG , "ModuleDialog, downloadUrl: " + AndroidacyUtil . hideToken ( moduleUrl ) + ", moduleId: " + moduleId + ", installTitle: " + installTitle + ", checksum: " + checksum + ", canInstall: " + canInstall ) ;
this . downloadMode = false ;
RepoModule repoModule = AndroidacyRepoData
. getInstance ( ) . moduleHashMap . get ( installTitle ) ;
RepoModule repoModule = AndroidacyRepoData . getInstance ( ) . moduleHashMap . get ( installTitle ) ;
String title , description ;
boolean mmtReborn = false ;
if ( repoModule ! = null ) {
@ -83,16 +80,13 @@ public class AndroidacyWebAPI {
title = installTitle ;
String checkSumType = Hashes . checkSumName ( checksum ) ;
if ( checkSumType = = null ) {
description = "Checksum: " + ( (
checksum = = null | | checksum . isEmpty ( ) ) ? "null" : checksum ) ;
description = "Checksum: " + ( ( checksum = = null | | checksum . isEmpty ( ) ) ? "null" : checksum ) ;
} else {
description = checkSumType + ": " + checksum ;
}
}
final MaterialAlertDialogBuilder builder =
new MaterialAlertDialogBuilder ( this . activity ) ;
builder . setTitle ( title ) . setMessage ( description ) . setCancelable ( true )
. setIcon ( R . drawable . ic_baseline_extension_24 ) ;
final MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder ( this . activity ) ;
builder . setTitle ( title ) . setMessage ( description ) . setCancelable ( true ) . setIcon ( R . drawable . ic_baseline_extension_24 ) ;
builder . setNegativeButton ( R . string . download_module , ( x , y ) - > {
this . downloadMode = true ;
IntentHelper . openCustomTab ( this . activity , moduleUrl ) ;
@ -102,17 +96,12 @@ public class AndroidacyWebAPI {
String config = null ;
if ( repoModule ! = null ) {
config = repoModule . moduleInfo . config ;
LocalModuleInfo localModuleInfo =
ModuleManager . getINSTANCE ( ) . getModules ( ) . get ( repoModule . id ) ;
hasUpdate = localModuleInfo ! = null & &
repoModule . moduleInfo . versionCode > localModuleInfo . versionCode ;
LocalModuleInfo localModuleInfo = ModuleManager . getINSTANCE ( ) . getModules ( ) . get ( repoModule . id ) ;
hasUpdate = localModuleInfo ! = null & & repoModule . moduleInfo . versionCode > localModuleInfo . versionCode ;
}
final String fModuleUrl = moduleUrl , fTitle = title ,
fConfig = config , fChecksum = checksum ;
final String fModuleUrl = moduleUrl , fTitle = title , fConfig = config , fChecksum = checksum ;
final boolean fMMTReborn = mmtReborn ;
builder . setPositiveButton ( hasUpdate ?
R . string . update_module : R . string . install_module , ( x , y ) - > IntentHelper . openInstaller ( this . activity ,
fModuleUrl , fTitle , fConfig , fChecksum , fMMTReborn ) ) ;
builder . setPositiveButton ( hasUpdate ? R . string . update_module : R . string . install_module , ( x , y ) - > IntentHelper . openInstaller ( this . activity , fModuleUrl , fTitle , fConfig , fChecksum , fMMTReborn ) ) ;
}
builder . setOnCancelListener ( dialogInterface - > {
if ( ! this . activity . backOnResume )
@ -122,11 +111,10 @@ public class AndroidacyWebAPI {
this . downloadMode = true ;
try {
return this . activity . downloadFileAsync ( moduleUrl ) ;
} catch ( IOException e ) {
} catch (
IOException e ) {
Log . e ( TAG , "Failed to download module" , e ) ;
AndroidacyWebAPI . this . activity . runOnUiThread ( ( ) - >
Toast . makeText ( AndroidacyWebAPI . this . activity ,
R . string . failed_download , Toast . LENGTH_SHORT ) . show ( ) ) ;
AndroidacyWebAPI . this . activity . runOnUiThread ( ( ) - > Toast . makeText ( AndroidacyWebAPI . this . activity , R . string . failed_download , Toast . LENGTH_SHORT ) . show ( ) ) ;
return null ;
}
} , "androidacy_repo" ) ;
@ -144,8 +132,10 @@ public class AndroidacyWebAPI {
}
void notifyCompatModeRaw ( int value ) {
if ( this . consumedAction ) return ;
if ( BuildConfig . DEBUG ) Log . i ( TAG , "Androidacy Compat mode: " + value ) ;
if ( this . consumedAction )
return ;
if ( BuildConfig . DEBUG )
Log . d ( TAG , "Androidacy Compat mode: " + value ) ;
this . notifiedCompatMode = value ;
if ( value < 0 ) {
value = 0 ;
@ -158,7 +148,8 @@ public class AndroidacyWebAPI {
@JavascriptInterface
public void forceQuit ( String error ) {
// Allow forceQuit and cancel in downloadMode
if ( this . consumedAction & & ! this . downloadMode ) return ;
if ( this . consumedAction & & ! this . downloadMode )
return ;
this . consumedAction = true ;
this . forceQuitRaw ( error ) ;
}
@ -166,10 +157,10 @@ public class AndroidacyWebAPI {
@JavascriptInterface
public void cancel ( ) {
// Allow forceQuit and cancel in downloadMode
if ( this . consumedAction & & ! this . downloadMode ) return ;
if ( this . consumedAction & & ! this . downloadMode )
return ;
this . consumedAction = true ;
this . activity . runOnUiThread (
this . activity : : forceBackPressed ) ;
this . activity . runOnUiThread ( this . activity : : forceBackPressed ) ;
}
/ * *
@ -177,10 +168,12 @@ public class AndroidacyWebAPI {
* /
@JavascriptInterface
public void openUrl ( String url ) {
if ( this . consumedAction ) return ;
if ( this . consumedAction )
return ;
this . consumedAction = true ;
this . downloadMode = false ;
if ( BuildConfig . DEBUG ) Log . i ( TAG , "Received openUrl request: " + url ) ;
if ( BuildConfig . DEBUG )
Log . d ( TAG , "Received openUrl request: " + url ) ;
if ( Uri . parse ( url ) . getScheme ( ) . equals ( "https" ) ) {
IntentHelper . openUrl ( this . activity , url ) ;
}
@ -191,10 +184,12 @@ public class AndroidacyWebAPI {
* /
@JavascriptInterface
public void openCustomTab ( String url ) {
if ( this . consumedAction ) return ;
if ( this . consumedAction )
return ;
this . consumedAction = true ;
this . downloadMode = false ;
if ( BuildConfig . DEBUG ) Log . i ( TAG , "Received openCustomTab request: " + url ) ;
if ( BuildConfig . DEBUG )
Log . d ( TAG , "Received openCustomTab request: " + url ) ;
if ( Uri . parse ( url ) . getScheme ( ) . equals ( "https" ) ) {
IntentHelper . openCustomTab ( this . activity , url ) ;
}
@ -223,8 +218,7 @@ public class AndroidacyWebAPI {
@JavascriptInterface
public boolean canInstall ( ) {
// With lockdown mode enabled or lack of root, install should not have any effect
return this . allowInstall & & this . hasRoot ( ) & &
! MainApplication . isShowcaseMode ( ) ;
return this . allowInstall & & this . hasRoot ( ) & & ! MainApplication . isShowcaseMode ( ) ;
}
/ * *
@ -238,8 +232,8 @@ public class AndroidacyWebAPI {
}
this . consumedAction = true ;
this . downloadMode = false ;
if ( BuildConfig . DEBUG ) Log . i ( TAG , "Received install request: " +
moduleUrl + " " + installTitle + " " + checksum ) ;
if ( BuildConfig . DEBUG )
Log . d ( TAG , "Received install request: " + moduleUrl + " " + installTitle + " " + checksum ) ;
if ( ! AndroidacyUtil . isAndroidacyLink ( moduleUrl ) ) {
this . forceQuitRaw ( "Non Androidacy module link used on Androidacy" ) ;
return ;
@ -257,14 +251,12 @@ public class AndroidacyWebAPI {
if ( this . effectiveCompatMode < 1 ) {
if ( ! this . canInstall ( ) ) {
this . downloadMode = true ;
this . activity . runOnUiThread ( ( ) - >
this . activity . webView . loadUrl ( moduleUrl ) ) ;
this . activity . runOnUiThread ( ( ) - > this . activity . webView . loadUrl ( moduleUrl ) ) ;
} else {
this . openNativeModuleDialogRaw ( moduleUrl , moduleId , installTitle , checksum , true ) ;
}
} else {
RepoModule repoModule = AndroidacyRepoData
. getInstance ( ) . moduleHashMap . get ( installTitle ) ;
RepoModule repoModule = AndroidacyRepoData . getInstance ( ) . moduleHashMap . get ( installTitle ) ;
String config = null ;
boolean mmtReborn = false ;
if ( repoModule ! = null & & repoModule . moduleInfo . name . length ( ) > = 3 ) {
@ -273,8 +265,7 @@ public class AndroidacyWebAPI {
mmtReborn = repoModule . moduleInfo . mmtReborn ;
}
this . activity . backOnResume = true ;
IntentHelper . openInstaller ( this . activity ,
moduleUrl , installTitle , config , checksum , mmtReborn ) ;
IntentHelper . openInstaller ( this . activity , moduleUrl , installTitle , config , checksum , mmtReborn ) ;
}
}
@ -283,7 +274,8 @@ public class AndroidacyWebAPI {
* /
@JavascriptInterface
public void openNativeModuleDialog ( String moduleUrl , String moduleId , String checksum ) {
if ( this . consumedAction ) return ;
if ( this . consumedAction )
return ;
this . consumedAction = true ;
this . downloadMode = false ;
if ( ! AndroidacyUtil . isAndroidacyLink ( moduleUrl ) ) {
@ -342,15 +334,15 @@ public class AndroidacyWebAPI {
* /
@JavascriptInterface
public void hideActionBar ( ) {
if ( this . consumedAction ) return ;
if ( this . consumedAction )
return ;
this . consumedAction = true ;
this . activity . runOnUiThread ( ( ) - > {
this . activity . hideActionBar ( ) ;
this . consumedAction = false ;
if ( this . allowHideNote ) {
this . allowHideNote = false ;
this . activity . webViewNote
. setVisibility ( View . GONE ) ;
this . activity . webViewNote . setVisibility ( View . GONE ) ;
}
} ) ;
}
@ -361,7 +353,8 @@ public class AndroidacyWebAPI {
* /
@JavascriptInterface
public void showActionBar ( final String title ) {
if ( this . consumedAction ) return ;
if ( this . consumedAction )
return ;
this . consumedAction = true ;
this . activity . runOnUiThread ( ( ) - > {
this . activity . showActionBar ( ) ;
@ -379,8 +372,7 @@ public class AndroidacyWebAPI {
@JavascriptInterface
public boolean isAndroidacyModule ( String moduleId ) {
LocalModuleInfo localModuleInfo = ModuleManager . getINSTANCE ( ) . getModules ( ) . get ( moduleId ) ;
return localModuleInfo ! = null & & ( "Androidacy" . equals ( localModuleInfo . author ) | |
AndroidacyUtil . isAndroidacyLink ( localModuleInfo . config ) ) ;
return localModuleInfo ! = null & & ( "Androidacy" . equals ( localModuleInfo . author ) | | AndroidacyUtil . isAndroidacyLink ( localModuleInfo . config ) ) ;
}
/ * *
@ -389,15 +381,16 @@ public class AndroidacyWebAPI {
* /
@JavascriptInterface
public String getAndroidacyModuleFile ( String moduleId , String moduleFile ) {
if ( moduleFile = = null | | this . consumedAction | |
! this . isAndroidacyModule ( moduleId ) ) return "" ;
if ( moduleFile = = null | | this . consumedAction | | ! this . isAndroidacyModule ( moduleId ) )
return "" ;
File moduleFolder = new File ( "/data/adb/modules/" + moduleId ) ;
File absModuleFile = new File ( moduleFolder , moduleFile ) . getAbsoluteFile ( ) ;
if ( ! absModuleFile . getPath ( ) . startsWith ( moduleFolder . getPath ( ) ) ) return "" ;
if ( ! absModuleFile . getPath ( ) . startsWith ( moduleFolder . getPath ( ) ) )
return "" ;
try {
return new String ( Files . readSU ( absModuleFile
. getAbsoluteFile ( ) ) , StandardCharsets . UTF_8 ) ;
} catch ( IOException e ) {
return new String ( Files . readSU ( absModuleFile . getAbsoluteFile ( ) ) , StandardCharsets . UTF_8 ) ;
} catch (
IOException e ) {
return "" ;
}
}
@ -408,15 +401,14 @@ public class AndroidacyWebAPI {
* /
@JavascriptInterface
public boolean setAndroidacyModuleMeta ( String moduleId , String content ) {
if ( content = = null | | this . consumedAction | |
! this . isAndroidacyModule ( moduleId ) ) return false ;
File androidacyMetaFile = new File (
"/data/adb/modules/" + moduleId + "/.androidacy" ) ;
if ( content = = null | | this . consumedAction | | ! this . isAndroidacyModule ( moduleId ) )
return false ;
File androidacyMetaFile = new File ( "/data/adb/modules/" + moduleId + "/.androidacy" ) ;
try {
Files . writeSU ( androidacyMetaFile ,
content . getBytes ( StandardCharsets . UTF_8 ) ) ;
Files . writeSU ( androidacyMetaFile , content . getBytes ( StandardCharsets . UTF_8 ) ) ;
return true ;
} catch ( IOException e ) {
} catch (
IOException e ) {
return false ;
}
}
@ -442,8 +434,7 @@ public class AndroidacyWebAPI {
* /
@JavascriptInterface
public int getMagiskVersionCode ( ) {
return InstallerInitializer . peekMagiskPath ( ) = = null ? 0 :
InstallerInitializer . peekMagiskVersion ( ) ;
return InstallerInitializer . peekMagiskPath ( ) = = null ? 0 : InstallerInitializer . peekMagiskVersion ( ) ;
}
/ * *
@ -480,8 +471,7 @@ public class AndroidacyWebAPI {
Resources . Theme theme = this . activity . getTheme ( ) ;
TypedValue typedValue = new TypedValue ( ) ;
theme . resolveAttribute ( R . attr . colorPrimary , typedValue , true ) ;
if ( typedValue . type > = TypedValue . TYPE_FIRST_COLOR_INT & &
typedValue . type < = TypedValue . TYPE_LAST_COLOR_INT ) {
if ( typedValue . type > = TypedValue . TYPE_FIRST_COLOR_INT & & typedValue . type < = TypedValue . TYPE_LAST_COLOR_INT ) {
return typedValue . data ;
}
theme . resolveAttribute ( android . R . attr . colorAccent , typedValue , true ) ;
@ -504,8 +494,7 @@ public class AndroidacyWebAPI {
Resources . Theme theme = this . activity . getTheme ( ) ;
TypedValue typedValue = new TypedValue ( ) ;
theme . resolveAttribute ( R . attr . backgroundColor , typedValue , true ) ;
if ( typedValue . type > = TypedValue . TYPE_FIRST_COLOR_INT & &
typedValue . type < = TypedValue . TYPE_LAST_COLOR_INT ) {
if ( typedValue . type > = TypedValue . TYPE_FIRST_COLOR_INT & & typedValue . type < = TypedValue . TYPE_LAST_COLOR_INT ) {
return typedValue . data ;
}
theme . resolveAttribute ( android . R . attr . background , typedValue , true ) ;
@ -517,11 +506,9 @@ public class AndroidacyWebAPI {
* /
@JavascriptInterface
public String getMonetColor ( String id ) {
@SuppressLint ( "DiscouragedApi" ) int nameResourceID = this . activity . getResources ( ) . getIdentifier ( "@android:color/" + id ,
"color" , this . activity . getApplicationInfo ( ) . packageName ) ;
@SuppressLint ( "DiscouragedApi" ) int nameResourceID = this . activity . getResources ( ) . getIdentifier ( "@android:color/" + id , "color" , this . activity . getApplicationInfo ( ) . packageName ) ;
if ( nameResourceID = = 0 ) {
throw new IllegalArgumentException (
"No resource string found with name " + id ) ;
throw new IllegalArgumentException ( "No resource string found with name " + id ) ;
} else {
int color = ContextCompat . getColor ( this . activity , nameResourceID ) ;
int red = Color . red ( color ) ;