修复 打包后ui脚本无法运行的问题

修复 打包后模块无法运行的问题
This commit is contained in:
hyb1996
2018-12-12 14:18:03 +08:00
parent c460425656
commit 05813499bc
33 changed files with 548 additions and 91 deletions

View File

@@ -9,6 +9,8 @@ import com.stardust.autojs.apkbuilder.ManifestEditor;
import com.stardust.autojs.apkbuilder.util.StreamUtils;
import com.stardust.autojs.project.BuildInfo;
import com.stardust.autojs.project.ProjectConfig;
import com.stardust.autojs.script.EncryptedScriptFileHeader;
import com.stardust.autojs.script.JavaScriptFileSource;
import com.stardust.pio.PFiles;
import com.stardust.util.AdvancedEncryptionStandard;
import com.stardust.util.MD5;
@@ -198,12 +200,16 @@ public class ApkBuilder {
}
private void encrypt(File toDir, File file) throws IOException {
PFiles.writeBytes(new File(toDir, file.getName()).getPath(), encrypt(file));
FileOutputStream fos = new FileOutputStream(new File(toDir, file.getName()));
EncryptedScriptFileHeader.INSTANCE.writeHeader(fos, (short) new JavaScriptFileSource(file).getExecutionMode());
encrypt(fos, file);
}
private byte[] encrypt(File file) throws IOException {
private void encrypt(FileOutputStream fos, File file) throws IOException {
try {
return new AdvancedEncryptionStandard(mKey.getBytes(), mInitVector).encrypt(PFiles.readBytes(file.getPath()));
byte[] bytes = new AdvancedEncryptionStandard(mKey.getBytes(), mInitVector).encrypt(PFiles.readBytes(file.getPath()));
fos.write(bytes);
fos.close();
} catch (Exception e) {
throw new IOException(e);
}
@@ -212,7 +218,7 @@ public class ApkBuilder {
public ApkBuilder replaceFile(String relativePath, String newFilePath) throws IOException {
if (newFilePath.endsWith(".js")) {
PFiles.writeBytes(new File(mWorkspacePath, relativePath).getPath(), encrypt(new File(newFilePath)));
encrypt(new FileOutputStream(new File(mWorkspacePath, relativePath)), new File(newFilePath));
} else {
StreamUtils.write(new FileInputStream(newFilePath), new FileOutputStream(new File(mWorkspacePath, relativePath)));
}

View File

@@ -5,6 +5,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import com.stardust.pio.UncheckedIOException;
import org.autojs.autojs.BuildConfig;
import com.stardust.util.DeveloperUtils;
@@ -20,6 +21,7 @@ public class ApkBuilderPluginHelper {
private static final String PLUGIN_PACKAGE_NAME = "org.autojs.apkbuilderplugin";
private static final String TEMPLATE_APK_PATH = "template.apk";
private static final boolean DEBUG_APK_PLUGIN = false;
public static boolean isPluginAvailable(Context context) {
return DeveloperUtils.checkSignature(context, PLUGIN_PACKAGE_NAME);
@@ -27,9 +29,9 @@ public class ApkBuilderPluginHelper {
public static InputStream openTemplateApk(Context context) {
try {
//if (BuildConfig.DEBUG) {
// return context.getAssets().open(TEMPLATE_APK_PATH);
//}
if (DEBUG_APK_PLUGIN && BuildConfig.DEBUG) {
return context.getAssets().open(TEMPLATE_APK_PATH);
}
return context.getPackageManager().getResourcesForApplication(PLUGIN_PACKAGE_NAME)
.getAssets().open(TEMPLATE_APK_PATH);
} catch (IOException e) {

View File

@@ -28,7 +28,6 @@ public class ScriptIntents {
public static final String EXTRA_KEY_LOOP_INTERVAL = "interval";
public static final String EXTRA_KEY_DELAY = "delay";
public static boolean isTaskerBundleValid(Bundle bundle) {
return bundle.containsKey(ScriptIntents.EXTRA_KEY_PATH) || bundle.containsKey(EXTRA_KEY_PRE_EXECUTE_SCRIPT);
}

View File

@@ -6,7 +6,6 @@ import android.text.TextUtils;
import com.stardust.app.GlobalAppContext;
import org.autojs.autojs.Pref;
import org.autojs.autojs.App;
import org.autojs.autojs.R;
import com.stardust.autojs.core.accessibility.AccessibilityService;
@@ -36,12 +35,12 @@ public class AccessibilityServiceTool {
public static void goToAccessibilitySetting() {
Context context = GlobalAppContext.get();
if (Pref.isFirstGoToAccessibilitySetting()) {
GlobalAppContext.toast(context.getString(R.string.text_please_choose) + context.getString(R.string._app_name));
GlobalAppContext.toast(context.getString(R.string.text_please_choose) + context.getString(R.string.app_name));
}
try {
AccessibilityServiceUtils.INSTANCE.goToAccessibilitySetting(context);
} catch (ActivityNotFoundException e) {
GlobalAppContext.toast(context.getString(R.string.go_to_accessibility_settings) + context.getString(R.string._app_name));
GlobalAppContext.toast(context.getString(R.string.go_to_accessibility_settings) + context.getString(R.string.app_name));
}
}

View File

@@ -158,7 +158,7 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
private void setUpToolbar() {
Toolbar toolbar = $(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitle(R.string._app_name);
toolbar.setTitle(R.string.app_name);
ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.text_drawer_open,
R.string.text_drawer_close);
drawerToggle.syncState();