Skip to content

Commit

Permalink
Support 32/64-bit virtual spaces.
Browse files Browse the repository at this point in the history
Fix work on android 6 and later.
  • Loading branch information
Enyby committed Aug 15, 2019
1 parent 810d073 commit 90ac09b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
12 changes: 6 additions & 6 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.virtualbackup"
android:versionCode="1"
android:versionName="1.0" >
package="com.virtualbackup32"
android:versionCode="2"
android:versionName="1.1" >

<uses-sdk
android:minSdkVersion="14"
Expand All @@ -18,11 +18,11 @@
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="Virtual Backup"
android:label="Virtual Backup 32"
android:theme="@android:style/Theme.DeviceDefault" >
<activity
android:name=".MainActivity"
android:label="Virtual Backup" >
android:name="com.virtualbackup.MainActivity"
android:label="Virtual Backup 32" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
35 changes: 32 additions & 3 deletions src/com/virtualbackup/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;

import com.virtualbackup32.R;

import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
Expand Down Expand Up @@ -41,6 +46,14 @@ protected void onCreate(Bundle savedInstanceState) {

Button restore = findViewById(R.id.restore);
restore.setOnClickListener(this);

if (Build.VERSION.SDK_INT >= 23) {
requestPermissions(new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
"android.permission.WRITE_MEDIA_STORAGE",
}, 0);
}
}

@Override
Expand Down Expand Up @@ -97,14 +110,30 @@ public void onClick(DialogInterface dialog, int which) {

status.setText(cmd[from] + "\n\n-->\n\n" + cmd[to]);

Log.e("VirtualBackup", "cmd: " + Arrays.toString(cmd));

new Thread(new Runnable() {
@Override
public void run() {
String descr;
String descr = "";
try {
new File(cmd[to]).mkdirs();
File tdir = new File(cmd[to]);
descr += "mkdirs '" + cmd[to] + "': " + tdir.mkdirs() + "\n";
descr += "exists: " + tdir.exists() + "\n";
descr += "isDir: " + tdir.isDirectory() + "\n";
byte[] err = new byte[4096];
if (!tdir.isDirectory()) {
Process proc = Runtime.getRuntime().exec(new String[] {"mkdir", "-p", cmd[to]});
int read = proc.getErrorStream().read(err);
if (read > 0) descr += "mkdir err: " + new String(err, 0, read) + "\n";
descr += "mkdir end: " + proc.waitFor();
descr += "exists: " + tdir.exists() + "\n";
descr += "isDir: " + tdir.isDirectory() + "\n";
}
Process proc = Runtime.getRuntime().exec(cmd);
descr = "end: " + proc.waitFor();
int read = proc.getErrorStream().read(err);
if (read > 0) descr += "cp err: " + new String(err, 0, read) + "\n";
descr += "cp end: " + proc.waitFor();
} catch (Exception e) {
Log.w(TAG, "Failed copy", e);
descr = e.toString();
Expand Down

0 comments on commit 90ac09b

Please sign in to comment.