Skip to content

Commit

Permalink
Staging v1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mayankmetha committed Aug 4, 2019
1 parent e9b7640 commit c04f785
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.3"
versionName "1.4"
}
buildTypes {
release {
Expand Down
149 changes: 125 additions & 24 deletions app/src/main/java/com/mayank/rucky/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public class MainActivity extends AppCompatActivity {
BufferedReader dis;
public static String getSHA512;
public static String genSHA512;
static private Boolean root = false;
static private String libPath = null;
private Boolean root = false;
static private int downloadId = 0;

@Override
protected void onCreate(Bundle savedInstanceState)throws NullPointerException {
Expand All @@ -84,7 +84,20 @@ protected void onCreate(Bundle savedInstanceState)throws NullPointerException {
setSupportActionBar(toolbar);
if (savedInstanceState == null) {
permission();
supportedFiles();
if(root) {
supportedFiles();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Root Access Required!");
builder.setCancelable(false);
builder.setNegativeButton("Exit", ((dialog, which) -> {
moveTaskToBack(true);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}));
AlertDialog rootMissing = builder.create();
rootMissing.show();
}
}
try {
PackageInfo pInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
Expand Down Expand Up @@ -757,6 +770,7 @@ void updater(int mode) {
.setCancelable(false)
.setPositiveButton("Download & Install", (dialog, id) -> {
getDownloadHash();
downloadId = 1;
Uri dl = Uri.parse("https://github.com/mayankmetha/Rucky/releases/download/"+newVersion+"/rucky.apk");
download(dl);
})
Expand Down Expand Up @@ -829,7 +843,8 @@ public void onReceive(Context context, Intent intent) {
dlStatus = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
long refId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
if (refId == downloadRef && dlStatus == DownloadManager.STATUS_SUCCESSFUL) {
generateHash();
if(downloadId == 1) generateHash();
else if(downloadId == 2) generateDependencyHash();
}
}
}
Expand Down Expand Up @@ -907,11 +922,7 @@ void generateHash() {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
alertBuilder.setMessage("Update file corrupted!")
.setCancelable(false)
.setPositiveButton("RETRY AGAIN", (dialogInterface, i) -> {
Uri dl = Uri.parse("https://github.com/mayankmetha/Rucky/releases/download/"+newVersion+"/rucky.apk");
download(dl);
})
.setNegativeButton("TRY LATER", (dialog, which) -> {
.setNegativeButton("TRY AGAIN LATER", (dialog, which) -> {
});
AlertDialog alert = alertBuilder.create();
alert.show();
Expand Down Expand Up @@ -945,21 +956,9 @@ private void permission() {
String rootCheck = dis.readLine();
if(rootCheck.contains("uid=0")) root = true;
}
} catch (Exception e) {
} catch (IOException e) {
e.printStackTrace();
}
if(!root) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Root Access Required!");
builder.setCancelable(false);
builder.setPositiveButton("Exit", (dialog, which) -> {
moveTaskToBack(true);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
});
AlertDialog rootExit = builder.create();
rootExit.show();
}
}

private void supportedFiles() {
Expand Down Expand Up @@ -992,11 +991,18 @@ private void supportedFiles() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Dependency file missing");
builder.setCancelable(false);
builder.setPositiveButton("Exit", (dialog, which) -> {
builder.setPositiveButton("Download & Install", (dialog, which) -> {
String arch = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? Build.SUPPORTED_ABIS[0] : Build.CPU_ABI;
downloadDependenciesHash(arch);
downloadId = 2;
Uri dl = Uri.parse("https://raw.githubusercontent.com/mayankmetha/Rucky/master/release/" + arch + "/rucky-hid");
downloadDependencies(dl);
});
builder.setNegativeButton("Exit", ((dialog, which) -> {
moveTaskToBack(true);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
});
}));
AlertDialog fileMissing = builder.create();
fileMissing.show();
} else {
Expand All @@ -1016,4 +1022,99 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}
}
}

private void downloadDependenciesHash(String arch) {
final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
assert conMgr != null;
final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
if (activeNetwork != null && activeNetwork.isConnected()) {
try {
Notification.Builder updateNotify;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
updateNotify = new Notification.Builder(this, CHANNEL_ID);
} else {
updateNotify = new Notification.Builder(this);
}
updateNotify.setContentTitle("Verifying dependencies")
.setContentText("Please Wait...")
.setSmallIcon(R.drawable.ic_notification)
.setAutoCancel(true);
getManager().notify(4,updateNotify.build());
URL url = new URL("https://raw.githubusercontent.com/mayankmetha/Rucky/master/release/"+arch+"/rucky-hid.sha512");
new fetchHash().execute(url);
getManager().cancel(4);
} catch (MalformedURLException e) {
e.printStackTrace();
}
} else {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
alertBuilder.setMessage("Please check the network connection")
.setCancelable(false)
.setPositiveButton("OK", (dialogInterface, i) -> {
});
AlertDialog alert = alertBuilder.create();
alert.show();
}
}

private void downloadDependencies(Uri uri) {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
alertBuilder.setMessage("Please leave the app open")
.setCancelable(false)
.setPositiveButton("OK", (dialogInterface, i) -> {
});
AlertDialog alert = alertBuilder.create();
alert.show();
File fDel = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/rucky-hid");
if (fDel.exists()) {
fDel.delete();
}
downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request req = new DownloadManager.Request(uri);
req.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
req.setAllowedOverRoaming(true);
req.setTitle("rucky-hid");
req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"/rucky-hid");
req.setVisibleInDownloadsUi(true);
DownloadManager.Query q = new DownloadManager.Query();
q.setFilterById(DownloadManager.STATUS_FAILED | DownloadManager.STATUS_SUCCESSFUL | DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING);
Cursor c = downloadManager.query(q);
while (c.moveToNext()) {
downloadManager.remove(c.getLong(c.getColumnIndex(DownloadManager.COLUMN_ID)));
}
downloadRef = downloadManager.enqueue(req);
IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
registerReceiver(downloadBR, filter);
}

void generateDependencyHash() {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/rucky-hid");
try {
genSHA512 = Files.asByteSource(file).hash(Hashing.sha512()).toString();
} catch (IOException e) {
e.printStackTrace();
}
if(getSHA512.equals(genSHA512)) {
installDependency();
} else {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
alertBuilder.setMessage("Dependency file corrupted!")
.setCancelable(false)
.setNegativeButton("TRY AGAIN LATER", (dialog, which) -> {
});
AlertDialog alert = alertBuilder.create();
alert.show();
}
}

private void installDependency() {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/rucky-hid");
String path = file.getAbsolutePath();
try {
dos.writeBytes("mv "+path+" /data/local/tmp/rucky-hid;chmod 755 /data/local/tmp/rucky-hid\n");
dos.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
5 changes: 1 addition & 4 deletions app/src/main/java/com/mayank/rucky/RootSettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
Preference versionPreference = findPreference("version");
assert versionPreference != null;
versionPreference.setSummary(Double.toString(currentVersion));
String currentArch;
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP)
currentArch = Build.SUPPORTED_ABIS[0];
else currentArch = Build.CPU_ABI;
String currentArch = Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP?Build.SUPPORTED_ABIS[0]:Build.CPU_ABI;
Preference archPreference = findPreference("arch");
assert archPreference != null;
archPreference.setSummary(currentArch);
Expand Down
4 changes: 4 additions & 0 deletions release/genSHA512.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
openssl sha512 ./arm64-v8a/rucky-hid | cut -d"=" -f2 | cut -d" " -f2 > ./arm64-v8a/rucky-hid.sha512
openssl sha512 ./armeabi-v7a/rucky-hid | cut -d"=" -f2 | cut -d" " -f2 > ./armeabi-v7a/rucky-hid.sha512
openssl sha512 ./x86/rucky-hid | cut -d"=" -f2 | cut -d" " -f2 > ./x86/rucky-hid.sha512
openssl sha512 ./x86_64/rucky-hid | cut -d"=" -f2 | cut -d" " -f2 > ./x86_64/rucky-hid.sha512
2 changes: 1 addition & 1 deletion release/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3
1.4

0 comments on commit c04f785

Please sign in to comment.