Skip to content

Commit

Permalink
On x86, ask the user to download Cydia Substrate
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuowei committed Feb 15, 2015
1 parent 01969e9 commit f82e534
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bin/
gen/
obj/
libs/armeabi-v7a/
libs/x86/

# Local configuration file (sdk path, etc)
local.properties
Expand Down
Binary file modified prebuilts/tinysubstrate-bin/x86/libmcpelauncher_tinysubstrate.so
100644 → 100755
Binary file not shown.
24 changes: 24 additions & 0 deletions res/layout/get_substrate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/get_substrate_explanation"
android:textSize="16sp"/>
<Button
android:text="@string/get_substrate_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="downloadClicked"/>
</LinearLayout>
</ScrollView>
4 changes: 4 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,9 @@ We are working on a fix for this, but in the meantime, BlockLauncher functions a
<string name="recorder_no_recording">There are no recordings to view.</string>
<string name="advertising_privacy_policy">Advertising privacy policy</string>
<string name="about_kamcord_credits">Certain video and audio capture functionality is Powered by Kamcord™ (kamcord.com), and your use of such functionality is subject to the Kamcord Terms of Use (kamcord.com/tos) and Privacy Policy (kamcord.com/privacy)</string>

<string name="get_substrate_explanation">You need to install the Substrate app to use BlockLauncher. (You do not have to set it up, and you do not need root access: you only need to install it.)</string>
<string name="get_substrate_button">Get Substrate</string>

<string name="report_error_title">Oh nose everything broke</string>
</resources>
35 changes: 35 additions & 0 deletions src/com/mojang/minecraftpe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import static net.zhuoweizhang.mcpelauncher.Utils.isSafeMode;
import net.zhuoweizhang.mcpelauncher.patch.PatchUtils;
import net.zhuoweizhang.mcpelauncher.ui.AboutAppActivity;
import net.zhuoweizhang.mcpelauncher.ui.GetSubstrateActivity;
import net.zhuoweizhang.mcpelauncher.ui.HoverCar;
import net.zhuoweizhang.mcpelauncher.ui.MainMenuOptionsActivity;
import net.zhuoweizhang.mcpelauncher.ui.ManagePatchesActivity;
Expand Down Expand Up @@ -198,6 +199,9 @@ public void onCreate(Bundle savedInstanceState) {
System.exit(0);
}
hasAlreadyInited = true;

checkForSubstrate();

int safeModeCounter = Utils.getPrefs(2).getInt("safe_mode_counter", 0);
System.out.println("Current fails: " + safeModeCounter);
if (safeModeCounter == MAX_FAILS) {
Expand Down Expand Up @@ -1988,6 +1992,37 @@ private void fixMyEpicFail() {
prefs.edit().putInt("last_bl_version", myVersion).apply();
}
}

private void checkForSubstrate() {
if (!Build.CPU_ABI.equals("x86")) return; // we're not on x86
PackageInfo substrateInfo = null;
try {
substrateInfo = this.getPackageManager().getPackageInfo("com.saurik.substrate", 0);
} catch (PackageManager.NameNotFoundException e) {
}
if (substrateInfo == null) {
finish();
startActivity(new Intent(this, GetSubstrateActivity.class));
try {
Thread.sleep(100);
android.os.Process.killProcess(android.os.Process.myPid());
} catch (Throwable t) {
}
return;
}
File substrateLibFile = this.getFileStreamPath("libmcpelauncher_tinysubstrate.so");
if (!substrateLibFile.exists()) {
// copy the substrate lib file over
File substrateSourceLibFile = new File(substrateInfo.applicationInfo.nativeLibraryDir, "libsubstrate.so");
try {
PatchUtils.copy(substrateSourceLibFile, substrateLibFile);
} catch (IOException ie) {
throw new RuntimeException(ie);
}
}
System.load(substrateLibFile.getAbsolutePath());
}

private class PopupTextWatcher implements TextWatcher, TextView.OnEditorActionListener {
public void afterTextChanged(Editable e) {
if (BuildConfig.DEBUG)
Expand Down
35 changes: 35 additions & 0 deletions src/net/zhuoweizhang/mcpelauncher/ui/GetSubstrateActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.zhuoweizhang.mcpelauncher.ui;

import android.app.*;
import android.content.*;
import android.net.*;
import android.os.*;
import android.view.*;

import net.zhuoweizhang.mcpelauncher.*;

public class GetSubstrateActivity extends Activity {

@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.get_substrate);
}

public void downloadClicked(View v) {
String url = isPlay()? "market://details?id=com.saurik.substrate" : "http://www.cydiasubstrate.com/";
Intent downloadIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
downloadIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(downloadIntent);
finish();
}

private boolean isPlay() {
try {
return getPackageManager().getInstallerPackageName(getPackageName()).equals("com.android.vending");
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}

0 comments on commit f82e534

Please sign in to comment.