Skip to content

Commit

Permalink
update code style
Browse files Browse the repository at this point in the history
fk eclipse did everything wrong
  • Loading branch information
androidlover5842 committed Mar 25, 2018
1 parent b0f3303 commit e2761d1
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 59 deletions.
10 changes: 6 additions & 4 deletions src/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@

import mkTree.MakeTree;
import util.RunCode;
import util.ShellExecuter;
import util.ShellExecutor;


public class MainActivity {
private static String applicationName = "TwrpBuilder";
private static ShellExecutor shell;


public static void usePosixParser(final String[] commandLineArguments)
Expand Down Expand Up @@ -82,12 +83,12 @@ public static void usePosixParser(final String[] commandLineArguments)
System.out.println("Building tree using: "+g);
if(!new File("recovery.img").exists())
{
ShellExecuter.cp(g,"recovery.img");
shell.cp(g,"recovery.img");
}
else
{
ShellExecuter.command("rm -rf recovery.img");
ShellExecuter.cp(g,"recovery.img");
shell.command("rm -rf recovery.img");
shell.cp(g,"recovery.img");
}

if(commandLine.hasOption("t"))
Expand Down Expand Up @@ -197,6 +198,7 @@ public static void printHelp(

public static void main(final String[] commandLineArguments)
{
shell=new ShellExecutor();
if (commandLineArguments.length < 1)
{
System.out.println("-- USAGE --");
Expand Down
65 changes: 33 additions & 32 deletions src/mkTree/MakeTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@

import util.*;

import javax.rmi.CORBA.Util;

public class MakeTree {
private long l=0;
private String compressionType;
private boolean lz4,lzma;
private String fstabIdata=ShellExecuter.CopyRight();
private ShellExecutor shell;
private String copyRight=shell.CopyRight();
public static boolean otg;
private GetBuildInfo info;
private Config config;
private String out;
public MakeTree(boolean mtk,String type){
config=new Config();
shell=new ShellExecutor();
out=config.outDir;
if(mtk)
{
Expand All @@ -28,15 +29,15 @@ public MakeTree(boolean mtk,String type){

extractFstab();
info=new GetBuildInfo();
if(!ShellExecuter.mkdir(info.getPathS()))
if(!shell.mkdir(info.getPathS()))
{
System.out.println("Failed to make dir");
System.exit(0);
}

if(info.getCodename().isEmpty())
{
ShellExecuter.command("sed 's/\\[\\([^]]*\\)\\]/\\1/g' "+info.propFile()+" | sed 's/: /=/g' | tee > b.prop && mv -f b.prop build.prop");
shell.command("sed 's/\\[\\([^]]*\\)\\]/\\1/g' "+info.propFile()+" | sed 's/: /=/g' | tee > b.prop && mv -f b.prop build.prop");
if(info.getCodename().isEmpty())
{
System.out.println("Failed to get info");
Expand Down Expand Up @@ -66,28 +67,28 @@ public MakeTree(boolean mtk,String type){


private void extractKernel(boolean mtk) {
ShellExecuter.command("chmod 777 umkbootimg");
shell.command("chmod 777 umkbootimg");
if(mtk)
{
ShellExecuter.command("./umkbootimg recovery.img");
shell.command("./umkbootimg recovery.img");
}
else
{
ShellExecuter.mkdir(out);
ShellExecuter.command("./umkbootimg -i recovery.img -o "+out);
shell.mkdir(out);
shell.command("./umkbootimg -i recovery.img -o "+out);
}
}

private void mkKernel(boolean mtk) {
System.out.println("Making kernel.mk");
if(new File(out+"recovery.img-zImage").exists())
{
ShellExecuter.cp(out+"recovery.img-zImage", info.getPathS()+"kernel");
shell.cp(out+"recovery.img-zImage", info.getPathS()+"kernel");
}
if(new File(out+"recovery.img-dt").length()!=l)
{

ShellExecuter.cp(out+"recovery.img-dt", info.getPathS()+"dt.img");
shell.cp(out+"recovery.img-dt", info.getPathS()+"dt.img");
new FWriter("kernel.mk",getKernelData(true));
}else {
new FWriter("kernel.mk",getKernelData(false));
Expand All @@ -97,12 +98,12 @@ private void mkKernel(boolean mtk) {

private String getKernelData(boolean dt) {
String idata;
String pagesize=ShellExecuter.commandnoapp("cat "+out+"recovery.img-pagesize");
String cmdline=ShellExecuter.commandnoapp("cat "+out+"recovery.img-cmdline");
String ramdiskofsset=ShellExecuter.commandnoapp("cat "+out+"recovery.img-ramdisk_offset");
String tagsoffset=ShellExecuter.commandnoapp("cat "+out+"recovery.img-tags_offset");
String kernelbase=ShellExecuter.commandnoapp("cat "+out+"recovery.img-base");
idata=ShellExecuter.CopyRight();
String pagesize=shell.commandnoapp("cat "+out+"recovery.img-pagesize");
String cmdline=shell.commandnoapp("cat "+out+"recovery.img-cmdline");
String ramdiskofsset=shell.commandnoapp("cat "+out+"recovery.img-ramdisk_offset");
String tagsoffset=shell.commandnoapp("cat "+out+"recovery.img-tags_offset");
String kernelbase=shell.commandnoapp("cat "+out+"recovery.img-base");
idata=copyRight;
idata+="# Kernel\n" +
"TARGET_PREBUILT_KERNEL := "+info.getPathS()+"kernel\n" +
"BOARD_KERNEL_CMDLINE := "+cmdline+" androidboot.selinux=permissive\n" +
Expand All @@ -117,21 +118,21 @@ private String getKernelData(boolean dt) {
}

public void extractFstab() {
compressionType=ShellExecuter.commandnoapp("cd "+out+" && file --mime-type recovery.img-ramdisk.* | cut -d / -f 2 | cut -d '-' -f 2");
compressionType=shell.commandnoapp("cd "+out+" && file --mime-type recovery.img-ramdisk.* | cut -d / -f 2 | cut -d '-' -f 2");
if(compressionType.equals("lzma"))
{
System.out.println("Found lzma comression in ramdisk");
ShellExecuter.command("mv "+out+"recovery.img-ramdisk.gz "+out+"recovery.img-ramdisk.lzma && lzma -d "+out+"recovery.img-ramdisk.lzma && cd "+out+" && cpio -i <recovery.img-ramdisk");
shell.command("mv "+out+"recovery.img-ramdisk.gz "+out+"recovery.img-ramdisk.lzma && lzma -d "+out+"recovery.img-ramdisk.lzma && cd "+out+" && cpio -i <recovery.img-ramdisk");
lzma=true;
}else if(compressionType.equals("gzip"))
{
System.out.println("Found gzip comression in ramdisk");
ShellExecuter.command("gzip -d "+out+"recovery.img-ramdisk.gz && cd "+out+" && cpio -i <recovery.img-ramdisk");
shell.command("gzip -d "+out+"recovery.img-ramdisk.gz && cd "+out+" && cpio -i <recovery.img-ramdisk");
}
else if(compressionType.equals("lz4"))
{
System.out.println("Found lz4 comression in ramdisk");
ShellExecuter.commandnoapp("cd "+out+" && lz4 -d recovery.img-ramdisk.* recovery.img-ramdisk && cpio -i <recovery.img-ramdisk ");
shell.commandnoapp("cd "+out+" && lz4 -d recovery.img-ramdisk.* recovery.img-ramdisk && cpio -i <recovery.img-ramdisk ");
lz4=true;
}
else
Expand All @@ -146,11 +147,11 @@ else if(compressionType.equals("lz4"))
private void FstablastMessage() {
if(new File(out+"etc/twrp.fstab").exists()) {
Fstab(out+"etc/twrp.fstab");
ShellExecuter.command("mkdir "+info.getPathS()+"stock && mv "+out+"etc/* "+info.getPathS()+"stock/");
shell.command("mkdir "+info.getPathS()+"stock && mv "+out+"etc/* "+info.getPathS()+"stock/");
}else if (new File(out+"etc/recovery.fstab").exists())
{
Fstab(out+"etc/recovery.fstab");
ShellExecuter.command("mkdir "+info.getPathS()+"stock && mv "+out+"etc/* "+info.getPathS()+"stock/");
shell.command("mkdir "+info.getPathS()+"stock && mv "+out+"etc/* "+info.getPathS()+"stock/");
}
System.out.println("Build fingerPrint: "+info.getFingerPrint());
System.out.println("tree ready for "+ info.getCodename());
Expand All @@ -168,7 +169,7 @@ public void MkFstab() {


private boolean checkPartition(String path,String partition){
String s=ShellExecuter.commandnoapp("cat "+path+" | grep -iw "+partition);
String s=shell.commandnoapp("cat "+path+" | grep -iw "+partition);
if (s.contains(partition))
{
return true;
Expand All @@ -180,7 +181,7 @@ private boolean checkPartition(String path,String partition){

private void Fstab(String path)
{
String toWrite=ShellExecuter.CopyRight();
String toWrite=copyRight;
if (checkPartition(path,"boot"))
{
toWrite+=grepPartition(path,"boot");
Expand Down Expand Up @@ -221,7 +222,7 @@ private void Fstab(String path)

private String grepPartition(String path,String partition) {
String fullpath=null;
String s =ShellExecuter.commandnoapp("for i in $(cat "+path+" | grep -wi /"+partition+")\n" +
String s =shell.commandnoapp("for i in $(cat "+path+" | grep -wi /"+partition+")\n" +
"do\n" +
"a=$(echo $i | grep /dev)\n" +
"echo $a\n" +
Expand All @@ -230,7 +231,7 @@ private String grepPartition(String path,String partition) {

if(s.isEmpty())
{
s =ShellExecuter.commandnoapp("for i in $(cat "+path+" | grep -wi /"+partition+")\n" +
s =shell.commandnoapp("for i in $(cat "+path+" | grep -wi /"+partition+")\n" +
"do\n" +
"a=$(echo $i | grep /emmc)\n" +
"echo $a\n" +
Expand Down Expand Up @@ -261,7 +262,7 @@ private void CheckCompression() {
}
if(idata!=null)
{
ShellExecuter.command("echo "+idata +" >> " +info.getPath()+"/kernel.mk");
shell.command("echo "+idata +" >> " +info.getPath()+"/kernel.mk");
}
}

Expand All @@ -271,7 +272,7 @@ public void MkOmni() {
}

private String getOmniData() {
String idata =ShellExecuter.CopyRight();
String idata =copyRight;
idata+="$(call inherit-product, $(SRC_TARGET_DIR)/product/full_base.mk)\n" +
"\n" +
"PRODUCT_COPY_FILES += "+info.getPathS()+"kernel:kernel\n" +
Expand All @@ -292,7 +293,7 @@ public void MkAndroid() {
}

private String getAndroidtData() {
String idata =ShellExecuter.CopyRight();
String idata =copyRight;
idata+="ifneq ($(filter "+info.getCodename()+",$(TARGET_DEVICE)),)\n" +
"\n" +
"LOCAL_PATH := "+info.getPath()+"\n" +
Expand All @@ -310,7 +311,7 @@ public void MkAndroidProducts() {
}

private String getAndroidProductsData() {
String idata =ShellExecuter.CopyRight();
String idata =copyRight;
idata+="LOCAL_PATH := "+info.getPath()+"\n" +
"\n" +
"PRODUCT_MAKEFILES := $(LOCAL_PATH)/omni_"+info.getCodename()+".mk";
Expand All @@ -328,7 +329,7 @@ public void MkBoardConfig(String type){
}

private String getBoardData(String type) {
String idata =ShellExecuter.CopyRight();
String idata =copyRight;
idata+="LOCAL_PATH := "+info.getPath()+"\n" +
"\n" +
"TARGET_BOARD_PLATFORM := "+info.getPlatform()+"\n" +
Expand Down
13 changes: 7 additions & 6 deletions src/util/Clean.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
import java.io.File;

public class Clean {

private ShellExecutor shell;
public Clean(){
ShellExecuter.commandnoapp("rm -rf build.prop recovery.img " );
shell=new ShellExecutor();
shell.commandnoapp("rm -rf build.prop recovery.img " );
if (new File("mounts").exists())
{
ShellExecuter.commandnoapp("rm mounts ");
shell.commandnoapp("rm mounts ");
}
if (new File("umkbootimg").exists())
{
ShellExecuter.commandnoapp("rm umkbootimg");
shell.commandnoapp("rm umkbootimg");
}

if (new File(Config.outDir).exists())
{
ShellExecuter.commandnoapp("rm -rf "+Config.outDir);
shell.commandnoapp("rm -rf "+Config.outDir);
}

if(new File("unpack-MTK.pl").exists())
{
ShellExecuter.command("rm unpack-MTK.pl");
shell.command("rm unpack-MTK.pl");
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/util/ExtractBackup.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ public class ExtractBackup {

private String rooted;
private String not_rooted;
private ShellExecutor shell;
public ExtractBackup(String name) {
rooted=ShellExecuter.commandnoapp("file --mime-type "+name+" | grep -w 'gzip' | cut -d / -f 2 | cut -d \"-\" -f 2");
not_rooted=ShellExecuter.commandnoapp("file --mime-type "+name+" | grep -w 'zip' | cut -d / -f 2 | cut -d \"-\" -f 2");
shell=new ShellExecutor();
rooted= shell.commandnoapp("file --mime-type "+name+" | grep -w 'gzip' | cut -d / -f 2 | cut -d \"-\" -f 2");
not_rooted= shell.commandnoapp("file --mime-type "+name+" | grep -w 'zip' | cut -d / -f 2 | cut -d \"-\" -f 2");
if(rooted.equals("gzip"))
{
extractGzip(name);
Expand All @@ -21,12 +23,12 @@ else if(not_rooted.equals("zip"))
}

private void extractGzip(String file) {
ShellExecuter.command("tar -xvf " + file);
shell.command("tar -xvf " + file);
}

private void extractZip(String file) {
ShellExecuter.command("unzip -o "+ file);
ShellExecuter.command("sed 's/\\[\\([^]]*\\)\\]/\\1/g' "+GetBuildInfo.propFile()+" | sed 's/: /=/g' | tee > b.prop && mv -f b.prop build.prop");
shell.command("unzip -o "+ file);
shell.command("sed 's/\\[\\([^]]*\\)\\]/\\1/g' "+GetBuildInfo.propFile()+" | sed 's/: /=/g' | tee > b.prop && mv -f b.prop build.prop");
new GetBuildInfo();
}
}
22 changes: 13 additions & 9 deletions src/util/GetBuildInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ public class GetBuildInfo {
private static String model,product,brand,codename,platform,api,size,fingerprint;
private static Config config;
private static String out=config.outDir;
private static ShellExecutor shell;

public static String propFile() {
shell=new ShellExecutor();
config=new Config();
String prop=null;
if(new File("build.prop").exists())
{
Expand All @@ -25,17 +29,17 @@ public static String propFile() {
}

public static String getModel() {
model=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.product.model= | cut -d = -f 2");
model= shell.commandnoapp("cat "+propFile()+" | grep ro.product.model= | cut -d = -f 2");
return model;
}

public static String getProduct(){
product=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.build.product= | cut -d = -f 2");
product= shell.commandnoapp("cat "+propFile()+" | grep ro.build.product= | cut -d = -f 2");
return product;
}

public static String getBrand() {
brand=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.product.brand= | cut -d = -f 2");
brand= shell.commandnoapp("cat "+propFile()+" | grep ro.product.brand= | cut -d = -f 2");
if(brand.contains("-"))
{
String newstr=brand.replace("-", "_");
Expand All @@ -46,7 +50,7 @@ public static String getBrand() {
}

public static String getCodename() {
codename=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.build.product= | cut -d = -f 2");
codename= shell.commandnoapp("cat "+propFile()+" | grep ro.build.product= | cut -d = -f 2");
if(codename.contains("-"))
{
String newstr=codename.replace("-", "_");
Expand All @@ -63,10 +67,10 @@ else if (codename.contains(" "))
}

public static String getPlatform() {
platform=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.board.platform= | cut -d = -f 2");
platform= shell.commandnoapp("cat "+propFile()+" | grep ro.board.platform= | cut -d = -f 2");
if (platform.isEmpty())
{
platform=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.mediatek.platform= | cut -d = -f 2");
platform= shell.commandnoapp("cat "+propFile()+" | grep ro.mediatek.platform= | cut -d = -f 2");
if(platform.isEmpty())
{
System.out.println("Device not supported");
Expand All @@ -77,17 +81,17 @@ public static String getPlatform() {
}

public static String getApi() {
api=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.product.cpu.abi= | cut -d = -f 2");
api= shell.commandnoapp("cat "+propFile()+" | grep ro.product.cpu.abi= | cut -d = -f 2");
return api;
}

public static String getFingerPrint() {
fingerprint=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.build.fingerprint= | cut -d = -f 2");
fingerprint= shell.commandnoapp("cat "+propFile()+" | grep ro.build.fingerprint= | cut -d = -f 2");
return fingerprint;
}

public static String getSize() {
size=ShellExecuter.commandnoapp("wc -c < recovery.img");
size= shell.commandnoapp("wc -c < recovery.img");
return size;
}

Expand Down
Loading

0 comments on commit e2761d1

Please sign in to comment.