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
1f66b736
Commit
1f66b736
authored
1 year ago
by
Zhi Dou
Committed by
Android (Google) Code Review
1 year ago
Browse files
Options
Downloads
Plain Diff
Merge "Add test for setSettingsLocked" into main
parents
c705fc05
0ef8cec9
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
packages/SettingsProvider/test/src/com/android/providers/settings/SettingsStateTest.java
+118
-0
118 additions, 0 deletions
...src/com/android/providers/settings/SettingsStateTest.java
with
118 additions
and
0 deletions
packages/SettingsProvider/test/src/com/android/providers/settings/SettingsStateTest.java
+
118
−
0
View file @
1f66b736
...
...
@@ -31,6 +31,7 @@ import java.io.File;
import
java.io.FileOutputStream
;
import
java.io.PrintStream
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
SettingsStateTest
extends
AndroidTestCase
{
...
...
@@ -626,4 +627,121 @@ public class SettingsStateTest extends AndroidTestCase {
assertEquals
(
VALUE2
,
settingsState
.
getSettingLocked
(
INVALID_STAGED_FLAG_1
).
getValue
());
}
}
public
void
testsetSettingsLockedKeepTrunkDefault
()
throws
Exception
{
final
PrintStream
os
=
new
PrintStream
(
new
FileOutputStream
(
mSettingsFile
));
os
.
print
(
"<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>"
+
"<settings version=\"120\">"
+
" <setting id=\"0\" name=\"test_namespace/flag0\" "
+
"value=\"false\" package=\"com.android.flags\" />"
+
" <setting id=\"1\" name=\"test_namespace/flag1\" "
+
"value=\"false\" package=\"com.android.flags\" />"
+
" <setting id=\"2\" name=\"test_namespace/com.android.flags.flag3\" "
+
"value=\"false\" package=\"com.android.flags\" />"
+
" <setting id=\"3\" "
+
"name=\"test_another_namespace/com.android.another.flags.flag0\" "
+
"value=\"false\" package=\"com.android.another.flags\" />"
+
"</settings>"
);
os
.
close
();
int
configKey
=
SettingsState
.
makeKey
(
SettingsState
.
SETTINGS_TYPE_CONFIG
,
0
);
SettingsState
settingsState
=
new
SettingsState
(
getContext
(),
mLock
,
mSettingsFile
,
configKey
,
SettingsState
.
MAX_BYTES_PER_APP_PACKAGE_UNLIMITED
,
Looper
.
getMainLooper
());
String
prefix
=
"test_namespace"
;
Map
<
String
,
String
>
keyValues
=
Map
.
of
(
"test_namespace/flag0"
,
"true"
,
"test_namespace/flag2"
,
"false"
);
String
packageName
=
"com.android.flags"
;
parsed_flags
flags
=
parsed_flags
.
newBuilder
()
.
addParsedFlag
(
parsed_flag
.
newBuilder
()
.
setPackage
(
packageName
)
.
setName
(
"flag3"
)
.
setNamespace
(
prefix
)
.
setDescription
(
"test flag"
)
.
addBug
(
"12345678"
)
.
setState
(
Aconfig
.
flag_state
.
DISABLED
)
.
setPermission
(
Aconfig
.
flag_permission
.
READ_WRITE
))
.
addParsedFlag
(
parsed_flag
.
newBuilder
()
.
setPackage
(
"com.android.another.flags"
)
.
setName
(
"flag0"
)
.
setNamespace
(
"test_another_namespace"
)
.
setDescription
(
"test flag"
)
.
addBug
(
"12345678"
)
.
setState
(
Aconfig
.
flag_state
.
DISABLED
)
.
setPermission
(
Aconfig
.
flag_permission
.
READ_WRITE
))
.
build
();
synchronized
(
mLock
)
{
settingsState
.
loadAconfigDefaultValues
(
flags
.
toByteArray
(),
settingsState
.
getAconfigDefaultValues
());
List
<
String
>
updates
=
settingsState
.
setSettingsLocked
(
"test_namespace/"
,
keyValues
,
packageName
);
assertEquals
(
3
,
updates
.
size
());
SettingsState
.
Setting
s
;
s
=
settingsState
.
getSettingLocked
(
"test_namespace/flag0"
);
assertEquals
(
"true"
,
s
.
getValue
());
s
=
settingsState
.
getSettingLocked
(
"test_namespace/flag1"
);
assertNull
(
s
.
getValue
());
s
=
settingsState
.
getSettingLocked
(
"test_namespace/flag2"
);
assertEquals
(
"false"
,
s
.
getValue
());
s
=
settingsState
.
getSettingLocked
(
"test_namespace/com.android.flags.flag3"
);
assertEquals
(
"false"
,
s
.
getValue
());
s
=
settingsState
.
getSettingLocked
(
"test_another_namespace/com.android.another.flags.flag0"
);
assertEquals
(
"false"
,
s
.
getValue
());
}
}
public
void
testsetSettingsLockedNoTrunkDefault
()
throws
Exception
{
final
PrintStream
os
=
new
PrintStream
(
new
FileOutputStream
(
mSettingsFile
));
os
.
print
(
"<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>"
+
"<settings version=\"120\">"
+
" <setting id=\"0\" name=\"test_namespace/flag0\" "
+
"value=\"false\" package=\"com.android.flags\" />"
+
" <setting id=\"1\" name=\"test_namespace/flag1\" "
+
"value=\"false\" package=\"com.android.flags\" />"
+
"</settings>"
);
os
.
close
();
int
configKey
=
SettingsState
.
makeKey
(
SettingsState
.
SETTINGS_TYPE_CONFIG
,
0
);
SettingsState
settingsState
=
new
SettingsState
(
getContext
(),
mLock
,
mSettingsFile
,
configKey
,
SettingsState
.
MAX_BYTES_PER_APP_PACKAGE_UNLIMITED
,
Looper
.
getMainLooper
());
Map
<
String
,
String
>
keyValues
=
Map
.
of
(
"test_namespace/flag0"
,
"true"
,
"test_namespace/flag2"
,
"false"
);
String
packageName
=
"com.android.flags"
;
synchronized
(
mLock
)
{
List
<
String
>
updates
=
settingsState
.
setSettingsLocked
(
"test_namespace/"
,
keyValues
,
packageName
);
assertEquals
(
3
,
updates
.
size
());
SettingsState
.
Setting
s
;
s
=
settingsState
.
getSettingLocked
(
"test_namespace/flag0"
);
assertEquals
(
"true"
,
s
.
getValue
());
s
=
settingsState
.
getSettingLocked
(
"test_namespace/flag1"
);
assertNull
(
s
.
getValue
());
s
=
settingsState
.
getSettingLocked
(
"test_namespace/flag2"
);
assertEquals
(
"false"
,
s
.
getValue
());
}
}
}
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