Skip to content

Commit

Permalink
Add backup support
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-yfh committed Mar 25, 2022
1 parent b2fb3f5 commit ff1abc1
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "ru.nikita.adb"
minSdkVersion 12
targetSdkVersion 20
versionCode 3
versionName "1.3"
versionCode 4
versionName "1.4"
}
buildTypes {
release {
Expand Down
51 changes: 47 additions & 4 deletions app/src/main/java/ru/nikita/adb/ADBActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.widget.EditText;
import android.widget.Switch;
import android.text.InputType;
import android.content.DialogInterface;
import android.content.Intent;
Expand All @@ -24,6 +25,7 @@

public class ADBActivity extends DevicesActivity {
private static final int APP_INSTALL_FILE=1;
private static final int RESTORE=2;
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.adb_activity);
Expand Down Expand Up @@ -151,10 +153,13 @@ public void appManager(View view){
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == Activity.RESULT_OK && data != null){
if(requestCode == APP_INSTALL_FILE){
String filePath = data.getData().getPath();
String filePath = data.getData().getPath();
if(requestCode == APP_INSTALL_FILE)
new ADBTask(text,binary).installAppFromFile(device,filePath);
}
else if(requestCode == RESTORE)
new ADBTask(text,binary).restore(device,filePath);


}
super.onActivityResult(requestCode, resultCode, data);
}
Expand Down Expand Up @@ -184,8 +189,46 @@ public void onClick(DialogInterface dialog, int which) {

builder.show();
}
public void backup(View view){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.backup);

View layout = getLayoutInflater().inflate(R.layout.backup, null);
builder.setView(layout);

final Switch backupAPK = (Switch)layout.findViewById(R.id.backup_apk);
final Switch backupUserApps = (Switch)layout.findViewById(R.id.backup_user_apps);
final Switch backupSystemApps = (Switch)layout.findViewById(R.id.backup_system_apps);
final Switch backupData = (Switch)layout.findViewById(R.id.backup_data);
final Switch backupCache = (Switch)layout.findViewById(R.id.backup_cache);

builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new ADBTask(text,binary).backup(device,
backupAPK.isChecked(),
backupUserApps.isChecked(),
backupSystemApps.isChecked(),
backupData.isChecked(),
backupCache.isChecked());
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});

builder.show();
}
public void restore(View view){
Intent intent = new Intent(this, FileManagerActivity.class);
startActivityForResult(intent, RESTORE);
}

public void executeCommand(View view){
EditText command = (EditText)findViewById(R.id.command);
new ADBTask(text,binary).execute(device, command.getText().toString());
new ADBTask(text,binary).shell(device, command.getText().toString());
}
}
24 changes: 24 additions & 0 deletions app/src/main/java/ru/nikita/adb/ADBTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import ru.nikita.adb.Task;
import ru.nikita.adb.Device;
import java.io.File;
import java.lang.String;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import android.widget.TextView;

class ADBTask extends Task{
Expand All @@ -18,6 +21,27 @@ public void reboot(Device device, String arg){
public void installAppFromFile(final Device device, String fileName){
execute(device,"install '"+fileName+"'");
}
public void backup(final Device device, boolean apk, boolean userApps,
boolean systemApps, boolean data, boolean cache) {
new File("/sdcard/ADB").mkdir();
String args = new String();
if(apk)
args += "-apk ";
if(data)
args += "-shsred ";
if(cache)
args += "-obb ";
if(userApps)
args += "-all ";
if(!systemApps)
args += "-nosystem ";
String fileName = "/sdcard/ADB/backup_"+new SimpleDateFormat("ddMMyy_hhmmss").format(Calendar.getInstance().getTime())+".ab";

execute(device,"backup -f '"+fileName+"' "+args);
}
public void restore(final Device device, String fileName){
execute(device,"restore '"+fileName+"'");
}
public void connectDevice(String ip, String port){
execute(String.format("connect %s:%s", ip, port));
}
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/layout/adb_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@
android:layout_height="wrap_content"
android:onClick="appManager"
android:text="@string/app_manager" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:onClick="backup"
android:layout_weight="1"
android:text="@string/backup" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:onClick="restore"
android:layout_weight="1"
android:text="@string/restore" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/res/layout/backup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="20dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<Switch
android:id="@+id/backup_apk"
android:checked="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/backup_apk" />
<Switch
android:id="@+id/backup_user_apps"
android:checked="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/backup_user_apps" />
<Switch
android:id="@+id/backup_system_apps"
android:checked="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/backup_system_apps" />
<Switch
android:id="@+id/backup_data"
android:checked="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/backup_data" />
<Switch
android:id="@+id/backup_cache"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/backup_cache" />
</LinearLayout>
7 changes: 7 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
<string name="file_pull">Копировать в /sdcard/ADB/</string>
<string name="file_choose">Выбор файла</string>
<string name="file_delete_confirm">Удалить?</string>
<string name="backup">Резервирование</string>
<string name="backup_apk">Резервировать .apk</string>
<string name="backup_user_apps">Пользовательские приложения</string>
<string name="backup_system_apps">Системные приложения</string>
<string name="backup_data">Данные приложений</string>
<string name="backup_cache">Кэш приложений</string>
<string name="restore">Восстановление</string>
<string name="reboot">Перезагрузить</string>
<string name="reboot_system">Система</string>
<string name="reboot_recovery">Режим восстановления</string>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
<string name="file_pull">Copy to /sdcard/ADB/</string>
<string name="file_choose">Choose file</string>
<string name="file_delete_confirm">Delete?</string>
<string name="backup">Backup</string>
<string name="backup_apk">Backup .apk</string>
<string name="backup_user_apps">Backup user apps</string>
<string name="backup_system_apps">Backup system apps</string>
<string name="backup_data">Backup app data</string>
<string name="backup_cache">Backup app cache</string>
<string name="restore">Restore</string>
<string name="reboot">Reboot</string>
<string name="reboot_system">System</string>
<string name="reboot_recovery">Recovery</string>
Expand Down

0 comments on commit ff1abc1

Please sign in to comment.