Project

General

Profile

RestoreApplicationInternalData » History » Version 4

Denis 'GNUtoo' Carikli, 10/28/2020 11:36 PM

1 1 Denis 'GNUtoo' Carikli
h1. RestoreApplicationInternalData
2
3
{{toc}}
4
5
h2. /!\ Warning: Draft
6
7
This article is in draft form and is being written:
8
* Everybody is welcome to contribute
9
* Some things might not be accurate yet, so beware before using the information contained in it.
10 2 Denis 'GNUtoo' Carikli
11
h2. Introduction
12
13
In some case, it is useful to be able to restore internal applications data:
14
* You may want to move the data of an application from a device to another
15
* 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.
16 3 Denis 'GNUtoo' Carikli
17
h2. Howto
18
19
TODO:
20
* Explain how to mount a full backup, and why not to restore full backup completely
21
* Explain how and why create a tarball of the application data
22
23
<pre>
24
$ adb shell "mount /dev/block/platform/dw_mmc/by-name/USERDATA /data"
25
</pre>
26
27
<pre>
28
$ adb shell
29
</pre>
30
31
<pre>
32
root@m0:/ # cd /data/data/                                                     
33
root@m0:/data/data # 
34
</pre>
35
36
<pre>
37
root@m0:/data/data # ls -lad org.smssecure.smssecure
38
__bionic_open_tzdata: couldn't find any tzdata when looking for localtime!
39
__bionic_open_tzdata: couldn't find any tzdata when looking for GMT!
40
__bionic_open_tzdata: couldn't find any tzdata when looking for posixrules!
41
drwxr-x--x 2 u0_a61 u0_a61 4096 2012-01-01 00:01 org.smssecure.smssecure
42
</pre>
43
44
Here the users and groups are @u0_a61@.
45
46
<pre>
47
root@m0:/data/data # mv org.smssecure.smssecure org.smssecure.smssecure.delme
48
</pre>
49
50
<pre>
51
root@m0:/data/data # tar tf /org.smssecure.smssecure.tar
52
./org.smssecure.smssecure/
53
./org.smssecure.smssecure/lib -> /data/app/org.smssecure.smssecure-1/lib/arm
54
[...]
55
</pre>
56
57
<pre>
58
root@m0:/data/data # tar xpf /org.smssecure.smssecure.tar --numeric-owner
59
</pre>
60
61
<pre>
62
root@m0:/data/data # ls -ld org.smssecure.smssecure 
63
__bionic_open_tzdata: couldn't find any tzdata when looking for localtime!
64
__bionic_open_tzdata: couldn't find any tzdata when looking for GMT!
65
__bionic_open_tzdata: couldn't find any tzdata when looking for posixrules!
66
drwxr-x--x 9 u0_a63 u0_a63 4096 2012-01-01 00:21 org.smssecure.smssecure
67
</pre>
68
69
<pre>
70
root@m0:/data/data # chown u0_a61:u0_a61 -R org.smssecure.smssecure            
71
root@m0:/data/data # 
72
</pre>
73
74
<pre>
75
root@m0:/data/data # rm -rf org.smssecure.smssecure.delme
76
root@m0:/data/data # 
77
</pre>
78
79
<pre>
80
root@m0:/data/data # restorecon                                                
81
usage: restorecon [-D] [-F] [-R] [-n] [-v] FILE...
82
83
Restores the default security contexts for the given files.
84
85
-D	apply to /data/data too
86
-F	force reset
87
-R	recurse into directories
88
-n	don't make any changes; useful with -v to see what would change
89
-v	verbose: show any changes
90
91
restorecon: Needs 1 argument
92
</pre>
93
94
<pre>
95
root@m0:/data/data # restorecon -D -F -R -v /data/                           
96
SELinux: Loaded file_contexts contexts from /file_contexts.
97
[...]
98
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.
99
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.
100
[...]
101
</pre>
102
103
<pre>
104
root@m0:/data/data # cd 
105
root@m0:/ # umount  /data/                                                     
106
root@m0:/ # 
107
</pre>
108
109
<pre>
110
root@m0:/ # sync
111
root@m0:/ # reboot
112
</pre>
113 4 Denis 'GNUtoo' Carikli
114
<pre>
115
01-01 01:27:48.260  4126  4126 D AndroidRuntime: Shutting down VM
116
01-01 01:27:48.265  4126  4126 E AndroidRuntime: FATAL EXCEPTION: main
117
01-01 01:27:48.265  4126  4126 E AndroidRuntime: Process: org.smssecure.smssecure, PID: 4126
118
01-01 01:27:48.265  4126  4126 E AndroidRuntime: Theme: themes:{}
119
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.
120
01-01 01:27:48.265  4126  4126 E AndroidRuntime: 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4754)
121
[...]
122
</pre>
123
124
Settings->Apps->Silence->Permissions