Skip to content

Commit c04f785

Browse files
author
mayankmetha
committed
Staging v1.4
1 parent e9b7640 commit c04f785

5 files changed

Lines changed: 132 additions & 30 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 19
99
targetSdkVersion 28
1010
versionCode 1
11-
versionName "1.3"
11+
versionName "1.4"
1212
}
1313
buildTypes {
1414
release {

app/src/main/java/com/mayank/rucky/MainActivity.java

Lines changed: 125 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public class MainActivity extends AppCompatActivity {
6969
BufferedReader dis;
7070
public static String getSHA512;
7171
public static String genSHA512;
72-
static private Boolean root = false;
73-
static private String libPath = null;
72+
private Boolean root = false;
73+
static private int downloadId = 0;
7474

7575
@Override
7676
protected void onCreate(Bundle savedInstanceState)throws NullPointerException {
@@ -84,7 +84,20 @@ protected void onCreate(Bundle savedInstanceState)throws NullPointerException {
8484
setSupportActionBar(toolbar);
8585
if (savedInstanceState == null) {
8686
permission();
87-
supportedFiles();
87+
if(root) {
88+
supportedFiles();
89+
} else {
90+
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
91+
builder.setTitle("Root Access Required!");
92+
builder.setCancelable(false);
93+
builder.setNegativeButton("Exit", ((dialog, which) -> {
94+
moveTaskToBack(true);
95+
android.os.Process.killProcess(android.os.Process.myPid());
96+
System.exit(1);
97+
}));
98+
AlertDialog rootMissing = builder.create();
99+
rootMissing.show();
100+
}
88101
}
89102
try {
90103
PackageInfo pInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
@@ -757,6 +770,7 @@ void updater(int mode) {
757770
.setCancelable(false)
758771
.setPositiveButton("Download & Install", (dialog, id) -> {
759772
getDownloadHash();
773+
downloadId = 1;
760774
Uri dl = Uri.parse("https://github.com/mayankmetha/Rucky/releases/download/"+newVersion+"/rucky.apk");
761775
download(dl);
762776
})
@@ -829,7 +843,8 @@ public void onReceive(Context context, Intent intent) {
829843
dlStatus = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
830844
long refId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
831845
if (refId == downloadRef && dlStatus == DownloadManager.STATUS_SUCCESSFUL) {
832-
generateHash();
846+
if(downloadId == 1) generateHash();
847+
else if(downloadId == 2) generateDependencyHash();
833848
}
834849
}
835850
}
@@ -907,11 +922,7 @@ void generateHash() {
907922
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
908923
alertBuilder.setMessage("Update file corrupted!")
909924
.setCancelable(false)
910-
.setPositiveButton("RETRY AGAIN", (dialogInterface, i) -> {
911-
Uri dl = Uri.parse("https://github.com/mayankmetha/Rucky/releases/download/"+newVersion+"/rucky.apk");
912-
download(dl);
913-
})
914-
.setNegativeButton("TRY LATER", (dialog, which) -> {
925+
.setNegativeButton("TRY AGAIN LATER", (dialog, which) -> {
915926
});
916927
AlertDialog alert = alertBuilder.create();
917928
alert.show();
@@ -945,21 +956,9 @@ private void permission() {
945956
String rootCheck = dis.readLine();
946957
if(rootCheck.contains("uid=0")) root = true;
947958
}
948-
} catch (Exception e) {
959+
} catch (IOException e) {
949960
e.printStackTrace();
950961
}
951-
if(!root) {
952-
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
953-
builder.setTitle("Root Access Required!");
954-
builder.setCancelable(false);
955-
builder.setPositiveButton("Exit", (dialog, which) -> {
956-
moveTaskToBack(true);
957-
android.os.Process.killProcess(android.os.Process.myPid());
958-
System.exit(1);
959-
});
960-
AlertDialog rootExit = builder.create();
961-
rootExit.show();
962-
}
963962
}
964963

965964
private void supportedFiles() {
@@ -992,11 +991,18 @@ private void supportedFiles() {
992991
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
993992
builder.setTitle("Dependency file missing");
994993
builder.setCancelable(false);
995-
builder.setPositiveButton("Exit", (dialog, which) -> {
994+
builder.setPositiveButton("Download & Install", (dialog, which) -> {
995+
String arch = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? Build.SUPPORTED_ABIS[0] : Build.CPU_ABI;
996+
downloadDependenciesHash(arch);
997+
downloadId = 2;
998+
Uri dl = Uri.parse("https://raw.githubusercontent.com/mayankmetha/Rucky/master/release/" + arch + "/rucky-hid");
999+
downloadDependencies(dl);
1000+
});
1001+
builder.setNegativeButton("Exit", ((dialog, which) -> {
9961002
moveTaskToBack(true);
9971003
android.os.Process.killProcess(android.os.Process.myPid());
9981004
System.exit(1);
999-
});
1005+
}));
10001006
AlertDialog fileMissing = builder.create();
10011007
fileMissing.show();
10021008
} else {
@@ -1016,4 +1022,99 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
10161022
}
10171023
}
10181024
}
1025+
1026+
private void downloadDependenciesHash(String arch) {
1027+
final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
1028+
assert conMgr != null;
1029+
final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
1030+
if (activeNetwork != null && activeNetwork.isConnected()) {
1031+
try {
1032+
Notification.Builder updateNotify;
1033+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
1034+
updateNotify = new Notification.Builder(this, CHANNEL_ID);
1035+
} else {
1036+
updateNotify = new Notification.Builder(this);
1037+
}
1038+
updateNotify.setContentTitle("Verifying dependencies")
1039+
.setContentText("Please Wait...")
1040+
.setSmallIcon(R.drawable.ic_notification)
1041+
.setAutoCancel(true);
1042+
getManager().notify(4,updateNotify.build());
1043+
URL url = new URL("https://raw.githubusercontent.com/mayankmetha/Rucky/master/release/"+arch+"/rucky-hid.sha512");
1044+
new fetchHash().execute(url);
1045+
getManager().cancel(4);
1046+
} catch (MalformedURLException e) {
1047+
e.printStackTrace();
1048+
}
1049+
} else {
1050+
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
1051+
alertBuilder.setMessage("Please check the network connection")
1052+
.setCancelable(false)
1053+
.setPositiveButton("OK", (dialogInterface, i) -> {
1054+
});
1055+
AlertDialog alert = alertBuilder.create();
1056+
alert.show();
1057+
}
1058+
}
1059+
1060+
private void downloadDependencies(Uri uri) {
1061+
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
1062+
alertBuilder.setMessage("Please leave the app open")
1063+
.setCancelable(false)
1064+
.setPositiveButton("OK", (dialogInterface, i) -> {
1065+
});
1066+
AlertDialog alert = alertBuilder.create();
1067+
alert.show();
1068+
File fDel = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/rucky-hid");
1069+
if (fDel.exists()) {
1070+
fDel.delete();
1071+
}
1072+
downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
1073+
DownloadManager.Request req = new DownloadManager.Request(uri);
1074+
req.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
1075+
req.setAllowedOverRoaming(true);
1076+
req.setTitle("rucky-hid");
1077+
req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"/rucky-hid");
1078+
req.setVisibleInDownloadsUi(true);
1079+
DownloadManager.Query q = new DownloadManager.Query();
1080+
q.setFilterById(DownloadManager.STATUS_FAILED | DownloadManager.STATUS_SUCCESSFUL | DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING);
1081+
Cursor c = downloadManager.query(q);
1082+
while (c.moveToNext()) {
1083+
downloadManager.remove(c.getLong(c.getColumnIndex(DownloadManager.COLUMN_ID)));
1084+
}
1085+
downloadRef = downloadManager.enqueue(req);
1086+
IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
1087+
registerReceiver(downloadBR, filter);
1088+
}
1089+
1090+
void generateDependencyHash() {
1091+
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/rucky-hid");
1092+
try {
1093+
genSHA512 = Files.asByteSource(file).hash(Hashing.sha512()).toString();
1094+
} catch (IOException e) {
1095+
e.printStackTrace();
1096+
}
1097+
if(getSHA512.equals(genSHA512)) {
1098+
installDependency();
1099+
} else {
1100+
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
1101+
alertBuilder.setMessage("Dependency file corrupted!")
1102+
.setCancelable(false)
1103+
.setNegativeButton("TRY AGAIN LATER", (dialog, which) -> {
1104+
});
1105+
AlertDialog alert = alertBuilder.create();
1106+
alert.show();
1107+
}
1108+
}
1109+
1110+
private void installDependency() {
1111+
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/rucky-hid");
1112+
String path = file.getAbsolutePath();
1113+
try {
1114+
dos.writeBytes("mv "+path+" /data/local/tmp/rucky-hid;chmod 755 /data/local/tmp/rucky-hid\n");
1115+
dos.flush();
1116+
} catch (IOException e) {
1117+
e.printStackTrace();
1118+
}
1119+
}
10191120
}

app/src/main/java/com/mayank/rucky/RootSettingsFragment.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
8686
Preference versionPreference = findPreference("version");
8787
assert versionPreference != null;
8888
versionPreference.setSummary(Double.toString(currentVersion));
89-
String currentArch;
90-
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP)
91-
currentArch = Build.SUPPORTED_ABIS[0];
92-
else currentArch = Build.CPU_ABI;
89+
String currentArch = Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP?Build.SUPPORTED_ABIS[0]:Build.CPU_ABI;
9390
Preference archPreference = findPreference("arch");
9491
assert archPreference != null;
9592
archPreference.setSummary(currentArch);

release/genSHA512.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
openssl sha512 ./arm64-v8a/rucky-hid | cut -d"=" -f2 | cut -d" " -f2 > ./arm64-v8a/rucky-hid.sha512
2+
openssl sha512 ./armeabi-v7a/rucky-hid | cut -d"=" -f2 | cut -d" " -f2 > ./armeabi-v7a/rucky-hid.sha512
3+
openssl sha512 ./x86/rucky-hid | cut -d"=" -f2 | cut -d" " -f2 > ./x86/rucky-hid.sha512
4+
openssl sha512 ./x86_64/rucky-hid | cut -d"=" -f2 | cut -d" " -f2 > ./x86_64/rucky-hid.sha512

release/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3
1+
1.4

0 commit comments

Comments
 (0)