Skip to content

Commit

Permalink
MagiskManager -> java
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Oct 7, 2017
1 parent c215447 commit 60181c4
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 910 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ obj/
libs/
*.zip
*.jks
*.apk

# Copied binaries
# Built binaries
ziptools/zipadjust
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
path = jni/magiskpolicy
url = https://github.com/topjohnwu/magiskpolicy.git
[submodule "MagiskManager"]
path = MagiskManager
path = java
url = https://github.com/topjohnwu/MagiskManager.git
[submodule "jni/busybox"]
path = jni/external/busybox
Expand Down
1 change: 0 additions & 1 deletion MagiskManager
Submodule MagiskManager deleted from 773c24
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

## Credits

**MagiskManager** (`MagiskManager`)
**MagiskManager** (`java`)

* Copyright 2016-2017, John Wu (@topjohnwu)
* All contributors and translators
Expand Down
74 changes: 44 additions & 30 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def zip_with_msg(zipfile, source, target):
print('zip: {} -> {}'.format(source, target))
zipfile.write(source, target)

def cp(source, target):
print('cp: {} -> {}'.format(source, target))
shutil.copyfile(source, target)

def build_all(args):
build_binary(args)
build_apk(args)
Expand All @@ -75,34 +79,31 @@ def build_apk(args):

for key in ['public.certificate.x509.pem', 'private.key.pk8']:
source = os.path.join('ziptools', key)
target = os.path.join('MagiskManager', 'app', 'src', 'main', 'assets', key)
print('cp: {} -> {}'.format(source, target))
shutil.copyfile(source, target)
target = os.path.join('java', 'app', 'src', 'main', 'assets', key)
cp(source, target)

for script in ['magisk_uninstaller.sh', 'util_functions.sh']:
source = os.path.join('scripts', script)
target = os.path.join('MagiskManager', 'app', 'src', 'main', 'assets', script)
print('cp: {} -> {}'.format(source, target))
shutil.copyfile(source, target)
target = os.path.join('java', 'app', 'src', 'main', 'assets', script)
cp(source, target)

os.chdir('MagiskManager')
os.chdir('java')

# Build unhide app and place in assets
proc = subprocess.run('{} unhide::assembleRelease'.format(os.path.join('.', 'gradlew')), shell=True)
proc = subprocess.run('{} unhide:assembleRelease'.format(os.path.join('.', 'gradlew')), shell=True)
if proc.returncode != 0:
error('Build Magisk Manager failed!')
source = os.path.join('unhide', 'build', 'outputs', 'apk', 'release', 'unhide-release-unsigned.apk')
target = os.path.join('app', 'src', 'main', 'assets', 'unhide.apk')
print('cp: {} -> {}'.format(source, target))
shutil.copyfile(source, target)
cp(source, target)

print('')

if args.release:
if not os.path.exists(os.path.join('..', 'release_signature.jks')):
error('Please generate a java keystore and place it in \'release_signature.jks\'')

proc = subprocess.run('{} app::assembleRelease'.format(os.path.join('.', 'gradlew')), shell=True)
proc = subprocess.run('{} app:assembleRelease'.format(os.path.join('.', 'gradlew')), shell=True)
if proc.returncode != 0:
error('Build Magisk Manager failed!')

Expand Down Expand Up @@ -141,38 +142,48 @@ def build_apk(args):
silentremove(unsigned)
silentremove(aligned)
else:
proc = subprocess.run('{} app::assembleDebug'.format(os.path.join('.', 'gradlew')), shell=True)
proc = subprocess.run('{} app:assembleDebug'.format(os.path.join('.', 'gradlew')), shell=True)
if proc.returncode != 0:
error('Build Magisk Manager failed!')

# Return to upper directory
os.chdir('..')

def sign_adjust_zip(unsigned, output):
def build_snet(args):
os.chdir('java')
proc = subprocess.run('{} snet:assembleRelease'.format(os.path.join('.', 'gradlew')), shell=True)
if proc.returncode != 0:
error('Build snet extention failed!')
source = os.path.join('snet', 'build', 'outputs', 'apk', 'release', 'snet-release-unsigned.apk')
target = os.path.join('..', 'snet.apk')
print('')
cp(source, target)
os.chdir('..')

zipsigner = os.path.join('ziptools', 'zipsigner', 'build', 'libs', 'zipsigner.jar')
def sign_adjust_zip(unsigned, output):
jarsigner = os.path.join('java', 'jarsigner', 'build', 'libs', 'jarsigner-fat.jar')

if os.name != 'nt' and not os.path.exists(os.path.join('ziptools', 'zipadjust')):
header('* Building zipadjust')
# Compile zipadjust
proc = subprocess.run('gcc -o ziptools/zipadjust ziptools/zipadjust_src/*.c -lz', shell=True)
if proc.returncode != 0:
error('Build zipadjust failed!')
if not os.path.exists(zipsigner):
header('* Building zipsigner.jar')
os.chdir(os.path.join('ziptools', 'zipsigner'))
proc = subprocess.run('{} shadowJar'.format(os.path.join('.', 'gradlew')), shell=True)
if not os.path.exists(jarsigner):
header('* Building jarsigner-fat.jar')
os.chdir('java')
proc = subprocess.run('{} jarsigner:shadowJar'.format(os.path.join('.', 'gradlew')), shell=True)
if proc.returncode != 0:
error('Build zipsigner.jar failed!')
os.chdir(os.path.join('..', '..'))
error('Build jarsigner-fat.jar failed!')
os.chdir('..')

header('* Signing / Adjusting Zip')

publicKey = os.path.join('ziptools', 'public.certificate.x509.pem')
privateKey = os.path.join('ziptools', 'private.key.pk8')

# Unsigned->signed
proc = subprocess.run(['java', '-jar', zipsigner,
proc = subprocess.run(['java', '-jar', jarsigner,
publicKey, privateKey, unsigned, 'tmp_signed.zip'])
if proc.returncode != 0:
error('First sign flashable zip failed!')
Expand All @@ -183,7 +194,7 @@ def sign_adjust_zip(unsigned, output):
error('Adjust flashable zip failed!')

# Adjusted -> output
proc = subprocess.run(['java', '-jar', zipsigner,
proc = subprocess.run(['java', '-jar', jarsigner,
"-m", publicKey, privateKey, 'tmp_adjusted.zip', output])
if proc.returncode != 0:
error('Second sign flashable zip failed!')
Expand Down Expand Up @@ -243,7 +254,7 @@ def zip_main(args):
zip_with_msg(zipf, source, target)

# APK
source = os.path.join('MagiskManager', 'app', 'build', 'outputs', 'apk',
source = os.path.join('java', 'app', 'build', 'outputs', 'apk',
'release' if args.release else 'debug', 'app-release.apk' if args.release else 'app-debug.apk')
target = os.path.join('common', 'magisk.apk')
zip_with_msg(zipf, source, target)
Expand Down Expand Up @@ -328,20 +339,20 @@ def zip_uninstaller(args):

def cleanup(args):
if len(args.target) == 0:
args.target = ['binary', 'apk', 'zip']
args.target = ['binary', 'java', 'zip']

if 'binary' in args.target:
header('* Cleaning Magisk binaries')
header('* Cleaning binaries')
subprocess.run(os.path.join(os.environ['ANDROID_HOME'], 'ndk-bundle', 'ndk-build') + ' clean', shell=True)

if 'apk' in args.target:
header('* Cleaning Magisk Manager')
os.chdir('MagiskManager')
if 'java' in args.target:
header('* Cleaning java')
os.chdir('java')
subprocess.run('{} clean'.format(os.path.join('.', 'gradlew')), shell=True)
os.chdir('..')

if 'zip' in args.target:
header('* Cleaning created zip files')
header('* Cleaning zip files')
for f in os.listdir('.'):
if '.zip' in f:
print('rm {}'.format(f))
Expand All @@ -364,6 +375,9 @@ def cleanup(args):
apk_parser = subparsers.add_parser('apk', help='build Magisk Manager APK')
apk_parser.set_defaults(func=build_apk)

snet_parser = subparsers.add_parser('snet', help='build snet extention for Magisk Manager')
snet_parser.set_defaults(func=build_snet)

zip_parser = subparsers.add_parser('zip', help='zip and sign Magisk into a flashable zip')
zip_parser.add_argument('versionString')
zip_parser.add_argument('versionCode', type=int)
Expand All @@ -372,7 +386,7 @@ def cleanup(args):
uninstaller_parser = subparsers.add_parser('uninstaller', help='create flashable uninstaller')
uninstaller_parser.set_defaults(func=zip_uninstaller)

clean_parser = subparsers.add_parser('clean', help='clean [target...] targets: binary apk zip')
clean_parser = subparsers.add_parser('clean', help='clean [target...] targets: binary java zip')
clean_parser.add_argument('target', nargs='*')
clean_parser.set_defaults(func=cleanup)

Expand Down
1 change: 1 addition & 0 deletions java
Submodule java added at 39b6df
7 changes: 0 additions & 7 deletions ziptools/zipsigner/.gitignore

This file was deleted.

36 changes: 0 additions & 36 deletions ziptools/zipsigner/build.gradle

This file was deleted.

Binary file removed ziptools/zipsigner/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 0 additions & 6 deletions ziptools/zipsigner/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

Loading

0 comments on commit 60181c4

Please sign in to comment.