Skip to content

Commit ff1abc1

Browse files
committed
Add backup support
1 parent b2fb3f5 commit ff1abc1

File tree

7 files changed

+140
-6
lines changed

7 files changed

+140
-6
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "ru.nikita.adb"
88
minSdkVersion 12
99
targetSdkVersion 20
10-
versionCode 3
11-
versionName "1.3"
10+
versionCode 4
11+
versionName "1.4"
1212
}
1313
buildTypes {
1414
release {

app/src/main/java/ru/nikita/adb/ADBActivity.java

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.app.Activity;
1111
import android.app.AlertDialog;
1212
import android.widget.EditText;
13+
import android.widget.Switch;
1314
import android.text.InputType;
1415
import android.content.DialogInterface;
1516
import android.content.Intent;
@@ -24,6 +25,7 @@
2425

2526
public class ADBActivity extends DevicesActivity {
2627
private static final int APP_INSTALL_FILE=1;
28+
private static final int RESTORE=2;
2729
@Override
2830
protected void onCreate(Bundle savedInstanceState) {
2931
setContentView(R.layout.adb_activity);
@@ -151,10 +153,13 @@ public void appManager(View view){
151153
@Override
152154
public void onActivityResult(int requestCode, int resultCode, Intent data) {
153155
if(resultCode == Activity.RESULT_OK && data != null){
154-
if(requestCode == APP_INSTALL_FILE){
155-
String filePath = data.getData().getPath();
156+
String filePath = data.getData().getPath();
157+
if(requestCode == APP_INSTALL_FILE)
156158
new ADBTask(text,binary).installAppFromFile(device,filePath);
157-
}
159+
else if(requestCode == RESTORE)
160+
new ADBTask(text,binary).restore(device,filePath);
161+
162+
158163
}
159164
super.onActivityResult(requestCode, resultCode, data);
160165
}
@@ -184,8 +189,46 @@ public void onClick(DialogInterface dialog, int which) {
184189

185190
builder.show();
186191
}
192+
public void backup(View view){
193+
AlertDialog.Builder builder = new AlertDialog.Builder(this);
194+
builder.setTitle(R.string.backup);
195+
196+
View layout = getLayoutInflater().inflate(R.layout.backup, null);
197+
builder.setView(layout);
198+
199+
final Switch backupAPK = (Switch)layout.findViewById(R.id.backup_apk);
200+
final Switch backupUserApps = (Switch)layout.findViewById(R.id.backup_user_apps);
201+
final Switch backupSystemApps = (Switch)layout.findViewById(R.id.backup_system_apps);
202+
final Switch backupData = (Switch)layout.findViewById(R.id.backup_data);
203+
final Switch backupCache = (Switch)layout.findViewById(R.id.backup_cache);
204+
205+
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
206+
@Override
207+
public void onClick(DialogInterface dialog, int which) {
208+
new ADBTask(text,binary).backup(device,
209+
backupAPK.isChecked(),
210+
backupUserApps.isChecked(),
211+
backupSystemApps.isChecked(),
212+
backupData.isChecked(),
213+
backupCache.isChecked());
214+
}
215+
});
216+
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
217+
@Override
218+
public void onClick(DialogInterface dialog, int which) {
219+
dialog.cancel();
220+
}
221+
});
222+
223+
builder.show();
224+
}
225+
public void restore(View view){
226+
Intent intent = new Intent(this, FileManagerActivity.class);
227+
startActivityForResult(intent, RESTORE);
228+
}
229+
187230
public void executeCommand(View view){
188231
EditText command = (EditText)findViewById(R.id.command);
189-
new ADBTask(text,binary).execute(device, command.getText().toString());
232+
new ADBTask(text,binary).shell(device, command.getText().toString());
190233
}
191234
}

app/src/main/java/ru/nikita/adb/ADBTask.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import ru.nikita.adb.Task;
44
import ru.nikita.adb.Device;
5+
import java.io.File;
56
import java.lang.String;
7+
import java.util.Calendar;
8+
import java.text.SimpleDateFormat;
69
import android.widget.TextView;
710

811
class ADBTask extends Task{
@@ -18,6 +21,27 @@ public void reboot(Device device, String arg){
1821
public void installAppFromFile(final Device device, String fileName){
1922
execute(device,"install '"+fileName+"'");
2023
}
24+
public void backup(final Device device, boolean apk, boolean userApps,
25+
boolean systemApps, boolean data, boolean cache) {
26+
new File("/sdcard/ADB").mkdir();
27+
String args = new String();
28+
if(apk)
29+
args += "-apk ";
30+
if(data)
31+
args += "-shsred ";
32+
if(cache)
33+
args += "-obb ";
34+
if(userApps)
35+
args += "-all ";
36+
if(!systemApps)
37+
args += "-nosystem ";
38+
String fileName = "/sdcard/ADB/backup_"+new SimpleDateFormat("ddMMyy_hhmmss").format(Calendar.getInstance().getTime())+".ab";
39+
40+
execute(device,"backup -f '"+fileName+"' "+args);
41+
}
42+
public void restore(final Device device, String fileName){
43+
execute(device,"restore '"+fileName+"'");
44+
}
2145
public void connectDevice(String ip, String port){
2246
execute(String.format("connect %s:%s", ip, port));
2347
}

app/src/main/res/layout/adb_activity.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@
127127
android:layout_height="wrap_content"
128128
android:onClick="appManager"
129129
android:text="@string/app_manager" />
130+
<LinearLayout
131+
android:layout_width="match_parent"
132+
android:layout_height="wrap_content">
133+
<Button
134+
android:layout_width="wrap_content"
135+
android:layout_height="match_parent"
136+
android:onClick="backup"
137+
android:layout_weight="1"
138+
android:text="@string/backup" />
139+
<Button
140+
android:layout_width="wrap_content"
141+
android:layout_height="match_parent"
142+
android:onClick="restore"
143+
android:layout_weight="1"
144+
android:text="@string/restore" />
145+
</LinearLayout>
130146
<TextView
131147
android:layout_width="match_parent"
132148
android:layout_height="wrap_content"

app/src/main/res/layout/backup.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="fill_parent"
4+
android:layout_height="fill_parent"
5+
android:orientation="vertical"
6+
android:padding="20dp"
7+
xmlns:android="http://schemas.android.com/apk/res/android">
8+
<Switch
9+
android:id="@+id/backup_apk"
10+
android:checked="true"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:text="@string/backup_apk" />
14+
<Switch
15+
android:id="@+id/backup_user_apps"
16+
android:checked="true"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
android:text="@string/backup_user_apps" />
20+
<Switch
21+
android:id="@+id/backup_system_apps"
22+
android:checked="true"
23+
android:layout_width="match_parent"
24+
android:layout_height="wrap_content"
25+
android:text="@string/backup_system_apps" />
26+
<Switch
27+
android:id="@+id/backup_data"
28+
android:checked="true"
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
android:text="@string/backup_data" />
32+
<Switch
33+
android:id="@+id/backup_cache"
34+
android:layout_width="match_parent"
35+
android:layout_height="wrap_content"
36+
android:text="@string/backup_cache" />
37+
</LinearLayout>

app/src/main/res/values-ru/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
<string name="file_pull">Копировать в /sdcard/ADB/</string>
2929
<string name="file_choose">Выбор файла</string>
3030
<string name="file_delete_confirm">Удалить?</string>
31+
<string name="backup">Резервирование</string>
32+
<string name="backup_apk">Резервировать .apk</string>
33+
<string name="backup_user_apps">Пользовательские приложения</string>
34+
<string name="backup_system_apps">Системные приложения</string>
35+
<string name="backup_data">Данные приложений</string>
36+
<string name="backup_cache">Кэш приложений</string>
37+
<string name="restore">Восстановление</string>
3138
<string name="reboot">Перезагрузить</string>
3239
<string name="reboot_system">Система</string>
3340
<string name="reboot_recovery">Режим восстановления</string>

app/src/main/res/values/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
<string name="file_pull">Copy to /sdcard/ADB/</string>
2929
<string name="file_choose">Choose file</string>
3030
<string name="file_delete_confirm">Delete?</string>
31+
<string name="backup">Backup</string>
32+
<string name="backup_apk">Backup .apk</string>
33+
<string name="backup_user_apps">Backup user apps</string>
34+
<string name="backup_system_apps">Backup system apps</string>
35+
<string name="backup_data">Backup app data</string>
36+
<string name="backup_cache">Backup app cache</string>
37+
<string name="restore">Restore</string>
3138
<string name="reboot">Reboot</string>
3239
<string name="reboot_system">System</string>
3340
<string name="reboot_recovery">Recovery</string>

0 commit comments

Comments
 (0)