Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_frameworks_base-old
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Farzin Kazemzadeh
platform_frameworks_base-old
Commits
9e8fef20
Commit
9e8fef20
authored
4 years ago
by
Ruslan Tkhakokhov
Committed by
Android (Google) Code Review
4 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Refactor XML config parsing" into sc-dev
parents
bbb6854f
343f1269
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/java/android/app/backup/FullBackup.java
+44
-11
44 additions, 11 deletions
core/java/android/app/backup/FullBackup.java
with
44 additions
and
11 deletions
core/java/android/app/backup/FullBackup.java
+
44
−
11
View file @
9e8fef20
...
...
@@ -41,6 +41,7 @@ import java.io.FileInputStream;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.Set
;
/**
...
...
@@ -460,24 +461,40 @@ public class FullBackup {
Set
<
PathWithRequiredFlags
>
excludes
,
Map
<
String
,
Set
<
PathWithRequiredFlags
>>
includes
)
throws
IOException
,
XmlPullParserException
{
verifyTopLevelTag
(
parser
,
"full-backup-content"
);
parseRules
(
parser
,
excludes
,
includes
,
Optional
.
empty
());
logParsingResults
(
excludes
,
includes
);
}
private
void
verifyTopLevelTag
(
XmlPullParser
parser
,
String
tag
)
throws
XmlPullParserException
,
IOException
{
int
event
=
parser
.
getEventType
();
// START_DOCUMENT
while
(
event
!=
XmlPullParser
.
START_TAG
)
{
event
=
parser
.
next
();
}
if
(!
"full-backup-content"
.
equals
(
parser
.
getName
()))
{
if
(!
tag
.
equals
(
parser
.
getName
()))
{
throw
new
XmlPullParserException
(
"Xml file didn't start with correct tag"
+
" (
<full-backup-content>
). Found \""
+
parser
.
getName
()
+
"\""
);
" (
"
+
tag
+
"
). Found \""
+
parser
.
getName
()
+
"\""
);
}
if
(
Log
.
isLoggable
(
TAG_XML_PARSER
,
Log
.
VERBOSE
))
{
Log
.
v
(
TAG_XML_PARSER
,
"\n"
);
Log
.
v
(
TAG_XML_PARSER
,
"===================================================="
);
Log
.
v
(
TAG_XML_PARSER
,
"Found valid
fullBackupContent
; parsing xml resource."
);
Log
.
v
(
TAG_XML_PARSER
,
"Found valid
"
+
tag
+
"
; parsing xml resource."
);
Log
.
v
(
TAG_XML_PARSER
,
"===================================================="
);
Log
.
v
(
TAG_XML_PARSER
,
""
);
}
}
private
void
parseRules
(
XmlPullParser
parser
,
Set
<
PathWithRequiredFlags
>
excludes
,
Map
<
String
,
Set
<
PathWithRequiredFlags
>>
includes
,
Optional
<
Integer
>
maybeRequiredFlags
)
throws
IOException
,
XmlPullParserException
{
int
event
;
while
((
event
=
parser
.
next
())
!=
XmlPullParser
.
END_DOCUMENT
)
{
switch
(
event
)
{
case
XmlPullParser
.
START_TAG
:
...
...
@@ -498,13 +515,7 @@ public class FullBackup {
break
;
}
int
requiredFlags
=
0
;
// no transport flags are required by default
if
(
TAG_INCLUDE
.
equals
(
parser
.
getName
()))
{
// requiredFlags are only supported for <include /> tag, for <exclude />
// we should always leave them as the default = 0
requiredFlags
=
getRequiredFlagsFromString
(
parser
.
getAttributeValue
(
null
,
"requireFlags"
));
}
int
requiredFlags
=
getRequiredFlagsForRule
(
parser
,
maybeRequiredFlags
);
// retrieve the include/exclude set we'll be adding this rule to
Set
<
PathWithRequiredFlags
>
activeSet
=
parseCurrentTagForDomain
(
...
...
@@ -542,7 +553,7 @@ public class FullBackup {
// Special case for sharedpref files (not dirs) also add ".xml" suffix file.
if
(
"sharedpref"
.
equals
(
domainFromXml
)
&&
!
canonicalFile
.
isDirectory
()
&&
!
canonicalFile
.
getCanonicalPath
().
endsWith
(
".xml"
))
{
!
canonicalFile
.
getCanonicalPath
().
endsWith
(
".xml"
))
{
final
String
canonicalXmlPath
=
canonicalFile
.
getCanonicalPath
()
+
".xml"
;
activeSet
.
add
(
new
PathWithRequiredFlags
(
canonicalXmlPath
,
...
...
@@ -554,6 +565,10 @@ public class FullBackup {
}
}
}
}
private
void
logParsingResults
(
Set
<
PathWithRequiredFlags
>
excludes
,
Map
<
String
,
Set
<
PathWithRequiredFlags
>>
includes
)
{
if
(
Log
.
isLoggable
(
TAG_XML_PARSER
,
Log
.
VERBOSE
))
{
Log
.
v
(
TAG_XML_PARSER
,
"\n"
);
Log
.
v
(
TAG_XML_PARSER
,
"Xml resource parsing complete."
);
...
...
@@ -613,6 +628,24 @@ public class FullBackup {
return
flags
;
}
private
int
getRequiredFlagsForRule
(
XmlPullParser
parser
,
Optional
<
Integer
>
maybeRequiredFlags
)
{
if
(
maybeRequiredFlags
.
isPresent
())
{
// This is the new config format where required flags are specified for the whole
// section, not per rule.
return
maybeRequiredFlags
.
get
();
}
if
(
TAG_INCLUDE
.
equals
(
parser
.
getName
()))
{
// In the legacy config, requiredFlags are only supported for <include /> tag,
// for <exclude /> we should always leave them as the default = 0.
return
getRequiredFlagsFromString
(
parser
.
getAttributeValue
(
null
,
"requireFlags"
));
}
return
0
;
}
private
Set
<
PathWithRequiredFlags
>
parseCurrentTagForDomain
(
XmlPullParser
parser
,
Set
<
PathWithRequiredFlags
>
excludes
,
Map
<
String
,
Set
<
PathWithRequiredFlags
>>
includes
,
String
domain
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment