Project

General

Profile

Actions

RestoreApplicationInternalData » History » Revision 4

« Previous | Revision 4/49 (diff) | Next »
Denis 'GNUtoo' Carikli, 10/28/2020 11:36 PM


RestoreApplicationInternalData

/!\ Warning: Draft

This article is in draft form and is being written:
  • Everybody is welcome to contribute
  • Some things might not be accurate yet, so beware before using the information contained in it.

Introduction

In some case, it is useful to be able to restore internal applications data:
  • You may want to move the data of an application from a device to another
  • If some files like /data/system/packages.xml or /data/system/appops.xml get corrupted, applications can loose access to their data. This can make the launcher and other applications crash.

Howto

TODO:
  • Explain how to mount a full backup, and why not to restore full backup completely
  • Explain how and why create a tarball of the application data
$ adb shell "mount /dev/block/platform/dw_mmc/by-name/USERDATA /data" 
$ adb shell
root@m0:/ # cd /data/data/                                                     
root@m0:/data/data # 
root@m0:/data/data # ls -lad org.smssecure.smssecure
__bionic_open_tzdata: couldn't find any tzdata when looking for localtime!
__bionic_open_tzdata: couldn't find any tzdata when looking for GMT!
__bionic_open_tzdata: couldn't find any tzdata when looking for posixrules!
drwxr-x--x 2 u0_a61 u0_a61 4096 2012-01-01 00:01 org.smssecure.smssecure

Here the users and groups are u0_a61.

root@m0:/data/data # mv org.smssecure.smssecure org.smssecure.smssecure.delme
root@m0:/data/data # tar tf /org.smssecure.smssecure.tar
./org.smssecure.smssecure/
./org.smssecure.smssecure/lib -> /data/app/org.smssecure.smssecure-1/lib/arm
[...]
root@m0:/data/data # tar xpf /org.smssecure.smssecure.tar --numeric-owner
root@m0:/data/data # ls -ld org.smssecure.smssecure 
__bionic_open_tzdata: couldn't find any tzdata when looking for localtime!
__bionic_open_tzdata: couldn't find any tzdata when looking for GMT!
__bionic_open_tzdata: couldn't find any tzdata when looking for posixrules!
drwxr-x--x 9 u0_a63 u0_a63 4096 2012-01-01 00:21 org.smssecure.smssecure
root@m0:/data/data # chown u0_a61:u0_a61 -R org.smssecure.smssecure            
root@m0:/data/data # 
root@m0:/data/data # rm -rf org.smssecure.smssecure.delme
root@m0:/data/data # 
root@m0:/data/data # restorecon                                                
usage: restorecon [-D] [-F] [-R] [-n] [-v] FILE...

Restores the default security contexts for the given files.

-D    apply to /data/data too
-F    force reset
-R    recurse into directories
-n    don't make any changes; useful with -v to see what would change
-v    verbose: show any changes

restorecon: Needs 1 argument
root@m0:/data/data # restorecon -D -F -R -v /data/                           
SELinux: Loaded file_contexts contexts from /file_contexts.
[...]
SELinux:  Relabeling /data/data/org.smssecure.smssecure from u:object_r:system_data_file:s0 to u:object_r:app_data_file:s0:c512,c768.
SELinux:  Relabeling /data/data/org.smssecure.smssecure/lib from u:object_r:system_data_file:s0 to u:object_r:app_data_file:s0:c512,c768.
[...]
root@m0:/data/data # cd 
root@m0:/ # umount  /data/                                                     
root@m0:/ # 
root@m0:/ # sync
root@m0:/ # reboot
01-01 01:27:48.260  4126  4126 D AndroidRuntime: Shutting down VM
01-01 01:27:48.265  4126  4126 E AndroidRuntime: FATAL EXCEPTION: main
01-01 01:27:48.265  4126  4126 E AndroidRuntime: Process: org.smssecure.smssecure, PID: 4126
01-01 01:27:48.265  4126  4126 E AndroidRuntime: Theme: themes:{}
01-01 01:27:48.265  4126  4126 E AndroidRuntime: java.lang.RuntimeException: Unable to create application org.smssecure.smssecure.ApplicationContext: java.lang.SecurityException: getActiveSubscriptionInfoList: Neither user 10061 nor current process has android.permission.READ_PHONE_STATE.
01-01 01:27:48.265  4126  4126 E AndroidRuntime:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4754)
[...]

Settings->Apps->Silence->Permissions

Updated by Denis 'GNUtoo' Carikli over 3 years ago · 4 revisions

Also available in: PDF HTML TXT