2626import brut .androlib .res .xml .ResXmlUtils ;
2727import brut .androlib .smali .SmaliBuilder ;
2828import brut .common .BrutException ;
29+ import brut .common .Log ;
2930import brut .directory .Directory ;
3031import brut .directory .DirectoryException ;
3132import brut .directory .ExtFile ;
4142import java .nio .file .Files ;
4243import java .util .*;
4344import java .util .concurrent .atomic .AtomicReference ;
44- import java .util .logging .Logger ;
4545import java .util .zip .ZipOutputStream ;
4646
4747public class ApkBuilder {
48- private static final Logger LOGGER = Logger . getLogger ( ApkBuilder .class .getName () );
48+ private static final String TAG = ApkBuilder .class .getName ();
4949
5050 private final ExtFile mApkDir ;
5151 private final Config mConfig ;
@@ -69,8 +69,7 @@ public void build(File outApk) throws AndrolibException {
6969 try {
7070 mApkInfo = ApkInfo .load (mApkDir );
7171 String minSdkVersion = mApkInfo .getSdkInfo ().getMinSdkVersion ();
72- mSmaliBuilder = new SmaliBuilder (minSdkVersion != null
73- ? SdkInfo .parseSdkInt (minSdkVersion ) : 0 );
72+ mSmaliBuilder = new SmaliBuilder (minSdkVersion != null ? SdkInfo .parseSdkInt (minSdkVersion ) : 0 );
7473 mAaptInvoker = new AaptInvoker (mApkInfo , mConfig );
7574
7675 String apkName = mApkInfo .getApkFileName ();
@@ -86,8 +85,8 @@ public void build(File outApk) throws AndrolibException {
8685 File outDir = new File (mApkDir , "build/apk" );
8786 OS .mkdir (outDir );
8887
89- LOGGER . info ( "Using Apktool " + mConfig .getVersion () + " on " + apkName
90- + (mWorker != null ? " with " + mConfig .getJobs () + " threads" : "" ));
88+ Log . i ( TAG , "Using Apktool " + mConfig .getVersion () + " on " + apkName
89+ + (mWorker != null ? " with " + mConfig .getJobs () + " threads" : "" ));
9190
9291 buildSources (outDir );
9392 buildResources (outDir );
@@ -129,8 +128,7 @@ private void buildSources(File outDir) throws AndrolibException {
129128 if (dirName .equals ("smali" )) {
130129 fileName = "classes.dex" ;
131130 } else if (dirName .startsWith ("smali_" )) {
132- fileName = dirName .substring (dirName .indexOf ('_' ) + 1 )
133- .replace ('@' , File .separatorChar ) + ".dex" ;
131+ fileName = dirName .substring (dirName .indexOf ('_' ) + 1 ).replace ('@' , File .separatorChar ) + ".dex" ;
134132 } else {
135133 continue ;
136134 }
@@ -149,11 +147,11 @@ private void copySourcesRaw(File outDir, String fileName) throws AndrolibExcepti
149147 File outFile = new File (outDir , fileName );
150148
151149 if (!mConfig .isForced () && !isFileNewer (inFile , outFile )) {
152- LOGGER . info ( fileName + " has not changed." );
150+ Log . i ( TAG , fileName + " has not changed." );
153151 return ;
154152 }
155153
156- LOGGER . info ( "Copying raw " + fileName + "..." );
154+ Log . i ( TAG , "Copying raw " + fileName + "..." );
157155 try {
158156 BrutIO .copyAndClose (Files .newInputStream (inFile .toPath ()), Files .newOutputStream (outFile .toPath ()));
159157 } catch (IOException ex ) {
@@ -182,11 +180,11 @@ private void buildSourcesSmaliJob(File outDir, String dirName, String fileName)
182180 File dexFile = new File (outDir , fileName );
183181
184182 if (!mConfig .isForced () && !isFileNewer (smaliDir , dexFile )) {
185- LOGGER . info ( dirName + " has not changed." );
183+ Log . i ( TAG , dirName + " has not changed." );
186184 return ;
187185 }
188186
189- LOGGER . info ( "Smaling " + dirName + " folder into " + fileName + "..." );
187+ Log . i ( TAG , "Smaling " + dirName + " folder into " + fileName + "..." );
190188 mSmaliBuilder .build (smaliDir , dexFile );
191189 }
192190
@@ -233,13 +231,12 @@ private void buildResources(File outDir) throws AndrolibException {
233231 }
234232
235233 private void copyManifestRaw (File outDir , File manifest ) throws AndrolibException {
236- if (!mConfig .isForced ()
237- && !isFileNewer (manifest , new File (outDir , "AndroidManifest.xml" ))) {
238- LOGGER .info ("AndroidManifest.xml has not changed." );
234+ if (!mConfig .isForced () && !isFileNewer (manifest , new File (outDir , "AndroidManifest.xml" ))) {
235+ Log .i (TAG , "AndroidManifest.xml has not changed." );
239236 return ;
240237 }
241238
242- LOGGER . info ( "Copying raw AndroidManifest.xml..." );
239+ Log . i ( TAG , "Copying raw AndroidManifest.xml..." );
243240 try {
244241 Directory in = mApkDir .getDirectory ();
245242
@@ -250,13 +247,12 @@ private void copyManifestRaw(File outDir, File manifest) throws AndrolibExceptio
250247 }
251248
252249 private void copyResourcesRaw (File outDir , File arscFile ) throws AndrolibException {
253- if (!mConfig .isForced ()
254- && !isFileNewer (arscFile , new File (outDir , "resources.arsc" ))) {
255- LOGGER .info ("resources.arsc has not changed." );
250+ if (!mConfig .isForced () && !isFileNewer (arscFile , new File (outDir , "resources.arsc" ))) {
251+ Log .i (TAG , "resources.arsc has not changed." );
256252 return ;
257253 }
258254
259- LOGGER . info ( "Copying raw resources.arsc..." );
255+ Log . i ( TAG , "Copying raw resources.arsc..." );
260256 try {
261257 Directory in = mApkDir .getDirectory ();
262258
@@ -267,9 +263,8 @@ private void copyResourcesRaw(File outDir, File arscFile) throws AndrolibExcepti
267263 }
268264
269265 private void buildManifestOnly (File outDir , File manifest ) throws AndrolibException {
270- if (!mConfig .isForced ()
271- && !isFileNewer (manifest , new File (outDir , "AndroidManifest.xml" ))) {
272- LOGGER .info ("AndroidManifest.xml has not changed." );
266+ if (!mConfig .isForced () && !isFileNewer (manifest , new File (outDir , "AndroidManifest.xml" ))) {
267+ Log .i (TAG , "AndroidManifest.xml has not changed." );
273268 return ;
274269 }
275270
@@ -284,7 +279,7 @@ private void buildManifestOnly(File outDir, File manifest) throws AndrolibExcept
284279 ResXmlUtils .fixingPublicAttrsInProviderAttributes (manifest );
285280
286281 if (mConfig .isDebuggable ()) {
287- LOGGER . info ( "Setting 'debuggable' attribute to 'true' in AndroidManifest.xml..." );
282+ Log . i ( TAG , "Setting 'debuggable' attribute to 'true' in AndroidManifest.xml..." );
288283 ResXmlUtils .setApplicationDebugTagTrue (manifest );
289284 }
290285
@@ -296,7 +291,7 @@ private void buildManifestOnly(File outDir, File manifest) throws AndrolibExcept
296291 throw new AndrolibException (ex );
297292 }
298293
299- LOGGER . info ( "Building AndroidManifest.xml with " + AaptManager .getBinaryName () + "..." );
294+ Log . i ( TAG , "Building AndroidManifest.xml with " + AaptManager .getBinaryName () + "..." );
300295 mAaptInvoker .invoke (tmpFile , manifest , null );
301296
302297 try (ZipRODirectory tmpDir = new ZipRODirectory (tmpFile )) {
@@ -316,10 +311,9 @@ private void buildManifestOnly(File outDir, File manifest) throws AndrolibExcept
316311 }
317312
318313 private void buildResourcesFully (File outDir , File manifest , File resDir ) throws AndrolibException {
319- if (!mConfig .isForced ()
320- && !isFileNewer (manifest , new File (outDir , "AndroidManifest.xml" ))
314+ if (!mConfig .isForced () && !isFileNewer (manifest , new File (outDir , "AndroidManifest.xml" ))
321315 && !isFileNewer (resDir , new File (outDir , "res" ))) {
322- LOGGER . info ( "AndroidManifest.xml and resources have not changed." );
316+ Log . i ( TAG , "AndroidManifest.xml and resources have not changed." );
323317 return ;
324318 }
325319
@@ -334,20 +328,20 @@ private void buildResourcesFully(File outDir, File manifest, File resDir) throws
334328 ResXmlUtils .fixingPublicAttrsInProviderAttributes (manifest );
335329
336330 if (mConfig .isDebuggable ()) {
337- LOGGER . info ( "Setting 'debuggable' attribute to 'true' in AndroidManifest.xml..." );
331+ Log . i ( TAG , "Setting 'debuggable' attribute to 'true' in AndroidManifest.xml..." );
338332 ResXmlUtils .setApplicationDebugTagTrue (manifest );
339333 }
340334
341335 if (mConfig .isNetSecConf ()) {
342- LOGGER . info ( "Adding permissive network security config in manifest..." );
336+ Log . i ( TAG , "Adding permissive network security config in manifest..." );
343337 File netSecConfOrig = new File (mApkDir , "res/xml/network_security_config.xml" );
344338 OS .mkdir (netSecConfOrig .getParentFile ());
345339 ResXmlUtils .modNetworkSecurityConfig (netSecConfOrig );
346340 ResXmlUtils .setNetworkSecurityConfig (manifest );
347341
348342 String targetSdkVersion = mApkInfo .getSdkInfo ().getTargetSdkVersion ();
349343 if (targetSdkVersion != null && SdkInfo .parseSdkInt (targetSdkVersion ) < ResConfig .SDK_NOUGAT ) {
350- LOGGER . warning ( "Target SDK version is lower than 24, Network Security Configuration might be ignored!" );
344+ Log . w ( TAG , "Target SDK version is lower than 24, Network Security Configuration might be ignored!" );
351345 }
352346 }
353347
@@ -359,7 +353,7 @@ private void buildResourcesFully(File outDir, File manifest, File resDir) throws
359353 throw new AndrolibException (ex );
360354 }
361355
362- LOGGER . info ( "Building resources with " + AaptManager .getBinaryName () + "..." );
356+ Log . i ( TAG , "Building resources with " + AaptManager .getBinaryName () + "..." );
363357 mAaptInvoker .invoke (tmpFile , manifest , resDir );
364358
365359 try (ZipRODirectory tmpDir = new ZipRODirectory (tmpFile )) {
@@ -388,7 +382,7 @@ private void copyOriginalFiles(File outDir) throws AndrolibException {
388382 return ;
389383 }
390384
391- LOGGER . info ( "Copying original files..." );
385+ Log . i ( TAG , "Copying original files..." );
392386 try {
393387 FileDirectory in = new FileDirectory (originalDir );
394388
@@ -415,7 +409,7 @@ private void buildApkFile(File outDir, File outApk) throws AndrolibException {
415409 // Convert to set for fast lookup.
416410 Set <String > doNotCompress = new HashSet <>(mApkInfo .getDoNotCompress ());
417411
418- LOGGER . info ( "Building apk file..." );
412+ Log . i ( TAG , "Building apk file..." );
419413 try (ZipOutputStream out = new ZipOutputStream (Files .newOutputStream (outApk .toPath ()))) {
420414 // Zip aapt output files.
421415 ZipUtils .zipDir (outDir , out , doNotCompress );
@@ -424,21 +418,21 @@ private void buildApkFile(File outDir, File outApk) throws AndrolibException {
424418 for (String dirName : ApkInfo .RAW_DIRS ) {
425419 File rawDir = new File (mApkDir , dirName );
426420 if (rawDir .isDirectory ()) {
427- LOGGER . info ( "Importing " + dirName + "..." );
421+ Log . i ( TAG , "Importing " + dirName + "..." );
428422 ZipUtils .zipDir (mApkDir , dirName , out , doNotCompress );
429423 }
430424 }
431425
432426 // Zip unknown files.
433427 File unknownDir = new File (mApkDir , "unknown" );
434428 if (unknownDir .isDirectory ()) {
435- LOGGER . info ( "Importing unknown files..." );
429+ Log . i ( TAG , "Importing unknown files..." );
436430 ZipUtils .zipDir (unknownDir , out , doNotCompress );
437431 }
438432 } catch (IOException ex ) {
439433 throw new AndrolibException (ex );
440434 }
441- LOGGER . info ( "Built apk into: " + outApk .getPath ());
435+ Log . i ( TAG , "Built apk into: " + outApk .getPath ());
442436 }
443437
444438 private boolean isFileNewer (File file , File reference ) {
0 commit comments